Disconnects and error handling

Moderators: adafruit_support_bill, adafruit

Forum rules
If you're posting code, please make sure your code does not include your Adafruit IO Active Key or WiFi network credentials.
Locked
User avatar
IamNabil
 
Posts: 2
Joined: Wed Nov 24, 2021 11:19 am

Disconnects and error handling

Post by IamNabil »

Hey folks! I am SUPER DUPER new to circuit python, but have managed to cobble together an environmental sensor package that I intend to put on my boat in the spring. It's an ESP32-S2 feather with a 1306 OLED panel and a BMP280, among other things. It connects to Adafruit IO, and pushes my data, and runs and runs, and everything is fine. However, every 12-36 hours, it will drop offline. The last message I see on the OLED is a complaint about a handshake, and when I hit the reset button, everything reconnects and is fine for another 12-36 hours.

My question is this: what is the proper way to handle this error? Is it possible to have the device automatically reset when it has a network error? I couldn't find any good docs about error handling, when I search for it, I just get the generic troubleshooting guide, and that doesn't help me here.

User avatar
brubell
Learn User Page
 
Posts: 2017
Joined: Fri Jul 17, 2015 10:33 pm

Re: Disconnects and error handling

Post by brubell »

. However, every 12-36 hours, it will drop offline. The last message I see on the OLED is a complaint about a handshake, and when I hit the reset button, everything reconnects and is fine for another 12-36 hours.
Are you able to obtain the error from the REPL? Can you copy and paste it here?

User avatar
T_Mo
 
Posts: 92
Joined: Thu Mar 15, 2018 7:10 pm

Re: Disconnects and error handling

Post by T_Mo »

I'm interested in this topic also, I can post an applicable exception error if needed.

User avatar
Rcayot
 
Posts: 321
Joined: Sat Feb 08, 2020 6:48 pm

Re: Disconnects and error handling

Post by Rcayot »

I am also interested. Occasionally my internet (satellite based) goes offline due to weather etc. When this happens the error crashes the program running the code to post data on AIO. I would like to know how to trap that error and reconnect automatically say every hour or so,

Roger Ayotte

User avatar
jwcooper
 
Posts: 1004
Joined: Tue May 01, 2012 9:08 pm

Re: Disconnects and error handling

Post by jwcooper »

Here is a fairly comprehensive demo of how you can make it a bit more resilient:
https://gist.github.com/tylerdcooper/91 ... d8eb1a5fce

Notice most networking calls are wrapped in try/except blocks, each block handling things in different ways. Reading from i2c devices is also wrapped in try/except and handled to prevent crashes.

This particular sketch goes into a deep sleep and there is no loop, as it's way easier than trying to maintain connection state. Once the device wakes up (every 180 seconds), it just starts all over again from the top, any critical errors, and it goes back to sleep to try again.

If you wanted to do this in a loop and not sleep, you'd need to check if wifi is still connected, etc (if not re-run the connect function, etc).

User avatar
IamNabil
 
Posts: 2
Joined: Wed Nov 24, 2021 11:19 am

Re: Disconnects and error handling

Post by IamNabil »

brubell wrote:
. However, every 12-36 hours, it will drop offline. The last message I see on the OLED is a complaint about a handshake, and when I hit the reset button, everything reconnects and is fine for another 12-36 hours.
Are you able to obtain the error from the REPL? Can you copy and paste it here?
I am able to see most of it on the OLED screen. It's an SSL handshake error. I bought an adalogger, so I'll try to have the logs export. Lately, it's been every couple of days, so it may be a bit before I am able to get it to crash again.

I apologize for not replying earlier, I had notifications turned off, and didn't know anyone had responded.

Locked
Forum rules
If you're posting code, please make sure your code does not include your Adafruit IO Active Key or WiFi network credentials.

Return to “Internet of Things: Adafruit IO and Wippersnapper”