Does anyoone know how I can have the sketch trigger itself to re-start, including re-running the setup() and re-initializing all globals... from an action in the sketch itself?
I know I can do something with "reset-mcu" on the Linino side. But, I want to have the sketch itself be able under some catastrophic condition to just restart all over.
When you wish to reset the chip under sketch control, just enable the watchdog timer and let it time out while you wait in a while loop. This is the only 100% complete way (using only software) to have a sketch start from scratch under user control..
Following the link above, I did #include <avr/wdt.h>
and at the end of setup() I put
wdt_enable(WDTO_2S);
and at the beginning of loop() I put
wdt_reset();
In the loop() I toggle the LED every second and that continues to work, but reading sensors and writing the data to the SD card does not work. If I comment out wdt_enable(WDTO_2S) and wdt_reset() everything works again. I have not done a lot of debugging yet, but just wanted to verify if anybody had the watch dog timer working correctly on Yun.
To answer my own question, it seems to work just fine on Yun.
Digging a little deeper in my code, I realized that it took more that 2 sec to read all my sensors. That triggered the WDT so the code never reached the point of writing the values to the SD.