Problem | Control DeepSleep duration with sensors connected

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
anishmg
New user
Posts: 7
Joined: 13 Jun 2018, 09:22

Problem | Control DeepSleep duration with sensors connected

#1 Post by anishmg » 13 Jun 2018, 09:42

Hi, I just started playing with ESPEasy - and it is quite amazing. However, after trying a number of sensors and successfully getting them to work, I started to work on a battery powered project, because ESP12 supports deepsleep and ESPEasy provides configuration for it to the user. So, with that in mind, I embarked upon a very simple project.

ESP NodeMCU board with ESP12E - with latest ESPEasy mega firmware flashed through ArduinoIDE.
BME280 sensor breakout board - Sensor delay set to 60s.
Node-red + mqtt broker on a separate machine.

What works:
Everything works as expected when deep sleep is not enabled. The BME280+NodeMCU periodically (every 1 min) send data to MQTT. I've tested with a number of other sensors.

What also works:
ESP8266 WITHOUT any sensor connected and deep sleep enabled. Also, I set awake time to 30s, and sleep time to 60s, and I see exactly that. The board boots, connects to WiFi, stays on for 30s, and then goes to sleep for 60s. Then wakes up and repeats the process.

What does not work, or is flakey:
Now with basic deepsleep working, I expected the same to happen with the BME280 connected and enabled. But, what happens is this:
1. Board boots
2. Serial log immediately upon booting shows BME280 data
3. Board tries to connect over wifi
4-a. It is sometimes able to connect, get an IP address, and send sensor data over mqtt. Instead of one message, it seems to publish sensor readout EVERY second. I seem to have no way to be able to control this. In this, the board seems to remain on for 30s (which is the sleep awake time)

4-b. It is sometimes not able to connect. I get the WiFi Changed Access point event but not the WiFi Connected event. Then shortly after that, the board again goes to deep sleep. (I have unchecked the "Go to deepsleep if not able to connect" checkbox, so that is not what is causing this to happen).


In running this many times, I observe the behavior to be flakey, and about 60% of the time, the board can't connect to wifi and goes to sleep, and 40% of the time it is able to connect, and sends sensor data MANY times (instead of one). None of this odd behavior seems to happen if there is no sensor or device connected/enabled.

So, it would be really helpful to know how I can get to do this:

1. Board boots
2. Connects to WiFi
3. Connects to MQTT broker
4. Reads sensor data ONCE and publishes data
5. Goes to SLEEP
6. Repeat

I have tried using rules to do this (on MQTT#Connect do ... publish XXX endon) but the flakiness persists. Any help or pointers would be very helpful!

Warmly,
Anish

Drum
Normal user
Posts: 300
Joined: 07 Feb 2016, 11:56

Re: Problem | Control DeepSleep duration with sensors connected

#2 Post by Drum » 13 Jun 2018, 12:12

That is interesting, I have several setup to do this with no issue, various boards and chips(8266 and 8285). When you say the Latest version, which version is that?
What is the power supply circuit?
The first suggestion is to use a known power supply, 5v 1A with a 3.3V voltage regulator. You can get odd behavior when batteries get low.
Also please review the wiki regarding power supply.
Details on the physical design (schematic) would be helpful, the voltage regulator is important.

I am probably using an older version (146) so I don't know how helpful all this will be.
Your settings are very similar to what I have, although there is no stay awake time, it boots, connects, sends data and sleeps for 10 minutes (600 seconds).
I do have the IP address set in my router, and it may help to fix the IP address in both the router and ESP.
I also added a rule to send the IP address when it boots.

on System#Boot do
Publish /%sysname%/IP,%ip%
endon

I use NodeRed to feed everything into a SQLite database, so I can track problems.

anishmg
New user
Posts: 7
Joined: 13 Jun 2018, 09:22

Re: Problem | Control DeepSleep duration with sensors connected

#3 Post by anishmg » 13 Jun 2018, 13:07

Hi, Thanks for your reply!

The board I am using is this

https://www.aliexpress.com/item/New-Wir ... autifyAB=0

Standard off the shelf nodemcu board with an onboard 3.3v regulator. I am powering this from the powered USB port on my thinkpad laptop. I have powered this from a dedicated 5v, 1A power supply and I dont see any difference in operation. Also, I tried this fork of tasmota (https://github.com/stefanbode/Sonoff-Tasmota) and it works in there, so I don't think power supply is the issue here.

As for versions, I tried the following:

ESPEasy_mega-20180606
ESPEasy_mega-20180606

I tried both - flashing the stock firmware and compiling and flashing over arduino ide. I also tried r120, and I think I hit this issue there as well, so it feels quite strange.

The settings on arduino ide while flashing are 4M (1M SPIFFS), and a complete flash erase. The issue is repeatable.

At this point I am thinking it might be some basic setting somewhere that I'm missing. I can share my config.dat if someone is willing to replicate the setup on a breadboard.

anishmg
New user
Posts: 7
Joined: 13 Jun 2018, 09:22

Re: Problem | Control DeepSleep duration with sensors connected

#4 Post by anishmg » 13 Jun 2018, 14:03

Okay, I tried the exact same hardware setup on R147, and there is no such issue on that version.

So, the issue does not exist on R147, but it does happen on the latest mega versions.

I am rechecking on R120 (because last I had checked, the issue was still present on that one).

anishmg
New user
Posts: 7
Joined: 13 Jun 2018, 09:22

Re: Problem | Control DeepSleep duration with sensors connected

#5 Post by anishmg » 13 Jun 2018, 14:04

Unfortunately, I also have to have PMSX007 dust sensors for this project, but that is not supported in R147 :(

anishmg
New user
Posts: 7
Joined: 13 Jun 2018, 09:22

Re: Problem | Control DeepSleep duration with sensors connected

#6 Post by anishmg » 13 Jun 2018, 14:18

Okay, Issue doesn't exist on R120 as well.

Rechecking mega builds --- just in case.

anishmg
New user
Posts: 7
Joined: 13 Jun 2018, 09:22

Re: Problem | Control DeepSleep duration with sensors connected

#7 Post by anishmg » 13 Jun 2018, 14:39

Okay, the issue of flakiness exists in the mega builds...

I tried the EXACT same setup as R147 and R120, and about 30% time I get this (serial log)

Code: Select all

INIT : Booting version: mega-20180611 (ESP82xx Core 2_4_1, NONOS SDK 2.2.1(cfd48f3), LWIP: 2.0.3)
233 : INIT : Rebooted from deepsleep #4
236 : FS   : Mounting...
261 : FS   : Mount successful, used 75802 bytes of 957314
591 : CRC  : program checksum       ...OK
623 : CRC  : SecuritySettings CRC   ...OK 
729 : INIT : Free RAM:22760
729 : INIT : I2C
729 : INIT : SPI not enabled
747 : INFO : Plugins: 71 [Normal] [Testing] (ESP82xx Core 2_4_1, NONOS SDK 2.2.1(cfd48f3), LWIP: 2.0.3)
748 : EVENT: System#Wake
752 : WIFI : Set WiFi to STA
784 : WIFI : Connecting cygnus x-1 attempt #0
786 : EVENT: System#Boot
795 : WD   : Uptime 0 ConnectFailures 0 FreeMem 21824
800 : BMx280 : Detected BME280
2387 : BME280: dew point 15.94C
2388 : BME280 : Address: 0x76
2388 : BME280 : Temperature: 25.99
2388 : BME280 : Humidity: 53.96
2388 : BME280 : Barometric Pressure: 802.56
2393 : EVENT: sensor1#Temperature=25.99
2398 : EVENT: sensor1#Humidity=53.96
2401 : EVENT: sensor1#Pressure=802.56
4520 : BME280: dew point 15.94C
4520 : BME280 : Address: 0x76
4521 : BME280 : Temperature: 25.99
4521 : BME280 : Humidity: 53.95
4521 : BME280 : Barometric Pressure: 802.57
4526 : EVENT: sensor1#Temperature=25.99
4531 : EVENT: sensor1#Humidity=53.95
4533 : EVENT: sensor1#Pressure=802.57
4644 : WIFI : Connected! AP: cygnus x-1 (40:C8:CB:11:50:BA) Ch: 1 Duration: 3778 ms
4646 : EVENT: WiFi#ChangedAccesspoint
6245 : BME280: dew point 16.08C
6246 : BME280 : Address: 0x76
6246 : BME280 : Temperature: 26.00
6246 : BME280 : Humidity: 54.39
6246 : BME280 : Barometric Pressure: 802.56
6251 : EVENT: sensor1#Temperature=26.00
6256 : EVENT: sensor1#Humidity=54.39
6259 : EVENT: sensor1#Pressure=802.56
6369 : WIFI : DHCP IP: 192.168.225.24 (esp12f-kg-1-0) GW: 192.168.225.1 SN: 255.255.255.0   duration: 1806 ms
6370 : EVENT: WiFi#Connected
and the other 70% of the time I get this

Code: Select all

INIT : Booting version: mega-20180611 (ESP82xx Core 2_4_1, NONOS SDK 2.2.1(cfd48f3), LWIP: 2.0.3)
232 : INIT : Rebooted from deepsleep #7
235 : FS   : Mounting...
260 : FS   : Mount successful, used 75802 bytes of 957314
590 : CRC  : program checksum       ...OK
622 : CRC  : SecuritySettings CRC   ...OK 
728 : INIT : Free RAM:22760
728 : INIT : I2C
728 : INIT : SPI not enabled
746 : INFO : Plugins: 71 [Normal] [Testing] (ESP82xx Core 2_4_1, NONOS SDK 2.2.1(cfd48f3), LWIP: 2.0.3)
747 : EVENT: System#Wake
751 : WIFI : Set WiFi to STA
783 : WIFI : Connecting cygnus x-1 attempt #0
785 : EVENT: System#Boot
795 : WD   : Uptime 0 ConnectFailures 0 FreeMem 21824
799 : BMx280 : Detected BME280
2387 : BME280: dew point 16.22C
2388 : BME280 : Address: 0x76
2388 : BME280 : Temperature: 25.30
2388 : BME280 : Humidity: 57.23
2389 : BME280 : Barometric Pressure: 802.64
2393 : EVENT: sensor1#Temperature=25.30
2399 : EVENT: sensor1#Humidity=57.23
2401 : EVENT: sensor1#Pressure=802.64
4518 : BME280: dew point 16.23C
4519 : BME280 : Address: 0x76
4519 : BME280 : Temperature: 25.33
4519 : BME280 : Humidity: 57.17
4520 : BME280 : Barometric Pressure: 802.64
4524 : EVENT: sensor1#Temperature=25.33
4529 : EVENT: sensor1#Humidity=57.17
4531 : EVENT: sensor1#Pressure=802.64
4645 : WIFI : Connected! AP: cygnus x-1 (40:C8:CB:11:50:BA) Ch: 1 Duration: 3773 ms
4647 : EVENT: WiFi#ChangedAccesspoint
6245 : BME280: dew point 16.23C
6246 : BME280 : Address: 0x76
6246 : BME280 : Temperature: 25.35
6246 : BME280 : Humidity: 57.10
6246 : BME280 : Barometric Pressure: 802.63
6251 : EVENT: sensor1#Temperature=25.35
6256 : EVENT: sensor1#Humidity=57.10
6259 : EVENT: sensor1#Pressure=802.63
7962 : BME280: dew point 16.18C
7962 : BME280 : Address: 0x76
7962 : BME280 : Temperature: 25.34
7963 : BME280 : Humidity: 56.95
7963 : BME280 : Barometric Pressure: 802.65
7968 : EVENT: sensor1#Temperature=25.34
7973 : EVENT: sensor1#Humidity=56.95
7975 : EVENT: sensor1#Pressure=802.65
8084 : EVENT: System#Sleep
8097 : EVENT: System#Sleep
8098 : SLEEP: Powering down to deepsleep...
In the latter case, which is happening more often, the system goes to sleep before it gets an IP address from the router, and hence is unable to publish. I suspect there is a missing check in the code somewhere which doesn't check for connection and publish information and just decides to sleep anyway. Also, to be sure -- "Sleep on Connection Failure" is unchecked. The sleep awake time is set to 10s.

So it seems that sleep mode on nodemcu boards with mega firmware has issues.

Thoughts?


Post Reply

Who is online

Users browsing this forum: No registered users and 47 guests