Syntactical sugar on top of the MQTT client cake
- Attach multiple callback handlers to the same topic or wildcard
- Simplified
unsubscribe(removes specific handler)
- Python 3.11.x
Create an instance of the mqtt topping with a default paho mqtt-client:
from mqtt_topping import MqttTopping
mqtt_topping = MqttTopping()
mqtt_topping.connect("127.0.0.1", 1883)Create an instance of the mqtt topping with a TouchDesigner mqtt-client:
from mqtt_topping import MqttTopping, TouchDesignerClientAdaptor
client = op('mqttclient')
client_adaptor = TouchDesignerClientAdaptor(client)
mqtt_topping = MqttTopping(client_adaptor)Subscribe to a topic:
def callback(topic, payload):
# handle message here
mqtt_topping.subscribe("test/topic/doTest", callback)Subscribe using a wild card:
mqtt_topping.subscribe("test/topic/#", callback)
mqtt_topping.subscribe("test/+/doTest", callback)Subscribe to raw payload without parsing:
mqtt_topping.subscribe("test/topic/doTest", callback, parse=False)Control QOS of subscription:
mqtt_topping.subscribe("test/topic/doTest", callback, qos=0)Unsubscribe a given callback from a topic:
def callback(topic, payload):
# handle message here
mqtt_topping.unsubscribe("test/topic/doTest", callback)Unsubscribe all callbacks from a topic:
mqtt_topping.force_unsubscribe("test/topic/doTest")Publish a message:
payload = {
"id": 0,
"name": "bob"
}
mqtt_topping.publish("test/topic/doTest", payload)To install dev dependencies:
python3 -m venv venv
source venv/bin/activate
pip install -r requirements_dev.txtTo run unit tests:
python -m pytest testsTo release a new version:
Update the field version in pyproject.toml and tag the version.