mirror of
https://github.com/tzapu/WiFiManager.git
synced 2026-04-27 17:15:53 +03:00
[GH-ISSUE #729] ESP-12E nodemcu unable to reconnect to WIFI after deepsleep #610
Labels
No labels
📶 WiFi
🕸️ HTTP
Branch
DEV Help Wanted
Discussion
Documentation
ESP32
Example
Good First Issue
Hotfix
In Progress
Incomplete
Needs Feeback
Priority
QA
Question
Task
Upstream/Dependancy
bug
duplicate
enhancement
invalid
pull-request
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/WiFiManager#610
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @kevcavein on GitHub (Sep 14, 2018).
Original GitHub issue: https://github.com/tzapu/WiFiManager/issues/729
Hi all,
I'm facing a problem that my ESP12E does not connect to my wifi after wake up from deepsleep. It happen randomly. Sometimes it happens just the second time after wake up from deep sleep, sometimes it happens after 2hrs and sometimes even 12hrs. After disconnecting, it will launch the AP webpage waiting for wifi SSID and password.
I'm using the latest wifimanger 2.4.2 and even revert to 2.4.0 before but still the same.
I'm very new to Arduino and my sample is mainly cut and paste from different reference.
Besides, i place the device very near to my wifi setup, should not be the wifi signal strength problem.
If this a same topic from another threat, please reference me to there. Most same topic seems to be 2years or 7months ago(which is closed).
Thanks in advance.
Below is my sketch.
#include <FS.h> //this needs to be first, or it all crashes and burns...
#define BLYNK_PRINT Serial // Comment this out to disable prints and save space
#include <ESP8266WiFi.h>
#include <DNSServer.h>
#include <ESP8266WebServer.h>
#include <WiFiManager.h> //https://github.com/tzapu/WiFiManager
#include <ArduinoJson.h> //https://github.com/bblanchon/ArduinoJson
char blynk_token[34] = "BLYNK_TOKEN";
bool shouldSaveConfig = false; //flag for saving data
#include <BlynkSimpleEsp8266.h>
#include <SimpleTimer.h>
SimpleTimer timer;
#include <OneWire.h>
#include <DallasTemperature.h>
#define ONE_WIRE_BUS 4 // Your ESP8266 pin (ESP8266 GPIO 4 = pin D2)
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
int roomTemperature; //temperature in C
void saveConfigCallback () { //callback notifying us of the need to save config
Serial.println("Should save config");
shouldSaveConfig = true;
}
void sendTemps()
{
sensors.requestTemperatures(); // Polls the sensors.
roomTemperature = sensors.getTempCByIndex(0); // Stores temperature. Change to getTempFByIndex(0) for ferenheit.
Blynk.virtualWrite(1, roomTemperature); // Send temperature to Blynk app virtual pin 1.
Serial.println("");
Serial.println("I'm gooooing to sleeeeeeeeep....ZZZZzzzzzzzzz");
ESP.deepSleep(900e6,WAKE_RF_DEFAULT);
delay(100);
Serial.println("*************");
}
void setup()
{
Serial.begin(115200);
Serial.println();
Serial.println("Mounting FS..."); //read configuration from FS json
if (SPIFFS.begin()) {
Serial.println("Mounted file system");
if (SPIFFS.exists("/config.json")) {
//file exists, reading and loading
Serial.println("Reading config file");
File configFile = SPIFFS.open("/config.json", "r");
if (configFile) {
Serial.println("Opened config file");
size_t size = configFile.size();
// Allocate a buffer to store contents of the file.
std::unique_ptr<char[]> buf(new char[size]);
configFile.readBytes(buf.get(), size);
DynamicJsonBuffer jsonBuffer;
JsonObject& json = jsonBuffer.parseObject(buf.get());
json.printTo(Serial);
if (json.success()) {
Serial.println("\nparsed json");
strcpy(blynk_token, json["blynk_token"]);
} else {
Serial.println("Failed to load json config");
}
}
}
} else {
Serial.println("Failed to mount FS");
}
WiFiManagerParameter custom_blynk_token("blynk", "blynk token", blynk_token, 34); // was 32 length
Serial.println(blynk_token);
WiFiManager wifiManager;
wifiManager.setSaveConfigCallback(saveConfigCallback); //set config save notify callback
wifiManager.addParameter(&custom_blynk_token); //add all your parameters here
wifiManager.setTimeout(600); // 10 minutes to enter data and then Wemos resets to try again.
if (!wifiManager.autoConnect("AutoConnectAP")) {
Serial.println("Failed to connect and hit timeout");
delay(3000);
//reset and try again, or maybe put it to deep sleep
ESP.reset();
delay(5000);
}
Serial.println("Connected To Access Point"); //if you get here you have connected to the WiFi
strcpy(blynk_token, custom_blynk_token.getValue()); //read updated parameters
if (shouldSaveConfig) { //save the custom parameters to FS
Serial.println("saving config");
DynamicJsonBuffer jsonBuffer;
JsonObject& json = jsonBuffer.createObject();
json["blynk_token"] = blynk_token;
}
Blynk.config(blynk_token);
bool result = Blynk.connect(180);
Blynk.syncAll();
if (result != true)
{
Serial.println("BLYNK Connection Fail");
wifiManager.resetSettings();
ESP.reset();
delay (5000);
}
else
{
Serial.println("BLYNK Connected");
}
sensors.begin(); // Starts the DS18B20 sensor(s).
sensors.setResolution(10);
timer.setInterval(2000L, sendTemps); // Temperature sensor read interval. 2000 (ms) = 2 seconds.
}
void loop()
{
Blynk.run(); // Initiates Blynk
timer.run(); // Initiates SimpleTimer
}
@tablatronix commented on GitHub (Sep 14, 2018):
maybe try hotfixes branch or development branch of WM
or provide some debug logs
@kevcavein commented on GitHub (Sep 14, 2018):
Sorry may I know what is hotfix branch or development branch? Sorry.. I'm very new..