Problem consistently communicating with Adafruit.io data dashboard

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.
User avatar
femur
 
Posts: 30
Joined: Sun Jan 22, 2012 9:53 pm

Problem consistently communicating with Adafruit.io data dashboard

Post by femur »

Hello,

I've been having this ongoing problem in one of my high school classes. We're doing some IoT data monitoring on a variety of plants. Everything seems to work well for a couple of days, after which the microcontroller starts flashing red and needs to be reset to begin posting data again. There seems to be an MQTT failure. Upon reset, everything is fine again for another couple of days.

I've tried a "Try, Except" statement to avoid the error and even a hard microcontroller reset when the failure happens. It must be the code because it's happening on all devices. I'm using the ESP32-S2 Feather with circuit python. An example of the code can get seen here: https://github.com/LWHSTechnicalArts/De ... sensors.py

Thank you for any advice!

User avatar
mikeysklar
 
Posts: 13824
Joined: Mon Aug 01, 2016 8:10 pm

Re: Problem consistently communicating with Adafruit.io data dashboard

Post by mikeysklar »

Are you able to capture the failure on a REPL console?

Would it be crazy to reset the devices every night at midnight? While that is not a resolution to the issue it avoids the worse case scenario of code crashing on its own and not coming back.

User avatar
femur
 
Posts: 30
Joined: Sun Jan 22, 2012 9:53 pm

Re: Problem consistently communicating with Adafruit.io data dashboard

Post by femur »

Thank you for your reply. It's hard to capture in the REPL since I have to keep it plugged into a computer for a couple of days before it happens.

Resetting at midnight or after a certain time is an option; I'm just wondering why that might be necessary. I'm wondering if there's something I don't understand about communication using the MQTT protocol with the adafruit.io site. We're well under the data limits. It there may be something in the MQTT library that's timing out?
It seems to be pretty consistently happening around 36 hours into operations. But I'm not sure of the exact timing.

User avatar
mikeysklar
 
Posts: 13824
Joined: Mon Aug 01, 2016 8:10 pm

Re: Problem consistently communicating with Adafruit.io data dashboard

Post by mikeysklar »

My guess would be a possible memory leak if the time to required reset is consistently in the 36 hours zone. You could explore it further with GC.

If you have a Raspberry Pi handy that can work well for trying to catch REPL crashes by plugging your boards into a Pi and having a remote console which can save everything.

User avatar
femur
 
Posts: 30
Joined: Sun Jan 22, 2012 9:53 pm

Re: Problem consistently communicating with Adafruit.io data dashboard

Post by femur »

Ahhh yes. This does seem like a strong possibility. I'll do some of the research you suggest. Thank you for these excellent suggestions!

User avatar
prabhu27390
 
Posts: 1
Joined: Tue Apr 04, 2023 1:11 am

Re: Problem consistently communicating with Adafruit.io data dashboard

Post by prabhu27390 »

Hi can someone help me to publish json document in adafruit mqtt server.

User avatar
adafruit_support_bill
 
Posts: 88037
Joined: Sat Feb 07, 2009 10:11 am

Re: Problem consistently communicating with Adafruit.io data dashboard

Post by adafruit_support_bill »

@prabhu27390 - Your post is off-topic. Please start a new thread for your question.

User avatar
femur
 
Posts: 30
Joined: Sun Jan 22, 2012 9:53 pm

Re: Problem consistently communicating with Adafruit.io data dashboard

Post by femur »

Hi,
I'm still having the same issue consistently posting to an adafruit.io feed or dashboard. Everything works for a number of hours (usually between 12 and 48 hours), but then I get an MQTT error. I've been running the code with a debug window open and I'm getting this error (also attached as screenshots with more detail) :

- MMQTTExeception: PINGESP not returned from broker.
or
- OSError [Errno 128] ENOTCONN

I'm using Adafruit ESP32 Feather V2 - 8MB Flash + 2 MB PSRAM - STEMMA QT.
It's happening to me in my class with more than a dozen of these controllers.

It happens even with the suggested example like this one (I changed it to post every 100 seconds)
https://github.com/adafruit/Adafruit_Ci ... esp32s2.py

I tried using the:
gc.collect()
end_mem = gc.mem_free()
and I'm not seeing memory issues.

I've also tried resetting the microcontroller every few hours and using a try...except statement to bypass the error.

I'm stumped? Any more advice out there? Thank you!
Attachments
Screen Shot 2023-04-03 at 8.20.08 AM.png
Screen Shot 2023-04-03 at 8.20.08 AM.png (33.02 KiB) Viewed 587 times
Screen Shot 2023-04-03 at 1.39.18 PM.png
Screen Shot 2023-04-03 at 1.39.18 PM.png (29.99 KiB) Viewed 587 times

User avatar
mikeysklar
 
Posts: 13824
Joined: Mon Aug 01, 2016 8:10 pm

Re: Problem consistently communicating with Adafruit.io data dashboard

Post by mikeysklar »

Good job catching both error messages.

What does your try/except logic look like are you catching OSError?

Code: Select all

try:
    # replace this with whatever call is on line #102 of your code
  except OSError as error:
    print(error)
    print("can't stop me now")
Are you running CircuitPython 8.0.5 stable with current libraries?

User avatar
femur
 
Posts: 30
Joined: Sun Jan 22, 2012 9:53 pm

Re: Problem consistently communicating with Adafruit.io data dashboard

Post by femur »

Thank you! I'm running circuit python 8.0.4 stable with matching libraries. However, when I first encountered the problem, I was running version 7 (which is to say I've tried both)

This is what I've been doing for the try except:

Code: Select all

	try:
            mqtt_client.loop()
        except:
            print ("mqtt fail")
            microcontroller.reset()
            time.sleep(30)
            pass

User avatar
mikeysklar
 
Posts: 13824
Joined: Mon Aug 01, 2016 8:10 pm

Re: Problem consistently communicating with Adafruit.io data dashboard

Post by mikeysklar »

Use my error try/except which should help get passed that form of crash.

I would also try being more explicit and see if it makes a difference with MQTT.

Code: Select all

try:
            mqtt_client.loop()
        except MMQTTExeception as mqttissue:
            print (mqttissue)
            print (“trying again…mqtt issue”)

Also it would be a good idea to update to the current libraries and CircuitPython so we can look into opening an issue with the github repo should the behavior continue after these minor try/except changes.

User avatar
femur
 
Posts: 30
Joined: Sun Jan 22, 2012 9:53 pm

Re: Problem consistently communicating with Adafruit.io data dashboard

Post by femur »

Thank you. I'll try this over the next days and let you know. Appreciate your help.

User avatar
mikeysklar
 
Posts: 13824
Joined: Mon Aug 01, 2016 8:10 pm

Re: Problem consistently communicating with Adafruit.io data dashboard

Post by mikeysklar »

Looking forward to seeing what you find. My experience has been you need to be explicit with the except error catching and cannot use an empty except line.

User avatar
femur
 
Posts: 30
Joined: Sun Jan 22, 2012 9:53 pm

Re: Problem consistently communicating with Adafruit.io data dashboard

Post by femur »

Hello!
I'm still running into problems after about 48 hours of data posting. Now I'm getting the following error: 'MMQTTException' is not defined.
I did update to circuitpython 8.0.5 with the matching libraries.
Ideas?

Thank you!
Attachments
Screen Shot 2023-04-20 at 3.00.56 PM.png
Screen Shot 2023-04-20 at 3.00.56 PM.png (16.61 KiB) Viewed 495 times
Screen Shot 2023-04-20 at 12.57.51 PM.png
Screen Shot 2023-04-20 at 12.57.51 PM.png (22.79 KiB) Viewed 495 times

User avatar
mikeysklar
 
Posts: 13824
Joined: Mon Aug 01, 2016 8:10 pm

Re: Problem consistently communicating with Adafruit.io data dashboard

Post by mikeysklar »

MMQTTException is misspelled. Remove the extra 'e'.

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”