Imp no longer responsive after an hour or less

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?

Here is the source code

` hardware.pin9.configure(DIGITAL_OUT_OD); hardware.pin1.configure(DIGITAL_OUT_OD);

class brightnessInput extends InputPort
{
name = “brightness control”
type = “float”

function set(value)
{
local cmd = value.tointeger()
local button = math.floor(cmd/10)
local time = cmd % 10
if (button == 1) {
hardware.pin9.write(0);
server.show(“pulsed pin9”)
} else {
hardware.pin1.write(0);
server.show(“pulsed pin1”)
}
imp.wakeup(time, buttons_up );
}
}

function buttons_up() {
hardware.pin1.write(1);
hardware.pin9.write(1);
server.show(“buttons up”)
}

// Register with the server
imp.configure(“Net Lamp”, [ brightnessInput() ], );

server.show(“Hello! BritePlanet has booted up!”);
buttons_up();

// End of code.`

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.

When’s the next release scheduled? And how do I update the firmware? Will it automatically update if I recompile and run my code?

Also, until then, what is the simplest ‘keepalive’ code? just a call to imp.wakeup() calling an empty function?

The firmware will update when we push the new release and your imp cold-boots.

Simplest workaround code:

function watchdog() { imp.wakeup(60*60, watchdog); } watchdog();