So I've posted about a couple of issues with the wifi seeming to get locked up. Seemed like the WDT was a reasonable solution. My code can't get to my WiFiReset function if it's hung up in some wifi call. So I am using the WDT Enabled version of the board from the Arduino Board menu. I had something of an issue when doing the initial development work, in that if I had rebooted the board, but it was waiting for me to enter something in the serial console, it would reboot, and that was annoying.
I thought I had solved that issue by including code like this:
void setup ( )
{
WDT_Disable(WDT);
unsigned long wdp_ms = 2048;
unsigned long wst;
pinMode ( WiFiResetPin, OUTPUT );
pinMode ( LEDPin, OUTPUT );
digitalWrite ( WiFiResetPin, HIGH );
digitalWrite ( LEDPin, LOW );
ResetWiFi ( );
Serial.begin ( 9600 );
while( !Serial.available ( ) )
{
Serial.println ( "Enter any key to begin" );
delay ( 1000 );
}
WDT_Enable( WDT, 0x2000 | wdp_ms | ( wdp_ms << 16 ));
wst = millis ( );
do
{
if ( millis ( ) - wst > 5000 )
{
DebugOutLn ( "Error connecting to WiFi network" );
ResetWiFi ( );
ImStillAlive ( );
wst = millis ( );
}
delay ( 10 );
} while ( wifi.ready ( ) != 1 );
BTW, my ImStillAlive function does two things: it toggles the built-in LED on pin 13, and it calls WDT_Restart ( WDT ); and that's the only call to WDT_Restart in the code.
So I'm surprised that my project still seems to lock up (it's powered by a 9V, 1A supply, BTW), I can see that the LED has stopped flashing completely. But the board doesn't ever seem to reboot!
Can you see anything wrong with my approach?