-
Notifications
You must be signed in to change notification settings - Fork 51
reconnect restoration #244
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
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Tested on my trusty #!/usr/bin/env python3
import adafruit_minimqtt.adafruit_minimqtt as MQTT
import ssl
import adafruit_logging as logging
import socketpool
import wifi
try:
from secrets import secrets
except ImportError:
print(
"WiFi and Adafruit IO credentials are kept in secrets.py, please add them there!"
)
raise
def connect_hook(client, user_data, result, code):
print(f"Connect: {user_data} {result} {code}")
def message_hook(client, topic, message):
# print(f"Message: topic='{topic}' message='{message}'")
print(f"Message: topic='{topic}'")
def main():
logger = logging.getLogger(__name__)
logger.setLevel(logging.INFO)
logger.info("Connecting to wifi")
wifi.radio.connect(secrets["ssid"], secrets["password"], timeout=10)
logger.info(f"Connected to {secrets['ssid']}")
logger.debug(f"IP: {wifi.radio.ipv4_address}")
pool = socketpool.SocketPool(wifi.radio) # pylint: disable=no-member
broker = "172.40.0.3"
port = 1883
mqtt_client = MQTT.MQTT(
broker=broker,
port=port,
socket_pool=pool,
ssl_context=ssl.create_default_context(),
)
mqtt_client.enable_logger(logging, log_level=logging.DEBUG)
mqtt_client.on_connect = connect_hook
mqtt_client.on_message = message_hook
mqtt_client.connect()
mqtt_client.subscribe('devices/foo/#')
mqtt_client.reconnect()
while True:
mqtt_client.loop()
try:
main()
except Exception as e:
print(f"Got exception: {e}") Produces the following output:
|
tyeth
reviewed
Mar 6, 2025
tyeth
approved these changes
Mar 6, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@tyeth I agree - merge 240 + 244 + 245, release. |
brentru
approved these changes
Mar 10, 2025
adafruit-adabot
added a commit
to adafruit/Adafruit_CircuitPython_Bundle
that referenced
this pull request
Mar 13, 2025
Updating https://github.com/adafruit/Adafruit_CircuitPython_DisplayIO_SH1107 to 2.0.1 from 2.0.0: > Merge pull request adafruit/Adafruit_CircuitPython_DisplayIO_SH1107#27 from FoamyGuy/use_ruff_remove_8x_compatibility Updating https://github.com/adafruit/Adafruit_CircuitPython_DisplayIO_SSD1306 to 3.0.1 from 3.0.0: > Merge pull request adafruit/Adafruit_CircuitPython_DisplayIO_SSD1306#51 from FoamyGuy/use_ruff_and_remove_8x_compat Updating https://github.com/adafruit/Adafruit_CircuitPython_SSD1680 to 2.0.1 from 2.0.0: > Merge pull request adafruit/Adafruit_CircuitPython_SSD1680#31 from makermelissa/main Updating https://github.com/adafruit/Adafruit_CircuitPython_JSON_Stream to 0.8.6 from 0.8.5: > Merge pull request adafruit/Adafruit_CircuitPython_JSON_Stream#7 from justmobilize/fix-iter-issues Updating https://github.com/adafruit/Adafruit_CircuitPython_MiniMQTT to 8.0.0 from 7.11.6: > Merge pull request adafruit/Adafruit_CircuitPython_MiniMQTT#247 from adafruit/ruff-format-reconnect-tests > Merge pull request adafruit/Adafruit_CircuitPython_MiniMQTT#244 from vladak/reconnect_restoration > Merge pull request adafruit/Adafruit_CircuitPython_MiniMQTT#240 from vladak/exceptions_tidy_up
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This change restores the behavior of disconnecting on
reconnect()
if already connected.