Thanks @borpin - I am obviously not the only one wanting to do this . I’m afraid that my Linux knowledge is sufficiently low as to not really understand a service file. But FWIW, these are the Dummies notes that I have cobbled together so far concerning restarting after boot …
To make the Raspberry Pi start the process on boot up automatically, do the following
In Terminal type
export & look for a line that is similar to
declare -x PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
In my case it was
declare -x PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/games:/usr/games"
sudo nano YOURFILENAME.sh . In the file type (on 4 lines)
#!/bin/bash -x export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/games:/usr/games***** sleep 20 rtl_433 -F json -M utc -R 43 | mosquitto_pub -t home/rtl_433 -l -h YOUR_MQTT_BROKER_IP -p 1883 -u YOUR_MQTT_BROKER_USERNAME -P YOUR_MQTT_BROKER_PASSWORD
… and then save it (Cntl+O, ENTER, Cntl+X)
Now make it executable with
sudo chmod +x YOURFILENAME.sh
Test that it works by running
sudo ./YOURFILENAME.sh and it should be OK.
Up until this point all is fine for me, but when I did this yesterday I continued with the next bit but something broke. Not 100% sure my notes are quite right …
Open a new Terminal window and type
sudo nano /etc/rc.local and put in it …
cd /home/pi(adjust path as required)
/the/full/path/to/YOURFILENAME.sh & NB: Don’t forget the “&”; in my case, it was *
cd /home/pi/jjbwatchman.sh &
exit 0 NB: This line should already be there, but I include it here to show where to put these lines
sudo nohup ./YOURFILENAME.sh & (don’t forget the &)
Reboot the Pi and it should provide the Watchman data automatically from now on