I run RTL_433 to push data from several sensors and a motion detector to an MQTT server for home automation. For some reason as of late it is just not that stable. Could even be a hardware failure with the dongle….I dunno. I generally just run the program command inside a terminal on the raspberry pi it is installed on and just walk away. When it crashes I have to log back in the Pi and re-run the command. Un-cool.
The command I use specifically is this:
rtl_433 -F json -M utc | mosquitto_pub -t home/rtl_433 -l
Again, that pushes data found on 433.920 MHz devices to publish a topic on my MQTT server called “home/rtl_433”.
Then I tried to do a cron job to start it but it still crashes. The great thing about linux is that you can write scripts to monitor jobs and restart them but it’s always so clunky.
Then I found out about a program called Supervisor. Install it on the Pi by
sudo apt-get install supervisor
I know this is a version or two behind but the way to install it through python “pip install supervisor”, I never could figure out how to make the conf file to control the darn thing. None of the tutorial stuff worked. So I have to sacrifice being a version or so behind by using the Pi repositories.
Anyway here’s how to quickly configure supervisor to monitor your instance of RTL_433 so it stays up and operational.
First create a script file for your command:
sudo nano rtl433.sh
Paste in the following:
#!/bin/bash rtl_433 -F json -M utc | mosquitto_pub -t home/rtl_433 -l
Hit Ctl plus the X key, answer Y and hit enter to save. Now make it executable:
sudo chmod +x rtl433.sh
Now let’s do the supervisor conf file.
sudo nano /etc/supervisor/supervisord.conf
Paste in the following at the bottom of the file making sure your command path is correct. I made my script file in the /home/pi directory. Autostart starts at boot, autorestart restarts it if it crashes or fails :
[program:rtl_433] command=/home/pi/rtl433.sh autostart=true autorestart=true stderr_logfile=/var/log/long.err.log stdout_logfile=/var/log/long.out.log
Hit CTL plus the X key, answer Y and hit enter to save the file.
Now restart the Pi or start rtl_433 then pull the RTL-SDR dongle out of the pi and plug it back in. Then check to see if the rtl_433 process is running.
Working. You are the master of both time and space.