Check also my other How To's:
[How To] Openwrt + Asterisk11 + GSM/SMS channel (chan_dongle):
https://forum.openwrt.org/viewtopic.php … 90#p253590
and
[HowTo] Openwrt cheap Digital Stereo WiFi Internet Radio & MP3 Player:
https://forum.openwrt.org/viewtopic.php … 63#p225463
and
[How To] Web SMS server with OpenWRT:
https://forum.openwrt.org/viewtopic.php?id=60910
-----------------------------------------------------------------------------------------
Quick and Mini How-to:
"OpenWRT - Controlling leds and a simple 5V relay board via Web interface"
on TP-Link TL-WR741nd with OpenWRT Backfire.
http://wiki.openwrt.org/toh/tp-link/tl-wr741nd
First, check you have the following kernel module and sofware installed:
opkg update
opkg install kmod-leds-gpio
opkg install kmod-ledtrig-gpio kmod-ledtrig-default-on
opkg install mini-sendmail
Led commands (example for "SYS" led = "DS1" on PCB)
---------------------------------------------------
led green:system (1= led on - 0= led off):
/bin/echo 1 > /sys/devices/platform/leds-gpio/leds/tl-wr741nd:green:system/brightness
/bin/echo 0 > /sys/devices/platform/leds-gpio/leds/tl-wr741nd:green:system/brightness
Check led state
---------------------
cat /sys/devices/platform/leds-gpio/leds/tl-wr741nd:green:system/brightness
Note: the other available Led on this router is QSS : tl-wr741nd:green:qss
-------------------------------------
Startup settings, edit /etc/rc.local:
/bin/echo none > /sys/devices/platform/leds-gpio/leds/tl-wr741nd:green:system/trigger
/bin/echo 1 > /sys/devices/platform/leds-gpio/leds/tl-wr741nd:green:system/brightness
exit 0
note: set default led status = off
--------
cgi-bin
--------
- edit /www/cgi-bin/on.cgi:
#!/bin/ash
echo 'ON'
/bin/sh /root/on
cat /www/cgi-bin/enabled.txt | mini_sendmail -fsender@domain.com -ssmtp.domain.com -p25 user@domain.com
note: switch on relay board and than send activation notification by email
- edit /www/cgi-bin/off.cgi:
#!/bin/ash
echo 'OFF'
/bin/sh /root/off
cat /www/cgi-bin/disabled.txt | mini_sendmail -fsender@domain.com -ssmtp.domain.com -p25 user@domain.com
note: switch ff relay board and than send deactivation notification by email
- edit /www/cgi-bin/test.cgi:
#!/bin/ash
echo '0 = Activated, 1 = Deactivated'
echo ' '
/bin/cat /sys/devices/platform/leds-gpio/leds/tl-wr741nd:green:system/brightness
note: show cannels status on screen (web page)
- edit /www/cgi-bin/enabled.txt:
subject: Activated!
- edit /www/cgi-bin/disabled.txt:
subject: Deactivated!
---------
Scripts:
---------
- edit /root/on:
/bin/echo 0 > /sys/devices/platform/leds-gpio/leds/tl-wr741nd:green:system/brightness
- edit /root/off:
/bin/echo 1 > /sys/devices/platform/leds-gpio/leds/tl-wr741nd:green:system/brightness
-----------------------------------------------
Important Notes:
- All cgi and scripts need "chmod 777"
- The signal from led catode is inverted: when the led is OFF the signal voltage is high = relay ON , when the led is ON the signal voltage is low = relay OFF
- The router starts blinking all leds on the startup sequence for several seconds, to avoid the relay board triggering on and off during router bootup, you need to (hardware) delay the activation of the relay boards until the router is fully booted, you may use a NE555 timer or better add a digital/relay logic to wait til the router is fully up.
-----------------------------------------------
Web control panel (basic example)
-----------------------------------------
give the following comand:
mv index.html luci.html
-edit /www/index.html:
------------------------------------------------
<br>
CENTRALINA DI COMANDO
<br>
------------------------------------------------
<p>
<FORM ACTION="/cgi-bin/off.cgi">
<INPUT TYPE=SUBMIT VALUE="Switch off">
</FORM>
<FORM ACTION="/cgi-bin/on.cgi">
<INPUT TYPE=SUBMIT VALUE="Switch on">
</FORM>
<p>
------------------------------------------------
<br>
STATUS CHECK
<br>
------------------------------------------------
<p>
<FORM ACTION="/cgi-bin/test.cgi">
<INPUT TYPE=SUBMIT VALUE="check status">
</FORM>
<p>
------------------------------------------------
<form action="luci.html">
<input type="submit" value="Luci control panel">
</form>
<p>
------------------------------------------------
<p> by P.M. Lovisolo 2014
-----------------------------------------
GPIO pin (3V) = Led Catode of DS1 (Sys led) close to C382, opposite to "+" label
Transistor = 2n2222 or equivalent
Diode=1n4004 or equivalent
Resistors = 1/4W 5 or 10%
Note: you may add a red led with a 1Kohm drop resistor in parallel to the relay coil.
Be very careful when soldering!
After the soldering process, block the connection wires to the PCB with a drop of glue to prevent pulling fragile pads away from router pcb!
----------------------------------------------------------------------
GPIOs are commonly used in router devices for buttons or leds. They only safely supply or sink (pull to GND) a maximum of 4mA aprox., and the voltage is usually 3V when active. Only two states are possible: high or low. Depending on how a device is activated by a GPIO, active low or active high is defined.
active high: the device is activated when the GPIO is HIGH
active low: the device is activated when the GPIO is LOW
Depending on your router model you may have the following configurations:
NOTES:
If you have installed OpenWrt on your router the leds should be controlled by the leds_gpio kernel module. Every led will have an entry in sysfs under /sys/class/leds
To manually control a led you should first set the trigger file to none, otherwise the led will be controlled for its original function, i.e. ethernet activity indicator:
echo none > trigger
Then you can set the value by writing to the brightness file. This file represents the brightness level which should range from 0 to the value contained in the max_brightness file. However, in most cases there will not be hardware brightness control for the leds (like with GPIO), so 0 will turn OFF the led and any non-zero value will turn it ON:
echo 0 > brightness
echo 1 > brightness
(Last edited by pilovis on 13 Nov 2015, 13:24)