I have the following very simple code which operates a lamp. It responds to internet commands when I power the system up, but after about an hour if I come back and try to operate it remotely it does not respond.
The lamp two buttons, one for Bright and one for Dim. The code works by sending it an integer which says which button to press and how long to hold it. The imp pulls the button down to ground to ‘press’ it.
The button to press is derived from the posted value’s ‘tens’ digit; if the value is less than 10, the press the brighten button, otherwise press the dim button. The duration is derived by taking the value mod 10, it hold the selected button low for that number of seconds.
I’m using imp.wakeup to set the time that the button is held low.
Why would this work for an hour, and then the imp stop responding??
Is there some longer term sleep mode that is getting activate automagically?
I’m wondering if this is some kind of “long poll” bug, where the imp thinks it’s got a connection to the server, and is happily listening but it really doesn’t?
To debug this, maybe I’ll try setting up a wakeup to poke some data to the server every ten minutes or something, and see if that fixes this.
I added this code which pings the server every five minutes, and that seems to keep the connection open indefinitely, at least I was able to come back after several hours and still remotely operate my lamp.
function watchdog() {
local now = date()
server.show(format(“watchdog ping %4d-%02d-%02d::%02d:%02d:%02d”,now.year, now.month, now.day, now.hour, now.min, now.sec))
imp.wakeup(300, watchdog)
}
watchdog()
My wifi router is one supplied by Verizon Fios. Maybe there is some issue with it holding the TCP long poll connection open for a long time?
The imp service keeps the connection open, there’s no need to send pings for that. The issue is that in the current release, if you don’t run some squirrel every hour or so (it doesn’t actually need to log), a buffer doesn’t get emptied and things grind to a halt on the imp.
Any squirrel at all will do - an event handler just has to be entered.