I have been using the NodeMCU and Lua for a while to create monitoring nodes that communicate via MQTT. I have tried to add an SDS011 dust sensor to one of these nodes but I'm getting random exception resets of the NodeMCU that seem to be caused just by the serial connection being active. The SDS011 sends a message every second, I have tried the hardware and soft UART with the same result.
I have checked the specs for the SDS011 and the serial connection is 3.3v, so I don't think it should be anything physical.
Even with a stripped down script as below I am getting crashes, I have tested on several NodeMCUs with the same result.
Script:
local l_sds_data = ""
function sds_read(l_sds_data)
print("sds_read "..node.heap())
end
s = softuart.setup(9600, 2, 3)
s:on("data", 10, sds_read)
The only way I found to keep the NodeMCU alive is to detect a soft reset and trigger an external reset, using the code below in init.lua. Without this hard reset the wifi would never reconnect. You can see the output of this code in the log further down.
-- Report on startup reason
rawcode, reason, exccause, epc1, epc2, epc3, excvaddr, depc = node.bootreason()
if reason == 0 then
print("Power up")
elseif reason == 1 then
print("Hardware watchdog")
elseif reason == 2 then
print("Exception reset")
print("EXCCAUSE "..exccause)
print("EPC1 "..epc1)
print("EPC2 "..epc2)
print("EPC3 "..epc3)
print("EXCVADDR "..excvaddr)
print("DEPC "..depc)
gpio.mode(6,gpio.OUTPUT,gpio.PULLUP)
gpio.write(gpio.LOW)
elseif reason == 3 then
print("Software watchdog")
elseif reason == 4 then
print("Software restart")
elseif reason == 5 then
print("Wake from deep sleep")
elseif reason == 6 then
print("External reset")
end
Every few minutes it crashes as the log extract below:
sds_read 35088
sds_read 35088
sds_read 35088
sds_read 35088
ets Jan 8 2013,rst cause:2, boot mode:(3,6)
load 0x40100000, len 27928, room 16
tail 8
chksum 0x8c
load 0x3ffe8000, len 2584, room 0
tail 8
chksum 0xf8
load 0x3ffe8a18, len 8, room 0
tail 8
chksum 0x12
csum 0x12
{‚Ÿâsä2’lŒ„ ìn~2cb„oàŽoäo~#Žƒ$ŽŽlònoŸŒonž 䛂’`~ƒ2„Nožì²œ¾{$~ƒc„noŸì’ƒ² „ãäƒoäÛr‚ûo|ìd$l c’œðŸ|r’dœnà‚nâ l`Œãr’lŒ$Œd`„âr²p‚äl„l Œãr“l¾Œl$`{lŽ‚b ŒŸÂcBì|ŒcprÜãÜbœplœ$ ìòNÎ2Nnâ $#lŒŽŒ€d$d$Žì„Œ€$rd€oü „¾"bl$ŽÛä#„¾BblŒcrl{
NodeMCU 3.0.0.0 built on nodemcu-build.com provided by frightanic.com
branch: master
commit: 8d091c476edf6ae2977a5f2a74bf5824d07d6183
release: 3.0-master_20200610
release DTS: 202006092026
SSL: false
build type: float
LFS: 0x0 bytes total capacity
modules: bme280,dht,file,gpio,i2c,mqtt,net,node,softuart,struct,tmr,u8g2,uart,wifi
build 2020-07-06 17:40 powered by Lua 5.1.4 on SDK 3.0.1-dev(fce080e)
Exception reset
EXCCAUSE 0
EPC1 1076054560
EPC2 0
EPC3 0
EXCVADDR 1076341284
DEPCàrl $Üž| Œlà|Œlìb|‚䲟|"ŒpŒp~òoŸloNÜãìcpŒŽ$r$rlpòoàƒl#oã|„ìŽã„bŒònoïl„ l on$`orŽ›’nä’`pûoàr„ÜœãàbNâ|ŒÛŽ"Œònoïl`2Nn$`orŽÛ’nãl`pûoàr„ÜœÂlbNâ|"Œònoïl`nol Nr²Ÿî„l r’ÛNŒ$`rƒ’›oä2’lŒŒäo~cc„p2roäN~BŽpâ€r$ûon¾ „noŸì’ƒ² ‚2Œonž 䛂“`~ƒb„noŸì’ƒ’ Œãä‚Nì|rƒòN|ì$ll B’ß|r“$Üoàƒoã l ŒÂœn‚l„l2„l`Œãr“lä$„l`Œãr’l¾Œl$`rl‚sl„ßâ„"ì„bŒBprœÂãBÜp$Ül äûoïoNâ d#$ŒŽ„l$l$Žì„Œ€$Žs$€oü ŒžãŒ#ll’ìc„ßâ„blŒcrl{
NodeMCU 3.0.0.0 built on nodemcu-build.com provided by frightanic.com
branch: master
commit: 8d091c476edf6ae2977a5f2a74bf5824d07d6183
release: 3.0-master_20200610
release DTS: 202006092026
SSL: false
build type: float
LFS: 0x0 bytes total capacity
modules: bme280,dht,file,gpio,i2c,mqtt,net,node,softuart,struct,tmr,u8g2,uart,wifi
build 2020-07-06 17:40 powered by Lua 5.1.4 on SDK 3.0.1-dev(fce080e)
External reset
Connecting to WiFi access point...
> Connection to AP(BTHub6-TPRH) established!
Waiting for IP address...
Wifi connection is ready! IP address is: 192.168.1.187
Startup will resume momentarily, you have 10 seconds to abort.
Waiting...
Running
sds_read 35072
sds_read 35072
sds_read 35072
I am using the Master branch of firmware from nodemcu-build.com
I have done some basic tests, such as unplugging the SDS011 connections, then I don't get any resets (or data of course).
Can anyone tell me where I am going wrong?
Thanks for any help you can offer!
Kris.