OpenWrt Forum Archive

Topic: Help create code control gpio via web interface.

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

I mod 64MB RAM, USB for my router Dlink DIR615 C2.
Dlink DIR615 C2 have 6 free GPIO, i use GPIO [0, 2, 7, 9] control relay module. It work fine, i can control relay module via ssh command.
My /etc/rc.local

# Put your custom commands here that should be executed once
# the system init finished. By default this file does nothing.
#gpio0
echo "0" > /sys/class/gpio/export
echo "out" > /sys/class/gpio/gpio0/direction
echo "1" > /sys/class/gpio/gpio0/value
#gpio2
echo "2" > /sys/class/gpio/export
echo "out" > /sys/class/gpio/gpio2/direction
echo "1" > /sys/class/gpio/gpio2/value
#gpio7
echo "7" > /sys/class/gpio/export
echo "out" > /sys/class/gpio/gpio7/direction
echo "1" > /sys/class/gpio/gpio7/value
#gpio9
echo "9" > /sys/class/gpio/export
echo "out" > /sys/class/gpio/gpio9/direction
echo "1" > /sys/class/gpio/gpio9/value
exit 0

I type echo "1" > /sys/class/gpio/gpio9/value to control GPIO, Could anyone share me code control GPIO [0, 2, 7, 9] via web interface!
Thank you very much!

https://lh6.googleusercontent.com/-_fWFDUoqPL8/VIusap0KGSI/AAAAAAAAJeA/IE3lBjbIiaQ/w979-h590-no/IMG_20141213_100131.jpg

https://lh3.googleusercontent.com/-cC6yrKb0Vac/VIuscbdWOyI/AAAAAAAAJdQ/l-wUSIjWg2s/w979-h590-no/IMG_20141213_100144.jpg

https://lh5.googleusercontent.com/-Bj3OO0epoNc/VIusd6qCCcI/AAAAAAAAJcw/0NDrn0B2iXY/w979-h590-no/IMG_20141213_100213.jpg

(Last edited by hoatienii on 13 Dec 2014, 04:57)

if you plan use only for output direction, you can simply add that gpios as LEDs. So you can configure via standard web interface LED tab.

{
                    .name           = "d-link:relay:relay0",
                    .gpio           = 0, /* GPIO of relay*/
                    .active_low     = 1, /*Default value put 0 or 1 to enable this by default*/
            }
neryba wrote:

if you plan use only for output direction, you can simply add that gpios as LEDs. So you can configure via standard web interface LED tab.

{
                    .name           = "d-link:relay:relay0",
                    .gpio           = 0, /* GPIO of relay*/
                    .active_low     = 1, /*Default value put 0 or 1 to enable this by default*/
            }

Yes i only use for output direction. Thank you very much your guide.
Where i add this code?

The discussion might have continued from here.