Infinite loop

I didn’t read enough about the imp before I started programming. I wrote a simple program to increment a variable and display the value on the node.

local i=0; do{ for(local a=0;a<50;a+=1) //loop 5 seconds { imp.sleep(0.1); }; i++; } while(1)

This is an infinite loop. I now see instructions not to do this. Ooops. The log says Power state: online=>offline.

My question is this: How do I recover? Do I just cycle power on the imp? My concern is that when I cycle the power, it will just run the same program and go offline again.

I am running it remotely. Is there any way to reset the imp remotely when it goes offline like this?

Just edit the code, save it, then power cycle the imp. It will load the new code.

There is not a way to reset it remotely when it goes offline like this, no. Whilst that’d be nice, and maybe we will have some way of forcibly suspending code that runs for too long on the imp without running the network stack, right now the imp OS keeps out of the way when user code is running so that there are few surprises with execution performance.

Is an external HW watchdog, that cycles power to the imp still the only solution to a while(1); like situation?

If so, I am interested to know how others have done it. Thanks.


Well, apart from avoiding infinite loops in your code…

As I said, we can detect such conditions and restart the squirrel, but that isn’t in a release currently.