adafruit / Adafruit_CC3000_Library

Library code for Adafruit's CC3000 WiFi breakouts &c
http://www.adafruit.com/products/1469
Other
270 stars 153 forks source link

intermittant hangs in read loop #148

Closed dzzie closed 9 years ago

dzzie commented 9 years ago

I have a project that runs 24x7 and uploads stats every 30 minutes. a couple times a week I find the system hung with the display showing its stuck in the read loop.

I have implemented a internal watchdog and the hang is severe enough to even lock that up so no reset is occurring. Has anyone else encountered similar behavior?

external watchdog comes next I guess.

ref: https://github.com/dzzie/humidor.net/blob/master/Arduino/humidor/humidor.ino#L424

simplified:

  startTime = millis(); //unsigned long
 #define IDLE_TIMEOUT_MS 7000 

  while (www.connected()) {

    if( (millis() - startTime) > IDLE_TIMEOUT_MS ) break;

    while (www.available()) {

        if( (millis() - startTime) > IDLE_TIMEOUT_MS ) break;

        char c = www.read();
        ...

    }
  }

  wdt_reset();
vicatcu commented 9 years ago

FWIW, I implemented an external watchdog (using an ATtiny85) on WildFire, largely to cope with this sort of thing. Not the most elegant solution perhaps, but certainly effective.

dzzie commented 9 years ago

including an external watchdog right on the wifi board is a great design. covers allot of bases for just a few extra cents.

Given that network and wifi stuff can be problematic and the complexity of all of the code going on behind the scenes the simplicity of the "fix" and the peace of mind it gives for stability I would say it is an elegant inclusion.

I think it would be great to have one built into the adafruit board as well.

the only premade external watchdog i was able to find is the Switchdoc labs watchdog which has a large footprint and is pretty pricey ($16).

http://www.amazon.com/SwitchDoc-Labs-WatchDog-Arduino-Raspberry/dp/B00OL1N7R2/ref=sr_1_2?ie=UTF8&qid=1442575011&sr=8-2&keywords=dual+watchdog

I also found a couple open source designs for external ones but I was being lazy and just went with the premade one for now to keep the project rolling.

https://github.com/mattbornski/Arduino-Watchdog-Circuit

vicatcu commented 9 years ago

I used an ATtiny85 (probably a smaller variant would do, and I wrote a custom firmware to make it a configurable watchdog. Code is here https://github.com/WickedDevice/TinyWDT . And an arduino library to configure/interact with it. Code is here https://github.com/WickedDevice/TinyWatchDog. On Sep 18, 2015 7:23 AM, "David Zimmer" notifications@github.com wrote:

including an external watchdog right on the wifi board is a great design. covers allot of bases for just a few extra cents.

Given that network and wifi stuff can be problematic and the complexity of all of the code going on behind the scenes the simplicity of the "fix" and the peace of mind it gives for stability I would say it is an elegant inclusion.

I think it would be great to have one built into the adafruit board as well.

the only premade external watchdog i was able to find is the http://www.amazon.com/SwitchDoc-Labs-WatchDog-Arduino-Raspberry/dp/B00OL1N7R2/ref=sr_1_2?ie=UTF8&qid=1442575011&sr=8-2&keywords=dual+watchdog http://Switchdoc%20labs%20watchdog which has a gigantic footprint and is pretty pricey ($16).

— Reply to this email directly or view it on GitHub https://github.com/adafruit/Adafruit_CC3000_Library/issues/148#issuecomment-141422529 .

dzzie commented 9 years ago

nice thanks for sharing

matthijskooijman commented 9 years ago

@dzzie, your code looks ok to me, none of the methods you are calling should block and the handling of millis seems sound. If the internal WDT (at least on AVR) does not help, then either you're still calling wdt_reset often enough, or there is a hardware problem. AFAIK there is nothing you can do in software to prevent the WDT from working (apart from accidentally disabling it, of course). The most likely candidate for a hang like this would be low voltage / brownout, possible caused by insufficient current capability in the power supply.

It would probably help to confirm where the CPU is looping exactly, or if it is even running at all (leds and debug output would help there, I gues).

dzzie commented 9 years ago

ok I will try running it for a while off of a bench power supply plugged into a UPS to eliminate variables from wall wart and ripples from power company.

so just to confirm these boards are known to be solid for long duration runs without intermittent hangs?

I wasnt sure if the internal watchdog could be corrupted and hang up or if all the code within the CC3000 could freeze up and cause this. This bug has been driving me crazy. Thanks for the response.

matthijskooijman commented 9 years ago

so just to confirm these boards are known to be solid for long duration runs without intermittent hangs?

Not sure what board you are using, but I've used Arduino boards for longer periods without any problems, yes.

dzzie commented 9 years ago

sorry meant the Adafruit CC3000 WiFi Shield + UNO

dzzie commented 9 years ago

I will close this out, regardless of cause, having the security of an external watchdog seems like the best solution and has prevented any long lasting freezes perfectly since implemented.