External command not working with script and relay board
Dear all,
I am trying to set up external command to power on/off my printer. When I execute the script in putty, everything is working fine and as expected.
The buttons are displayed in the settings menu but it is not working.
I will really appreciate some help on this.
Scripts
I am trying to set up external command to power on/off my printer. When I execute the script in putty, everything is working fine and as expected.
The buttons are displayed in the settings menu but it is not working.
I will really appreciate some help on this.
Scripts
relay_01_on.sh
#!/bin/bash
gpio mode 0 out
gpio write 0 0
relay_01_off.sh:
#!/bin/bash
gpio mode 0 out
gpio write 0 1
extcommands
extcommands
<command>
<name>Power ON Anycubic Kossel Linear Plus</name>
<execute>bash /home/pi/scripts/relay_01_on.sh </execute>
<confirm> Turn ON Anycubic Kossel Linear Plus</confirm>
</command>
<command>
<name>Power OFF Anycubic Kossel Linear Plus</name>
<execute>bash /home/pi/scripts/relay_01_off.sh </execute>
<confirm> Turn OFF Anycubic Kossel Linear Plus</confirm>
</command>
Comments
chmod 755 filename
so everybody can execute them. Adjust path in extcommands.xml and restart server.
I am probably doing something wrong but I cannot get these scripts working. I am not an expert and collected all the info from google.
Step 1: copy scripts to /var/lib/Repetier-Server/scripts
--> scripts are .sh file
Step 2: set permission
pi@Repetier-Server:/var/lib/Repetier-Server/scripts $ chmod 755 relay_01_on.sh
pi@Repetier-Server:/var/lib/Repetier-Server/scripts $ chmod 755 relay_01_off.sh
Step 3: update extcommands file
What am I missing ?
#!/bin/bash
and linux knows that script needs to be started with bash. Then omit bash parameter.
Then try running it as user repeteirserver
I am probably doing something wrong again.
I confirm that both files are in the correct folder and I double checked the spelling as well. See the printscreen
Can you confirm that both script file extcommands file are correct ?
extcommands file:
#!/bin/bash
should be first line in your shell scripts to mark them to be executed with bash.
In extcommands it should be
<execute>/var/lib/Repetier-Server/scripts/relay_01_on.sh </execute>
Still having this "No such file or directory" message and nothing happens when I try to run the script from the console
sudo -u repetierserver /var/lib/Repetier-Server/scripts/relay_01_on.sh
shows the error message? In that case does
/var/lib/Repetier-Server/scripts/relay_01_on.sh
work?
If it works as pi then the path is not readable by repetierserver. Check all directory and file permissions with
ls -l folder
Especially
ls -l /var/lib/Repetier-Server
and
ls -l /var/lib/Repetier-Server/scripts
Also please show output of
cat /var/lib/Repetier-Server/scripts/relay_01_on.sh
to see if you modified it as required.
1.
2.
4.
type gpio
should show it somewhere reachable in path variable since you did not enter full path to the command.
type gpio
If it is in your home directory the script will not find it.
The strange thing is when I test a command that does not exist I get:
pi@Felix:~ $ sudo -u repetierserver ./test.shdd
sudo: ./test.shdd: command not found
While you get: No such file or directory
The fact that you can cat the file you can not start also shows that it is there and permissions are correct. So it must be in the file but I don't see it. Have double checked and on my pi at bash is in /bin/bash - if not that line would not work and maybe cause the problem. So for safety what does
type bash
return and what linux are you using? From output I thought it was our pi server image in some version.
I purged the install. Where am I supposed to install it and how to proceed ?
I saw different ways to install gpio in this article. This is a bit cleared but I need to know the best method to install and where to export gpio.
sudo apt-get install wiringpi
to install it globally like described here: http://wiringpi.com/download-and-install/
No need to build from sources. After that it is installed in /usr/bin and available for all users.
Here is the step by step that I have followed:
1. Flash SD card with Etcher (Repetier-Server-Image_0_93_0_v20) + insert pro license
2. Install wiringpi (sudo apt-get install wiringpi)
3. Run sudo apt-get update & sudo apt-get upgrade
4. Copy the following bash scripts (/var/lib/Repetier-Server/scripts) and set permission
a) I have had to run the following cmd to be allowed to copy in that folder (sudo chown -R pi /var/lib/Repetier-Server)
Copied with Filezilla
e.g.: filename: relay_01_on.sh
#!/bin/bash
b) set permission
5) Delete and re upload extcommand file
6) serve reboot + power off / power on
I am probably doing something wrong somewhere in the process but for now I am still not able to run this script.
Not you #/bin/bash ends with cr lf which does not work. You need the file in unix text format anding only with lf.
Best is to delete the file and create it with
nano scriptname.sh
on the ssh console. Then it has correct line ending.
Still getting the same results.
This is the lines that I inserted when using nano cmd
Did I miss something ?
I have had to re set permissions.
I confirm that it is working now.
Thanks a lot for your help