Skip to content

artcom/mqtt-topping-py

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

33 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

MQTT topping for Python

Syntactical sugar on top of the MQTT client cake

Features

Enhanced Subscriptions

  • Attach multiple callback handlers to the same topic or wildcard
  • Simplified unsubscribe (removes specific handler)

System requirements

  • Python 3.11.x

Usage

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)

Development

To install dev dependencies:

python3 -m venv venv
source venv/bin/activate
pip install -r requirements_dev.txt

To run unit tests:

python -m pytest tests

To release a new version:

Update the field version in pyproject.toml and tag the version.

About

Syntactical sugar on top of the MQTT client cake

Resources

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages