5

I have many raspberry Pis monitoring temperature and humidity in real time and publishing the data continuously to an MQTT broker (I am using Mosquitto at the moment). The Raspberry pis are all publishing to different topics. I would then like to send all this data to a flask web server, as in this diagram:

enter image description here

But Obviously flask can't subscribe to MQTT topics. I was thinking I could add an additional MQTT client that would subscribe to the topics and then it could send the messages over to the server via an http request in the on_message callback. This client would probably be running as a process on the same machine.

enter image description here

Is there a better way to do this?

1

2 Answers 2

1

First, you can definitively make you web server subscribe to MQTT, it's just the business of setting up a thread and providing the callbacks. Using the paho mqtt module for this, it's just a matter of using the Client class and calling loop_start() to launch the thread. However, depending of your needs, it may not be the best solution to make your webserver to subscribe to MQTT; it's not possible to say because you did not provide any details on your webserver specs.

You may also consider adding a database in your architecture. In your second setup, the "client" can push data in the DB and the webserver query data from the DB (MongoDB is quite simple to setup and use for such a use case).

0

Are you fixed on the technologies you have mentioned? If not you could explore platforms like Azure and AWS which have great IoT services available (even for free till a limit).

So if I get it correctly what you want to achieve is to send temperature data across to a web server where you would probably have an app for the user to visualize this data or run some analytics.

Platforms like Azure let you achieve this very easily without worrying about the underlying tech, scalability etc.

For e.g, you could use the Azure IoT Hub (which supports Mqtt/ Amqp etc) for ingestion of the temperature data. Once the data is in the hub you can subscribe to event hub that lets you subscribe to all the data or selected data coming in from an IoT hub. Once you have this data you can act on it using may be azure functions or just push it into a azure storage (db).

Hope it helps.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.