Hello! My wife and I really like weather related things, so I thought I would have some fun with SDR (Software Defined Radio) and a TIG (Telegraf, InfluxDB, Grafana) Stack to provide my own home weather station. In this project I started with a single Raspberry Pi 3, I will say I am awaiting an Intel Nuc that I will move all this too now that I got things working the way I want. So let's get to it:
I got the following two pieces of hardware and used a Raspberry Pi 3 that I already had one hand. I got two of the sensors one for the inside and one for the outside, use some good batteries and the sensor will live longer. I also setup alerts in grafana to tell me when the batteries are getting low.
So go ahead and place the sensor and plug the SDR into the Pi (Running Raspian Stretch). Usually depending on the last time I updated the pi I run:
>>sudo apt-get update
>>sudo apt-get upgrade -y
>>sudo reboot
Now that this is completed go ahead and build the software for rtl_433 (sometimes you may need SoapySDR sometimes not just depends)
git clone https://github.com/merbanan/rtl_433.git
git clone https://github.com/pothosware/SoapySDR.git
cd SoapySDR/
git pull origin master
mkdir build
cd build
cmake ..
sudo make install
SoapySDRUtil --info
Now that SoapySDR is built and running lets move to the rtl_433 for non-pi's and other Debian distro's you may need to add
sudo apt-get install libtool libusb-1.0.0-dev librtlsdr-dev rtl-sdr build-essential autoconf cmake pkg-config
cd rtl_433/
mkdir build
cd build
cmake ..
sudo make install
sudo ldconfig
In my case I turned on one sensor to keep things simple, to start run the following and it should find your device
rtl_433 -v
.....rtl_433 version 18.12-77-g6ab7b46 branch master at 201901271510 inputs file rtl_tcp RTL-SDR SoapySDR
...
Found 1 device(s)
trying device 0: Realtek, RTL2838UHIDIR, SN: 00000001
Detached kernel driver
Found Rafael Micro R820T tuner
Using device 0: Generic RTL2832U OEM
Exact sample rate is: 250000.000414 Hz
[R82XX] PLL not locked!
Sample rate set to 250000 S/s.
Bit detection level set to 0 (Auto).
Tuner gain set to Auto.
Reading samples in async mode...
Tuned to 433.920MHz.
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
time : 2019-01-28 13:17:45
model : Acurite tower sensor id : 1348
sensor_id : 0x0544 channel : A Temperature: 23.3 C Humidity : 29 battery low: 0
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
Now that you have found the sensor lets prepare the rest of the software
The Node-RED that comes with the Pi is usually an older release so go ahead and update it to the latest.
>>bash <(curl -sL https://raw.githubusercontent.com/node-red/raspbian-deb-package/master/resources/update-nodejs-and-nodered)
>>cd ~/.node-red
>>npm rebuild
>>npm ls --depth=0
>>npm outdated
>>npm update
Now that Node-RED is updated lets install and configure mosquitto aka MQTT - I kept things very simple to get things up and running I went back later and applied appropriate security. I also installed the client and the broker on the same system.
>>sudo apt-get update
>>sudo apt-get upgrade -y
>>sudo apt-get install mosquitto mosquitto-clients
>>sudo systemctl enable mosquitto.service
>>sudo systemctl start mosquitto.service
>>sudo systemctl status mosquitto.service
In two terminal windows
Window One - open a new topic
>>mosquitto_sub -t hello/world
Window Two - Publish something to the topic
>>mosquitto_pub -d -t hello/world -m "Hello from the other terminal"
Client mosqpub/7389 sending CONNECT
Client mosqpub/7389 received CONNACK
Client mosqpub/7389 sending PUBLISH (d0, q0, r0, m1, 'hello/world', ... (29 bytes))
Client mosqpub/7389 sending DISCONNECT
Window One Sees
mosquitto_sub -t hello/world
Hello from the other terminal
Now lets get MQTT into the mix and send the rtl_433 output to as MQTT messages - -R 40(is the device type of the acurite sensor I am using)
Send stats to mqtt
rtl_433 -M notime -F json -R 40 | mosquitto_pub -t home/acurite -l
rtl_433 version 18.12-77-g6ab7b46 branch master at 201901271510 inputs file rtl_tcp RTL-SDR SoapySDR
Registered 1 out of 120 device decoding protocols [ 40 ]
Detached kernel driver
Found Rafael Micro R820T tuner
Exact sample rate is: 250000.000414 Hz
[R82XX] PLL not locked!
Sample rate set to 250000 S/s.
Tuner gain set to Auto.
Tuned to 433.920MHz.
mosquitto_sub -t home/acurite
pi@weatherpi:~ $ mosquitto_sub -t home/acurite
{"model" : "Acurite tower sensor", "id" : 1348, "sensor_id" : 1348, "channel" : "A", "temperature_C" : 23.000, "humidity" : 29, "battery_low" : 0}
{"model" : "Acurite tower sensor", "id" : 825, "sensor_id" : 825, "channel" : "A", "temperature_C" : -17.900, "humidity" : 54, "battery_low" : 0}
Now that we are pumping the output into MQTT lets create 2 New DB's in Influxdb ( I know I don't have the install instructions in here for influx but the doc on their site is super easy to follow) - could have probably done this in one DB, but I like having things separated and clean.
sudo influx
Connected to http://localhost:8086 version 1.7.3
InfluxDB shell version: 1.7.3
Enter an InfluxQL query
CREATE DATABASE Office
CREATE USER office WITH PASSWORD 'office'
GRANT ALL ON Office to office
CREATE RETENTION POLICY thirty_days ON Office DURATION 30d REPLICATION 1 DEFAULT
SHOW RETENTION POLICIES ON Office
name duration shardGroupDuration replicaN default
---- -------- ------------------ -------- -------
autogen 0s 168h0m0s 1 false
thirty_days 720h0m0s 24h0m0s 1 true
> CREATE DATABASE FrontPorch
> CREATE USER porch with PASSWORD 'porch'
> GRANT ALL ON FrontPorch to porch
> CREATE RETENTION POLICY thirty_days ON FrontPorch DURATION 30d REPLICATION 1 DEFAULT
> SHOW RETENTION POLICIES on FrontPorch
name duration shardGroupDuration replicaN default
---- -------- ------------------ -------- -------
autogen 0s 168h0m0s 1 false
thirty_days 720h0m0s 24h0m0s 1 true
Now go into Node-RED First you have to install influxdb go to Manage Palette and click on Install and search for influxdb
Once installed it will add influxdb controls to your palette under Storage
Once that was completed you can build the flow to capture the MQTT sensor data split the office data to the OfficeDB and the Front Porch Data to the FrontPorchDB
Ok so as you can see there are debug nodes connected to pretty much everything so I can check on how things are working. From Left to Right >>>
- My MQTT Node Subscribed to my topic as discussed above
- Connected to a switch as in my case I had two sensors setup at this point and I used the ID of the Sensor to split the data
{"model" : "Acurite tower sensor", "id" : 825, "sensor_id" : 825, "channel" : "A", "temperature_C" : 1.200, "humidity" : 86, "battery_low" : 0}
{"model" : "Acurite tower sensor", "id" : 825, "sensor_id" : 825, "channel" : "A", "temperature_C" : 1.200, "humidity" : 86, "battery_low" : 0}
{"model" : "Acurite tower sensor", "id" : 825, "sensor_id" : 825, "channel" : "A", "temperature_C" : 1.200, "humidity" : 86, "battery_low" : 0}
{"model" : "Acurite tower sensor", "id" : 1348, "sensor_id" : 1348, "channel" : "A", "temperature_C" : 21.500, "humidity" : 32, "battery_low" : 0}
{"model" : "Acurite tower sensor", "id" : 1348, "sensor_id" : 1348, "channel" : "A", "temperature_C" : 21.500, "humidity" : 32, "battery_low" : 0}
{"model" : "Acurite tower sensor", "id" : 1348, "sensor_id" : 1348, "channel" : "A", "temperature_C" : 21.500, "humidity" : 32, "battery_low" : 0}
- Then used two JSON Nodes to convert the payload into an object
- Finally write those objects out to each of the respective influx databases
Now that there is data going into influx we can now install Grafana and start charting things. (Again Grafana is super simple to install - just check out the website)
You can do loads of cool stuff with the tools they have available. I am also bringing in some DarkSky API items to show forecast
I hope you have as much fun as I did under-taking this project! Eventually I am going to get a cheap android tablet or something and display the Grafana Dashboard in Kiosk mode that way we can always see our little weather station.
Comments