Quantcast
Channel: Raspberry Pi Forums
Viewing all articles
Browse latest Browse all 7503

Beginners • Re: Asking for pointers with a humidity sensor plan.

$
0
0
I do something similar with the dht22 sensor. The simple way to collect all the readings in a central location is have the sensor program write to a log file on the zero (you can save date/time,temp,humidity or whatever you like). I use a cron job to run the dht22 program that writes the value to a log file. Then simply use ssh to transfer the last reading to your central hub. I just transfer the data to another Linux box that is a server and display the current date/time, temp and humidity on a web page (you can do the same to capture all rooms on a common server)

Dead-bang simple. The cron entry I use is:

Code:

0,10,20,30,40,50 * * * * /mnt/bin/dht22cron && /mnt/scr/th2vl.sh
Which updates the reading every 10 minutes. (this is running on a Milkv-Duo, but could run on a Pi Zero as well, but that's why you see the /mnt/bin location). The dht22cron program just samples the dht22 sensor and writes the data to a log file. The th2vl.sh (short for temp-humidity to valkyrie) just grabs the last reading and pipes it to the server named valkyrie saving to a file on the server /srv/http/dl/files/mvduo-th.txt.

The transfer script is likewise dead-bang simple:

Code:

#!/bin/sh# tail -n1 /mnt/log/sensor-dht22.txt | ssh david@valkyrie 'cat > /srv/http/dl/files/mvduo-th.txt'
(you could keep the log on the server just by using append redirection '>>' instead of the replace '>' redirection storing the data on the server)

So you are just tailing the log file and grabbing the last entry and then piping via ssh to the location on the server you want to collect the data in. The authentication uses a public/private key-pair so no password is needed, and the server has ssh keyboard authentication completely disabled to remain secure.

You can do it anyway you like, but using just what you already have, cron, ssh and whatever you sample your dht22 sensor with was just about as easy as it gets. Just a simple AJAX call to a sever-side php script reads the data file on the server and displays the output. So I know the den is fine:
dht22-den.png

Statistics: Posted by drankinatty — Sun Oct 26, 2025 12:14 am



Viewing all articles
Browse latest Browse all 7503

Trending Articles