channels-asgi-mqtt
channels-asgi-mqtt copied to clipboard
An Example would be helpful
Hi,
I am trying to integrate it in our project but because of lack of example, I am not able to do it. It would be really helpful if an example integration is committed in this project.
check this pr for an example project
@Ali-aqrabawi thanks for the example. Somehow, I was able to consume mqtt message like you did. But I am not sure how to publish mqtt messages. Can you please help me in this?
@mustaqeem not sure if there is a better way but waht you can do is to write to the mqtt channel with message type = mqtt.pub
from asgiref.sync import async_to_sync
from channels.layers import get_channel_layer
msg = {
"topic": "my_topic",
"payload": "any payload"
}
channel_layer = get_channel_layer()
async_to_sync(channel_layer.send)(
"mqtt",
{
"type": "mqtt.pub",
"text": msg
}
)
btw, did you find a way to receive messages from the channel without running the workers?
Thanks @Ali-aqrabawi . I don't think, messages can be received without running workers.
@Ali-aqrabawi , In my project, there are multiple services communicating over mqtt. With your example, I am able to receive message but I am not able to publish message to mqtt that other service can consume.
Dear mustaqeem.I have set up the same project and i have one issues.If you know it pls help me