OpenWRT - Home Automation - Controlling a simple relay board

sezione dedicata ai sistemi operativi alternativi Open Source

OpenWRT - Home Automation - Controlling a simple relay board

Messaggio da leggereda root » 24/12/2014, 15:29

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

Immagine

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.

Immagine

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:

Immagine

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
Maurizio
Avatar utente
root
Amministratore
 
Messaggi: 347
Iscritto il: 10/04/2012, 10:55
Località: Ovada

Re: OpenWRT - Controlling leds and a simple 5V relay board

Messaggio da leggereda root » 24/12/2014, 17:11

If you use a Router with USB interface you can add SMS control functionality to the relay board using Gnokii.

Simply send a SMS to activate or deactivate a led (relay board).

Note: thanks to: http://www.nabuk.org/f/index.php?topic=2864.0

example of SMS command script for Huawei E169 USB 3G dongle and TP-Link TL-MR3020 router (Attitude Adjustment):

opkg update
opkg install luci-proto-3g
opkg install kmod-usb-core kmod-usb2 libusb usb-modeswitch usb-modeswitch-data usbutils kmod-usb-serial kmod-usb-serial-option kmod-usb-serial-wwan
opkg install gnokii
mkdir /root/sms


Now plug the USB 3G dongle and restart the router, than check with dmesg that you see 3 lines like this:
usb 1-1: GSM modem (1-port) converter now attached to ttyUSBx

if so, edit /root/getsms.sh:

####################################
# TP-Link TL-MR3020 + Huawei E 169 3G dongle + Gnokii
# OpenWRT Attitude Adjustment
#
# GetSMS - controlla la presenza di
# nuovi SMS sulla periferica e se
# riconosce dei comandi esegue delle
# operazioni.
#
#SMS#
#Send
On text to switch on the relay
#Send
Off text to switch off the relay
####################################


# Variabili
folder=/root/sms # Cartella di destinazione
newsms=$folder/newsms # Nuovi SMS
dbsms=$folder/dbsms # Database SMS
newcmd=$folder/newcmd # Nuovi comandi
dbcmd=$folder/dbcmd # Database comandi


numsms=3 # Numero di SMS da leggere

# Riempie il file newsms
gnokii --getsms ME 0 $numsms -d > $newsms


# Riempie il file newcmd
grep Text -A1 $newsms | grep -v "Text\|--" > $newcmd


# Conta i comandi
numcmd=$(grep -c "^" $newcmd)


# Se non ci sono nuovi comandi non prosegue
if [ $numcmd -eq 0 ]
then
exit 1
fi


# Analizza i comandi
for ancmd in $(cat $newcmd)
do
case $ancmd
in
On) echo 0 > /sys/devices/platform/leds-gpio/leds/tp-link:green:3g/brightness # canale ON
echo $ancmd >> $dbcmd;;
Off) echo 1 > /sys/devices/platform/leds-gpio/leds/tp-link:green:3g/brightness # canale OFF
echo $ancmd >> $dbcmd;;
*) ;;
esac
done


# Aggiunge gli sms al database SMS
cat $newsms >> $dbsms


# Svuota i file newcmd e newsms
> $newcmd
> $newsms


# Svuota memoria SMS
gnokii --deletesms ME 0 4
gnokii --deletesms SM 0 4


exit 0

save the file than:

chmod 777 /root/getsms.sh


Gnokii configuration file

edit /root/.gnokiirc:


[global]
model = AT
port = /dev/ttyUSB2
connection = serial


save the file than:

cp /root/.gnokiirc /etc/.gnokiirc


Cron configuration file (check for new SMS every 60 seconds

edit /etc/crontabs/root:

*/1 * * * * /bin/sh /root/getsms.sh

save the file than:

chmod 777 /etc/crontabs/root

-----------------------------------------------
NOTE: you can also send SMS messages from OpenWRT with gnokii using the following commandline:
echo "SMS test message from OpenWRT" | gnokii --sendsms +39393xxxxxx
-----------------------------------------------

LOGGING

Example of /root/sms/dbcmd (commands database):

On
Off
Off
On
Off
On
Off
On
Off

Example of /root/sms/dbsms (sms database):

0. Inbox Message (unread)
Date/time: 24/05/2014 15:49:29 +0200
Sender: 8214 Msg Center: +393358822000
Text:
On
0. Inbox Message (unread)
Date/time: 24/05/2014 15:50:19 +0200
Sender: 8214 Msg Center: +393358819500
Text:
Off
0. Inbox Message (unread)
Date/time: 24/05/2014 15:53:28 +0200
Sender: 8214 Msg Center: +393358822000
Text:
Off
0. Inbox Message (unread)
Date/time: 24/05/2014 16:13:19 +0200
Sender: 8214 Msg Center: +393358823500
Text:
On
0. Inbox Message (unread)
Date/time: 24/05/2014 16:14:14 +0200
Sender: 8214 Msg Center: +393358823500
Text:
Off
0. Inbox Message (unread)
Date/time: 24/05/2014 16:40:52 +0200
Sender: 8214 Msg Center: +393358819500
Text:
On
0. Inbox Message (unread)
Date/time: 24/05/2014 16:41:17 +0200
Sender: 8214 Msg Center: +393358822000
Text:
Off
0. Inbox Message (unread)
Date/time: 24/05/2014 20:13:03 +0200
Sender: 8214 Msg Center: +393358819500
Text:
On
0. Inbox Message (unread)
Date/time: 24/05/2014 20:14:14 +0200
Sender: 8214 Msg Center: +393358819500
Text:
Off

--------------------------------------------------------------

TEST

root@OpenWrt:~# gnokii --identify
GNOKII Version 0.6.21
IMEI : 3581090248xxxxx
Manufacturer : huawei
Model : E169
Product name : E169
Revision : 11.314.11.00.00

1) when no SMS received:

root@OpenWrt:~# sh /root/getsms.sh
GNOKII Version 0.6.21
GetSMS ME 0 failed! (The given location is empty.)
GetSMS ME 1 failed! (The given location is empty.)
GetSMS ME 2 failed! (The given location is empty.)
GetSMS ME 3 failed! (The given location is empty.)

root@OpenWrt:~# cat /sys/devices/platform/leds-gpio/leds/tp-link:green:3g/brightness
0

THE RELAY IS OFF

2) SMS sent with On text (Date/time: 24/12/2014 17:35:05 +0100):

root@OpenWrt:~# sh /root/getsms.sh
GNOKII Version 0.6.21
(message deleted)
GetSMS ME 1 failed! (The given location is empty.)
GetSMS ME 2 failed! (The given location is empty.)
GetSMS ME 3 failed! (The given location is empty.)

Content of /root/sms/dbsms:
0. Inbox Message (unread)
Date/time: 24/12/2014 17:35:05 +0100
Sender: 8214 Msg Center: +393358822000
Text:
On


Content of /root/sms/dbcmd:
On

root@OpenWrt:~# cat /sys/devices/platform/leds-gpio/leds/tp-link:green:3g/brightness
1

THE RELAY IS ON

3) SMS sent with Off text (Date/time: 24/12/2014 17:40:25 +0100):

root@OpenWrt:~# sh /root/getsms.sh
GNOKII Version 0.6.21
(message deleted)
GetSMS ME 1 failed! (The given location is empty.)
GetSMS ME 2 failed! (The given location is empty.)
GetSMS ME 3 failed! (The given location is empty.)

Content of /root/sms/dbsms:
0. Inbox Message (unread)
Date/time: 24/12/2014 17:35:05 +0100
Sender: 8214 Msg Center: +393358822000
Text:
On
0. Inbox Message (unread)
Date/time: 24/12/2014 17:40:25 +0100
Sender: 8214 Msg Center: +393358822000
Text:
Off


Content of /root/sms/dbcmd:
On
Off


root@OpenWrt:~# cat /sys/devices/platform/leds-gpio/leds/tp-link:green:3g/brightness
0

THE RELAY IS OFF
Maurizio
Avatar utente
root
Amministratore
 
Messaggi: 347
Iscritto il: 10/04/2012, 10:55
Località: Ovada

Re: OpenWRT - Controlling leds and a simple 5V relay board

Messaggio da leggereda root » 28/12/2014, 0:11

If you use Attitude Adjustment the cgi code for "echo" command is different (I don't know why)

#!/bin/ash
/bin/sh /root/on
cat /www/cgi-bin/enabled.txt | mini_sendmail -fsender@domain.com -ssmtp.domain.com -p25 user@domain.com
echo ''
echo ''
/bin/cat /sys/devices/platform/leds-gpio.0/leds/HW553:blue:adsl/brightness
echo '1 = Off, 0 = On'
Maurizio
Avatar utente
root
Amministratore
 
Messaggi: 347
Iscritto il: 10/04/2012, 10:55
Località: Ovada

Re: OpenWRT - Controlling leds and a simple 5V relay board

Messaggio da leggereda root » 28/12/2014, 0:33

You may add an USB Keyboard to locally control the relay board using triggerhappy.

See https://forum.openwrt.org/viewtopic.php?id=49013 for more info and instructions about Triggerhappy

I installed Openwrt Attitude Adjustment on Huawei EchoLife HG553 (Vodafone Station) with USB keyboard, USB webcam, USB 3G dongle to obtain a 3 channels remote control with the following features:

- Local control via USB keyboard/keypad
- Remote control via internet webpage
- Remote control via SMS (internet connection not needed)
- Email and SMS notification for any channel status change
- Video remote control via USB webcam (mjpg-streamer)
- Audio remote control via USB webcam's microphone (ssh arecord | aplay - alsa)

Vodafone Station has three usable channels with two leds each (red and blue), I used the blue leds to indicate channels deactivated and the red ones to indicate active channels .
Also, Vodafone Station does not have the problem that many routers have during startup sequence when all leds blink for several seconds.

You can buy single 3V/5V relay board on Ebay for about 4 Euro each

Immagine
Maurizio
Avatar utente
root
Amministratore
 
Messaggi: 347
Iscritto il: 10/04/2012, 10:55
Località: Ovada

Re: OpenWRT - Controlling leds and a simple 5V relay board

Messaggio da leggereda root » 28/12/2014, 0:48

Openwrt Attitude Adjustment on Huawei EchoLife HG553 (Vodafone Station)
Three channels remote control

#Channels OFF - blue leds ON - red leds OFF
# relay boards connected to blue led catodes
#
# channel 1
/bin/echo 1 > /sys/devices/platform/leds-gpio.0/leds/HW553:blue:adsl/brightness
/bin/echo 0 > /sys/devices/platform/leds-gpio.0/leds/HW553:red:adsl/brightness
# channel 2
/bin/echo 1 > /sys/devices/platform/leds-gpio.0/leds/HW553:blue:internetkey/brightness
/bin/echo 0 > /sys/devices/platform/leds-gpio.0/leds/HW553:red:internetkey/brightness
# channel 3
/bin/echo 1 > /sys/devices/platform/leds-gpio.0/leds/HW553:blue:lan/brightness
/bin/echo 0 > /sys/devices/platform/leds-gpio.0/leds/HW553:red:lan/brightness



#Channels ON- blue leds OFF - red leds ON
#relay boards connected to blue led catodes
#
# channel 1
/bin/echo 0 > /sys/devices/platform/leds-gpio.0/leds/HW553:blue:adsl/brightness
/bin/echo 1 > /sys/devices/platform/leds-gpio.0/leds/HW553:red:adsl/brightness
# channel 2
/bin/echo 0 > /sys/devices/platform/leds-gpio.0/leds/HW553:blue:internetkey/brightness
/bin/echo 1 > /sys/devices/platform/leds-gpio.0/leds/HW553:red:internetkey/brightness
# channel 3
/bin/echo 0 > /sys/devices/platform/leds-gpio.0/leds/HW553:blue:lan/brightness
/bin/echo 1 > /sys/devices/platform/leds-gpio.0/leds/HW553:red:lan/brightness


NOTE: red leds are not connected to anything, they are just used to show channels status.


-Web page example:

<meta http-equiv="refresh" content="5; URL=index.html">
<iframe
src ="/cgi-bin/test.cgi"
width="48%">
</iframe>
<br>
----------------------------------------------------------------------------------------------------------------------------------
<br>
Numero per comando da SMS: +393349xxx
<br>
testo SMS da inviare:
<br>
CANALE 1 = <b>On1</b> e <b>Off1</b> / CANALE 2 = <b>On2</b> e <b>Off2</b> / CANALE 3 = <b>On3</b> e <b>Off3</b>
<br>
----------------------------------------------------------------------------------------------------------------------------------
<br>
COMANDI CANALE 1
<p>
<FORM ACTION="/cgi-bin/off1.cgi">
<INPUT TYPE=SUBMIT VALUE="Spegni">
</FORM>
<FORM ACTION="/cgi-bin/on1.cgi">
<INPUT TYPE=SUBMIT VALUE="Accendi">
</FORM>
<p>
------------------------------------------------
<br>
COMANDI CANALE 2
<p>
<FORM ACTION="/cgi-bin/off2.cgi">
<INPUT TYPE=SUBMIT VALUE="Spegni">
</FORM>
<FORM ACTION="/cgi-bin/on2.cgi">
<INPUT TYPE=SUBMIT VALUE="Accendi">
</FORM>
<p>
------------------------------------------------
<br>
COMANDI CANALE 3
<p>
<FORM ACTION="/cgi-bin/off3.cgi">
<INPUT TYPE=SUBMIT VALUE="Spegni">
</FORM>
<FORM ACTION="/cgi-bin/on3.cgi">
<INPUT TYPE=SUBMIT VALUE="Accendi">
</FORM>
<p>
------------------------------------------------
<br>
<form action="luci.html">
<input type="submit" value="Pannello di controllo">
</form>
<p>
------------------------------------------------
<br>
<form action="http://192.168.1.143:8081/javascript_simple.html">
<input type="submit" value="Webcam">
</form>
<p>
------------------------------------------------
<p> by P.M. Lovisolo 2014
<br>
parknat12@yahoo.com



- /www/cgi-bin/test.cgi:

#!/bin/ash
echo ''
echo ''
/bin/cat /sys/devices/platform/leds-gpio.0/leds/HW553:blue:adsl/brightness
echo ''
echo ''
/bin/cat /sys/devices/platform/leds-gpio.0/leds/HW553:blue:internetkey/brightness
echo ''
echo ''
/bin/cat /sys/devices/platform/leds-gpio.0/leds/HW553:blue:lan/brightness
echo ''
echo 'Canali 1,2,3 : 1 = spento, 0 = acceso'



Important notes:
connect 3G dongle directly to the upper USB port
Connect a powered (5V) USB HUB to the lower USB port, than connect USB webcam ad USB keyboard to the USB Hub.


Immagine
Maurizio
Avatar utente
root
Amministratore
 
Messaggi: 347
Iscritto il: 10/04/2012, 10:55
Località: Ovada

Remote Audio Monitoring

Messaggio da leggereda root » 28/12/2014, 11:35

used a Microsoft HD 5000 USB webcam (1280x720 px max) with integrated microphone.

opkg install kmod-usb-core kmod-usb-ohci kmod-usb-uhci
opkg install kmod-sound-core kmod-usb-audio usbutils kmod-sound-cs5535audio
opkg install kmod-sound-i8x0 kmod-sound-soc-core
opkg install kmod-usb2
opkg install alsa-utils
opkg install alsa-lib


Open port 22 TCP on the ADSL router and forward it to the Openwrt device.

to listen to the audio:
ssh root@IP_ADDRESS -p 22 arecord -r 8000 -t wav -c 1 -f S16_LE | aplay -r 8000 -t wav -c 1 -f S16_LE
note: you need to enter root password.

Note: you'd better change ssh port to a non standard value (ex. 24)

Extra stuffs.
---------------

to control the audio levels:
alsamixer
(F4 for input controls - esc to exit)

To save anytime your current audio volume level, launch the following command:
/usr/sbin/alsactl -f /etc/alsa0.state store 0

and then to restore this on boot, create the file "/etc/init.d/alsa-cfg" and put the following text:

#!/bin/sh /etc/rc.common
START=98
start() {
alsactl -f /etc/alsa0.state restore 0
}


then make it executable:
chmod +x /etc/init.d/alsa-cfg

then enable it on boot with the following two commands:
/etc/init.d/alsa-cfg enable
Maurizio
Avatar utente
root
Amministratore
 
Messaggi: 347
Iscritto il: 10/04/2012, 10:55
Località: Ovada

Remote Video Monitoring

Messaggio da leggereda root » 28/12/2014, 11:41

- Microsoft HD 5000 webcam (autofocus)

opkg install kmod-video-uvc
opkg install kmod-i2c-core
opkg install kmod-video-core
opkg install kmod-usb-core
opkg install kmod-usb-uhci
opkg install kmod-usb-ohci
opkg install kmod-usb2
opkg install usbutils
opkg install kmod-video-gspca-core
opkg install kmod-video-gspca-sonixj
opkg install mjpg-streamer

than edit /etc/config/mjpg-streamer:

config mjpg-streamer core
option enabled "1"
option device "/dev/video0"
option resolution "640x480"
option fps "1"
option www "/www/webcam"
option port "8081"


note: to keep low CPU % usage do not go over 640x480 pixels resolution and 3 fps max (HD 5000 can go up to 1280x720 px)

enable mjpg-streamer at boot:
/etc/init.d/mjpg-streamer enable

Open port 8081 TCP on the ADSL router and forward it to the Openwrt device.

to see the webcam:
http://IP_ADDRESS:8081
Maurizio
Avatar utente
root
Amministratore
 
Messaggi: 347
Iscritto il: 10/04/2012, 10:55
Località: Ovada

Re: OpenWRT - Controlling leds and a simple 5V relay board

Messaggio da leggereda root » 28/12/2014, 17:40

in case you do not have any internet connectivity and want to have the channel status report sent by SMS:

- create empty DB file /root/status (just once)
touch /root/status

- edit /root/sms-status:

####################################
# Openwrt + USB dongle + Gnokii
#
# Write channel status to file
####################################


# Variabili
folder=/root # Cartella di destinazione
dbstatus=$folder/status # File Status


# Cancella file /root/status
rm /root/status


# Aggiunge status canali al file
echo "Status canali 1,2,3 : 1=Off, 0=On" >> $dbstatus
cat /sys/devices/platform/leds-gpio.0/leds/HW553:blue:adsl/brightness >> $dbstatus
cat /sys/devices/platform/leds-gpio.0/leds/HW553:blue:internetkey/brightness >> $dbstatus
cat /sys/devices/platform/leds-gpio.0/leds/HW553:blue:lan/brightness >> $dbstatus
exit 0


than:
chmod 777 /root/sms-status


- edit /www/cgi-bin/sms.cgi:

#!/bin/ash
/bin/sh /root/sms-status
cat /root/status | gnokii --sendsms +393336xxxxxx
cat /root/status | mini_sendmail -fsender@domain.com -ssmtp.provider.com -p25 user@domain.com


note: this cgi sends channels status by SMS and email, if you don't need email notification delete the last line.

than:
chmod 777 /www/cgi-bin/sms.cgi

to get the status by SMS run:
sh /www/cgi-bin/sms.cgi

- [Optional] Cron configuration file (sends channels status by email every night at 00:00):

edit /etc/crontabs/root ad add the following line:

0 0 * * * cat /root/status | mini_sendmail -fsender@domain.com -ssmtp.provider.com -p25 user@domain.com
----------------------------------------------------------------

Modifications to file "/root/getsms.sh" file for three channels control and Status feedback by SMS:

...
# Analizza i comandi
for ancmd in $(cat $newcmd)
do
case $ancmd
in
On1) /www/cgi-bin/on1.cgi # Canale 1 ON + email
echo $ancmd >> $dbcmd;;
Off1) /www/cgi-bin/off1.cgi # Canale 1 OFF + email
echo $ancmd >> $dbcmd;;
On2) /www/cgi-bin/on2.cgi # Canale 2 ON + email
echo $ancmd >> $dbcmd;;
Off2) /www/cgi-bin/off2.cgi # Canale 2 OFF + email
echo $ancmd >> $dbcmd;;
On3) /www/cgi-bin/on3.cgi # Canale 3 ON + email
echo $ancmd >> $dbcmd;;
Off3) /www/cgi-bin/off3.cgi # Canale 3 OFF + email
echo $ancmd >> $dbcmd;;
Status) /www/cgi-bin/sms.cgi # Aggiorna status canali lo manda per SMS
echo $ancmd >> $dbcmd;;
*) ;;
esac
done

...

Note: remember to create "/www/cgi-bin/on(x).cgi" and "/www/cgi-bin/off(x).cgi" files
Maurizio
Avatar utente
root
Amministratore
 
Messaggi: 347
Iscritto il: 10/04/2012, 10:55
Località: Ovada

Re: OpenWRT - Controlling leds and a simple 5V relay board

Messaggio da leggereda root » 28/12/2014, 18:53

Please note this device can be fully controlled and monitored by SMS, without needing any internet connectivity :)
This sounds quite strange for a router :D , but is very helpful if you want to remote control something in distant areas where there is no internet coverage, or you want to keep full control on it, even if there is an internet outage.
Obviously if you have Internet connectivity (Wi-fi/3G/LAN) you'll have more options available, like audio and video remote monitoring.
Maurizio
Avatar utente
root
Amministratore
 
Messaggi: 347
Iscritto il: 10/04/2012, 10:55
Località: Ovada

Re: OpenWRT - Controlling leds and a simple 5V relay board

Messaggio da leggereda root » 29/12/2014, 16:48

I've just added another feature to this Home Automation Server:
Auto-restore of previous channels status after a reboot/crash/power outage

You'll find all my "ready-to-use" configuration files and script, for Vodafone Station Huawei EchoLife HG553 + OpenWRT Attitude Adjustment, here:
http://www.lovisolo.com/asterisk/software/openwrt/Vodafone-Station-Home-Automation-Server/

If you want to use a different router, you'll just need to change the "/sys/devices/platform/leds-gpio..." trigger lines, with the ones suitable for your board.

Complete list of the board functionalities (using my files above):

- Three (or six) indipendent channels output (via simple relays board)
- Multiple input control (USB keyboard/USB keypad/USB mouse keys) with triggerhappy
- Full local control via keyboard/keypad/mouse
- Full local monitoring via red/blue leds on the router
- Full remote/local control/monitoring via internet webpage
- Full remote control/monitoring via SMS (internet connection not needed)
- Email and/or SMS notification for any channel status change
- Automatic restore of the previous channels status after a reboot/crash
- Realtime video remote/local control via USB webcam (mjpg-streamer)
- Realtime audio remote/local control via USB webcam's microphone (ssh arecord | aplay - alsa)

Web Control/Monitoring Page (including Luci & Webcam):

http://IP_Address/index.html

List of remote SMS commands:

On1 = Activate Channel 1
On2 = Activate Channel 2
On3 = Activate Channel 3
Off1 = Deactivate Channel 1
Off2 = Deactivate Channel 2
Off3 = Deactivate Channel 3
Status = Send all channels status by SMS

List of local USB Keyboard control keys

F1 = Activate Channel 1
F2 = Activate Channel 2
F3 = Activate Channel 3
F4 = Deactivate Channel 1
F5 = Deactivate Channel 2
F6 = Deactivate Channel 3
F9 = Activate All Channels
F10 = Deactivate All Channels

Enjoy :)


Final notes: with Vodafone Station Huawei EchoLife HG553, you can have up to six indipendent output channels if you control and use both, red and blue leds, to drive the relays.
Maurizio
Avatar utente
root
Amministratore
 
Messaggi: 347
Iscritto il: 10/04/2012, 10:55
Località: Ovada

Prossimo

Torna a OpenWRT e sistemi operativi vari

Chi c’è in linea

Visitano il forum: Nessuno e 1 ospite

cron