mqtt_client
MQTTClient class for publishing measurements to MQTT broker.
Classes
|
Implementation of Eclipse Paho MQTT Python client. |
MQTTClient
- class icicle.mqtt_client.MQTTClient(clientID='', ssl=True)
Bases:
object
Implementation of Eclipse Paho MQTT Python client.
- __init__(clientID='', ssl=True)
Initialises a MQTT client instance and sets default connect and disconnect callbacks.
- Parameters:
clientID – Unique client ID string used when connecting to the broker. If clientID is zero length or None, then one will be randomly generated.
- connect(broker, port=1883, username=None, password=None)
Connects the client to a broker.
- Parameters:
broker – Hostname or IP address of the remote broker.
port – Network port of the server host to connect to. Defaults to 1883.
username – Sets username for broker authentification. Defaults to None.
password – Sets password for broker authentification. Defaults to None.
- disconnect()
- loop_forever()
Loop client forever.
Handles reconnecting automatically. Loop will not return until client calls disconnect().
- loop_start()
Start client loop.
Handles reconnecting automatically.
- loop_stop()
Stop client loop.
- publish(topic, msg)
Sends a message from the client to the broker.
- Parameters:
topic – A string specifiying the topic the message should be published on.
msg – A string specifying the message to send. Passing an int or float will result in the message being converted to a string.
- subscribe(sub, callback=None)
Subscribes the client to a topic and sets a default message callback.
- Parameters:
sub – A string specifying the topic to subscribe to.
callback – F-string specifying the on_message callback for the subscribed topic. If None the global on_message callback will be set to f”Received ‘{msg.payload.decode()}’ from ‘{msg.topic}’”. Defaults to None.