• Skip to main content
  • Skip to primary sidebar

RNTLab.com

The Ultimate Shortcut to Learn Electronics and Programming with Open Source Hardware and Software

  • Courses
  • Forum
    • Forum
    • Ask Question
  • Shop
  • Account
  • Blog
  • Login

Problem with D1mini depsleep

Q&A Forum › Problem with D1mini depsleep
0 Vote Up Vote Down
Hans-Joachim Koch asked 2 years ago

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?

Question Tags: d1 deepsleep
12 Answers
0 Vote Up Vote Down
Best Answer
Sara Santos Staff answered 2 years ago

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

0 Vote Up Vote Down
Hans-Joachim Koch answered 2 years ago

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.

0 Vote Up Vote Down
Sara Santos Staff answered 2 years ago

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

0 Vote Up Vote Down
Hans-Joachim Koch answered 2 years ago

No change. Unfortunately it does not work. The connection to MQTT is not established, not even on the first pass.

0 Vote Up Vote Down
Hans-Joachim Koch answered 2 years ago

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.

0 Vote Up Vote Down
Sara Santos Staff answered 2 years ago

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

0 Vote Up Vote Down
Hans-Joachim Koch answered 2 years ago

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.

0 Vote Up Vote Down
Sara Santos Staff answered 2 years ago

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

0 Vote Up Vote Down
Hans-Joachim Koch answered 2 years ago

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.

0 Vote Up Vote Down
Sara Santos Staff answered 2 years ago

If you want, you can send me your code and I can test it on my boards.
Regards,
Sara

0 Vote Up Vote Down
Hans-Joachim Koch answered 2 years ago

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.

0 Vote Up Vote Down
Sara Santos Staff answered 2 years ago

Ok.
I’ll close this issue for now.
If you want to come back to this issue, you just need to answer here or you can open a new question in our forum.
Regards,
Sara

Primary Sidebar

Login to Ask or Answer Questions

This Forum is private and it’s only available for members enrolled in our Courses.

Login »

Latest Course Updates

  • [New Edition] Build ESP32-CAM Projects eBook – 2nd Edition April 16, 2025
  • [eBook Updated] Learn ESP32 with Arduino IDE eBook – Version 3.2 April 16, 2025

You must be logged in to view this content.

Contact Support - Refunds - Privacy - Terms - MakerAdvisor.com - Member Login

Copyright © 2013-2025 · RandomNerdTutorials.com · All Rights Reserved

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.