asgimqtt
is a simple MQTT interface for ASGI.
Install with pip
:
pip install asgimqtt
Connect the server to a running MQTT broker:
asgimqtt --host localhost --port 1883 django_project.asgi:channel_layer
In your Django code:
# routing.py channels_routing = [ route("mqtt.sub", mqtt_consumer), ]
Note: you can only receive messages published in MQTT
broker (channel
mqtt.sub
).
The keys are:
host
: host of theMQTT
brokerport
: port of theMQTT
brokertopic
: topic of theMQTT
messagepayload
: payload of theMQTT
messageqos
: quality of service of theMQTT
message (0, 1 or 2)