konnected-io / konnected-security

Konnected connects wired sensors and switches to SmartThings, Home Assistant, Hubitat and OpenHAB
https://konnected.io
Apache License 2.0
418 stars 323 forks source link

PANIC: unprotected error in call to Lua API (/opt/nodemcu-firmware/local/fs/httpd_req.lua:26: bad argument #2 to 'sub' (number expected, got nil)) #74

Closed bazza2000 closed 5 years ago

bazza2000 commented 6 years ago

Setup a new NodeMCU running Konnected. Install, WIFI setup and initial Home Assistant (0.81.5) upload/programming all worked fine, however, after restart home assistant for a non-konnected updated (just adding some known-devices) I now get the following every 20-30 seconds and then it resets (and continues to reset every 20-30 seconds):


Heap:   27968   UPnP:   Sent SSDP NOTIFY
PANIC: unprotected error in call to Lua API (/opt/nodemcu-firmware/local/fs/httpd_req.lua:26: bad argument #2 to 'sub' (number expected, got nil))

During the time between boot and reset I've tested a single door sensor is working, this is output from such a test:


Heap:   31432   Initialized actuator Pin:       5       Trigger:        1      Initial state:   0
Heap:   31744   HTTP Call:      200     state   1       pin     1
Heap:   31808   HTTP Call:      200     state   1       pin     2
Heap:   31912   HTTP Call:      200     state   1       pin     5
Heap:   32008   HTTP Call:      200     state   1       pin     6
Heap:   32080   HTTP Call:      200     state   0       pin     5
Heap:   27968   UPnP:   Sent SSDP NOTIFY
PANIC: unprotected error in call to Lua API (/opt/nodemcu-firmware/local/fs/httpd_req.lua:26: bad argument #2 to 'sub' (number expected, got nil))

What I've found is that subsequent home assistant restarts and uploads make it stable again (i.e. no resets) then further home assistant restarts (all just basic configuration updates to non-konnected devices) might cause it to go in to the PANIC loop again.

Happy to run diagnostics if anyone can give me the details as I can pretty readily recreate.

heythisisnate commented 6 years ago

Based on the line number of the panic error, it looks like this is being caused by a HTTP request from some device on your network that may be malformed. Do you have anything set up that would be pinging the Konnected device?

bazza2000 commented 6 years ago

Hi nate, thanks for the quick response. Yeah, could be another device, although I have about 50 on my network, so I need to narrow it down, is there any way for me to add debug so I can print the source ip of the request?

bazza2000 commented 5 years ago

Fix identified in pull request #76 Tested for over 4 days now, been stable which has included numerous hassio updates and hence re-download of settings etc which was the usual cause of the panic.

heythisisnate commented 5 years ago

Thank you for identifying and fixing! This fix has been incorporated in release 2.2.5.