[GH-ISSUE #611] Cannot connect to MQTT broker after entering WiFi credentials #509

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

Originally created by @akshay-rsm on GitHub (May 29, 2018).
Original GitHub issue: https://github.com/tzapu/WiFiManager/issues/611

Basic Infos

Hardware

WiFimanager Branch/Release: Development

Esp8266

Hardware: ESP-12e
Core Version: 2.4.1, stable

Description

I have an ESP-12E module that uses WiFiManager to store WiFi credentials before connecting to an MQTT broker. I found that after entering WiFi credentials for the first time, any previously instantiated WiFiClient/PubSubClient objects do not work. If I reset the module after storing the credentials in EEPROM, however, it works (Essentially, the opening and closing of the captive portal messes it up). I managed to fix this by explicitly putting the module in STA mode (using WiFi.mode(WIFI_STA)). My guess is that after closing the captive portal, WiFiManager puts the module in another mode(WIFI_AP_STA) that renders the PubSubClient/WiFiClient objects useless.

Settings in IDE

Module: NodeMCU ver 1.0

Additional libraries:

Sketch


#include <Arduino.h>
#include <ESP8266WiFi.h>          
#include <PubSubClient.h>
#include <WiFiManager.h>  

WiFiClient espClient; //instantiated client objects
PubSubClient client(espClient);

void setup() {
    Serial.begin(115200);
    EEPROM.begin(512);
    SPIFFS.begin();
    WiFiManager wifiManager;              //WiFiManager instance

    wifiManager.autoConnect("AP_NAME","password"); //blocking loop
 
    WiFi.mode(WIFI_STA);                 //sets it right
    
}

void loop() {
   rest.handle(client);
}
Originally created by @akshay-rsm on GitHub (May 29, 2018). Original GitHub issue: https://github.com/tzapu/WiFiManager/issues/611 ### Basic Infos #### Hardware WiFimanager Branch/Release: Development Esp8266 Hardware: ESP-12e Core Version: 2.4.1, stable ### Description I have an ESP-12E module that uses WiFiManager to store WiFi credentials before connecting to an MQTT broker. I found that after entering WiFi credentials for the first time, any previously instantiated WiFiClient/PubSubClient objects do not work. If I reset the module after storing the credentials in EEPROM, however, it works (Essentially, the opening and closing of the captive portal messes it up). I managed to fix this by explicitly putting the module in STA mode (using WiFi.mode(WIFI_STA)). My guess is that after closing the captive portal, WiFiManager puts the module in another mode(WIFI_AP_STA) that renders the PubSubClient/WiFiClient objects useless. ### Settings in IDE Module: NodeMCU ver 1.0 Additional libraries: ### Sketch ```cpp #include <Arduino.h> #include <ESP8266WiFi.h> #include <PubSubClient.h> #include <WiFiManager.h> WiFiClient espClient; //instantiated client objects PubSubClient client(espClient); void setup() { Serial.begin(115200); EEPROM.begin(512); SPIFFS.begin(); WiFiManager wifiManager; //WiFiManager instance wifiManager.autoConnect("AP_NAME","password"); //blocking loop WiFi.mode(WIFI_STA); //sets it right } void loop() { rest.handle(client); } ```
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#509
No description provided.