Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Frequent errors in .loop calls with CircuitPython 8 #124

Open
brucewinter opened this issue Oct 5, 2022 · 6 comments
Open

Frequent errors in .loop calls with CircuitPython 8 #124

brucewinter opened this issue Oct 5, 2022 · 6 comments
Labels
bug Something isn't working

Comments

@brucewinter
Copy link

brucewinter commented Oct 5, 2022

No problems with CircuitPython 7, but with 8 I get frequent errors in .loop calls, about 1 error for 5->10 0calls, done once a second.

This is my code:

def mqtt_connect():
    try:
        print("Connecting to mqtt server ...")
#       mqtt_client.connect()
        mqtt_client.reconnect()
        print('Connected :)')
        mqtt_subscribes()
    except Exception as e:
        print("mqtt connect error")
        print(e)

... in loop ...

       ...
        time.sleep(1.0)
        try: 
            mqtt_client.loop()   
        except (ValueError, RuntimeError) as e:
            print("Failed to get data, retrying\n", e)
            wifi.reset()
            mqtt_client.reconnect()
            continue
        except OSError as e:
            print('mqtt OSError')
            print(e.errno)
            print(e)
            print('reconnecting ...')
            mqtt_connect()
        except Exception as e:
            print('mqtt other error')
            print(e)
            print('reconnecting ...')
            mqtt_connect()

This is the error:

New message on topic sensor/Outside Temperature: 76.8
Temp Out: 76.8
mqtt other error

Connecting to mqtt server ...
Connected to mqtt server
Connected :)
Subscribed to ha/heartbeatM with QOS level 0
Subscribed to sensor/Outside Temperature with QOS level 0

I also tried wifi.reset() but got: 'module' object has no attribute 'reset'

The resulting error structure 'e' is empty. Any suggestions?

Thanks!

@tekktrik
Copy link
Member

tekktrik commented Oct 6, 2022

This may be related to #101 or #108

@brucewinter
Copy link
Author

Thanks for the pointers! I tried modifing the OSError check suggested at the end of #101 and the _wait_for_msg() instead of .loop from #108. Also tried the suggesions change the default timeout in _wait_for_msg from 0.1 to 1.0, from circuitpython issues #6988. None of these changes fixed my problem.

Note that this problem is only with Circuitpython 8, the same code works great withg Circuitpython 7. Also tried the lastest build of 8, same problem.

I forgot to mention I am using the Feather ESP32-S2 with TFT. I have some other Adafruit ESP32 boards arriving tomrrow that I will try as well.

Thanks again for the help.

@mopore
Copy link

mopore commented Oct 17, 2022

I experiencing the same with a Feather ESP32-S3 TFT and CircuitPython 8.0.0-beta.2.

@tekktrik tekktrik added the bug Something isn't working label Oct 18, 2022
@rdagger
Copy link

rdagger commented Oct 24, 2022

Same problem on QT PY ESP32-S2. Subscribing to a topic on Adafruit IO works reliably in CircuitPython 7.3.3 but unusable in CircuitPython 8.

  File "/lib/adafruit_minimqtt/adafruit_minimqtt.py", line 864, in loop
  File "/lib/adafruit_minimqtt/adafruit_minimqtt.py", line 894, in _wait_for_msg
�]0;�10.0.7.41 | 894@/lib/adafruit_minimqtt/adafruit_ MMQTTException | 8.0.0-beta.3�\

I couldn't even get the subscribe method to work until I hard coded a longer timeout. I tried zero and longer timeouts for the loop method, but nothing seems to work.

@GearlooseTechnology
Copy link

GearlooseTechnology commented Mar 9, 2023

This code will crash upon wifi reconnect.

try:
   self.client.loop()
except Exception as e:
   self.debug(f"Could not connect to MQTT broker")
   self.debug(e)
   self.client.reconnect(resub_topics=False)

I'm very sorry to say, but I have never experienced such a crappy library as this one. Random crashes and hangs everywhere.

@vladak
Copy link
Contributor

vladak commented Jan 31, 2024

I'm very sorry to say, but I have never experienced such a crappy library as this one. Random crashes and hangs everywhere.

To be fair, the library got more robust in the last year, so it is recommended to try the latest version. Also, it is evident from the above comments (running on CircuitPython 7 vs 8) that it sometimes is merely a victim of CircuitPython (CP) changes. All in all, the best thing is to approach the problems one by one and make sure they are being solved whether they are in the library or in CP or both.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

6 participants