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

Recurring exception in loop() function #177

Open
heximcz opened this issue Sep 23, 2023 · 3 comments
Open

Recurring exception in loop() function #177

heximcz opened this issue Sep 23, 2023 · 3 comments

Comments

@heximcz
Copy link

heximcz commented Sep 23, 2023

After updating MiniMQTT from version 7.3.2 to 7.4.1, I have a problem with the loop() function, which, upon closer investigation, throws an MMQTTException (this issue occurs every second call). The exact link where the error occurs is here: L1035. For my purposes, I am modified the line to return an error.

raise MMQTTException(f"OSError: error: {error}, errno: {error.errno}.")

Here is a snippet from the testing code:

    try:
        # check if subscribes is enabled
        if mqtt.is_subscriber():
            try: 
                mqtt.mqtt_client.loop()
            except MQTT.MMQTTException as e:
                print('MQTTException ...')
                print(e)
            else:
               print ('Loop OK ...')

        # BME680
        pub_data = dict({})
        pub_data["temperature"], \
            pub_data["humidity"], \
            pub_data["pressure"], \
            pub_data["gas"], \
            pub_data["altitude"], \
            pub_data["dewpoint"] = bme680.get_measurement(dew_point=True)

        # pub values from sensor
        mqtt.pub(pub_data)

        # wait one minute
        time.sleep(60)
    except KeyboardInterrupt as e:
        print("Keyboard exit!")
        import sys
        sys.exit()
    except:
        microcontroller.reset()

Here is the output from Thonny's debugging console:

Attempting to connect to broker.
Connected to MQTT Broker!
Flags: 0
RC: 0
Subscribed to <topic> with QOS level 0

MQTTException ...
OSError: error: -116, errno: -116.
RAW T: 34.2737, CPU T: 31.3517
T: 30.7, RH: 100, hPa: 642, Gas: 430446, Alt: 347, Dew: 30.7
Published to <topic> with PID 1

Loop OK ...
RAW T: 30.9062, CPU T: 31.3517
T: 27.6, RH: 51, hPa: 1018, Gas: 482123, Alt: 218, Dew: 16.6
Published to <topic> with PID 1

MQTTException ...
OSError: error: -116, errno: -116.
RAW T: 29.5876, CPU T: 30.8835
T: 26.4, RH: 55, hPa: 1018, Gas: 449328, Alt: 218, Dew: 16.6
Published to <topic> with PID 1

...

In version 7.3.2, the loop() function worked without any issues. From what I have investigated, it appears that the error is not affected by whether I am using the original CircuitPython 8.0.5 or the latest version 8.2.6.

Links to my complete example code and the MiniMQTT wrapper.

Hardware:
Raspberry Pico W

Broker:
Mosquitto 2.0.18

Can I modify my code as I'm writing below, but it doesn't seem very elegant to me, especially since it worked in the previous version.

try:
    mqtt.mqtt_client.loop()
except MQTT.MMQTTException as e:
    pass       

Thank you and have a great day!

@vladak
Copy link
Contributor

vladak commented Oct 25, 2023

The negative errno value was reported on #101 (comment) and supposedly fixed in CP 8.0.0 beta specifically for Pico W (#101 (comment)).

@heximcz
Copy link
Author

heximcz commented Nov 17, 2023

Hello Vladak,
I don't have a problem with CP. A newer version of Adafruit_CircuitPython_MiniMQTT than 7.3.2 does not work for me. Now I try the latest version of CP and Adafruit_CircuitPython_MiniMQTT and the problem is still the same. I had to revert to Adafruit_CircuitPython_MiniMQTT 7.3.2.

@schaefer01
Copy link

in loop() the call to receive generates an exception from if nothing is received but its ok for nothing to be received if nothing was sent.

loop() ->_wait_for_msg() ->_sock_exact_recv(1

I'm going to patch by adding a parameter to _wait_for_msg() to return silently if there's no data received
and only set this in the loop call

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants