 
 
 void setup() {
-  Serial.begin(115200);
-  pinMode(BUTTON, INPUT);
-  pinMode(RELAY, OUTPUT);
-  pinMode(LED, OUTPUT);
-  pinMode(SPARE, INPUT);
-
-  EEPROM.begin(512);
-
-  digitalWrite(LED, LOW);
-  delay(3000);
-  digitalWrite(LED, HIGH);
-
-    for (int addr = 0; addr < sizeof(eepromArray); addr++){
-          char tmpChar = (char)EEPROM.read(addr);
-          ((char*)eepromArray)[addr] = tmpChar;
-    }
-
-      sensorName = eepromArray[0];
-      String wifiName   = eepromArray[1];
-      String wifiPwd    = eepromArray[2];
-      String mqttIp     = eepromArray[3];
-      String mqttPort   = eepromArray[4];
-
-  //If button pressed at boot
-
-  if(digitalRead(BUTTON) == 0){
-        Serial.println("a bitch");
-      bootMode = BOOT_MODE_CONFIG;
-      Serial.println("starting config server");
-
-      WiFi.mode(WIFI_AP);
-      WiFi.softAPConfig(apIP, apIP, IPAddress(255, 255, 255, 0));
-      int result = WiFi.softAP("ESP_CONFIG");
-      if(result == true)
-      {
-        Serial.println("Config server ready");
-      }
-      else
-      {
-        Serial.println("Config server failed to start!");
-      }
-          
-    
-      server.on("/", handleRoot);
-      server.begin();
-
-  }
-  else{
-      Serial.println("Starting with config :");
-      Serial.print("\tObject Name :");
-      Serial.println(sensorName);
-      Serial.print("\tWifi Access point :");
-      Serial.println(wifiName);
-      Serial.print("\tWifi pwd :");
-      Serial.println(wifiPwd);
-      Serial.print("\tMQTT address :");
-      Serial.println(mqttIp.c_str());
-      Serial.print("\tMQTT port :");
-      Serial.println(mqttPort);
-
-      if(mqttPort != ""){
-          bootMode = BOOT_MODE_MQTT;
+    Serial.begin(115200);
+    pinMode(BUTTON, INPUT);
+    pinMode(RELAY, OUTPUT);
+    pinMode(LED, OUTPUT);
+    pinMode(SPARE, INPUT);
+
+    digitalWrite(LED, LOW);
+    delay(3000);
+    digitalWrite(LED, HIGH);
+
+    myConfigServer = new ConfigServer(configServerIP);
+
+    //If button pressed at boot
+    if(digitalRead(BUTTON) == 0){
+        Serial.println("Entering config boot mode");
+        bootMode = BOOT_MODE_CONFIG;
+        myConfigServer->start();
+    }
+    else{
+        MqttConfig tmpConfig = myConfigServer->getMqttConfig();
+
+        if(tmpConfig.mqttPort != ""){
+            bootMode = BOOT_MODE_MQTT;
+            myMqtt = new MqttConnection(tmpConfig.sensorName.c_str(), tmpConfig.wifiName.c_str(), tmpConfig.wifiPwd.c_str(), tmpConfig.mqttIp.c_str(), tmpConfig.mqttPort.toInt());
+      
+            myMqtt->registerCustomProcessing(&processCommandMsg);
+            myMqtt->addSubscription("command");
+
+            if(myMqtt->connected()){
+                deviceMqttReadyBlink();
+            }
+            else
+            {
+                Serial.println("could not connect to MQTT server");
+            }
+        }
+        else{
+            WiFi.mode(WIFI_STA);
+            WiFi.begin(tmpConfig.wifiName.c_str(), tmpConfig.wifiPwd.c_str());
          
-          strcpy(tmpS, mqttIp.c_str());
-          myMqtt = new MqttConnection(sensorName.c_str(), wifiName.c_str(), wifiPwd.c_str(), tmpS, mqttPort.toInt());
-      
-          myMqtt->registerCustomProcessing(&processCommandMsg);
-          myMqtt->addSubscription("command");
-
-          if(myMqtt->connected()){
-              deviceMqttReadyBlink();
-          }
-          else
-          {
-            Serial.println("could not connect to MQTT server");
-           }
-      }
-      else{
-          WiFi.mode(WIFI_STA);
-          WiFi.begin(wifiName.c_str(), wifiPwd.c_str());
-         
-          while (WiFi.status() != WL_CONNECTED) {
-              delay(500);
-              Serial.print(".");
-           }
-           Serial.println("");
-           Serial.print("Connected to ");
-           Serial.println(wifiName);
-           Serial.print("IP address: ");
-           Serial.println(WiFi.localIP());
+            while (WiFi.status() != WL_CONNECTED) {
+                delay(500);
+                Serial.print(".");
+            }
+            Serial.println("");
+            Serial.print("Connected to ");
+            Serial.println(tmpConfig.wifiName);
+            Serial.print("IP address: ");
+            Serial.println(WiFi.localIP());
 
             server.on("/", handleRootDefault);
             server.begin();
             
-            Serial.print("Connect to http://xxxxxx.local or http://");
             Serial.println(WiFi.localIP());
             Serial.println("last number : ");
             int addressNumber = WiFi.localIP()[3];

            blinkSlow(dec);
            delay(2000);
            blinkSlow(unit);
          


            
      }


"</html>";


void returnOK()
{
  server.sendHeader("Connection", "close");
