Using Django with real‑time IoT sensor data, has anyone tried this?

Hi everyone, I’m thinking about building a small web dashboard using Django to display live sensor data from microcontroller devices (e.g., ESP32). I found a tutorial on The Engineering Projects that shows how ESP32 can send sensor readings over HTTP to a cloud service or server https://www.theengineeringprojects.com/2022/02/esp32-http-post-with-thingspeak-and-ifttt.html, and it made me wonder if Django could be used as the backend instead of a generic IoT service. I’ve seen a few Arduino forum threads and Raspberry Pi community projects where people push data into simple dashboards or cloud spreadsheets, and some even link sensor data with web interfaces. For those who built something similar with Django: how did you structure your models/views to handle data influx? Did you use WebSockets or polling for live updates, and what are the trade‑offs you observed (latency, load, data retention)?

Welcome @ariajames !

First, for background - I’ve done a lot of this in the past.
If you search this forum for

It’s not clear to me from your description which direction the requests occur.

If the microcontroller is sending the data as an http request, then your Django view for that url is an ordinary view. There’s nothing special or different that need to be done for it.

If it’s capable of sending data through other means, then that may be worth investigating.

On the other hand, if your project needs to issue the requests to retrieve the data from the server, then you want to do this external to your Django project - perhaps as a Django management command.

Another issue is to consider how frequently you need to retrieve the data.

Don’t forget to check for other connectivity options if you’re needing to pull this data more frequently than (roughly) every 5 seconds.

The design of the models is not affected by this at all. What the controller sends and what you want to keep are the only factors involved, and again, it’s just standard Django.

It depends upon the rate at which updates need to be retrieved and presented to the browser. I’ve worked with devices feeding data at 100ms cycles (10 / second) - those required websockets for live data feeds. But for devices requesting data evey 5 - 10 seconds, then you can consider polling.

There are some other factors to consider regarding the “locality” of the devices to the server and the relative locality of the server to the browsers. You may also need to consider how many browsers are going to be connecting to view this data and how it needs to be presented on the browser.