Power state, how to keep it on

My imp likes to turn off after a bit, the power state going to “offline” after a short time, 15-20min. Is there a way to change that? I really would like it to stay on a couple hours at a time. I think 24hours would be great, but I can work around a couple hours. Any thoughts?

It shouldn’t be going offline at all; the server only marks an imp as offline when it doesn’t reply to a server ping. We have units that have been up for months (they’ll go offline-online briefly during server updates, but remain connected)… and the intent is that they will, bugs permitting, never go offline if the application requires that.

Typically you see imps going offline if you are using infinite loops in your code (any while(1)'s, for example, or long imp.sleep() calls). The imp needs to “fall off” the end of your code back into the event processing loop in order for network traffic to be processed. Anything in your code that might be causing that problem?

Does it need to do anything at all? Is a loop necessary to keep it awake? I have a test imp that just has a program that shows the state of the imp (MAC, wifi, power, mem, etc). It has no loop or anything, the program just runs and ends.
But if I want to rerun it from the planner after a while, it has gone offline. I need to power it up again to have it show its status.

This is my code:
imp.configure(“What’s my status?”, [], []);
server.show(format(“Impee ID: %s”, hardware.getimpeeid())) ;
server.show(format(“Supply voltage: %f”, hardware.voltage()));
server.show(format(“Signal: %d dBm”, imp.rssi()));
server.show(format(“BSSID: %s”, imp.getbssid()));
server.show(format(“MAC: %s”, imp.getmacaddress()));
server.show(format(“Memory available: %d bytes”, imp.getmemoryfree()));
// End of code.

I too am having an issue with this. Last night when I came home, my unit was unresponsive and the node log indicated it was offline, so I reset it and worked with it last night. This morning I see it went offline at 8 am EST and it is again unresponsive (according to the planner). No loops in mine, just looking for an input from the web to change a port state. I don’t have the logs from 2 days ago, but I have from yesterday:
1/14/2013 9:48:35 PM: Device booting
1/15/2013 8:01:04 AM: Power state: online=>offline

I suppose the power supply could be bad or unstable. That was going to be my next step, but I happened to see this thread.

Most likely, you’re running into a NAT timeout, ie your router has torn down the NAT because your connection appears to be idle. We currently have server-initiated pings, where the server will ping all connected devices and mark them offline if they don’t respond (this is what generates the offline transition you’re seeing). This generates bidirectional traffic, but there’s a hole…

If your imp isn’t sending any messages, it doesn’t know the NAT has gone; the TCP stack still thinks the link is up (just very quiet); it’ll find out when it tries to transmit something and gets a TCP RST from the gateway at which point it’ll reconnect.

We do have client-initiated pings implemented, they’re just not yet enabled. Until then, you can workaround this issue with a little bit of code like this:

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

// start sending something every ~5 minutes

woah! Started some talk now.

Thanks for the watchdog stuff. should help.

Tonight, mine started to act worse, even with the watchdog code. It was starting to go offline every 10-20 minutes. The interesting thing was that even after the log reported “Power state: online=>offline”, “watchdog” would still keep getting reported after, but the impee remained unresponsive to my HTTP IN requests until reboot.

However, after a “imp OS upgraded” came though, it has been acting fine ever since.

Yep, server side and client side fixes. Please keep a close eye out for any other errant behavior and let us know if you see any.

Interesting. I have been seeing similar behavior. Imp could send data out no problem but after a long idle period it would not respond to a http push.

Ill try Hugo’s code fix.

Same problem - goes offline after 15 min. even when there’s activity. I have the watchdog code running as well. Am I missing something here? I’m sure I have the latest fixes with the autoupgade.

There still appears to be a corner case that’s problematic, but we think it’s server-side. Working on it!

Thanks Hugo. Here’s the server log from this morning if it helps with your debugging. It went offline for 15 min at 7:50 and came back online, went off again after 10 min.

Friday, January 18, 2013 07:42:48: watchdog
Friday, January 18, 2013 07:42:58: watchdog
Friday, January 18, 2013 07:50:18: Power state: online=>offline
Friday, January 18, 2013 08:05:17: Power state: offline=>online
Friday, January 18, 2013 08:05:17: Device booting
Friday, January 18, 2013 08:05:18: Device configured to be "UartCrossAir"
Friday, January 18, 2013 08:05:18: watchdog
Friday, January 18, 2013 08:05:28: watchdog
Friday, January 18, 2013 08:05:38: watchdog
Friday, January 18, 2013 08:05:48: watchdog
Friday, January 18, 2013 08:05:58: watchdog
Friday, January 18, 2013 08:06:08: watchdog
Friday, January 18, 2013 08:06:18: watchdog
Friday, January 18, 2013 08:06:28: watchdog
Friday, January 18, 2013 08:06:38: watchdog
Friday, January 18, 2013 08:06:48: watchdog
Friday, January 18, 2013 08:06:58: watchdog
Friday, January 18, 2013 08:07:08: watchdog
Friday, January 18, 2013 08:14:37: Power state: online=>offline

Were the watchdog logs supposed to be coming out every minute? Strange that there were 7 minutes of them missing before the server marked you offline. Hmm.

We’ll take a look at the logs at our and and see if we can work out what’s happening with your imp.

I set watchdog to check every 10 secs actually. Not sure why nothing was logged for 7 min before going offline.

I just noticed that the same thing happened when it was marked offline at 07:50:18 as well. Nothing was logged from watchdog for about 7 mins then too!

I have the same problem! Using the imp to control LED lights in my kitchen using PWM via HTTPin (dimming depending on value sent via HTTP). Although my lights remain on (so the Imp continues to output a PWM signal) I cannot get access to the Imp after some time. I have not yet figured out after how much time it gets unresponsive but when I turn the kitchen light to a low setting before going to bed, I am sure to find the Imp being unresponsive the next morning.

@moose: Have you seen this in the last day?

Unfortunately: yes. See below log of last action by me (16:24:39) and spontaneously going offline of Imp on 05:47:58.
19 januari 2013 16:24:39 CET: LED freq 100 Hz, duty cycle 1.000
20 januari 2013 05:47:58 CET: Power state: online=>offline

@moose: According to the logs, your imp missed a ping and hence the connection was closed. Does the imp send anything, or is it receive only?

It is receive only.