Thanks for taking the time to respond, gogol.
Different people have different ideas about how to use a forum. Sometimes people complain when a thread talks about too many different issues. I've looked back at the threads I've started, and those I've contributed to, and I still feel that they are more valuable organized that way:
Is there a way to do a "hard" reset in software? -- seems like something someone might also be curious about
What's the right way to recover from a failed client connection? -- again, this seems like a potentially interesting topic to others, but different from the above
Help with WatchDog? -- this thread uncovered a useful nugget, at least from my perspective. Maybe it's common knowledge elsewhere that you can only set the WDT mode once, but it was news to me.
Certainly from *my* perspective, they are all part of the longer story of the development of my particular application, but I personally don't think that a single long thread per person, documenting all the issues they ran into while building their particular device, is better from the perspective of someone browsing the forum.
I have coded the Pin 106 wifi reset. I made the solder jumper mod. My code calls my reset function when it detects a network error. My problem is, the code can't get to the wifi reset function when it is hung. I was certainly hoping that the wifi reset would be a viable solution, but I am no longer getting the timeouts I was. I now get hung, and often it's just very early in setup when waiting for wifi -- it appears to get hung in wifi.ready. Here's my setup function:
#define WiFiResetPin 106
#define LEDPin 13
void setup ( )
{
#if defined DEBUG
WDT_Disable(WDT);
#endif
unsigned long wdp_ms = 2048;
unsigned long wst;
pinMode ( WiFiResetPin, OUTPUT );
pinMode ( LEDPin, OUTPUT );
digitalWrite ( WiFiResetPin, HIGH );
digitalWrite ( LEDPin, LOW );
ResetWiFi ( );
DebugOutLn ( "Starting setup..." );
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 );
DebugOutLn ( "Connected to wifi!" );
}
And here's ResetWiFi:
void ResetWiFi ( void )
{
int i;
// requires SJ4 to be soldered closed (non-default) and SJ3 to be cut open (default)
DebugOutLn ( "* * * * Resetting WiFi module! * * * *" );
digitalWrite ( WiFiResetPin, LOW );
delay ( 15 );
digitalWrite ( WiFiResetPin, HIGH );
wifi.begin ( 9600 );
for ( i=0; i<100; i++ )
{
ImStillAlive ( );
delay ( 20 );
}
}
And ImStillAlive:
void ImStillAlive ( )
{
static bool ledon=false;
WDT_Restart ( WDT );
ledon = !ledon;
digitalWrite ( LEDPin, ledon ? HIGH : LOW );
}
I could explain what my code is doing later on in the loop function, but I rarely get past setup. I will see the "Starting Setup" string, but only occasionally "Connected to wifi" and never "Error connecting to WiFi network" so I'm inclined to believe that it's hung in a call to wifi.ready. In general terms, it's a client application, retrieving a web page. There are 2 different sites, and 3 different URLs altogether, but I only retrieve one at a time. There should only be a single connection open, and if I get an error on a connection I would call the reset function.
And my real concern here is that this part used to work pretty reliably. It used to occasionally fail to connect. And as I noted elsewhere, moving to an external power supply didn't help (it is always on external power now, and I've tried a couple of different adapters).
So I would consider trying Erik's suggestion of chunking, if it can fit with the library I'm using, but nobody has followed up to give me a pointer to what sample that is. I follow the github repo, but none of the examples use the word "chunked" in their name or description. And more importantly, I'm not getting past setup 90% of the time or more.