OpenWRT - Home Automation - Controlling a simple relay board

sezione dedicata ai sistemi operativi alternativi Open Source

Re: OpenWRT - Home Automation - Controlling a simple relay b

Messaggio da leggereda root » 06/01/2015, 0:21

... if you have a router that supports GPIO inputs (Vodafone Station does NOT) you can connect the PIR sensor directly to GPIO without using USB, simply connect the collector of the Optocoupler output transistor to a GPIO input pin (button active low image).

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

Re: OpenWRT - Home Automation - Controlling a simple relay b

Messaggio da leggereda root » 25/01/2015, 14:59

Note:

changes from Attitude Adjustment to Barrier Breaker for Vodafone Station A.K.A Huawei EchoLife HG553 :

If you have installed Barrier Breaker, you should change the following lines (anywhere they appear):

/sys/devices/platform/leds-gpio.0/leds/HW553:blue:internetkey/brightness
/sys/devices/platform/leds-gpio.0/leds/HW553:red:internetkey/brightness

to

/sys/devices/platform/leds-gpio.0/leds/HW553:blue:hspa/brightness
/sys/devices/platform/leds-gpio.0/leds/HW553:red:hspa/brightnes
Maurizio
Avatar utente
root
Amministratore
 
Messaggi: 348
Iscritto il: 10/04/2012, 10:55
Località: Ovada

Re: OpenWRT - Home Automation - Controlling a simple relay b

Messaggio da leggereda root » 25/01/2015, 14:59

IMPORTANT NOTE:

Since i discovered (it's my fault :( ) that during bootup all three channels are ON (cause the blue leds are off), I used the "red power led" as a consensus switch to Power (+5 Vcc) the "three cannels relay board" only after the full bootup sequence is finished.

To do so I used another relay channel (transistor+relay) and connected it to the red Power led cathode, than I put the following two lines in "/etc/rc.local" at the end of the file, just before "exit 0" command:

/bin/sleep 10
/bin/echo 1 > /sys/devices/platform/leds-gpio.0/leds/HW553:red:power/brightness
Maurizio
Avatar utente
root
Amministratore
 
Messaggi: 348
Iscritto il: 10/04/2012, 10:55
Località: Ovada

Re: OpenWRT - Home Automation - Controlling a simple relay b

Messaggio da leggereda root » 28/01/2015, 15:01

Baresip Openwrt SIP client

Baresip it's a good program but official documentation is hardly inexistent and sucks, like many small linux programs, as usual I had to figure out how to configure and use it.
How the hell do they create programs without writing a decent documentation? :mad: :mad:

- Prerequisites:

1) install Alsa and USB audio support
2) connect an USB audio adapter with a speaker and a microphone or a USB phone / headset (with microphone)
note: you might also use a USB webcam with internal microphone or just a USB microphone, in both cases you don't need an USB audio adapter but you won't have any speaker (one way audio)
3) adjust audio levels of speaker and microphone with command: alsamixer

note: see my other "How To" for detailed instructions how to configure USB audio: https://forum.openwrt.org/viewtopic.php?pid=225463#p225463


- Installation and configuration of Baresip on Barrier Breaker (Baresip doesn't work on Attitue Adjustment: broken audio!):

opkg update
opkg install kmod-usb-hid
opkg install kmod-hid kmod-hid-generic
opkg install baresip baresip-mod-alsa baresip-mod-cons baresip-mod-evdev baresip-mod-g711
opkg install baresip-mod-stdio baresip-mod-uuid


Launch baresip once to generate the default configuration files on /root/.baresip:

baresip

after a few seconds stop it with ctrl+c
then you need to edit the configuration files

cd /root/.baresip

first edit "accounts" file

delete everything and insert the following line (use the values of your SIP accont):

<sip:user:password@sip-provider.com:port>;stunserver=stun:stun.ekiga.net


Note: you can add optional parameters to this line just by adding one or more of them with the following format:
<sip:user:password@domain;uri-params>;addr-params

example:
<sip:user:password@sip-provider.com:5060;transport=udp>;answermode=auto;stunserver=stun:stun.ekiga.net

list of optional URI params:

# ;transport={udp,tcp,tls}

list of optional addr-params:

# ;answermode={manual,early,auto}
# ;audio_codecs=speex/16000,pcma,...
# ;auth_user=username
# ;mediaenc={srtp,srtp-mand,srtp-mandf,dtls_srtp,zrtp}
# ;medianat={stun,turn,ice}
# ;outbound="sip:primary.example.com;transport=tcp"
# ;outbound2=sip:secondary.example.com
# ;ptime={10,20,30,40,...}
# ;regint=3600
# ;regq=0.5
# ;rtpkeep={zero,stun,dyna,rtcp}
# ;sipnat={outbound}
# ;stunserver=stun:[user:pass]@host[:port]


then edit "config" file

delete everything and insert the following lines:

#comments added by pilovis
#
poll_method epoll
input_device /dev/input/event0 #eventually adapt input device for your system
input_port 5555
sip_trans_bsize 128
audio_player alsa,default # audio speaker device
audio_source alsa,default # audio microphone device
audio_alert alsa,default # audio ring device
#
# if you want to use more than one audio device you need to use: alsa,default:CARD=devicename
# to discover device name use command: aplay -L
# -----------------------------------------------------------
audio_srate 8000-48000
audio_channels 1-2
rtp_tos 184
rtcp_enable yes
rtcp_mux no
#jitter_buffer_delay 15-35 # uncomment this line only in case you use an external voip provider and you experience high ping latence
rtp_stats no
dns_server 8.8.8.8:53 # use your preferred DNS server
module_path /usr/lib/baresip/modules
module stdio.so
module evdev.so
module g711.so
module alsa.so
module stun.so
module turn.so
module_tmp account.so
module_app contact.so
module_app menu.so
natbd_server creytiv.com # I'm not sure this line is necessary when you set "stunserver" option on user account
# and/or for local accounts: <user:password@localhost>
natbd_interval 600 # same as above, you might try to comment "#" both lines and test if baresip works
# eof


Launch Baresip:

baresip

then press "?" for all available commands

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

- Baresip remote audio monitoring

Make an automatic SIP phone call with the following command:

(/bin/echo sip:other-user@voip-provider.com; /bin/sleep 60; /bin/echo q) | /usr/bin/baresip -f /root/.baresip -e d

Note: "sleep 60; echo q" set the total call duration time at 60 seconds including ring time, after that "quit" command is sent to baresip, even if the remote party has not answered the call yet.

When the remote party answers the phone, he/she hears the ambient audio captured from the local microphone, also if he/she talks, his/her voice is sent to the local speaker (if connected and active).

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

- Launch Baresip as a daemon and configure it to auto answer all incoming calls

first configure baresip for auto answer all incoming calls by editing the "/root/.baresip/accounts" file as the following:

<sip:user:password@sip-provider.com:5060;transport=udp>;answermode=auto;stunserver=stun:stun.ekiga.net

then launch it as a daemon with the following command:

/usr/bin/baresip -f /root/.baresip -d

then try to call your local sip account, baresip won't ring but will answer the call and will start streaming the local audio to you (remote caller), same as above, if you talk, people near to the openwrt router will hear your voice through the speaker (speakerphone mode)

NOTE: if you use baresip as a daemon and you also want to issue an automatic call from local (openwrt) to remote (eg.: your mobile), you should change the previous auto call command to the following:

(/bin/echo sip:other-user@voip-provider.com; /bin/sleep 60; /bin/echo b) | /usr/bin/baresip -f /root/.baresip -e d

basically here we are sending "b" command (HANGUP CALL) to baresip instead of "q" (QUIT BARESIP) because we want to keep baresip running in background.

If you want to use a USB Voip phone or a USB headset but you want to have a separate speaker that rings for the incoming calls, you need an extra USB audio adapter for the speaker, alsa will recognize it with a different device name, then you just need to modifiy "config" file as the following:

audio_player alsa,default:CARD=headset_devicename
audio_source alsa,default:CARD=headset_devicename
audio_alert alsa,default:CARD=other_devicename


note: to find the two device names launch command: aplay -L
----------------------------------------------------------------------------------------

- USB Keypad

if you connect an USB numeric keypad to your router, you can use it to answer the incoming calls (Enter Key) and/or to dial phone numbers followed by "Enter" key to start the call.
To hangup/cancel the call press "Del" key.

Note: if you want to use the keypad to accept incoming calls by pressing "Enter", you need to modify the account configuration file as the following:

<sip:user:password@sip-provider.com:5060;transport=udp>;answermode=manual

Immagine

If you use a USB Phone you don't need the USB audio adapter.

Immagine

if you install "kmod-usb-cm109" you can use some (old) USB Voip phones with support of their integrated keys, like
KIP 1000, G-talk , Atcom au100, Allied-Telesis Corega USBPH01, same for "kmod-usb-yealink" that support Yealing Voip phones.

Immagine ImmagineImmagine

NOTE:

if you have installed Asterisk11 on the same router and you want to connect Baresip to local Asterisk, this is the account configuration example:

<sip:user:password@localhost>;answermode=manual



- To start Baresip at bootup but only after Asterisk has fully started, add the following line to /etc/rc.local:

/bin/sleep 10
/etc/init.d/asterisk start
/usr/bin/baresip -f /root/.baresip -d &&
exit 0


Don't use /etc/init.d/baresip enable or start, cause is broken (config path missing) and will not start at bootup nor will launch baresip daemon :mad: :mad:
Maurizio
Avatar utente
root
Amministratore
 
Messaggi: 348
Iscritto il: 10/04/2012, 10:55
Località: Ovada

Re: OpenWRT - Home Automation - Controlling a simple relay b

Messaggio da leggereda root » 17/04/2015, 4:03

Burglar alarm with motion detection
SMS + eMail + phone call on triggered allarm
SMS & Web remote control
Remote Audio & Video monitoring
1 channel output 1500 W max

Total cost = 70 Euro
Details & instructions @

Youtube video:
https://www.youtube.com/watch?v=nSt9eXwbLkk


Immagine

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

Re: OpenWRT - Home Automation - Controlling a simple relay b

Messaggio da leggereda root » 17/04/2015, 4:06

Basic Authentication on uhttpd

To add a password to uhttpd (web page access) do the following:

uci set uhttpd.main.config=/etc/httpd.conf
uci commit uhttpd
echo "/:root:password" > $(uci get uhttpd.main.config)
/etc/init.d/uhttpd restart
Maurizio
Avatar utente
root
Amministratore
 
Messaggi: 348
Iscritto il: 10/04/2012, 10:55
Località: Ovada

Re: OpenWRT - Home Automation - Controlling a simple relay b

Messaggio da leggereda root » 17/04/2015, 4:09

Since mjpg-streamer documentation sucks, I'm putting here some useful information about it:


- to remotely capture a snapshot image from mjpg-streamer and save it to a jpg format:

wget http://user:password@mjpg-streamer-address:port/?action=snapshot -O output.jpg

- to remotely capture a streaming video from mjpg-streamer and save it to a file (mjpg format) format (open it with VLC):

wget http://user:password@mjpg-streamer-address:port/?action=stream -O output.mjpg

- to remotely capture a streaming video from mjpg-streamer and save it to a file (mjpg format) with a timestamp into the filename (open it with VLC):

now=$(date +"%Y-%m-%d----%H-%M-%S") ; wget http://user:password@mjpg-streamer-address:port/?action=stream -O output$now.mjpg

filename example: "output2015-01-13----01-10-13.mjpg"


- to put an overlay "time" on streaming video this is the mjpg-streamer "/www/webcam/index.html" modified file:

<html>
<head>
<title>MJPG-Streamer</title>
<style>
.container { position:relative; }
.container video {
position:relative;
z-index:0;
}


.overlay {
position:absolute;
top:0;
left:0;
z-index:1;
}
</style>
</head>
<body>
<div class="container">
<img src="/?action=stream"/>
<div class="overlay">
<div style="position:absolute;width:290px;font-size:200%;font-weight:bold; background-color:lightgray; filter:alpha(opacity=60); opacity:.6;" id="time_span"> </div>


</div>
</div>

<script type='text/javascript'>
timer();


function timer(){
var now = new Date,
hours = now.getHours(),
ampm = hours<=11 ? ' AM' : ' PM'
minutes = now.getMinutes(),
seconds = now.getSeconds(),
t_str = "&nbsp;" + [hours,
(minutes < 10 ? "0" + minutes : minutes),
(seconds < 10 ? "0" + seconds : seconds)]
.join(':') + ampm + "&nbsp;&nbsp;&nbsp;&nbsp;";
document.getElementById('time_span').innerHTML = t_str;
setTimeout(timer,1000);
}


</script>

</body>
</html>



- to launch mjpg-streamer from commandline:

mjpg_streamer -i "./input_uvc.so -f 5 -r 640x480" -o "./output_http.so -w ./www"

note: this command does not use the /etc/config/mjpg-streamer configuration file

or:

/etc/init.d/mjpg-streamer start

note: this command uses the /etc/config/mjpg-streamer configuration file


"/etc/config/mjpg-streamer" configuration file:

config mjpg-streamer 'core'
option enabled '1'
option input 'uvc'
option output 'http'
option device '/dev/video0'
option resolution '640x480'
option fps '5'
option www '/www/webcam'
option port '8080'
option username 'user'
option password 'password'



- to enable mjpg-streamer autostart at bootup:

/etc/init.d/mjpg-streamer enable


- script to remotely capture a streaming video for one hour from mjpg-streamer and save it to a file (mjpg format) with a timestamp into the filename, than stops and starts another recording, and so on (infinite loop)

#!/bin/bash
while :
do
now=$(date +"%Y-%m-%d----%H-%M-%S")
wget http://user:password@mjpg-streamer-addr ... ion=stream -O output$now.mjpg &
sleep 3600
ps -ef | grep wget | awk '{print $2}' | xargs kill
done




... more to come
Maurizio
Avatar utente
root
Amministratore
 
Messaggi: 348
Iscritto il: 10/04/2012, 10:55
Località: Ovada

Re: OpenWRT - Home Automation - Controlling a simple relay b

Messaggio da leggereda root » 07/09/2016, 0:29

Netgear DGND3700V1 has 11 LEDs of wich 9 of them can be used to control 9 relays, fortunately these 9 LEDs do not turn on or do not start blinking during startup process :)

The downside of this router is that the internal PCI WiFi module is bad supported on OpenWRT, as a workaround you can use a different WiFI PCI board or connect an external USB WiFi dongle to the router (or use an ethernet cable).

This router is very powerful: it has 2x400 Mhz CPUs, 2xUSB2 ports, 2 integrated Switch buttons (plus reset) both usable directly by triggerhappy, 1 WAN and 4 LAN ethernet connectors, 128 Mbytes of RAM plus 64 Mbytes of Swap (NAND) and 32 Mbytes of Flash (NOR).

Here are the commands to switch ON the 9 LEDs (to switch them off use "echo 0 > ..."):

/bin/echo 1 > /sys/devices/platform/leds-gpio.0/leds/DGND3700v1_3800B:blue:wifi5g/brightness
/bin/echo 1 > /sys/devices/platform/leds-gpio.0/leds/DGND3700v1_3800B:green:dsl/brightness
/bin/echo 1 > /sys/devices/platform/leds-gpio.0/leds/DGND3700v1_3800B:green:inet/brightness
/bin/echo 1 > /sys/devices/platform/leds-gpio.0/leds/DGND3700v1_3800B:green:usb-back/brightness
/bin/echo 1 > /sys/devices/platform/leds-gpio.0/leds/DGND3700v1_3800B:green:usb-front/brightness
/bin/echo 1 > /sys/devices/platform/leds-gpio.0/leds/DGND3700v1_3800B:green:wifi2g/brightness
/bin/echo 1 > /sys/devices/platform/leds-gpio.0/leds/DGND3700v1_3800B:green:wps/brightness
/bin/echo 1 > /sys/devices/platform/leds-gpio.0/leds/DGND3700v1_3800B:red:inet/brightness
/bin/echo 1 > /sys/devices/platform/leds-gpio.0/leds/DGND3700v1_3800B:green:lan/brightness


LED name, Color, GPIO, #note
power, red, 22, # it turns on at bootup
power, green, 24, # it turns on and starts blinking at bootup
lan, green, 23, # usable
usb-back, green, 14, # usable
wifi2g, green, 26, # usable
wifi5g, blue, 27, # usable
dsl, green, 2, # usable
inet, red, 4, # usable
inet, green, 5, # usable
usb-front, green, 13, # usable
wps, green, 11, # usable


Board switches as seen by triggerhappy:

root@OpenWrt:~# thd --dump /dev/input/event*
EV_KEY KEY_WPS_BUTTON 1 /dev/input/event0
# KEY_WPS_BUTTON 1 command
EV_KEY KEY_WPS_BUTTON 0 /dev/input/event0
# KEY_WPS_BUTTON 0 command
EV_KEY KEY_WLAN 1 /dev/input/event0
# KEY_WLAN 1 command
EV_KEY KEY_WLAN 0 /dev/input/event0
# KEY_WLAN 0 command


KEY_WLAN = gpio-10
KEY_WPS_BUTTON = gpio-35


Usable GPIOs:

root@OpenWrt:~# cat /sys/kernel/debug/gpio
GPIOs 0-37, bcm63xx-gpio:
gpio-2 (DGND3700v1_3800B:gre) out hi
gpio-4 (DGND3700v1_3800B:red) out hi
gpio-5 (DGND3700v1_3800B:gre) out hi
gpio-10 (wlan ) in hi
gpio-11 (DGND3700v1_3800B:gre) out hi
gpio-12 (reset ) in hi
gpio-13 (DGND3700v1_3800B:gre) out hi
gpio-14 (DGND3700v1_3800B:gre) out hi
gpio-22 (DGND3700v1_3800B:red) out hi
gpio-23 (DGND3700v1_3800B:gre) out hi
gpio-24 (DGND3700v1_3800B:gre) out lo
gpio-26 (DGND3700v1_3800B:gre) out lo
gpio-27 (DGND3700v1_3800B:blu) out lo
gpio-35 (wps ) in hi
Maurizio
Avatar utente
root
Amministratore
 
Messaggi: 348
Iscritto il: 10/04/2012, 10:55
Località: Ovada

Re: OpenWRT - Home Automation - Controlling a simple relay b

Messaggio da leggereda root » 15/09/2016, 21:59

just a note:

if you want to stream video from the remote location with you OpenWRT box, do not use mjpg-streamer.
I mean, if you want to check the remote location for just a few seconds, it's OK,
but when you start a realtime video streaming, after a few minutes that you are connected to see, mjpg-streamer crashes and the device "/dev/video0" disappears, the only way to recover it, it is to reboot the router or unplug and plug again the USB webcam.
Use Motion instead, it uses more CPU resources but it is stable and never crashes!
Maurizio
Avatar utente
root
Amministratore
 
Messaggi: 348
Iscritto il: 10/04/2012, 10:55
Località: Ovada

Re: OpenWRT - Home Automation - Controlling a simple relay b

Messaggio da leggereda root » 13/11/2016, 18:22

In case you want to use mjpg-streamer anyway, this is the script to check if the process is active, if it is not, the script restart mjpg-streamer:

#!/bin/sh
# check if the process "mjpg-streamer" is active
#
if ps w | grep -v grep | grep '/usr/bin/mjpg_streamer --input input_uvc.so --device /dev/video0 --fps 1 --resolution 1280x720 --output o' > /dev/null
then
# echo "OK"
/bin/sleep 1
else
# echo "KO"
/init.d/mjpg-streamer restart
fi


Notes:
change "--fps 1" with the frame per seconds value you are using, eg: --fps 8,
the same for "--resolution 1280x720"


then put the following line in "/etc/crontabs/root" to check the mjpg-streamer process every minute:

*/1 * * * * /bin/sh /root/mjpg-streamer_check.sh
Maurizio
Avatar utente
root
Amministratore
 
Messaggi: 348
Iscritto il: 10/04/2012, 10:55
Località: Ovada

PrecedenteProssimo

Torna a OpenWRT e sistemi operativi vari

Chi c’è in linea

Visitano il forum: Nessuno e 1 ospite

cron