Hello,
I have a small problem with the sketch ESP8266_Publish_BME280 from the SmartHome eBook.
I have the D1mini and a battery shield on it. Unfortunately, everything uses too much power and the 2ah battery runs out quickly.
I now wanted to put the D1 into DeepSleep during rest periods and to do this I’ve set inside “loop”:
// if (currentMillis – previousMillis >= interval) {
// previousMillis = currentMillis;
and the last bracket commented out.
Additionally, I added inside “loop” at the end
ESP.deepSleep(30e6);
Works well so far, can be seen in the SerialMonitor. The D1 wakes up every 30 seconds (short time just for testing), then starts the connection to WiFi, but NOT the connection to MQTT. The measured values are displayed correctly in the SerialMonitor, but no longer in the dashboard. The text “Connecting to MQTT” does not appear after the WiFi connection.
What can I do?
Hi.
Try using the following lines before connecting to Wi-Fi:
WiFi.forceSleepBegin();
delay(1);
WiFi.forceSleepWake();
delay(1);
Let me know if this solves the issue.
Regards,
Sara
Hi Sara, thanks for the quick answer. Unfortunately it does not work. I installed it here:
void connectToWifi() {
WiFi.forceSleepBegin();
delay(1);
WiFi.forceSleepWake();
delay(1);
Serial.println(“Connecting to Wi-Fi…”);
WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
}
Maybe the wrong place? Without these lines, the connection to MQTT happened the first time and then no more after every wake up. With these lines the connection to MQTT does not happen at all, not even for the first loop.
Yes. That’s the right place. Keeping those lines, make the following change.
Instead of
ESP.deepSleep(30e6);
Use
ESP.deepSleep(30e6, WAKE_RF_DISABLED);
Let me know if this works
Regards,
Sara
No change. Unfortunately it does not work. The connection to MQTT is not established, not even on the first pass.
Hi Sara,
would it be possible that you and Rui, as experts, could expand the sketch to do exactly what I couldn’t do? I think I’m not the only one who wants to take temperature measurements over longer periods of time and wants to save the battery with DeepSleep. Such temperature/humidity/pressure measurements are probably made at longer intervals of 30 or 60 minutes, for which DeepSleep would be useful.
Greetings, Hajo.
Just try one last thing:
Before calling the sleep function, add the following
WiFi.disconnect();
So, something like this:
WiFi.disconnect();
delay(100);
ESP.deepSleep(10e6);
Let me know the results.
Regards,
Sara
No chance. It seems impossible to extend this sketch to DeepSleep. When connecting to WiFi, the message appears Connecting to Wi-Fi… but not the message Connected to Wi-Fi. There is no message at all about MQTT.
I have now restored the original version and everything works fine, except the battery drains more quickly.
Thanks for your help. Please mark this request as completed. Greetings, Hajo.
Do you have another ESP8266 board to experiment with?
I remember in the past, some of our students had issues with deep sleep using a Wemos D1 Mini.
If you can experiment with other ESP8266 board models, maybe it will work.
Regards,
Sara
I have several D1mini. All of them work well with DeepSleep, including this one. I tried this with simple sketches. I give up. Regards, Hajo.
If you want, you can send me your code and I can test it on my boards.
Regards,
Sara
Hello Sara, thank you for your offer. Unfortunately I no longer have the code that you added as per your suggestions. I’m back to the original version from your ebook. Greetings, Hajo.