OpenWrt Forum Archive

Topic: Custom Command Syntax for GPIO

The content of this topic has been archived on 29 Mar 2018. There are no obvious gaps in this topic, but there may still be some posts missing at the end.

Hi all,

Apologies if this has been answered a dozen times, I'm pretty inexperienced with Linux/BusyBox and couldn't understand how to get this to work.

I'm using a Raspberry Pi running OpenWRT and have a couple of Relay drivers on GPIO Ports 23 & 24. I've inserted the following commands in the Local Startup (under System -> Startup) to generate the refences folders for each GPIO line.

echo "23" > /sys/class/gpio/export
echo "24" > /sys/class/gpio/export
echo "out" > /sys/class/gpio/gpio23/direction
echo "out" > /sys/class/gpio/gpio24/direction

If I run the commands:

echo 1 > /sys/class/gpio/gpio23/value
echo 0 > /sys/class/gpio/gpio23/value

I can switch a Relay ON and OFF.

What I'd like to do is assign the commands to actually control the Relay State to the System -> Custom Commands so I can push a GUI button and have the Relay change State.

I've pasted in my command "echo 1 > /sys/class/gpio/gpio23/value" into the Command line field, but when it's run, I get the output

# echo 1 ">" /sys/class/gpio/gpio23/value
1 > /sys/class/gpio/gpio23/value

How do I make the 'echo' in this command output to the file /sys/class/gpio/gpio23/value and not to the screen?

Thanks in advance
Rich

Quote the digit "1"

anomeome wrote:

Quote the digit "1"

That's what I thought was needed, but this has a strange effect.

The Custom Command Page shows:

Command: echo "0" > /sys/class/gpio/gpio23/value

When this is run, I get the output:

# echo 0 ">" /sys/class/gpio/gpio23/value
0 > /sys/class/gpio/gpio23/value

which is even stranger...

Did you try this from the cli? html?

anomeome wrote:

Did you try this from the cli? html?

When I enter the commands via the CLI, it works fine.

When the same commands are entered into the Custom Command fields in the OpenWRT html GUI, the "echo" sends the text following it to the screen, rather than to the /sys/class/gpio/gpio23/value file which will alter the relay state.

Would seem the command is being run at a higher level, rather than at the command line level, so the 'echo' is interpreted literally, without seeing the ">" option afterwards.

Good Day,

Did you get through with adding a button to your Raspberry Pi?

Hardware: Rasberry Pi B
OpenWrt version: CHAOS CALMER (15.05.1, r48532)

I want to use power and reset buttons that I recovered from an ATX case to shutdown and reset a Client AP Wifi connection on button press.

A Wifi reset function was successfully assigned to a slider button on a TP-Link TL-MR3040 on Chaos Calmer. I no longer have that hardware but I want to replicate this device using a Raspberry Pi. In the past I have also used the Raspberry Pi (Raspbian) with Python to control relays.

One lead of the button is connected to a ground pin and the other to the GPIO pin #. I tried the following:

echo "25" > /sys/class/gpio/export
echo "in" > /sys/class/gpio/gpio25/direction
cat /sys/class/gpio/gpio25/value

and

echo "24" > /sys/class/gpio/export
echo "in" > /sys/class/gpio/gpio24/direction
cat /sys/class/gpio/gpio24/value

But the value is always 0 when I depress (press and hold) the buttons. I also switched the 'polarity' of the button leads but still get values of 0.

ATX momentary switches are all the buttons I have access to. Shouldn't these work?
How can I get a custom command to execute with a momentary button press?

Thanks in advance for the assistance!

(Last edited by BenGman on 23 May 2016, 11:58)

I get a similar issue:
When I put command:
do something && then do something
into system - custom command then run it, It always runs as
do something "&&" then do something

Any way to avoid the transform?

(Last edited by NemoAlex on 26 Jun 2016, 16:57)

Also,
wget -O - http://xxx | sh
has been converted to
wget -O - "http://xxx" "|" sh

This is going to drive me crazy.

The discussion might have continued from here.