Command "send" not running when script is run from rc.local

Hei,

I’ve set up Pi MusicBox on my RaspberryPi2, which is working fine, but I’m now having trouble with a script, but only when I am running it at startup.
This script controls an LED and a button (both connected to GPIOs), and also controls a remote controlled socket (the transmitter is also connected to a GPIO).
The LED and the button work as designed. But here’s my problem:
If I run the script from the terminal, the socket is also turned on or off as it should, but if I run the script at startup (I’ve added following entry in /etc/rc.local, before the line exit 0, as it is required: python /home/scripts/scriptname.py & ), the socket doesn’t do anything…

To control the socket, I’ve installed everything according to this tutorial:
http://www.forum-raspberrypi.de/Thread-tutorial-funksteckdosen-mit-ios-android-version-2
I had to install build-essential before. So basically, I did this:
apt-get update
apt-get install build-essential
apt-get install git-core
cd ~
git clone git://git.drogon.net/wiringPi
cd wiringPi
./build
cd ~
git clone git://github.com/xkonni/raspberry-remote
cd raspberry-remote
make send
cp send /usr/local/bin/

I don’t understand why the command send doesn’t work when I autorun the script at startup. On a previous project, I was using OSMC, and the exact same script with the same install procedure worked just fine. (With OSMC, I didn’t have to install build-essential as it already was.)

Any suggestions how to get this running?
Thanks folks!

P.S.: sorry if I didn’t provide enough details or some required information. All this is still quite new to me and there are quite a few things that I struggle with… Please feel free to ask, I’ll gladly provide anything you need.

It’s worth remembering that things in rc.local will run as root so you’ll
need to ensure all your permissions are compatible with that I.e any device
permissions.

I’m not sure I understand the problem exactly. Is your python script
running the ‘send’ program? Or are these two unrelated things you are
trying to run in rc.local? Maybe it would be clearer if you provided the
contents of your script.

Yes, my python script is running the ‘send’ program. Here it is:


import RPi.GPIO as GPIO
import os
import time

GPIO.setmode(GPIO.BOARD)

LED1=[7]
GPIO.setup(LED1, GPIO.OUT)
GPIO.output(LED1, True)
GPIO.setup(5, GPIO.IN)

os.system(‘send 11111 4 1’)

while True:
if not (GPIO.input(5)):
GPIO.output(LED1, False)
time.sleep(.3)
GPIO.output(LED1, True)
time.sleep(.3)
GPIO.output(LED1, False)
time.sleep(.3)
GPIO.output(LED1, True)
os.system(‘send 11111 4 0’)
os.system(“sudo shutdown -h now”)
time.sleep(.5)

GPIO.output(LED1) is an LED
GPIO.input(5) is a button

The script turns the socket on with os.system('send 11111 4 1'), and when the button is pressed, turns the socket off with os.system('send 11111 4 0'). These are the parts that don’t work when the script is run from rc.local. When I run it from the terminal, they work.
The script also controls the LED and sends the shutdown command. These commands always work.

How do I check those permissions?

EDIT: indenting doesn’t seem to work. How can I post code with correct formatting?

I’d guess that /usr/local/bin is not on the path when you run it from
rc.local. You can try using /usr/local/bin/send in your script instead.
Also check that root has permission to execute /usr/local/bin/send
(probably does).

To format a block of code put three grave characters before and after it.
Kalkulon1 https://discourse.mopidy.com/users/kalkulon1
November 26

Yes, my python script is running the ‘send’ program. Here it is:

I guess that root has the correct permission, as send does what it has to when I run it from the terminal (logged in as root). As soon as I have time I’ll check if inserting the complete path helps. Probably tomorrow.

I’ll keep you updated. Thanks for your help.

Oops Yeh I forgot it’s the root user in musicbox 0.6. But hopefully it’s
just the path issue.

When using /usr/local/bin/send, everything’s working fine! Thanks for your help.
Just for my understanding: in PiMusicBox rc.local doesn’t have access to /usr/local/bin, but in other systems (like e.g. OSMC) it does?

I think in most systems rc.local runs with a very limited path. Yes, Osmc
did it differently for some reason. You can also define it explicitly at
the top of the file if you want.