[GH-ISSUE #1358] WiFi connection issue arduino vs platformIO #1162

Open
opened 2026-02-28 01:28:48 +03:00 by kerem · 0 comments
Owner

Originally created by @JC-Electronics-Design on GitHub (Feb 13, 2022).
Original GitHub issue: https://github.com/tzapu/WiFiManager/issues/1358

Basic Info

WiFimanager Branch/Release: 2.0.5-beta (on both Arduino IDE as well as PlatformIO)

Esp8266/Esp32: ESP8266

Hardware: NodeMCU 1.0 (ESP-12E module)

Core Version: 3.0.2 (on both Arduino IDE as well as PlatformIO)

Description

I use PlatformIO for most of my programming, but with this project I'm having some trouble.
The issue I'm having is that when I try to connect to my router via WifiManager by selecting the SSID and entering the correct credentials, is that when I click "Save" and WifiManager tries to connect to the router it fails. When I look at the debug info from PlatformIO I see this line: "*wm:[2] Connection result: WL_NO_SSID_AVAIL". (full debug output below)

As a simple test I thought I'd try the exact same code in the Arduino IDE and see what happens. When I upload the code via Arduino and go through the exact same steps (configure WiFi -> Click correct SSID -> Fill in password -> click save) WifiManager is able to connect to my router no problems. Even MQTT messages are sent without any problems. The debug output from Arduino can also be seen below.

I have been looking into what could be the issue here but can't seem to find the culprit.

I also tried the basic example code in PlatformIO with the same result (WL_NO_SSID_AVAIL).

Can any of you help me with this issue? Thanks in advance!
If any additional info is required please let me know!

Settings in IDE

PlatformIO

#BEGIN
[env:nodemcuv2]
platform = espressif8266
board = nodemcuv2
framework = arduino
upload_speed = 921600
monitor_speed = 115200
lib_deps = 
	paulstoffregen/OneWire@^2.3.6
	milesburton/DallasTemperature@^3.9.1
	256dpi/MQTT@^2.5.0
	bblanchon/ArduinoJson@^6.19.1
	https://github.com/tzapu/WiFiManager.git
#END

Arduino IDE

image

Additional libraries:
#include <FS.h>
#include <ArduinoJson.h>
#include <MQTTClient.h>
#include <HSBColor.h>
#include <OneWire.h>
#include <DallasTemperature.h>

Sketch

#BEGIN
/*
 * PD-01RGB-WIFI1 Software version v1.0
 * JC Design 
 */
#include <FS.h>                   //this needs to be first, or it all crashes and burns...

#include <WiFiManager.h>          //https://github.com/tzapu/WiFiManager
#include <ArduinoJson.h>          //https://github.com/bblanchon/ArduinoJson

#include <MQTTClient.h>
#include <HSBColor.h>
#include <OneWire.h>
#include <DallasTemperature.h>

//Uncomment to enable debug messages via serial port
#define SERIAL_DEBUG

//define your default values here, if there are different values in config.json, they are overwritten.
//length should be max size + 1
char mqtt_server_ip[40] = "10.0.1.10";
char mqtt_port[6] = "1883";
char mqtt_device_id[40] = "PD-01RGB-WIFI1";

char temperature_topic[40];
char time_between_temp_read[5] = "60";
char button_topic[40];
char button_check[2];
char rgb_topic[40];

//default custom static IP
char static_ip[16] = "10.0.1.11";
char static_gw[16] = "10.0.1.1";
char static_sn[16] = "255.255.255.0";

WiFiManager wm; // global wm instance
WiFiClient net;
MQTTClient client;

// Wifi manager variables
#define resetConfigPin 0          //Choose a compatible pin, When low will reset the wifi manager config
bool shouldSaveConfig = true;
#define builtin_led 2

// Touch button variables
#define BUTTON_PIN 5
bool enable_button = true;
char custom_button_html[27];
bool button_state = false;
bool button_config = false;

// Temperature sensor variables
#define temp_offset -3            //Temperature offset value
float temp;                       //Stores temperature value
String s_temp;
char messTemp[10];
OneWire ds(4);                    //DS18b20 on gpio4
DallasTemperature dsTemp(&ds);
bool start = true;
unsigned long Lasttime = 0;

// bool offline = false;
// int counter = 0;
// long last_client_millis = 0;

// #define WIFI_DELAY 2000
// #define CLIENT_DELAY  2000      //time in milliseconds

// LED output variables
struct LedPin {
  byte red;
  byte green;
  byte blue;
};
LedPin ledPin = {13, 12, 14};
int LedValue[3] = {0, 0, 0};

// Wifi handling variables
bool mqtt_connected = false;
unsigned long last_client_connect = -1;        
unsigned long client_connect_delay = 1000;      //delay between checking connection, in milliseconds

/********************************/

//callback notifying us of the need to save config
void saveConfigCallback () {
  #ifdef SERIAL_DEBUG
    Serial.println("Should save config");
  #endif
  shouldSaveConfig = true;
  //save the custom parameters to FS
  if (shouldSaveConfig && button_config) {
    #ifdef SERIAL_DEBUG
      Serial.println("saving config");
    #endif
#ifdef ARDUINOJSON_VERSION_MAJOR >= 6
    DynamicJsonDocument json(1024);
#else
    DynamicJsonBuffer jsonBuffer;
    JsonObject& json = jsonBuffer.createObject();
#endif
    json["ip"] = WiFi.localIP().toString();
    json["gateway"] = WiFi.gatewayIP().toString();
    json["subnet"] = WiFi.subnetMask().toString();

    json["mqtt_server_ip"] = mqtt_server_ip;
    json["mqtt_port"] = mqtt_port;
    json["mqtt_device_id"] = mqtt_device_id;
    json["temperature_topic"] = temperature_topic;
    json["time_between_temp_read"] = time_between_temp_read;
    json["button_check"] = button_check;
    json["button_topic"] = button_topic;
    json["rgb_topic"] = rgb_topic;

    File configFile = SPIFFS.open("/config.json", "w");
    if (!configFile) {
      #ifdef SERIAL_DEBUG
        Serial.println("failed to open config file for writing");
      #endif
    }

#ifdef ARDUINOJSON_VERSION_MAJOR >= 6
    serializeJson(json, Serial);
    serializeJson(json, configFile);
#else
    json.printTo(Serial);
    json.printTo(configFile);
#endif
    configFile.close();
    button_config = false;
    //end save
  }
}

void messageReceived(String &topic, String &payload) {
  String msgTopic = topic;
  String msgString = payload;
  #ifdef SERIAL_DEBUG
    Serial.print(msgTopic);
    Serial.print(": ");
    Serial.println(msgString);
  #endif

  if(msgTopic == rgb_topic) {
    if(msgString == "ON") {
      analogWrite(ledPin.red, 1023);
      analogWrite(ledPin.green, 1023);
      analogWrite(ledPin.blue, 1023);
      #ifdef SERIAL_DEBUG
        Serial.println("1023,1023,1023");
      #endif
    }
    else if(msgString == "OFF") {
      analogWrite(ledPin.red, 0);
      analogWrite(ledPin.green, 0);
      analogWrite(ledPin.blue, 0);
      #ifdef SERIAL_DEBUG
        Serial.println("0,0,0");
      #endif
    }
    else {
      int firstComma = msgString.indexOf(',') + 1;                  //find first comma in string
      int secondComma = msgString.indexOf(',', firstComma + 1);     //find second comma in string
      int thirdComma = msgString.indexOf(',', secondComma + 1);     //find third comma in string
      String hue = msgString.substring(0, (firstComma - 1));
      String saturation = msgString.substring(firstComma, secondComma);
      String brightness = msgString.substring((secondComma+1), thirdComma);

      #ifdef SERIAL_DEBUG
        Serial.print(hue); Serial.print(",");
        Serial.print(saturation); Serial.print(",");
        Serial.println(brightness);
      #endif
    
      H2R_HSBtoRGB(hue.toInt(), saturation.toInt(), brightness.toInt(), LedValue);

      LedValue[0] = (LedValue[0]*4)+3;
      LedValue[1] = (LedValue[1]*4)+3;
      LedValue[2] = (LedValue[2]*4)+3;
      
      if(LedValue[0] < 100)
        LedValue[0] = 0;
      else if(LedValue[0] > 980)
        LedValue[0] = 1023;
      if(LedValue[1] < 100)
        LedValue[1] = 0;
      else if(LedValue[1] > 980)
        LedValue[1] = 1023;
      if(LedValue[2] < 100)
        LedValue[2] = 0;
      else if(LedValue[2] > 980)
        LedValue[2] = 1023;

      #ifdef SERIAL_DEBUG
        Serial.print(LedValue[0]); Serial.print(",");
        Serial.print(LedValue[1]); Serial.print(",");
        Serial.println(LedValue[2]);
      #endif
      
      analogWrite(ledPin.red, LedValue[0]);
      analogWrite(ledPin.green, LedValue[1]);
      analogWrite(ledPin.blue, LedValue[2]);
    }
  }
}

// void wifi_handler() {
//   if(WiFi.status() != WL_CONNECTED || !client.connected()) {
//     #ifdef SERIAL_DEBUG
//       Serial.print("wifi: "); Serial.println(WiFi.status());      //Keep the serial, otherwise it doesn't work (too fast)
//       Serial.print("Counter: ");  Serial.println(counter);
//     #endif
//     if(!offline) {
//       offline = true;
//     }
//     if((counter > WIFI_DELAY || counter == 0) && WiFi.status() != WL_CONNECTED) {
//       connect();
//       counter = 1;
//     }
//     counter++;
//   }
//   if(offline && WiFi.status() == WL_CONNECTED && ((millis() - last_client_millis) > CLIENT_DELAY)) {
//     Serial.println("check client..........................");
//     if(client.connect(mqttDeviceID)) {
//       offline = false;
//       counter = 0;
//       OTA_init();
//       client.subscribe(subscribeTopic1);
//       client.subscribe(subscribeTopic2);
//       Serial.println("Connected!");
//     }
//     last_client_millis = millis();
//   }
// }

void reconnect() {
  // Loop until we're reconnected
  if(!client.connected() && ((millis() - last_client_connect) > client_connect_delay)) {
    #ifdef SERIAL_DEBUG
      Serial.print("\nAttempting MQTT connection...");
    #endif
    // Attempt to connect
    // If you do not want to use a username and password, change next line to
    // if (client.connect("ESP8266Client")) {
    if(client.connect(mqtt_device_id)) {
      client.subscribe(rgb_topic);
      mqtt_connected = true;
      #ifdef SERIAL_DEBUG
        Serial.print("   Connected!");
        Serial.println(mqtt_connected);
      #endif
    } 
    last_client_connect = millis();
  }
}

void setup() {
  #ifdef SERIAL_DEBUG
    Serial.begin(115200);
    delay(1000);
    Serial.println("JC Design");
    Serial.println("PD-01RGB-WIFI1");
    Serial.println("Start program...");
  #endif
  pinMode(ledPin.red, OUTPUT);
  pinMode(ledPin.green, OUTPUT);
  pinMode(ledPin.blue, OUTPUT);
  pinMode(builtin_led, OUTPUT);
  pinMode(4, INPUT);              //Temp sensor as input
  
  analogWrite(ledPin.red, 0);
  analogWrite(ledPin.green, 0);
  analogWrite(ledPin.blue, 0);

  //Wifi Manager start
  #ifdef SERIAL_DEBUG
    Serial.println("mounting FS...");
  #endif

  if(SPIFFS.begin()) {
    #ifdef SERIAL_DEBUG
      Serial.println("mounted file system");
    #endif

    if(SPIFFS.exists("/config.json")) {
      //file exists, reading and loading
      #ifdef SERIAL_DEBUG
        Serial.println("reading config file");
      #endif
      File configFile = SPIFFS.open("/config.json", "r");
      if(configFile) {
        #ifdef SERIAL_DEBUG
          Serial.println("opened config file");
        #endif
        size_t size = configFile.size();
        // Allocate a buffer to store contents of the file.
        std::unique_ptr<char[]> buffer(new char[size]);

        configFile.readBytes(buffer.get(), size);

      #ifdef ARDUINOJSON_VERSION_MAJOR >= 6
        DynamicJsonDocument json(1024);
        auto deserializeError = deserializeJson(json, buffer.get());
        serializeJson(json, Serial);
        if(!deserializeError) {
      #else
        DynamicJsonBuffer jsonBuffer;
        JsonObject& json = jsonBuffer.parseObject(buf.get());
        json.printTo(Serial);
        if(json.success()) {
      #endif
          #ifdef SERIAL_DEBUG
            Serial.println("\nparsed json");
          #endif

          //IP settings
          if(json["ip"]) {
            #ifdef SERIAL_DEBUG
              Serial.println("setting custom ip from config");
            #endif

            strcpy(static_ip, json["ip"]);
            strcpy(static_gw, json["gateway"]);
            strcpy(static_sn, json["subnet"]);

            #ifdef SERIAL_DEBUG
              Serial.println(static_ip);
            #endif
          } 
          else {
            #ifdef SERIAL_DEBUG
              Serial.println("no custom ip in config");
            #endif
          }

          //MQTT settings
          strcpy(mqtt_server_ip,          json["mqtt_server_ip"]);
          strcpy(mqtt_port,               json["mqtt_port"]);
          strcpy(mqtt_device_id,          json["mqtt_device_id"]);
          strcpy(temperature_topic,       json["temperature_topic"]);
          strcpy(time_between_temp_read,  json["time_between_temp_read"]);
          strcpy(button_check,            json["button_check"]);
          strcpy(button_topic,            json["button_topic"]);
          strcpy(rgb_topic,               json["rgb_topic"]);
        } 
        else {
          #ifdef SERIAL_DEBUG
            Serial.println("failed to load json config");
          #endif
        }
      }
    }
  } 
  else {
    #ifdef SERIAL_DEBUG
      Serial.println("failed to mount FS");
    #endif
  }

  #ifdef SERIAL_DEBUG
    Serial.println(static_ip);
    Serial.println(mqtt_server_ip);
    Serial.println(mqtt_port);
  #endif

  //set config save notify callback
  wm.setSaveConfigCallback(saveConfigCallback);

  // create parameters
  WiFiManagerParameter custom_mqtt_server_ip("mqtt_server_ip", "MQTT server ip", mqtt_server_ip, 40);
  WiFiManagerParameter custom_mqtt_port("mqtt_port", "MQTT port", mqtt_port, 6);
  WiFiManagerParameter custom_mqtt_device_id("mqtt_device_id", "MQTT device id", mqtt_device_id, 40);
  WiFiManagerParameter custom_temp_topic("temp_topic", "Temperature sensor topic", temperature_topic, 40);
  WiFiManagerParameter custom_temp_time("temp_time", "Time between temp readings (s)", time_between_temp_read, 6);
  
  enable_button = atoi(button_check);
  strcpy(custom_button_html, "type=\"checkbox\"");      //reference: https://github.com/kentaylor/WiFiManager/blob/master/examples/ConfigOnSwitchFS/ConfigOnSwitchFS.ino
  if(enable_button) {
    strcat(custom_button_html, " checked");
  }
  #ifdef SERIAL_DEBUG
    Serial.print("enable button value: ");  Serial.println(enable_button);
    Serial.print("custom html: ");  Serial.println(custom_button_html);
  #endif
  WiFiManagerParameter custom_button_enable("touchbutton", "Enable Touch Button", "T", 2, custom_button_html, WFM_LABEL_BEFORE);
  WiFiManagerParameter custom_button_topic("button_topic", "Button topic", button_topic, 40);
  WiFiManagerParameter custom_rgb_topic("rgb_topic", "RGB output topic", rgb_topic, 40);

  //set static ip
  // IPAddress _ip, _gw, _sn;
  // _ip.fromString(static_ip);
  // _gw.fromString(static_gw);
  // _sn.fromString(static_sn);

  // wm.setSTAStaticIPConfig(_ip, _gw, _sn);

  //add parameters
  wm.addParameter(&custom_mqtt_server_ip);
  wm.addParameter(&custom_mqtt_port);
  wm.addParameter(&custom_mqtt_device_id);
  wm.addParameter(&custom_temp_topic);
  wm.addParameter(&custom_temp_time);
  wm.addParameter(&custom_button_enable);
  wm.addParameter(&custom_button_topic);
  wm.addParameter(&custom_rgb_topic);

  std::vector<const char *> menu = {"wifi","param","info","sep","restart","exit"};
  wm.setMenu(menu);

  // set dark theme
  wm.setClass("invert");

  wm.setTimeout(300);

  //Start wifimanager portal
  digitalWrite(builtin_led, LOW);       //Drive pin low to turn on LED

  if (!wm.autoConnect("PD-01RGB-WIFI1", "JCDesign")) {
    #ifdef SERIAL_DEBUG
      Serial.println("failed to connect and hit timeout");
    #endif
    delay(3000);
    //reset and try again, or maybe put it to deep sleep
    ESP.restart();
    delay(5000);
  }
  else {
    #ifdef SERIAL_DEBUG
      Serial.println("Connected to WiFi network!");
    #endif
  }

  strcpy(mqtt_server_ip, custom_mqtt_server_ip.getValue());
  strcpy(mqtt_port, custom_mqtt_port.getValue());
  strcpy(mqtt_device_id, custom_mqtt_device_id.getValue());
  strcpy(temperature_topic, custom_temp_topic.getValue());
  strcpy(time_between_temp_read, custom_temp_time.getValue());
  
  enable_button = (strncmp(custom_button_enable.getValue(), "T", 1) == 0);
  itoa(enable_button, button_check, 10);
  #ifdef SERIAL_DEBUG
    Serial.print("button enable: ");
    Serial.println(enable_button);
    Serial.print(", char value: ");
    Serial.println(button_check);
  #endif

  strcpy(button_topic, custom_button_topic.getValue());
  strcpy(rgb_topic, custom_rgb_topic.getValue());
  
  //save the custom parameters to FS
  if (shouldSaveConfig) {
    #ifdef SERIAL_DEBUG
      Serial.println("saving config");
    #endif
#ifdef ARDUINOJSON_VERSION_MAJOR >= 6
    DynamicJsonDocument json(1024);
#else
    DynamicJsonBuffer jsonBuffer;
    JsonObject& json = jsonBuffer.createObject();
#endif
    json["ip"] = WiFi.localIP().toString();
    json["gateway"] = WiFi.gatewayIP().toString();
    json["subnet"] = WiFi.subnetMask().toString();

    json["mqtt_server_ip"] = mqtt_server_ip;
    json["mqtt_port"] = mqtt_port;
    json["mqtt_device_id"] = mqtt_device_id;
    json["temperature_topic"] = temperature_topic;
    json["time_between_temp_read"] = time_between_temp_read;
    json["button_check"] = button_check;
    json["button_topic"] = button_topic;
    json["rgb_topic"] = rgb_topic;

    File configFile = SPIFFS.open("/config.json", "w");
    if (!configFile) {
      #ifdef SERIAL_DEBUG
        Serial.println("failed to open config file for writing");
      #endif
    }

#ifdef ARDUINOJSON_VERSION_MAJOR >= 6
    serializeJson(json, Serial);
    serializeJson(json, configFile);
#else
    json.printTo(Serial);
    json.printTo(configFile);
#endif
    configFile.close();
    //end save
  }

  //Wifi Manager end
  digitalWrite(builtin_led, HIGH);      //Drive pin high to turn off LED

  if(enable_button)
    pinMode(BUTTON_PIN, INPUT);
  
  delay(100);
  client.begin(mqtt_server_ip, net);
  client.onMessage(messageReceived);
}

void loop() {
  // wifi_handler();

  if(!client.connected()) {
    mqtt_connected = false;
    reconnect();
  } 
  
  if(mqtt_connected) {
    client.loop();
    delay(10);

    if(enable_button) {
      if(!button_state && digitalRead(BUTTON_PIN) == HIGH) {
        button_state = true;
        client.publish(button_topic, "TOGGLE");
        #ifdef SERIAL_DEBUG
          Serial.println("Button Pressed");
        #endif
      }
      else if(digitalRead(BUTTON_PIN) == LOW) {
        button_state = false;
      }
    }
    
    if(((!start && ((millis() - Lasttime) > (atoi(time_between_temp_read)*1000))) || (start && millis() > 40000))) {
      if(start) {
        dsTemp.requestTemperatures(); 
        delay(1000); 
      }
      dsTemp.requestTemperatures();
      delay(20);
      temp = dsTemp.getTempCByIndex(0) + temp_offset;
      String s_temp = String(temp);
      s_temp.toCharArray(messTemp, s_temp.length()+1);
      client.publish(temperature_topic, messTemp);
      start = false;
      Lasttime = millis();
      #ifdef SERIAL_DEBUG
        Serial.println(temp);
      #endif
    }
  }

  //if gpio0 pressed go to AP mode for config
  if(digitalRead(resetConfigPin) == LOW) {
    digitalWrite(builtin_led, LOW);       //Drive pin low to turn on LED
    #ifdef SERIAL_DEBUG
      Serial.println("Enter On Demand AP...");
    #endif
    //set config save notify callback
    wm.setSaveConfigCallback(saveConfigCallback);
    button_config = true;

    // create parameters
    WiFiManagerParameter custom_mqtt_server_ip("mqtt_server_ip", "MQTT server ip", mqtt_server_ip, 40);
    WiFiManagerParameter custom_mqtt_port("mqtt_port", "MQTT port", mqtt_port, 6);
    WiFiManagerParameter custom_mqtt_device_id("mqtt_device_id", "MQTT device id", mqtt_device_id, 40);
    WiFiManagerParameter custom_temp_topic("temp_topic", "Temperature sensor topic", temperature_topic, 40);
    WiFiManagerParameter custom_temp_time("temp_time", "Time between temp readings (s)", time_between_temp_read, 6);
    
    enable_button = atoi(button_check);
    strcpy(custom_button_html, "type=\"checkbox\"");      //reference: https://github.com/kentaylor/WiFiManager/blob/master/examples/ConfigOnSwitchFS/ConfigOnSwitchFS.ino
    if(enable_button) {
      strcat(custom_button_html, " checked");
    }
    #ifdef SERIAL_DEBUG
      Serial.print("enable button value: ");  Serial.println(enable_button);
      Serial.print("custom html: ");  Serial.println(custom_button_html);
    #endif
    WiFiManagerParameter custom_button_enable("touchbutton", "Enable Touch Button", "T", 2, custom_button_html, WFM_LABEL_BEFORE);
    WiFiManagerParameter custom_button_topic("button_topic", "Button topic", button_topic, 40);
    WiFiManagerParameter custom_rgb_topic("rgb_topic", "RGB output topic", rgb_topic, 40);

    //set static ip
    // IPAddress _ip, _gw, _sn;
    // _ip.fromString(static_ip);
    // _gw.fromString(static_gw);
    // _sn.fromString(static_sn);

    // wm.setSTAStaticIPConfig(_ip, _gw, _sn);

    std::vector<const char *> menu = {"wifi","param","info","sep","restart","exit"};
    wm.setMenu(menu);
  
    // set dark theme
    wm.setClass("invert");

    wm.setTimeout(300);

    //Start wifimanager portal
    if (!wm.startConfigPortal("PD-01RGB-WIFI1", "JCDesign")) {
      #ifdef SERIAL_DEBUG
        Serial.println("failed to connect and hit timeout");
      #endif
      delay(3000);
      //reset and try again, or maybe put it to deep sleep
      ESP.restart();
      delay(5000);
    }
    else {
      #ifdef SERIAL_DEBUG
        Serial.println("Connected to WiFi network!");
      #endif
    }

    //save config

    #ifdef SERIAL_DEBUG
      Serial.println("Exit On Demand AP...");
    #endif
    digitalWrite(builtin_led, HIGH);       //Drive pin high to turn off LED
  }
}

#END

Debug Messages

PlatformIO serial monitor output

*wm:[2] Added Parameter: mqtt_server_ip
*wm:[2] Added Parameter: mqtt_port
*wm:[2] Added Parameter: mqtt_device_id
*wm:[2] Added Parameter: temp_topic
*wm:[2] Added Parameter: temp_time
*wm:[2] Added Parameter: touchbutton
*wm:[2] Added Parameter: button_topic
*wm:[2] Added Parameter: rgb_topic
*wm:[1] AutoConnect
*wm:[1] No Credentials are Saved, skipping connect
*wm:[2] Starting Config Portal
*wm:[2] AccessPoint set password is VALID
*wm:[2] Disabling STA
*wm:[2] Enabling AP
*wm:[1] StartAP with SSID: PD-01RGB-WIFI1
*wm:[1] AP IP address: 192.168.4.1
*wm:[1] Starting Web Portal
*wm:[2] HTTP server started
*wm:[2] Config Portal Running, blocking, waiting for clients...
*wm:[2] Portal Timeout In 300 seconds
*wm:[2] Portal Timeout In 271 seconds
*wm:[2] Portal Timeout In 241 seconds
*wm:[2] <- Request redirected to captive portal
*wm:[2] <- HTTP Root
*wm:[2] <- Request redirected to captive portal
*wm:[2] <- HTTP Root
*wm:[2] <- Request redirected to captive portal
*wm:[2] <- HTTP Root
*wm:[2] <- HTTP Wifi
*wm:[2] WiFi Scan SYNC started
*wm:[2] WiFi Scan completed in 2185 ms
*wm:[1] 7 networks found
*wm:[2] DUP AP: WiFi-2.4-774C
*wm:[2] AP: -58 telenet-1650778
*wm:[2] AP: -58 TelenetWiFree
*wm:[2] AP: -66 DIRECT-k4M2026W Wireless
*wm:[2] AP: -84 WiFi-2.4-0DD6
*wm:[2] AP: -85 Proximus Public Wi-Fi
*wm:[2] AP: -86 WiFi-2.4-774C
*wm:[2] <- Request redirected to captive portal
*wm:[2] <- HTTP Root
*wm:[2] <- HTTP WiFi save
*wm:[2] processing save
*wm:[2] Connecting as wifi client...
*wm:[2] setSTAConfig static ip not set, skipping
*wm:[1] Connecting to NEW AP: telenet–1650778
*wm:[1] connectTimeout not set, ESP waitForConnectResult...
*wm:[2] Connection result: WL_NO_SSID_AVAIL
*wm:[0] [ERROR] Connect to new AP Failed
*wm:[2] Processing - Disabling STA
*wm:[2] <- Request redirected to captive portal
*wm:[2] <- HTTP Root
*wm:[2] <- Request redirected to captive portal
*wm:[2] <- HTTP Root
*wm:[2] Portal Timeout In 299 seconds
*wm:[2] <- Request redirected to captive portal
*wm:[2] <- HTTP Root
*wm:[2] <- HTTP Exit
*wm:[2] shutdownConfigPortal
*wm:[2] restoring usermode STA
*wm:[2] WiFi Reconnect, was idle
*wm:[2] wifi status: WL_STATION_WRONG_PASSWORD
*wm:[2] wifi mode: STA
*wm:[2] configportal closed
*wm:[1] config portal exiting

Arduino IDE serial monitor output

*wm:[2] Added Parameter: mqtt_server_ip
*wm:[2] Added Parameter: mqtt_port
*wm:[2] Added Parameter: mqtt_device_id
*wm:[2] Added Parameter: temp_topic
*wm:[2] Added Parameter: temp_time
*wm:[2] Added Parameter: touchbutton
*wm:[2] Added Parameter: button_topic
*wm:[2] Added Parameter: rgb_topic
*wm:[1] AutoConnect
*wm:[1] No Credentials are Saved, skipping connect
*wm:[2] Starting Config Portal
*wm:[2] AccessPoint set password is VALID
*wm:[2] Disabling STA
*wm:[2] Enabling AP
*wm:[1] StartAP with SSID: PD-01RGB-WIFI1
*wm:[1] AP IP address: 192.168.4.1
*wm:[1] Starting Web Portal
*wm:[2] HTTP server started
*wm:[2] Config Portal Running, blocking, waiting for clients...
*wm:[2] Portal Timeout In 300 seconds
*wm:[2] <- Request redirected to captive portal
*wm:[2] <- HTTP Root
*wm:[2] <- Request redirected to captive portal
*wm:[2] <- HTTP Root
*wm:[2] <- Request redirected to captive portal
*wm:[2] <- HTTP Root
*wm:[2] <- HTTP Wifi
*wm:[2] WiFi Scan SYNC started
*wm:[2] WiFi Scan completed in 2187 ms
*wm:[1] 8 networks found
*wm:[2] DUP AP: telenet-1650778
*wm:[2] DUP AP: WiFi-2.4-774C
*wm:[2] AP: -54 DIRECT-k4M2026W Wireless
*wm:[2] AP: -60 telenet-1650778
*wm:[2] AP: -61 TelenetWiFree
*wm:[2] AP: -80 Proximus Public Wi-Fi
*wm:[2] AP: -81 WiFi-2.4-774C
*wm:[2] AP: -89 WiFi-2.4-0DD6
*wm:[2] Portal Timeout In 297 seconds
*wm:[2] <- Request redirected to captive portal
*wm:[2] <- HTTP Root
*wm:[2] <- HTTP WiFi save
*wm:[2] processing save
*wm:[2] Connecting as wifi client...
*wm:[2] setSTAConfig static ip not set, skipping
*wm:[1] Connecting to NEW AP: telenet-1650778
*wm:[1] connectTimeout not set, ESP waitForConnectResult...
*wm:[2] Connection result: WL_CONNECTED
*wm:[1] Connect to new AP [SUCCESS]
*wm:[1] Got IP Address:
*wm:[1] 192.168.0.128
Should save config
*wm:[2] shutdownConfigPortal
*wm:[2] restoring usermode STA
*wm:[2] wifi status: WL_CONNECTED
*wm:[2] wifi mode: STA
*wm:[2] configportal closed
*wm:[1] config portal exiting
Connected to WiFi network!

Originally created by @JC-Electronics-Design on GitHub (Feb 13, 2022). Original GitHub issue: https://github.com/tzapu/WiFiManager/issues/1358 ### Basic Info WiFimanager Branch/Release: 2.0.5-beta (on both Arduino IDE as well as PlatformIO) Esp8266/Esp32: ESP8266 Hardware: NodeMCU 1.0 (ESP-12E module) Core Version: 3.0.2 (on both Arduino IDE as well as PlatformIO) ### Description I use PlatformIO for most of my programming, but with this project I'm having some trouble. The issue I'm having is that when I try to connect to my router via WifiManager by selecting the SSID and entering the correct credentials, is that when I click "Save" and WifiManager tries to connect to the router it fails. When I look at the debug info from PlatformIO I see this line: "*wm:[2] Connection result: WL_NO_SSID_AVAIL". (full debug output below) As a simple test I thought I'd try the exact same code in the Arduino IDE and see what happens. When I upload the code via Arduino and go through the exact same steps (configure WiFi -> Click correct SSID -> Fill in password -> click save) WifiManager is able to connect to my router no problems. Even MQTT messages are sent without any problems. The debug output from Arduino can also be seen below. I have been looking into what could be the issue here but can't seem to find the culprit. I also tried the basic example code in PlatformIO with the same result (WL_NO_SSID_AVAIL). Can any of you help me with this issue? Thanks in advance! If any additional info is required please let me know! ### Settings in IDE #### PlatformIO ```cpp #BEGIN [env:nodemcuv2] platform = espressif8266 board = nodemcuv2 framework = arduino upload_speed = 921600 monitor_speed = 115200 lib_deps = paulstoffregen/OneWire@^2.3.6 milesburton/DallasTemperature@^3.9.1 256dpi/MQTT@^2.5.0 bblanchon/ArduinoJson@^6.19.1 https://github.com/tzapu/WiFiManager.git #END ``` #### Arduino IDE ![image](https://user-images.githubusercontent.com/34834753/153776266-aaa706ed-55c0-4156-97aa-1f43302e483a.png) Additional libraries: #include <FS.h> #include <ArduinoJson.h> #include <MQTTClient.h> #include <HSBColor.h> #include <OneWire.h> #include <DallasTemperature.h> ### Sketch ```cpp #BEGIN /* * PD-01RGB-WIFI1 Software version v1.0 * JC Design */ #include <FS.h> //this needs to be first, or it all crashes and burns... #include <WiFiManager.h> //https://github.com/tzapu/WiFiManager #include <ArduinoJson.h> //https://github.com/bblanchon/ArduinoJson #include <MQTTClient.h> #include <HSBColor.h> #include <OneWire.h> #include <DallasTemperature.h> //Uncomment to enable debug messages via serial port #define SERIAL_DEBUG //define your default values here, if there are different values in config.json, they are overwritten. //length should be max size + 1 char mqtt_server_ip[40] = "10.0.1.10"; char mqtt_port[6] = "1883"; char mqtt_device_id[40] = "PD-01RGB-WIFI1"; char temperature_topic[40]; char time_between_temp_read[5] = "60"; char button_topic[40]; char button_check[2]; char rgb_topic[40]; //default custom static IP char static_ip[16] = "10.0.1.11"; char static_gw[16] = "10.0.1.1"; char static_sn[16] = "255.255.255.0"; WiFiManager wm; // global wm instance WiFiClient net; MQTTClient client; // Wifi manager variables #define resetConfigPin 0 //Choose a compatible pin, When low will reset the wifi manager config bool shouldSaveConfig = true; #define builtin_led 2 // Touch button variables #define BUTTON_PIN 5 bool enable_button = true; char custom_button_html[27]; bool button_state = false; bool button_config = false; // Temperature sensor variables #define temp_offset -3 //Temperature offset value float temp; //Stores temperature value String s_temp; char messTemp[10]; OneWire ds(4); //DS18b20 on gpio4 DallasTemperature dsTemp(&ds); bool start = true; unsigned long Lasttime = 0; // bool offline = false; // int counter = 0; // long last_client_millis = 0; // #define WIFI_DELAY 2000 // #define CLIENT_DELAY 2000 //time in milliseconds // LED output variables struct LedPin { byte red; byte green; byte blue; }; LedPin ledPin = {13, 12, 14}; int LedValue[3] = {0, 0, 0}; // Wifi handling variables bool mqtt_connected = false; unsigned long last_client_connect = -1; unsigned long client_connect_delay = 1000; //delay between checking connection, in milliseconds /********************************/ //callback notifying us of the need to save config void saveConfigCallback () { #ifdef SERIAL_DEBUG Serial.println("Should save config"); #endif shouldSaveConfig = true; //save the custom parameters to FS if (shouldSaveConfig && button_config) { #ifdef SERIAL_DEBUG Serial.println("saving config"); #endif #ifdef ARDUINOJSON_VERSION_MAJOR >= 6 DynamicJsonDocument json(1024); #else DynamicJsonBuffer jsonBuffer; JsonObject& json = jsonBuffer.createObject(); #endif json["ip"] = WiFi.localIP().toString(); json["gateway"] = WiFi.gatewayIP().toString(); json["subnet"] = WiFi.subnetMask().toString(); json["mqtt_server_ip"] = mqtt_server_ip; json["mqtt_port"] = mqtt_port; json["mqtt_device_id"] = mqtt_device_id; json["temperature_topic"] = temperature_topic; json["time_between_temp_read"] = time_between_temp_read; json["button_check"] = button_check; json["button_topic"] = button_topic; json["rgb_topic"] = rgb_topic; File configFile = SPIFFS.open("/config.json", "w"); if (!configFile) { #ifdef SERIAL_DEBUG Serial.println("failed to open config file for writing"); #endif } #ifdef ARDUINOJSON_VERSION_MAJOR >= 6 serializeJson(json, Serial); serializeJson(json, configFile); #else json.printTo(Serial); json.printTo(configFile); #endif configFile.close(); button_config = false; //end save } } void messageReceived(String &topic, String &payload) { String msgTopic = topic; String msgString = payload; #ifdef SERIAL_DEBUG Serial.print(msgTopic); Serial.print(": "); Serial.println(msgString); #endif if(msgTopic == rgb_topic) { if(msgString == "ON") { analogWrite(ledPin.red, 1023); analogWrite(ledPin.green, 1023); analogWrite(ledPin.blue, 1023); #ifdef SERIAL_DEBUG Serial.println("1023,1023,1023"); #endif } else if(msgString == "OFF") { analogWrite(ledPin.red, 0); analogWrite(ledPin.green, 0); analogWrite(ledPin.blue, 0); #ifdef SERIAL_DEBUG Serial.println("0,0,0"); #endif } else { int firstComma = msgString.indexOf(',') + 1; //find first comma in string int secondComma = msgString.indexOf(',', firstComma + 1); //find second comma in string int thirdComma = msgString.indexOf(',', secondComma + 1); //find third comma in string String hue = msgString.substring(0, (firstComma - 1)); String saturation = msgString.substring(firstComma, secondComma); String brightness = msgString.substring((secondComma+1), thirdComma); #ifdef SERIAL_DEBUG Serial.print(hue); Serial.print(","); Serial.print(saturation); Serial.print(","); Serial.println(brightness); #endif H2R_HSBtoRGB(hue.toInt(), saturation.toInt(), brightness.toInt(), LedValue); LedValue[0] = (LedValue[0]*4)+3; LedValue[1] = (LedValue[1]*4)+3; LedValue[2] = (LedValue[2]*4)+3; if(LedValue[0] < 100) LedValue[0] = 0; else if(LedValue[0] > 980) LedValue[0] = 1023; if(LedValue[1] < 100) LedValue[1] = 0; else if(LedValue[1] > 980) LedValue[1] = 1023; if(LedValue[2] < 100) LedValue[2] = 0; else if(LedValue[2] > 980) LedValue[2] = 1023; #ifdef SERIAL_DEBUG Serial.print(LedValue[0]); Serial.print(","); Serial.print(LedValue[1]); Serial.print(","); Serial.println(LedValue[2]); #endif analogWrite(ledPin.red, LedValue[0]); analogWrite(ledPin.green, LedValue[1]); analogWrite(ledPin.blue, LedValue[2]); } } } // void wifi_handler() { // if(WiFi.status() != WL_CONNECTED || !client.connected()) { // #ifdef SERIAL_DEBUG // Serial.print("wifi: "); Serial.println(WiFi.status()); //Keep the serial, otherwise it doesn't work (too fast) // Serial.print("Counter: "); Serial.println(counter); // #endif // if(!offline) { // offline = true; // } // if((counter > WIFI_DELAY || counter == 0) && WiFi.status() != WL_CONNECTED) { // connect(); // counter = 1; // } // counter++; // } // if(offline && WiFi.status() == WL_CONNECTED && ((millis() - last_client_millis) > CLIENT_DELAY)) { // Serial.println("check client.........................."); // if(client.connect(mqttDeviceID)) { // offline = false; // counter = 0; // OTA_init(); // client.subscribe(subscribeTopic1); // client.subscribe(subscribeTopic2); // Serial.println("Connected!"); // } // last_client_millis = millis(); // } // } void reconnect() { // Loop until we're reconnected if(!client.connected() && ((millis() - last_client_connect) > client_connect_delay)) { #ifdef SERIAL_DEBUG Serial.print("\nAttempting MQTT connection..."); #endif // Attempt to connect // If you do not want to use a username and password, change next line to // if (client.connect("ESP8266Client")) { if(client.connect(mqtt_device_id)) { client.subscribe(rgb_topic); mqtt_connected = true; #ifdef SERIAL_DEBUG Serial.print(" Connected!"); Serial.println(mqtt_connected); #endif } last_client_connect = millis(); } } void setup() { #ifdef SERIAL_DEBUG Serial.begin(115200); delay(1000); Serial.println("JC Design"); Serial.println("PD-01RGB-WIFI1"); Serial.println("Start program..."); #endif pinMode(ledPin.red, OUTPUT); pinMode(ledPin.green, OUTPUT); pinMode(ledPin.blue, OUTPUT); pinMode(builtin_led, OUTPUT); pinMode(4, INPUT); //Temp sensor as input analogWrite(ledPin.red, 0); analogWrite(ledPin.green, 0); analogWrite(ledPin.blue, 0); //Wifi Manager start #ifdef SERIAL_DEBUG Serial.println("mounting FS..."); #endif if(SPIFFS.begin()) { #ifdef SERIAL_DEBUG Serial.println("mounted file system"); #endif if(SPIFFS.exists("/config.json")) { //file exists, reading and loading #ifdef SERIAL_DEBUG Serial.println("reading config file"); #endif File configFile = SPIFFS.open("/config.json", "r"); if(configFile) { #ifdef SERIAL_DEBUG Serial.println("opened config file"); #endif size_t size = configFile.size(); // Allocate a buffer to store contents of the file. std::unique_ptr<char[]> buffer(new char[size]); configFile.readBytes(buffer.get(), size); #ifdef ARDUINOJSON_VERSION_MAJOR >= 6 DynamicJsonDocument json(1024); auto deserializeError = deserializeJson(json, buffer.get()); serializeJson(json, Serial); if(!deserializeError) { #else DynamicJsonBuffer jsonBuffer; JsonObject& json = jsonBuffer.parseObject(buf.get()); json.printTo(Serial); if(json.success()) { #endif #ifdef SERIAL_DEBUG Serial.println("\nparsed json"); #endif //IP settings if(json["ip"]) { #ifdef SERIAL_DEBUG Serial.println("setting custom ip from config"); #endif strcpy(static_ip, json["ip"]); strcpy(static_gw, json["gateway"]); strcpy(static_sn, json["subnet"]); #ifdef SERIAL_DEBUG Serial.println(static_ip); #endif } else { #ifdef SERIAL_DEBUG Serial.println("no custom ip in config"); #endif } //MQTT settings strcpy(mqtt_server_ip, json["mqtt_server_ip"]); strcpy(mqtt_port, json["mqtt_port"]); strcpy(mqtt_device_id, json["mqtt_device_id"]); strcpy(temperature_topic, json["temperature_topic"]); strcpy(time_between_temp_read, json["time_between_temp_read"]); strcpy(button_check, json["button_check"]); strcpy(button_topic, json["button_topic"]); strcpy(rgb_topic, json["rgb_topic"]); } else { #ifdef SERIAL_DEBUG Serial.println("failed to load json config"); #endif } } } } else { #ifdef SERIAL_DEBUG Serial.println("failed to mount FS"); #endif } #ifdef SERIAL_DEBUG Serial.println(static_ip); Serial.println(mqtt_server_ip); Serial.println(mqtt_port); #endif //set config save notify callback wm.setSaveConfigCallback(saveConfigCallback); // create parameters WiFiManagerParameter custom_mqtt_server_ip("mqtt_server_ip", "MQTT server ip", mqtt_server_ip, 40); WiFiManagerParameter custom_mqtt_port("mqtt_port", "MQTT port", mqtt_port, 6); WiFiManagerParameter custom_mqtt_device_id("mqtt_device_id", "MQTT device id", mqtt_device_id, 40); WiFiManagerParameter custom_temp_topic("temp_topic", "Temperature sensor topic", temperature_topic, 40); WiFiManagerParameter custom_temp_time("temp_time", "Time between temp readings (s)", time_between_temp_read, 6); enable_button = atoi(button_check); strcpy(custom_button_html, "type=\"checkbox\""); //reference: https://github.com/kentaylor/WiFiManager/blob/master/examples/ConfigOnSwitchFS/ConfigOnSwitchFS.ino if(enable_button) { strcat(custom_button_html, " checked"); } #ifdef SERIAL_DEBUG Serial.print("enable button value: "); Serial.println(enable_button); Serial.print("custom html: "); Serial.println(custom_button_html); #endif WiFiManagerParameter custom_button_enable("touchbutton", "Enable Touch Button", "T", 2, custom_button_html, WFM_LABEL_BEFORE); WiFiManagerParameter custom_button_topic("button_topic", "Button topic", button_topic, 40); WiFiManagerParameter custom_rgb_topic("rgb_topic", "RGB output topic", rgb_topic, 40); //set static ip // IPAddress _ip, _gw, _sn; // _ip.fromString(static_ip); // _gw.fromString(static_gw); // _sn.fromString(static_sn); // wm.setSTAStaticIPConfig(_ip, _gw, _sn); //add parameters wm.addParameter(&custom_mqtt_server_ip); wm.addParameter(&custom_mqtt_port); wm.addParameter(&custom_mqtt_device_id); wm.addParameter(&custom_temp_topic); wm.addParameter(&custom_temp_time); wm.addParameter(&custom_button_enable); wm.addParameter(&custom_button_topic); wm.addParameter(&custom_rgb_topic); std::vector<const char *> menu = {"wifi","param","info","sep","restart","exit"}; wm.setMenu(menu); // set dark theme wm.setClass("invert"); wm.setTimeout(300); //Start wifimanager portal digitalWrite(builtin_led, LOW); //Drive pin low to turn on LED if (!wm.autoConnect("PD-01RGB-WIFI1", "JCDesign")) { #ifdef SERIAL_DEBUG Serial.println("failed to connect and hit timeout"); #endif delay(3000); //reset and try again, or maybe put it to deep sleep ESP.restart(); delay(5000); } else { #ifdef SERIAL_DEBUG Serial.println("Connected to WiFi network!"); #endif } strcpy(mqtt_server_ip, custom_mqtt_server_ip.getValue()); strcpy(mqtt_port, custom_mqtt_port.getValue()); strcpy(mqtt_device_id, custom_mqtt_device_id.getValue()); strcpy(temperature_topic, custom_temp_topic.getValue()); strcpy(time_between_temp_read, custom_temp_time.getValue()); enable_button = (strncmp(custom_button_enable.getValue(), "T", 1) == 0); itoa(enable_button, button_check, 10); #ifdef SERIAL_DEBUG Serial.print("button enable: "); Serial.println(enable_button); Serial.print(", char value: "); Serial.println(button_check); #endif strcpy(button_topic, custom_button_topic.getValue()); strcpy(rgb_topic, custom_rgb_topic.getValue()); //save the custom parameters to FS if (shouldSaveConfig) { #ifdef SERIAL_DEBUG Serial.println("saving config"); #endif #ifdef ARDUINOJSON_VERSION_MAJOR >= 6 DynamicJsonDocument json(1024); #else DynamicJsonBuffer jsonBuffer; JsonObject& json = jsonBuffer.createObject(); #endif json["ip"] = WiFi.localIP().toString(); json["gateway"] = WiFi.gatewayIP().toString(); json["subnet"] = WiFi.subnetMask().toString(); json["mqtt_server_ip"] = mqtt_server_ip; json["mqtt_port"] = mqtt_port; json["mqtt_device_id"] = mqtt_device_id; json["temperature_topic"] = temperature_topic; json["time_between_temp_read"] = time_between_temp_read; json["button_check"] = button_check; json["button_topic"] = button_topic; json["rgb_topic"] = rgb_topic; File configFile = SPIFFS.open("/config.json", "w"); if (!configFile) { #ifdef SERIAL_DEBUG Serial.println("failed to open config file for writing"); #endif } #ifdef ARDUINOJSON_VERSION_MAJOR >= 6 serializeJson(json, Serial); serializeJson(json, configFile); #else json.printTo(Serial); json.printTo(configFile); #endif configFile.close(); //end save } //Wifi Manager end digitalWrite(builtin_led, HIGH); //Drive pin high to turn off LED if(enable_button) pinMode(BUTTON_PIN, INPUT); delay(100); client.begin(mqtt_server_ip, net); client.onMessage(messageReceived); } void loop() { // wifi_handler(); if(!client.connected()) { mqtt_connected = false; reconnect(); } if(mqtt_connected) { client.loop(); delay(10); if(enable_button) { if(!button_state && digitalRead(BUTTON_PIN) == HIGH) { button_state = true; client.publish(button_topic, "TOGGLE"); #ifdef SERIAL_DEBUG Serial.println("Button Pressed"); #endif } else if(digitalRead(BUTTON_PIN) == LOW) { button_state = false; } } if(((!start && ((millis() - Lasttime) > (atoi(time_between_temp_read)*1000))) || (start && millis() > 40000))) { if(start) { dsTemp.requestTemperatures(); delay(1000); } dsTemp.requestTemperatures(); delay(20); temp = dsTemp.getTempCByIndex(0) + temp_offset; String s_temp = String(temp); s_temp.toCharArray(messTemp, s_temp.length()+1); client.publish(temperature_topic, messTemp); start = false; Lasttime = millis(); #ifdef SERIAL_DEBUG Serial.println(temp); #endif } } //if gpio0 pressed go to AP mode for config if(digitalRead(resetConfigPin) == LOW) { digitalWrite(builtin_led, LOW); //Drive pin low to turn on LED #ifdef SERIAL_DEBUG Serial.println("Enter On Demand AP..."); #endif //set config save notify callback wm.setSaveConfigCallback(saveConfigCallback); button_config = true; // create parameters WiFiManagerParameter custom_mqtt_server_ip("mqtt_server_ip", "MQTT server ip", mqtt_server_ip, 40); WiFiManagerParameter custom_mqtt_port("mqtt_port", "MQTT port", mqtt_port, 6); WiFiManagerParameter custom_mqtt_device_id("mqtt_device_id", "MQTT device id", mqtt_device_id, 40); WiFiManagerParameter custom_temp_topic("temp_topic", "Temperature sensor topic", temperature_topic, 40); WiFiManagerParameter custom_temp_time("temp_time", "Time between temp readings (s)", time_between_temp_read, 6); enable_button = atoi(button_check); strcpy(custom_button_html, "type=\"checkbox\""); //reference: https://github.com/kentaylor/WiFiManager/blob/master/examples/ConfigOnSwitchFS/ConfigOnSwitchFS.ino if(enable_button) { strcat(custom_button_html, " checked"); } #ifdef SERIAL_DEBUG Serial.print("enable button value: "); Serial.println(enable_button); Serial.print("custom html: "); Serial.println(custom_button_html); #endif WiFiManagerParameter custom_button_enable("touchbutton", "Enable Touch Button", "T", 2, custom_button_html, WFM_LABEL_BEFORE); WiFiManagerParameter custom_button_topic("button_topic", "Button topic", button_topic, 40); WiFiManagerParameter custom_rgb_topic("rgb_topic", "RGB output topic", rgb_topic, 40); //set static ip // IPAddress _ip, _gw, _sn; // _ip.fromString(static_ip); // _gw.fromString(static_gw); // _sn.fromString(static_sn); // wm.setSTAStaticIPConfig(_ip, _gw, _sn); std::vector<const char *> menu = {"wifi","param","info","sep","restart","exit"}; wm.setMenu(menu); // set dark theme wm.setClass("invert"); wm.setTimeout(300); //Start wifimanager portal if (!wm.startConfigPortal("PD-01RGB-WIFI1", "JCDesign")) { #ifdef SERIAL_DEBUG Serial.println("failed to connect and hit timeout"); #endif delay(3000); //reset and try again, or maybe put it to deep sleep ESP.restart(); delay(5000); } else { #ifdef SERIAL_DEBUG Serial.println("Connected to WiFi network!"); #endif } //save config #ifdef SERIAL_DEBUG Serial.println("Exit On Demand AP..."); #endif digitalWrite(builtin_led, HIGH); //Drive pin high to turn off LED } } #END ``` ### Debug Messages #### PlatformIO serial monitor output *wm:[2] Added Parameter: mqtt_server_ip *wm:[2] Added Parameter: mqtt_port *wm:[2] Added Parameter: mqtt_device_id *wm:[2] Added Parameter: temp_topic *wm:[2] Added Parameter: temp_time *wm:[2] Added Parameter: touchbutton *wm:[2] Added Parameter: button_topic *wm:[2] Added Parameter: rgb_topic *wm:[1] AutoConnect *wm:[1] No Credentials are Saved, skipping connect *wm:[2] Starting Config Portal *wm:[2] AccessPoint set password is VALID *wm:[2] Disabling STA *wm:[2] Enabling AP *wm:[1] StartAP with SSID: PD-01RGB-WIFI1 *wm:[1] AP IP address: 192.168.4.1 *wm:[1] Starting Web Portal *wm:[2] HTTP server started *wm:[2] Config Portal Running, blocking, waiting for clients... *wm:[2] Portal Timeout In 300 seconds *wm:[2] Portal Timeout In 271 seconds *wm:[2] Portal Timeout In 241 seconds *wm:[2] <- Request redirected to captive portal *wm:[2] <- HTTP Root *wm:[2] <- Request redirected to captive portal *wm:[2] <- HTTP Root *wm:[2] <- Request redirected to captive portal *wm:[2] <- HTTP Root *wm:[2] <- HTTP Wifi *wm:[2] WiFi Scan SYNC started *wm:[2] WiFi Scan completed in 2185 ms *wm:[1] 7 networks found *wm:[2] DUP AP: WiFi-2.4-774C *wm:[2] AP: -58 telenet-1650778 *wm:[2] AP: -58 TelenetWiFree *wm:[2] AP: -66 DIRECT-k4M2026W Wireless *wm:[2] AP: -84 WiFi-2.4-0DD6 *wm:[2] AP: -85 Proximus Public Wi-Fi *wm:[2] AP: -86 WiFi-2.4-774C *wm:[2] <- Request redirected to captive portal *wm:[2] <- HTTP Root *wm:[2] <- HTTP WiFi save *wm:[2] processing save *wm:[2] Connecting as wifi client... *wm:[2] setSTAConfig static ip not set, skipping *wm:[1] Connecting to NEW AP: telenet–1650778 *wm:[1] connectTimeout not set, ESP waitForConnectResult... *wm:[2] Connection result: WL_NO_SSID_AVAIL *wm:[0] [ERROR] Connect to new AP Failed *wm:[2] Processing - Disabling STA *wm:[2] <- Request redirected to captive portal *wm:[2] <- HTTP Root *wm:[2] <- Request redirected to captive portal *wm:[2] <- HTTP Root *wm:[2] Portal Timeout In 299 seconds *wm:[2] <- Request redirected to captive portal *wm:[2] <- HTTP Root *wm:[2] <- HTTP Exit *wm:[2] shutdownConfigPortal *wm:[2] restoring usermode STA *wm:[2] WiFi Reconnect, was idle *wm:[2] wifi status: WL_STATION_WRONG_PASSWORD *wm:[2] wifi mode: STA *wm:[2] configportal closed *wm:[1] config portal exiting #### Arduino IDE serial monitor output *wm:[2] Added Parameter: mqtt_server_ip *wm:[2] Added Parameter: mqtt_port *wm:[2] Added Parameter: mqtt_device_id *wm:[2] Added Parameter: temp_topic *wm:[2] Added Parameter: temp_time *wm:[2] Added Parameter: touchbutton *wm:[2] Added Parameter: button_topic *wm:[2] Added Parameter: rgb_topic *wm:[1] AutoConnect *wm:[1] No Credentials are Saved, skipping connect *wm:[2] Starting Config Portal *wm:[2] AccessPoint set password is VALID *wm:[2] Disabling STA *wm:[2] Enabling AP *wm:[1] StartAP with SSID: PD-01RGB-WIFI1 *wm:[1] AP IP address: 192.168.4.1 *wm:[1] Starting Web Portal *wm:[2] HTTP server started *wm:[2] Config Portal Running, blocking, waiting for clients... *wm:[2] Portal Timeout In 300 seconds *wm:[2] <- Request redirected to captive portal *wm:[2] <- HTTP Root *wm:[2] <- Request redirected to captive portal *wm:[2] <- HTTP Root *wm:[2] <- Request redirected to captive portal *wm:[2] <- HTTP Root *wm:[2] <- HTTP Wifi *wm:[2] WiFi Scan SYNC started *wm:[2] WiFi Scan completed in 2187 ms *wm:[1] 8 networks found *wm:[2] DUP AP: telenet-1650778 *wm:[2] DUP AP: WiFi-2.4-774C *wm:[2] AP: -54 DIRECT-k4M2026W Wireless *wm:[2] AP: -60 telenet-1650778 *wm:[2] AP: -61 TelenetWiFree *wm:[2] AP: -80 Proximus Public Wi-Fi *wm:[2] AP: -81 WiFi-2.4-774C *wm:[2] AP: -89 WiFi-2.4-0DD6 *wm:[2] Portal Timeout In 297 seconds *wm:[2] <- Request redirected to captive portal *wm:[2] <- HTTP Root *wm:[2] <- HTTP WiFi save *wm:[2] processing save *wm:[2] Connecting as wifi client... *wm:[2] setSTAConfig static ip not set, skipping *wm:[1] Connecting to NEW AP: telenet-1650778 *wm:[1] connectTimeout not set, ESP waitForConnectResult... *wm:[2] Connection result: WL_CONNECTED *wm:[1] Connect to new AP [SUCCESS] *wm:[1] Got IP Address: *wm:[1] 192.168.0.128 Should save config *wm:[2] shutdownConfigPortal *wm:[2] restoring usermode STA *wm:[2] wifi status: WL_CONNECTED *wm:[2] wifi mode: STA *wm:[2] configportal closed *wm:[1] config portal exiting Connected to WiFi network!
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/WiFiManager#1162
No description provided.