MiniMQTT Client Identifier
By default, MiniMQTT will generate a unique, randomly generated client identifier based off the
CircuitPython device's microcontroller's UUID and a random number. The broker will see a client named
something like
cpy-3123
If you'd like to set a custom client_id (what the broker sees the CircuitPython device as), you can provide
a string. Do make sure the client_id 's you create are unique, or your broker will disconnect them.
client = MQTT(broker = secrets['broker'],
username = secrets['user'],
password = secrets['pass'],
client_id = 'brentspyportal')
MiniMQTT Logging
MiniMQTT uses the CircuitPython logger module (https://adafru.it/Ehw) for printing different types of
errors, depending on the priority the logger was set to.
To attach a logger to a MiniMQTT client, simply
client = MQTT.MQTT(broker = secrets['broker'],
username = secrets['user'],
password = secrets['pass'],
log = True)
Then, you will need to add another line setting the logger's level. While the logger is initialized to the INFO
level by default, you may want to see more information about your current MQTT session.
To set the logger to a higher priority logging level , like DEBUG, add the following line
after
the MQTT
client has been initialized:
client.set_logger_level(DEBUG)
MiniMQTT Last Will and Testament
MiniMQTT supports setting publishing a message to a specific topic when your MQTT client disconnects.
For more information about MQTT's Last Will - check this guide (https://adafru.it/Fmf).
To use the last will - specify the topic you'd like to publish to and provide it with a message to publish
when the client disconnects.
client.set_will(topic='device/status/', message='Goodbye!')
This method must be called before the connect method . The last will and testament also must be
allowed by your MQTT Broker - Adafruit IO does
not
support this feature.