For help, advice and discussion about stuff not related to aviation. Play nice: no religion, no politics and no axe grinding please.
  • 1
  • 20
  • 21
  • 22
  • 23
  • 24
  • 31
User avatar
By stevelup
FLYER Club Member  FLYER Club Member
#1822642
Yep, you'll need to do something to make that start on power up.

Easiest way is simply to do:-

sudo /etc/rc.local

and paste your command in there adding a final & at the end - this is important. If you don't add the &, the pi won't continue booting after it gets to your script.

There are more complicated (and better) ways of doing it but this will do the trick for this simple task.

It's not ideal because it won't re-launch if it crashes etc. If you want to do it properly, method 4 here is the 'right' way on a modern Linux.

https://www.dexterindustries.com/howto/ ... t-startup/
Colonel Panic liked this
By Colonel Panic
#1822882
Having started "a process" on a RPi via Terminal, when I come to close Terminal.app it warns me that the process will end. How can I get around this as I only want to interact with the RPi via ssh and don't want to leave a Terminal window open 24/7?

Code: Select allrtl_433 -F json -M utc -R 43 | mosquitto_pub -t home/rtl_433 -l -h <my_ip_address> -p 1883 -u <myusername> -P <mypassword>

I tried the script below & rebooted the RPi, and then quit Terminal.app, but that doesn't work either inasmuch as the feed doesn't start up.

Code: Select allsudo /etc/rc.local rtl_433 -F json -M utc -R 43 | mosquitto_pub -t home/rtl_433 -l -h <my_ip_address> -p 1883 -u <myusername> -P <mypassword> &

I must be missing something here... :oops:

EDITED TO ADD: Also, what would be the syntax to undo / remove the sudo /etc/rc.local script?
User avatar
By stevelup
FLYER Club Member  FLYER Club Member
#1822914
To answer your first question, Start the line with...

nohup

... and end it with an &

That then won’t ‘hang up’ when the terminal disconnects. But of course if the device restarts you would need to run the command again.

To answer your other question, you were supposed to edit /etc/rc.local and put that text in it

Not just type what you typed.

So

sudo nano /etc/rc.local

Paste the command in

Save and reboot.

I don’t mean this to sound like it does, and I’m sure you will take it as intended, but I think you should have a proper play with this stuff and learn a bit more about Linux if you are going to be tinkering like this.

Just copy and pasting other people’s instructions doesn’t help you understand what’s happening unfortunately.
By Colonel Panic
#1823132
No offence taken, and your comments are valid; my trouble is that I want to run before I can walk - nothing new there :oops:

I've been doing some reading around the topics and have learnt a fair bit now - even understanding what rtl_433 -F json -M utc -R 43 | mosquitto_pub -t home/rtl_433 -l -h mylanip -p 1883 -u my username -P mypassword actually means, to the extent that the -p 1883 isn't required at all (but haven't tried it). I also read up on why the dvb_usb_28xxu needs blacklisting, & learnt that I could pick up any passing Citroen Tyre Pressure monitoring data if I so chose :D

I removed the 0777 permission and it didn't break anything, but whilst
rtl_433 -F json -M utc -R 43 | mosquitto_pub -t home/rtl_433 -l -h mylanip -p 1883 -u my username -P mypassword
does work, neither
nohup rtl_433 -F json -M utc -R 43 | mosquitto_pub -t home/rtl_433 -l -h mylanip -p 1883 -u my username -P mypassword &
nor
nohup rtl_433 -F json -M utc -R 43 | mosquitto_pub -t home/rtl_433 -l -h mylanip -p 1883 -u my username -P mypassword >./nohup.out 2>./nohup.err &
do, and I'm not sure why. But tomorrow I will try hooking up a monitor directly to the RPi, and this _should_ solve the problem of closing Terminal windows etc.
User avatar
By stevelup
FLYER Club Member  FLYER Club Member
#1823244
Ok, what I'd do is make a little shell script with your command in it.

So, do

sudo nano myfile.sh

or whatever you want to call it.

In the file,

#!/bin/bash
rtl_433 -F json -M utc -R 43 | mosquitto_pub -t home/rtl_433 -l -h mylanip -p 1883 -u my username -P mypassword


Save it, and then make it executable

sudo chmod +x my file.sh

Test it...

sudo ./myfile.sh

Should be ok....

Now try nohupping it ...

sudo nohup ./myfile.sh &

If that works, you know within reasonable certainty that you can then launch that shell script via rc.local

sudo nano /etc/rc.local and put in (don't forget the &)

/the/full/path/to/myfile.sh &

Reboot and see if it starts by itself.
By Colonel Panic
#1823307
Wonderful - many thanks & I will do that this afternoon. Presumably I would put the/the/full/path/to/myfile.sh & between the fi line and the exit 0 line? Does any of the existing stuff need to be un-hashed?

Image
By Colonel Panic
#1823508
Your method above works perfectly up to and including the nohupping, and the feed continues even with all Terminal windows closed. But it doesn't survive a Pi reboot. Reading around the subject, might it be better to use system.d rather than rc.local?
https://www.raspberrypi.org/documentati ... c-local.md
https://www.raspberrypi.org/documentati ... systemd.md

I am running Raspberry Pi OS, which is based on Debian, but not sure if it is Buster-based.

FWIW, herewith my /etc/rc.local file

Code: Select all#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.

# Print the IP address
_IP=$(hostname -I) || true
if [ "$_IP" ]; then
  printf "My IP address is %s\n" "$_IP"
fi

/home/pi/jjbwatchman.sh &

exit 0
User avatar
By stevelup
FLYER Club Member  FLYER Club Member
#1823510
I did suggest you used systemd a few posts ago. But... If you can't get it working via rc.local, you've got no chance of getting it working via systemd which is much more complicated.

Let's work out why it's not working. Could be paths. Not all paths will be populated at the time rc.local runs.

Log in to your device as normal and type export

Look for the line like this:-

declare -x PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"

edit your .sh file and between the 'shebang' (#!/bin/bash) and your command add a line that says:-

export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin (so the bit between the quotes you discovered above)

Basically, the paths are where Linux looks for files when it tries to run them. rc.local runs with a very minimal path - literally just access to core Linux stuff. Your rtl and mosquitto stuff probably isn't in that path - it will be somewhere else.
By Colonel Panic
#1823547
Thanks; mine is
declare -x PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/games:/usr/games"

But changing my .sh to this still didn't work past a reboot.

Code: Select all#!/bin/bash
export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/games:/usr/games
rtl_433 -F json -M utc -R 43 | mosquitto_pub -t home/rtl_433 -l -h 192.168.2.50 -p 1883 -u my username -P mypassword


In case it matters, when I use FileZilla to do a search...
rc.local is at /etc/rc.local
jjbwatchman.sh is at /home/pi/jjbwatchman.sh
Everything concerning the name "rtl_433" is within /home/pi/rtl_433/
A file called mosquito is at /usr/bin/mosquitto, but there are several other references in /usr/share/doc/...
User avatar
By stevelup
FLYER Club Member  FLYER Club Member
#1823553
OK, try adding...

cd /home/pi

... to your rc.local file before the main command.

Code: Select all#!/bin/bash
export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/games:/usr/games
cd /home/pi
rtl_433 -F json -M utc -R 43 | mosquitto_pub -t home/rtl_433 -l -h 192.168.2.50 -p 1883 -u my username -P mypassword

also just out of interest, what is the result of typing

which rtl_433
By Colonel Panic
#1823573
cd /home/pi ... to your rc.local file before the main command.
Code: Select all#!/bin/bash
export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/games:/usr/games
cd /home/pi
rtl_433 -F json -M utc -R 43 | mosquitto_pub -t home/rtl_433 -l -h 192.168.2.50 -p 1883 -u my username -P mypassword

edit your .sh file and between the 'shebang' (#!/bin/bash) and your command add a line that says:-

export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin (so the bit between the quotes you discovered above)


Sorry - I'm confused about whether I should put the export PATH line in the .sh or rc.local file :?



Re your other question ...
Code: Select allpi@raspberrypi:~ $ which rtl_433
/usr/local/bin/rtl_433
pi@raspberrypi:~ $
User avatar
By stevelup
FLYER Club Member  FLYER Club Member
#1823838
Sorry, I meant in your script file jjbwatchman.sh

Your rtl_433 executable is indeed in the path

Let's add some logging...

In your /etc/rc.local:-

Code: Select all/home/pi/jjbwatchman.sh 2>&1 > /home/pi/jjbwatchman.log &


reboot, then have a look at jjbwatchman.log - might shed some light on why it's not starting.
By Colonel Panic
#1823858
I can't begin to express how chuffed I am that I now know that that means "send standard errors & standard outputs" from the shell script to a new file called jjbwatchman.log. And changing the > to >> would be additive rather than replace. All thanks to signing up for a Linux for Dimwits course on Udemy.com 8)

Meanwhile I will do as suggested & revert.
stevelup liked this
By Colonel Panic
#1823868
OK, just to confirm / clarify, my /etc/rc.local file is
Code: Select all#!/bin/bash
export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/games:/usr/games
cd /home/pi
rtl_433 -F json -M utc -R 43 | mosquitto_pub -t home/rtl_433 -l -h 192.168.2.50 -p 1883 -u myuser -P mypassword

and my jjbwatchman.sh file is
Code: Select all#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.

# Print the IP address
_IP=$(hostname -I) || true
if [ "$_IP" ]; then
  printf "My IP address is %s\n" "$_IP"
fi
/home/pi/jjbwatchman.sh 2>&1 > /home/pi/jjbwatchman.log &
exit 0


After a reboot, the log file is ... empty :?

This is nohup.out if relevant
Code: Select allTrying conf file at "/usr/local/etc/rtl_433/rtl_433.conf"...
Trying conf file at "/etc/rtl_433/rtl_433.conf"...
Registered 1 out of 177 device decoding protocols [ 43 ]
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.
Allocating 15 zero-copy buffers
Signal caught, exiting!
rtl_433 version 20.11-47-g8151ad45 branch master at 202101311534 inputs file rtl_tcp RTL-SDR
Use -h for usage help and see https://triq.org/ for documentation.
Trying conf file at "rtl_433.conf"...
Trying conf file at "/root/.config/rtl_433/rtl_433.conf"...
Trying conf file at "/usr/local/etc/rtl_433/rtl_433.conf"...
Trying conf file at "/etc/rtl_433/rtl_433.conf"...
Registered 1 out of 177 device decoding protocols [ 43 ]
usb_claim_interface error -6
rtl_433 version 20.11-47-g8151ad45 branch master at 202101311534 inputs file rtl_tcp RTL-SDR
Use -h for usage help and see https://triq.org/ for documentation.
Trying conf file at "rtl_433.conf"...
Trying conf file at "/root/.config/rtl_433/rtl_433.conf"...
Trying conf file at "/usr/local/etc/rtl_433/rtl_433.conf"...
Trying conf file at "/etc/rtl_433/rtl_433.conf"...
Registered 1 out of 177 device decoding protocols [ 43 ]
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.
Allocating 15 zero-copy buffers
rtl_433 version 20.11-47-g8151ad45 branch master at 202101311534 inputs file rtl_tcp RTL-SDR
Use -h for usage help and see https://triq.org/ for documentation.
Trying conf file at "rtl_433.conf"...
Trying conf file at "/root/.config/rtl_433/rtl_433.conf"...
Trying conf file at "/usr/local/etc/rtl_433/rtl_433.conf"...
Trying conf file at "/etc/rtl_433/rtl_433.conf"...
Registered 1 out of 177 device decoding protocols [ 43 ]
usb_claim_interface error -6
Signal caught, exiting!


This might be informative?
pi@raspberrypi:~ $ ls -l
total 20
drwxr-xr-x 2 pi pi 4096 Jan 11 13:01 Bookshelf
-rw-r--r-- 1 root root 0 Feb 1 15:46 jjbwatchman.log
-rwxr-xr-x 1 root root 241 Feb 1 14:26 jjbwatchman.sh
-rw------- 1 root root 5742 Feb 1 15:46 nohup.out
drwxr-xr-x 15 pi pi 4096 Jan 31 15:42 rtl_433
  • 1
  • 20
  • 21
  • 22
  • 23
  • 24
  • 31