Montag, 28. Juli 2014

Roller Shutter project: GPIO Relay Initialization on system boot

For my roller shutter controller project, I needed to ensure that the GPIO Pins for the Relay board get correctly exportet on system boot. I had a script called in the directory /home/pi/relay. When I executed the script everything worked and I could trigger the relays with my webinterface I made before. Now there was a problem:
How to get this to work on system boot?
I found several different ways to do this on the internet, and tried two different ways to do it:
The first was an entry in the /etc/rc.local, the second a crontab entry (via sudo crontab -e) with @reboot for execution. Both of those methods failed even though I could see at least the rc.local was getting executed, because for a test I put the command touch /home/pi/somefile in it, wich got executed on boot. (I did not try this for crontab)
After some trial and error and looking around in the internet I found the problem:
I was using the program gpio in my file, wich is located at /usr/local/bin/gpio. When you execute a program with just the executable name, the system searches for an executable with that name in your $PATH variable wich gets set while starting up the system. And thats exactly the problem: It gets set after rc.local is executed or cron executes the jobs marked with @reboot.
So to fix my problem I just had to change my calls from gpio to /usr/local/bin/gpio and everything worked like a charm.

Next problem:
In my scripts to move the roller shutter down and up I use another script wich stops the shutters (turns both relays off). I call that before turning anything on because I don't know how the roller shutter reacts when it gets a signal for up and down at the same time. When I just use the scripts from the console this works fine, meaning you will never see both relays on. But here is my problem: I have a web interface setup, wich has links to php-files that use shell_exec to execute my scripts. When I use the web interface the stop script does not seem to get executed, and so I can get both relays on.

Keine Kommentare:

Kommentar veröffentlichen