I’m working on a project where I need to create a real-time dashboard for users to visualize data collected from sensors. I’m using STM32 microcontrollers to collect data from sensors.
The sensor data is sent to an MQTT broker. and I’m considering using Django to handle the backend. The idea is to:
Subscribe to the MQTT broker to receive sensor data.
Store the data in a database (I’m thinking of using InfluxDB for time-series data).
Create a real-time dashboard for users to visualize the data.
Is Django a good choice for this kind of real-time application? If not, what alternatives would you recommend?
I’d appreciate any advice, suggestions, or examples you can share. Thank you in advance for your help!
The implementation depends upon precisely what you mean by “real-time”
How soon after the data is collected do you need to see it in the browser?
You have some different options, but most of them are going to involve some JavaScript in the browser - if nothing else, to trigger a refresh of some kind.
What you choose for the backend should be what you’re familiar with, but make sure you’re clear at the start what the architecture is going to be. You’ll want to identify what processing of which data occurs at each step, and what the responsibility of each component is.
Thank you for your response! I appreciate the confirmation that Django can handle this. To answer your questions and provide more context: I’d like the data to appear in the browser within 1-2 minutes of being collected by the sensors. and The dashboard should update dynamically without requiring manual refreshes.
I’m not an expert in Django, but I’m somewhat familiar with it . I’m also exploring tools like Node-RED and Telegraf for data processing and integration with MQTT and InfluxDB ( or PostgreSQL ) . Do you think it’s better to handle everything in Django ?
Thank you again for your help!
That’s going to depend, in part, to the amount of time that it takes to acquire the data and pass it through whatever you’re going to do with it before making it available to Django.
If you don’t want full-page refreshes, then you can use AJAX or WebSockets to update the page. Either way, there’s going to be JavaScript involved.
I’m not familiar with either one, so I can’t comment.
MQTT is a protocol, not a product (unless there’s some package out there named “MQTT” that I’m not aware of.) Personally, if this is a “point-to-point” type of connection, I wouldn’t bother with it. (And have never used it in my situations like this.)
I don’t know if it’s “better”, but I handle everything in Django/Python, if only to minimize the learning curve for the other people working on those projects.
I’ve described a project here in the forum (can’t find the posts at the moment) where we do something very similar to this.
I have a Django / Channels project (a “Channels worker” task) that reads the data coming in, and publishes it to the channels layer, which is Redis.
I have another Channels worker that responds to the messages in the channel and processes it as needed. (Usually by writing to the database.)
I have another Channels worker that takes the processed data and generates the data to be displayed, sending it as a channels message to a Channels Group.
The browsers connected to the Channels Group gets the message, and the JavaScript on that page updates the page.
It works, we have no problems with it at all. But whether it’s “better” in any meaningful sense would be an opinion.