From c493c7b945a388a20e322e537dd0522ab9566ce8 Mon Sep 17 00:00:00 2001 From: Leland Sindt Date: Sun, 18 Feb 2024 12:51:07 -0600 Subject: [PATCH] Add `timeout` value. Add `timeout` value to avoid `MMQTTException: loop timeout (0) must be bigger than socket timeout (1))` error. --- .../native_networking/minimqtt_adafruitio_native_networking.py | 2 +- .../minimqtt_pub_sub_blocking_native_networking.py | 2 +- ...nimqtt_pub_sub_blocking_topic_callbacks_native_networking.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/examples/native_networking/minimqtt_adafruitio_native_networking.py b/examples/native_networking/minimqtt_adafruitio_native_networking.py index 512b83e..3fcd817 100644 --- a/examples/native_networking/minimqtt_adafruitio_native_networking.py +++ b/examples/native_networking/minimqtt_adafruitio_native_networking.py @@ -90,7 +90,7 @@ def message(client, topic, message): photocell_val = 0 while True: # Poll the message queue - mqtt_client.loop() + mqtt_client.loop(timeout=1) # Send a new message print(f"Sending photocell value: {photocell_val}...") diff --git a/examples/native_networking/minimqtt_pub_sub_blocking_native_networking.py b/examples/native_networking/minimqtt_pub_sub_blocking_native_networking.py index 0ba76df..57b71f9 100644 --- a/examples/native_networking/minimqtt_pub_sub_blocking_native_networking.py +++ b/examples/native_networking/minimqtt_pub_sub_blocking_native_networking.py @@ -92,7 +92,7 @@ def message(client, topic, message): # NOTE: Network reconnection is handled within this loop while True: try: - mqtt_client.loop() + mqtt_client.loop(timeout=1) except (ValueError, RuntimeError) as e: print("Failed to get data, retrying\n", e) wifi.reset() diff --git a/examples/native_networking/minimqtt_pub_sub_blocking_topic_callbacks_native_networking.py b/examples/native_networking/minimqtt_pub_sub_blocking_topic_callbacks_native_networking.py index 82b9ce1..55a7769 100644 --- a/examples/native_networking/minimqtt_pub_sub_blocking_topic_callbacks_native_networking.py +++ b/examples/native_networking/minimqtt_pub_sub_blocking_topic_callbacks_native_networking.py @@ -104,7 +104,7 @@ def on_message(client, topic, message): # NOTE: NO code below this loop will execute while True: try: - client.loop() + client.loop(timeout=1) except (ValueError, RuntimeError) as e: print("Failed to get data, retrying\n", e) wifi.reset()