Improve the canonical "node-wifi-mqtt" firmware


#21

Well, it seems the deepsleep does not work out of the box. However, I’m powering the MCU through USB. I will try to perform some debug soon,

Cheers

Giuseppe


#22

Well it works! It was my fault. I just needed to connect the D0 pin with RST pin. This enables wakeup of the MCU. Of course, some spurious data is sent to UART, but in fact, in low power use-cases I think UART prints will be enabled just in debug contexts.

Cheers,
Giuseppe


#23

Very cool, thanks for testing!

Thanks again, we will add an appropriate comment to the source code.

Do you see any way to improve this? Currently, there’s a Serial.flush(); before going to deep sleep mode. Should we add another one right after waking up in setup()?


#24

Please be aware that our improvements now have been merged into the master branch, so please find the current version at node-wifi-mqtt.ino.

Thanks again for your efforts!

Cheers,
Andreas.


#25

Unfortunately, still no way to make the Serial silent when sleeping it. But well, it still remains an acceptable glitch

Cheers,
Giuseppe


#26

please change:
- #define DEEPSLEEP_TIME MEASUREMENT_INTERVAL * 1000UL * 1000UL
+ #define DEEPSLEEP_TIME MEASUREMENT_INTERVAL * 1000UL
since measurement interval is in ms already

DeepSleep works for me. Remember to wire connect RST with GPIO16 to enable wake up capability. Might be a different GPIO on a board other than my Adafruit Feather HUZZAH.


#27

Hi there,

regarding the hardware wiring required to enable wakeup of the MCU:

… where @Thias is using an Adafruit Feather HUZZAH: Which kind of device are you currently using, @gtuveri, where the respective pin is labeled D0?

I’m just asking to make the documentation as precise as possible.


#28

Good morning,
I’m using a simple 3.- NodeMCU AMICA R2, whose pin definition is reported here [1] and also depicted here [2]. In fact I ordered at the same time an Adafruit Feather HUZZAH, but unfortunately i’m still waiting for receiving it.

[1] https://nodemcu.readthedocs.io/en/master/en/modules/gpio/
[2] http://crufti.com/content/images/2015/11/nodemcudevkit_v1-0_io.jpg

Cheers,
Giuseppe


#29

Its GPIO#16 on both boards. The Feather HUZZAH has it also labeled as #16. So, D0 on @gtuveri’s board is GPIO16 according to


#30

Something I’d like to share with you is the vastly improved power consumption with ESP.deepSleep(). Before I had about 25% battery drain per day with a 6600mAh LiPo battery running 1xHX711, 1xDHT22 and 1xDS18B20. After 12 hours with ESP.deepSleep enabled I estimate battery drain to settle at about 4-5% per day. That’s absolutely fantastic! My solar panel will ensure to operate the board independent of external power supplies throughout the year.

Conclusion: A smaller battery would have done the job as well :D

PS: There will be more battery drain in the upcoming days, because I’ll switch back to delay(5min) for evaluating the lower boundary of battery level until the unit switches off itself. My calculation for the ADC <-> Level mapping seem to lack of precision.


#31

Thanks for providing insights into the power consumption using the deep sleep mode. Good to hear about its improvements!

We made some experimental changes at node-wifi-mqtt-silent by using the SerialDebugger library.

Please be aware there have been some amendments at the updated SerialDebugger library to make it actually compile (as the most recent update to this library was on 2009-04-15, it’s actually dated somehow). By using our repository and switching to the branch “node-wifi-mqtt-silent”, you should be up to speed:

git checkout node-wifi-mqtt-silent
git submodule update --recursive --init

As usual, i didn’t get the chance to run it on real hardware yet. Maybe you want to try this on your irons?
We are happy to receive valuable feedback as usual by both of you :-). Thanks in advance!

Cheers and have a good weekend,
Andreas.

P.S.: To have a look at the detailed changes, please visit:
https://github.com/hiveeyes/arduino/commit/639f3e77


#32

Thanks for such a great work, Andreas and Thias! I will keep you updated.

Cheers,
Giuseppe


#33

Dear @gtuveri and @Thias,

may i humbly ask if one of you could find some minutes for testing the most recent development iteration using the SerialDebugger library? If this thing still works, we could merge the changes into the master branch.

Thanks in advance,
Andreas.


#34

Dear Andreas,
Of course I will. Tomorrow morning I will perform the tests.

Thanks!

See you,
Giuseppe


#35

Dear Andreas,
I did not perform a very comprehensive test but at least for my setup the firmware works. Readability of the serial output would improve by removing the line breaks after “NOTIFICATION:”. The IP address is shown incorrectly as you can see in the output below. Changing line 915 to Serial.println(WiFi.localIP()); prints the IP properly (but bypasses the SerialDebugger?).

194 - NOTIFICATION:
                                wifi_connect | Connecting to WiFi 
316 - NOTIFICATION:
                                wifi_connect | Retrying WiFi connection in a few seconds:  0.40

716 - NOTIFICATION:
                                wifi_connect | Retrying WiFi connection in a few seconds:  0.40

1116 - NOTIFICATION:
                                wifi_connect | Retrying WiFi connection in a few seconds:  0.40

1517 - NOTIFICATION:
                                wifi_connect | Retrying WiFi connection in a few seconds:  0.40

1917 - NOTIFICATION:
                                wifi_connect | Retrying WiFi connection in a few seconds:  0.40

2317 - NOTIFICATION:
                                wifi_connect | Retrying WiFi connection in a few seconds:  0.40

7259 - NOTIFICATION:
                                wifi_connect | WiFi connected! IP address:  381462720

7761 - NOTIFICATION:
                                mqtt_connect | Connecting to MQTT broker 
7870 - NOTIFICATION:
                                mqtt_connect | Successfully connected to MQTT broker 
7870 - NOTIFICATION:
                                read_weight | Read weight (HX711) 
8206 - NOTIFICATION:
                                read_weight | Read weight (HX711) Weight: -12.18

8206 - NOTIFICATION:
                                read_temperature_array | Read temperature array (DS18B20) 
9253 - NOTIFICATION:
                                read_humidity_temperature | Read humidity and temperature (DHTxx) 
9258 - NOTIFICATION:
                                read_battery_level | Battery ADC:  621

9284 - NOTIFICATION:
                                read_battery_level | Battery level:  38%
{"weight":-12.18,"airtemperature":23.90,"airhumidity":43.60,"broodtemperature":23.44,"battery_level":38}
9462 - NOTIFICATION:
                                transmit_readings | MQTT publish succeeded

#36

Dear Matthias,

thanks for testing! We just pushed some fixes to the branch “node-wifi-mqtt-silent”, which might mitigate the issues you brought to the table. Hopefully they work actually. Would you check again?

Thanks in advance!

Cheers,
Andreas.


#37

SerialDebugger.debug() always starts with a new line. So no need to use Serial.println() after or before SerialDebugger.debug() . Serial.print() should fit better

With:

Serial.print("Weight: " + String(weight));
SerialDebugger.print(adc_level);
SerialDebugger.print(WiFi.localIP().toString().c_str());
SerialDebugger.print(WIFI_RETRY_DELAY);

output then changes to

194 - INFO:     wifi_connect | Connecting to WiFi 
348 - INFO:     wifi_connect | Retrying WiFi connection in a few seconds:  0.40
748 - INFO:     wifi_connect | Retrying WiFi connection in a few seconds:  0.40
1148 - INFO:    wifi_connect | Retrying WiFi connection in a few seconds:  0.40
1548 - INFO:    wifi_connect | Retrying WiFi connection in a few seconds:  0.40
1949 - INFO:    wifi_connect | Retrying WiFi connection in a few seconds:  0.40
2349 - INFO:    wifi_connect | Retrying WiFi connection in a few seconds:  0.40
7101 - INFO:    wifi_connect | WiFi connected! IP address:  192.168.188.22
7604 - INFO:    mqtt_connect | Connecting to MQTT broker 
7632 - INFO:    mqtt_connect | Successfully connected to MQTT broker 
7632 - INFO:    read_weight | Read weight (HX711) 
7966 - INFO:    read_weight | Read weight (HX711) Weight: -10.72
7966 - INFO:    read_temperature_array | Read temperature array (DS18B20) 
8990 - INFO:    read_humidity_temperature | Read humidity and temperature (DHTxx) 
8995 - INFO:    read_battery_level | Battery ADC:  618
8998 - INFO:    read_battery_level | Battery level:  37%
{"weight":-10.72,"airtemperature":21.40,"airhumidity":44.00,"entrytemperature":20.69,"battery_level":37}
9166 - INFO:    transmit_readings | MQTT publish succeeded

#38

Many thanks @Thias!
I just tested the firmware; it seems to work flawlessly. However, I still have one remark: does it make any sense to perform a fixed number of Wi-Fi connection trials (e.g. 15), then proceeding? Wouldn’t be better to indefinitely try to estabilish the connection, maybe with a more reasonable delay (in order not to rapidly discharge the battery; if sensor_battery is enabled, we can also avoid to fully discharge the battery by breaking the loop and printing a error string if battery level is lower than a fixed threshold) ? This is also useful as nodes does not need to be rebooted if they are powered on before activating the Wi-Fi access.

Cheers,
Giuseppe


#39

Thanks, @Thias. We just pushed an update reflecting your recommendations.


#40

Dear Giuseppe,

thanks for your suggestions!

We just pushed some updates regarding your recommendations to the branch “node-wifi-mqtt-connectivity” (see node-wifi-mqtt.ino). We didn’t add the complexity to monitor the battery level but rather added simple enhancements to not proceed with measurements. This prevents the battery from draining too much by sending the node into deep sleep mode when connectivity couldn’t be established.

The new connectivity flow should account for that, as “wifi_connect()” is now called inside “measure()”.

Are you fine with that? We are looking forward for tests on the iron by one of you.

Cheers,
Andreas.