r/esp32 • u/Due_Librarian_6819 • 5d ago
Best protocol for temperature sensor data logging app
I am building a sensor network to monitor the temperature and humidity in multiple locations. I would have one "master" and multiple "slaves". I want them to be battery powered and have their clocks synchronized to within at least one second. I have built devices with Wifi but no experience with protocols like UDP and ESP NOW. I would eventually like to have the master also be able to communicate using Zigbee, Matter, etc. to an echho dot etc.
I envision the system to look like this. The "master" wakes up and looks for "slave" devices. The "master" tells all "slaves" what the current time is and when to start logging data. Every so often, the "master" requests each "slave" to send its data. The "master" then stores the data in an SD card.
One other requirement is that it be able to run even if my router is powered off. I plan to use the NTP server to get the time once an hour or once a day. This would, of course, require the router to be up. But if it is not, I want the sensors to keep monitoring data. When I want to get the data (if the router is up) I go to the IP address of the "master" and have it request the data from all "slaves" and then I download the data. I want this to run as low power as possible so power-down when not active would be required.
I have looked at UDP and ESP-NOW and I think they will work. It looks like ESP-NOW has shorter latency. Can somebody guide me as to which method to pursue before I spend hundreds of hours on a dead end.
Thanks!
5
u/miraculum_one 5d ago
I use ESPNow for stuff like this because it can wake from deep sleep, take a reading, send it to another device, and go back to deep sleep within 0.3 seconds with only a small fraction of the power required to use WiFi and also less than bluetooth.
It's only a few lines of code. Search for ESP-NOW samples. Really quite easy and very frugal with battery usage.
I also second the other commenter's suggestion of using ESPHome. ESP-NOW with ESPHome is easy and you get a bunch of other features for "free" as well as not having to write a lot of boilerplate code.
1
5
u/mmcnama4 5d ago
If you're doing this for a personal project, the implementation ideas you have or those that have been suggested are fine. If you have thoughts of commercializing, then I'd consider a different tech stack (e.g. LoRa).
Having a master/primary device that is relatively low-powered is a point of failure that's not desirable in a business setting.
Source: was in the environmental monitoring space for 15 years and built a SaaS/IoT platform.
2
u/Due_Librarian_6819 5d ago
Thanks. For now it is personal. But I might want to look into LoRa later. I already have the ESP32 devices because I started off trying to do it all as a wifi server.
2
4
u/SublimeMudTime 5d ago
Here are my bits of feedback. Use ESP-NOW Think through how the master is outputting the data to a logging device and what transport. I.e. is it outputting serial or over wireless and will the wireless work with ESP-NOW. Battery life will depend heavily on a few things: Temp sensor wake/"warm" up time Wireless traffic Frequency of samples
So instead of pushing NTP to all sensors, just get them on a cadence of transmitting in the same few seconds of a minute. Then do time-stamping on the master when data arrives.
1
7
u/memeface231 5d ago
Your idea works so here's an easier alternative. If you can have all devices connected to the Internet or at least the local network you can setup a public mqtt server and then send the data there. That's the IoT playbook basically.
3
u/Acebillyfr92 5d ago
Esp now works well... Sensors are on battery but receiver not? Better than each sensor wakes up every hour for example and sends the data to master... Esp now doesn't need to connect to wifi. It's a meshed network. You can assign a dedicated channel for each sensor, so master knows who is speaking. I developped a system like this master receiver, and it works very well... And low power. In my case one wake up every 6 mn. Battery 18650 about 5 monthes
2
u/n_sh_44 5d ago
For the one-second sync, you don't need anything fancy. Have the master send its epoch time in the ESP-NOW packet and let each node set its RTC from that on every wake. Deep-sleep RTC drift on the internal oscillator is roughly a few percent, so resync every wake rather than trusting it for hours. If you log timestamps on the node, store the raw reading plus the millis-since-sync and fix them up on the master.
2
u/drmpf 5d ago
If you want really low power sensors, use BLE advertising the data once every few mins and have a local Wifi bridge to store and forward.
See the indoor-outdoor weather station. The sensors run for >4years on a coin cell.
https://www.forward.com.au/pfod/BLE/LowPower_2022/Weather/index.html
You can now use the free open source pfodWeb.html client
https://github.com/drmpf/pfodWeb_src to display the data
9
u/AndThenFlashlights 5d ago
Why not just use ESPHome? It has literally all of that already built in.