 const char WIFIFAIL[] PROGMEM = {'WiFi: failed to connect to the AP'};
 const char WIFICONF[] PROGMEM = {'Current config: '};
 const char WIFIIP[] PROGMEM = {'IP: '};
+const char WIFICONNECTTRY[] PROGMEM = {'Trying to connect to the AP... '};
 
 /* Global constants */
 #define MAX_CONNTRY 5
 #define PWM_FREQ 100
 #define CONFNAME "/wificreds.conf"
 
+#define SLEDS_OFF { digitalWrite(D6, false); digitalWrite(D7, false); digitalWrite(D8, false); }
+#define CAPTIVE_ON { digitalWrite(D6, false); digitalWrite(D7, false); digitalWrite(D8, true); }
+#define BOOT_ON { digitalWrite(D6, true); digitalWrite(D7, true); digitalWrite(D8, false); }
+#define ERROR_ON { digitalWrite(D6, true); digitalWrite(D7, false); digitalWrite(D8, false); }
+#define OK_ON { digitalWrite(D6, false); digitalWrite(D7, true); digitalWrite(D8, false); }
+
+#define DEBUG 1
+
 /* Global variables */
 ESP8266WebServer myServer(8080);
+WiFiManager wfMan;
+
 String stassid = "";
 String stapass = "";
+String mqtt_channel = "";
+String mqtt_user = "";
+String mqtt_pass = "";
+
+WiFiManagerParameter mqttchannel("mqttchannel", "MQTT Channel",(const char*)mqtt_channel.c_str(), 40);
+WiFiManagerParameter mqttuser("mqttuser", "MQTT User", (const char*)mqtt_user.c_str(), 20);
+WiFiManagerParameter mqttpass("mqttpass", "MQTT Password",(const char*)mqtt_pass.c_str(), 20);
 
 void deleteWifiConfig() {
   cli();


  /* No saved config file => start in AP mode with the config portal */
  if (!hasSavedConfig) {
    // Setup WiFiManager and start the config portal
    WiFiManager wfMan;
    String ssid = "ESP" + String(ESP.getChipId());
    wfMan.setConfigPortalTimeout(180);
    wfMan.setAPCallback(configModeCallback);

          Serial.println(FPSTR(CONFPARSED));
          stassid = String((const char*)json["sta_ssid"]);
          stapass = String((const char*)json["sta_pass"]);
          mqtt_channel = String((const char*)json["mqtt_channel"]);
          mqtt_user = String((const char*)json["mqtt_user"]);
          mqtt_pass = String((const char*)json["mqtt_pass"]);
          
          hasSavedConfig = true;
        } else {
          Serial.println(FPSTR(CONFPARSEFAIL));
