OpenWRT - Home Automation - Controlling a simple relay board

sezione dedicata ai sistemi operativi alternativi Open Source

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

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

Now I did the dirty job :) but still need to implement the followings features:

- Withelist for the authorized SMS senders, only authorized numbers can issue commands to the router.
- Simple autentication login with password for the control web page.
- Graphical indications for the channels status on the web control page (ex. red and green dots).

Is anyone willing to help me?
Please do not use PHP, it's too resources costly for this small router ;)

Please write to parknat(at)yahoo.com.
Maurizio
Avatar utente
root
Amministratore
 
Messaggi: 348
Iscritto il: 10/04/2012, 10:55
Località: Ovada

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

Messaggio da leggereda root » 30/12/2014, 23:10

Immagine
Vodafone Station (a.k.a. Huawei EchoLife HG553) Home Automation Server.

The led channel status indicator on the V.S. (CH1-3) is pink (red+blue) for "Off" state and red for "On" state.

The other router on the left (vertical) is a Pirelli Voipgate ADSL router, hacked with Eutelia firmware to use it as a Voip FXS gateway (2 analog phone RJ11 ports) connected to the Vodafone Station (Asterisk 1.8 also installed on V.S.)

The small router with the keypad and multi-led lighted USB Hub :D that you see on the upper right side is another project of mine:
Openwrt MP3 Player and Internet Radio wi-fi stereo ;)

All components I used are TRASHWARE that means zero cost! :)
Immagine

Another particularity of my OpenWRT projects:
to amplify the audio output I designed a trashware Hi-Fi stereo vacuum tube amplifier using old television's used tubes :D

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 » 30/12/2014, 23:24

I've just tested another interesting feature: "Commands sent from phone" :)

I installed Asterisk 1.8 on my router board and tested the "System" function of Asterisk that enables it to run system commands directly from a dialplan, it works great on OpenWRT!

The idea is to create an IVR that answers the Voip call, than asks the caller to dial the login password and if the password is correct asks the caller to choose an option from a list, example:

"Welcome to the home automation server, please enter your password followed by the # key"
"Thank you"
"Press 1 to activate channel 1"
"Press 2 to deactivate channel 1"
"Press 3 to activate channel 2"
...


I don't have enough time at the moment to fully develop this feature, but if anyone is willing to help can write me @ parknat12(at)yahoo.com ;)
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 » 31/12/2014, 17:13

In addition to the USB keyboard, I added a three channels digital input (on/off) just by using an old USB mouse :D

In any mouse there are three button switches (SW1-2-3 in the picture) that triggerhappy can handle.

Immagine

Triggerhappy discovering function:

root@OpenWrt:~# thd --dump /dev/input/event*

EV_KEY BTN_LEFT 1 /dev/input/event0
# BTN_LEFT 1 command
EV_KEY BTN_LEFT 0 /dev/input/event0
# BTN_LEFT 0 command
EV_KEY BTN_MIDDLE 1 /dev/input/event0
# BTN_MIDDLE 1 command
EV_KEY BTN_MIDDLE 0 /dev/input/event0
# BTN_MIDDLE 0 command
EV_KEY BTN_RIGHT 1 /dev/input/event0
# BTN_RIGHT 1 command
EV_KEY BTN_RIGHT 0 /dev/input/event0
# BTN_RIGHT 0 command

# values for key events are 1 (pressed), 0 (released)


than to associate a command to each button when is pressed, add the following lines to your triggerhappy configuration file (/etc/triggerhappy/triggers.d/example.conf):

BTN_LEFT 1 /path/command &
BTN_MIDDLE 1 /path/command &
BTN_RIGHT 1 /path/command &


or to associate a command when the button is released:

BTN_LEFT 0 /path/command &
...


This is a generic schematic of a USB mouse:

Immagine

Each button switch needs to be grounded to give "1" level for tryggerhappy, you can connect in parallel to the switch a transistor/mosfet, a relay or an optocoupler to perform this function.


P.S.: Triggerhappy does not handle the rotary encoder of the mouse, but Openwrt does, if you want to see what openwrt sees when the rotary encoder of the mouse is turned use this command:
cat /dev/input/event0 |hexdump

You'll get something like this:

Clockwise rotation:

root@OpenWrt:~# cat /dev/input/event0 |hexdump
0000000 54a4 185d 0007 1259 0002 0008 0000 0001
0000010 54a4 185d 0007 1267 0000 0000 0000 0000
0000020 54a4 185e 0000 3c9c 0002 0008 0000 0001
0000030 54a4 185e 0000 3caa 0000 0000 0000 0000
0000040 54a4 185e 0006 95d2 0002 0008 0000 0001
0000050 54a4 185e 0006 95e0 0000 0000 0000 0000
0000060 54a4 185e 0007 eda1 0002 0008 0000 0001
0000070 54a4 185e 0007 edae 0000 0000 0000 0000
0000080 54a4 185e 0008 a911 0002 0008 0000 0001
0000090 54a4 185e 0008 a91e 0000 0000 0000 0000
00000a0 54a4 185e 000a 00f2 0002 0008 0000 0001
00000b0 54a4 185e 000a 0100 0000 0000 0000 0000
00000c0 54a4 185e 000b b674 0002 0008 0000 0001
00000d0 54a4 185e 000b b680 0000 0000 0000 0000

Counter clockwise rotation:

root@OpenWrt:~# cat /dev/input/event0 |hexdump
0000000 54a4 1865 000b d96a 0002 0008 ffff ffff
0000010 54a4 1865 000b d977 0000 0000 0000 0000
0000020 54a4 1865 000e 4a6c 0002 0008 ffff ffff
0000030 54a4 1865 000e 4a78 0000 0000 0000 0000
0000040 54a4 1866 0000 9e86 0002 0008 ffff ffff
0000050 54a4 1866 0000 9e95 0000 0000 0000 0000
0000060 54a4 1866 0001 f647 0002 0008 ffff ffff
0000070 54a4 1866 0001 f654 0000 0000 0000 0000
0000080 54a4 1866 0003 cb1d 0002 0008 ffff ffff
0000090 54a4 1866 0003 cb2b 0000 0000 0000 0000
00000a0 54a4 1866 0005 a001 0002 0008 ffff ffff
00000b0 54a4 1866 0005 a00f 0000 0000 0000 0000
00000c0 54a4 1866 0007 f1c9 0002 0008 ffff ffff
00000d0 54a4 1866 0007 f1d5 0000 0000 0000 0000
00000e0 54a4 1866 000a dfe4 0002 0008 ffff ffff
00000f0 54a4 1866 000a dff2 0000 0000 0000 0000
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 » 01/01/2015, 12:59

After a bad new years eve :D I added an hand made USB PIR motion sensor :idea:

I modified a Home PIR Motion sensor and connected the output to one button switch of the Mouse PCB you see above :)

The modification consists in completely disconnecting all the relay outputs from the PIR circuit and connect the two pins (N.O. output) to the mouse PCB in parallel to a switch button:

Immagine

When a motion is detected this is the triggerhappy output:

EV_KEY BTN_LEFT 1 /dev/input/event2
# BTN_LEFT 1 command


when released:

EV_KEY BTN_LEFT 0 /dev/input/event2
# BTN_LEFT 0 command


Immagine

Immagine

The PIR motion sensor I used has also the light sensor and a timer integrated.
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 » 02/01/2015, 22:50

I've connected the 5V relays board to the router :)

Immagine

The relays board was luckily found rummaging through old hardware, I noticed an usb voip phone skype adapter I wasn't ever been able to use with linux, the adapter had three relays so I immediately destroyed it to recover the PCB portion with relays and their drivers :)

I took +5V to power the relays board from the lower USB connector but noticed that the router has got some problems due to increased load current.
As soon as I can I will add a +5V voltage regulator and will connect it directly to the + 12V router's power supply.
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 » 05/01/2015, 1:25

Finally, the 12V to 5V switching voltage regulator was added :)
I recovered it from a cheap car USB charger.

Anyway, the Vodafone station still have USB problems, the USB support for this router is broken!

This the final version of my Home Automation Router, wires have been glued to PCB and the two boards are kept in place with double-sided adhesive tape:

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 » 05/01/2015, 15:00

Instructions how to transform a cheap 110/220Vac Home PIR Motion Sensor in a "USB PIR motion sensor" for OpenWRT/Raspberry/Arduino


Immagine

Open the device, inside you'll find two printed circuit boards: a PIR module operating from + 5V to 24V (see picture) and a relay module with transformer less capacitor power supply, to reduce the 110 or 220 Vac main line voltage to 24 Vcc non stabilized for the relay and 5-12 Vcc stabilized for the sensor board.

Some examples of internal PCBs:

model 1:
Immagine

model 2:
Immagine

model 3:
Immagine



Cut the "three wires" ribbon cable that connects the two boards togheter, save the relay module for future use and keep the PIR sensor board.

The pin-out of my sensor board is Vcc , GND and output signal, from left to right as seen in the picture of the model 2, but it can be different for other boards even if similar, always check the labels on PCB.

Connect the +5V and GND of the PIR sensor board in parallel to the +5V and GND of the mouse board (+5V and GND from USB connector)

Optocoupler connection:

we need an optocoupler to interconnect sensor board output signal to the mouse board, the optocoupler I used is the 817b I found in an old USB modem.

Immagine

Pin1 (anode): + 5Vcc
Pin2 (cathode): output signal from sensor board
Pin3 (Emitter): GND
Pin4 (Collector): Mouse Button Switch (terminal connected to Integrated Circuit)

Note: the Opto-coupler can be easily found in many old devices like modems, UPS, serial interfaces.

Use triggerhappy to detect status of PIR motion sensor.

Enjoy :)

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

Example of USB mouse circuit board to be used in conjuction of the PIR sensor (without leds):

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 » 05/01/2015, 16:27

the finished job:

Note: the phone is connected to Asterisk (VOIP)

Immagine

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 » 05/01/2015, 22:57

If you don't want or can't use a PIR sensor for motion detection, you can also use a USB webcam and "Motion" package.

opkg update
opkg install kmod-video-core kmod-video-uvc
opkg install motion


Those are the lines to be modified in "/etc/motion.conf" configuration file:

width 640
height 480
framerate 2
threshold 3000
output_pictures off
ffmpeg_output_movies off
stream_maxrate 1
stream_localhost off
#
# command to be executed on motion detection, ex. /root/motion_detected.sh
#
on_motion_detected
/root/motion_detected.sh


Note: if you want motion to save captured images on motion detection (Warning: a lot of disk space is needed!), change the line: output_pictures off
to:
output_pictures on

To run motion simply use motion command

With Motion you can have both, motion detection and realtime image streaming (http://IP_ADDRESS:8081).
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