Flask-Socketio to MQTT bridge #1870
-
I have to write an IoT server that receives (a) MQTT messages from IoT devices and (b) socket messages from a mobile app. My project is essentially a socketIO to MQTT bridge. I use Paho-MQTT Python library. |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 4 replies
-
Unfortunately I do not have the answer to your question. If your MQTT library can be used under gevent or eventlet, then it is likely to work well alongside Socket.IO. Worst case you can always use the threading mode, which will allow you to use a regular thread for MQTT. |
Beta Was this translation helpful? Give feedback.
-
I think you can create a thread under socketio and use a queue to send message received from socketio into the thread that will process mqtt messages, and I believe you can use emit outside context to send messages from the mqtt thread. |
Beta Was this translation helpful? Give feedback.
-
I made a curious observation about flask-socketio server freezing: I mixed a blocking thread with gevent based socketio server, which was a big mistake, as you have pointed out. To reproduce the bug, I put these two lines in my other thread:
As expected, this froze the entire socketio application. |
Beta Was this translation helpful? Give feedback.
Unfortunately I do not have the answer to your question. If your MQTT library can be used under gevent or eventlet, then it is likely to work well alongside Socket.IO. Worst case you can always use the threading mode, which will allow you to use a regular thread for MQTT.