-
Notifications
You must be signed in to change notification settings - Fork 130
Misterhouse (proxy) on OPENWRT
Some time ago I played with OpenWrt on my asus router. I managed to have MisterHouse running on my router. I believe this info can be interesting for other people playing with MisterHouse so I decided to contribute my experience to this wiki. Hopefully someone can use parts or even the full guide in his setup.
Installing OpenWrt on your router is already well explained on the openwrt wiki This guide describes my experience with installing kamikaze 8.09 on my router but it should work on other hardware too . I have the Asus WL-500g Deluxe and installed the latest OpenWrt image kamikaze 8.09 After installation make sure you setup your network and enable ssh access. Just login to your router with telnet telnet 192.168.1.1 and type passwd passwd this will set a password for the root user, disables telnet and enables ssh. After this you should always use ssh to access your router. - add usb stick The next step is to add some extra storage because my router only has 4 Mb flash on board. I use an USB memory stick for this, an USB hard drive also works but uses more power. The first thing I do after logging in (with ssh this time) ssh 192.168.1.1 is updating the packages list with the package management tool ‘opkg’. opkg update If the update fails your network is most likely not yet configured. You can point your browser to http://192.168.1.1 and fill in the settings under the network link or you can do it command line. With the command uci show network you can check your settings. And with the following commands uci set network.lan.ipaddr=192.168.1.1
uci set network.lan.netmask=255.255.255.0
uci set network.lan.gateway=192.168.1.254
uci set network.lan.dns=192.168.1.254 you can change your settings. Don’t forget uci commit to activate your changes and to save them so they survive a reboot. When your packages list is updated you are ready to start installing the packages needed to mount an USB memory stick or hard drive. On my asus WL-500g deluxe i installed the following packages : opkg install kmod-usb-storage kmod-usb2 kmod-fs-ext2 with the ‘dmesg’ command you should now see your hardware in the kernel log. From here I followed the Packages on external media guide from the OpenWrt wiki to use my usb stick for extra package space. Below is a summary of my command line commands. mkdir -p /mnt/usb
mount /dev/scsi/host0/bus0/target0/lun0/part1 /mnt/usb
echo ‘mount /dev/scsi/host0/bus0/target0/lun0/part1 /mnt/usb’ > /etc/init.d/externalmount
chmod +x /etc/init.d/externalmount
ln -s /etc/init.d/externalmount /etc/rc.d/S60externalmount Also the following lines are added to /etc/opkg.conf and /etc/profile :
Add dest usb /mnt/usb to /etc/opkg.conf and export PATH=/bin:/sbin:/usr/bin:/usr/sbin:/mnt/usb/bin:/mnt/usb/sbin:/mnt/usb/usr/bin:/mnt/usb/usr/sbin
export LD_LIBRARY_PATH=/lib:/usr/lib:/mnt/usb/lib:/mnt/usb/usr/lib to /etc/profile. Reboot your router and check if your media is mounted under /mnt/usb . If all went well you can start installing packages opkg -d usb install packagename
- Important remark !**
The first step is to install Perl and all the modules MisterHouse need .Install following packages with the opkg command opkg install packagename perl
perlbase-autoloader
perlbase-base
perlbase-bytes
perlbase-config
perlbase-cwd
perlbase-data
perlbase-db-file
perlbase-errno
perlbase-essential
perlbase-fcntl
perlbase-file
perlbase-filehandle
perlbase-getopt
perlbase-integer
perlbase-io
perlbase-posix
perlbase-re
perlbase-selectsaver
perlbase-socket
perlbase-symbol
perlbase-term
perlbase-text
perlbase-time
perlbase-xsloader
perlbase-sys
perlbase-encode
perlbase-universal
perlbase-net
perlbase-filehandle Then install MisterHouse. Installing MisterHouse is nothing more than unpacking the code to your mounted USB media and altering the config file(s). First download the latest stable code tarball and unpack it. cd /mnt/usb
wget http://prdownloads.sourceforge.net/misterhouse/misterhouse-2.105.tar.gz
tar xzvf misterhouse-2.105.tar.gz . Now you have a directory /mnt/usb/mh
As a first test you can try to run MisterHouse to see if all perl packages needed are installed and working. cd /mnt/usb/mh/bin
./mhl You may see some GD.pm and TK perl module errors in the log but can ignore them for the moment. We will disable these functions later. If you see a line “PM: Saving object states … done” then you are good and know that misterhouse is running. You can even browse to http://192.168.1.1:8080 to see the web interface.
The next step is to create your own code files and to alter the MisterHouse configuration file for your needs. This is explained on the MisterHouse homepage or in the docs section of your MisterHouse install directory .
A first step could be to disable TK and GD code by adding the following lines to your mh.private.ini file tk=0
gd=0 For my own project I run MisterHouse as a proxy. A proxy is a stripped down MisterHouse process that can interact with a main full MisterHouse install on another server for example. Next post I will explain how i setup my MisterHouse proxy with a Velleman K8055 USB IO board, a 1-wire usb interface and a bluetooth dongle to detect if my mobile phone is nearby.
A MisterHouse proxy is used to offload slow hardware interfaces or slow processes from the main MisterHouse process. Another reason could be that you cannot connect some hardware physically to your main MisterHouse box but like to have that hardware available to your main MisterHouse box. Gregg from the MisterHouse mailing list pointed me to the xAP protocol support built into the MisterHouse code. So I started testing out the code. The principle is that you define the same Item types on both the proxy and the main MisterHouse machine. The Xap protocol then takes care of keeping these variables in sync. The first thing I did was creating my own directories outside the MisterHouse install directory, this will make further upgrades much easier. Here are my steps : Create a directory on the same level as the MisterHouse install directory root@OpenWrt:/mnt/usb# ls
etc lib lost+found mh usr
mkdir my-mh
cd my-mh Copy the code dir and data dir mkdir code
cp -r ../mh/code/proxy code
mkdir data
cp -r ../mh/data/proxy data Because I am setting up a MisterHouse proxy I only copied the proxy sub directories of the data and code directories. I also copied the mh.private.ini config file and some startup scripts and altered them to use the newly created directories. cp ../mh/bin/mh_proxy.ini mh.private.ini The mh.private.ini file overrides the main mh.ini configuration file in the MisterHouse installation directory and is used to make your personal configuration changes. This is how my file looks like:
code_dir=$Pgm_Root/../my_mh/code/proxy
data_dir=$Pgm_Root/../my_mh/data/proxy
code_select = code_select.txt
code_unselect = code_unselect.txt
sound_program=
server_telnet_port=
server_mhsend_port=
xpl_disable=1
xap_enable_items=1
voice_text=
- only_load=proxy_server.pl
xcmd_file=
sleep_time=100
sleep_count=1
tk=0
title=Proxy MisterHouse
gd=0
x10_errata=1
server_proxy_port=
xap_echo_all=1
http_port = 8080 I also copied the mh_proxy startup script and the mhl script and altered them to reflect my proxy setup cp ../mh/bin/mhl ../mh/bin/mh_proxy . This is my mh_proxy script that I use to start MisterHouse as a proxy
- !/bin/sh
./mhl “$@” And this is the mhl script that actually starts and monitors the MisterHouse process
- !/bin/sh
echo
echo Deleting startup file
touch mh.startup
export LANG=C
echo Running mh
perl /mnt/usb/mh/bin/mh “$@”
rc=$?
echo mh rc=$rc
if [$rc]; then
echo mh exited normally
exit
fi
if [-f]; then
echo mh failed on startup … will not restart
exit
fi
echo mh had an unexpected exit … sleep a bit, then restarting
date >> mh_restart.log
sleep 5
done Now you can use the mh_proxy script to start MisterHouse on your router.
Next you can start enabling or disabling code. Because I enabled the web interface on port 8080 in mh.private.ini you can browse to your router and use the web interface to enable or disable code. Note that you need a reload to activate the changes. You can also go to the data directory and edit the code_select.txt and code_unselect.txt files to list the code files you want to enable or disable. It is important to understand that the code_select.txt file list the code files you want to enable from the MisterHouse install directory/code/common directory and that code_unselect.txt lists the files you want to disable from your personal code directory. I enabled the following code files from the common code dir mh_control.pl
xAP_command.pl
xAP_send.pl My own code dir has the following files root@OpenWrt:/mnt/usb# ls my_mh/code/proxy/
digitemp.pl k8055-file.pl mh.menu proxy_server.pl triggers.mhp and my code_unselect.txt looks like this proxy_server.pl So this means that all code files (the ones with .pl extension) are running except proxy_server.pl .
Like you can see in the code_select.txt file I enabled the xAP_command.pl and xAP_send.pl code files you need to also enable them on your main MisterHouse box and add the line “xap_enable_items=1″ to your mh.private.ini file on the main misterhouse box. I have only tested this with Generic_Items but if you create a new Item with the same name on both your proxy and the main MisterHouse box the state of these Items will be synced. This works very well for me.
image:http://www.hobby-boards.com/catalog/images/ds9490r-a.jpg width="100" height="80"After installing MisterHouse on my OpenWrt router I started adding devices. I plugged a 1-wire usb interface into my router and started playing around. There are at least two software programs that work for me in OpenWrt Kamikaze 8.09
I installed the package owserver with the opkg command line tool opkg -d usb install owserver When the package was installed i started the owserver. owserver – u -p 5555 On my desktop running ubuntu I installed owfs sudo apt-get install owfs which is the client for the owserver program and will create a filesystem whit all the sensors data. sudo mkdir /mnt/ow
sudo owfs -s 192.168.1.1:5555 /mnt/ow Works like a charm for me drwxr-xr-x 1 root root 8 2009-03-16 21:28 .
drwxr-xr-x 22 root root 4096 2009-02-23 21:16 ..
drwxrwxrwx 1 root root 8 2009-03-19 15:59 10.096994010800
drwxrwxrwx 1 root root 8 2009-03-19 15:59 10.585394010800
drwxrwxrwx 1 root root 8 2009-03-19 15:59 10.6A6E94010800
drwxrwxrwx 1 root root 8 2009-03-19 15:59 10.A09B94010800
drwxrwxrwx 1 root root 8 2009-03-19 15:59 10.A77594010800
drwxrwxrwx 1 root root 8 2009-03-19 15:59 10.F77094010800
drwxrwxrwx 1 root root 8 2009-03-19 15:59 81.E74C2A000000
drwxr-xr-x 1 root root 8 2009-03-16 21:28 bus.0
drwxr-xr-x 1 root root 8 2009-03-16 21:28 settings
drwxr-xr-x 1 root root 8 2009-03-16 21:28 statistics
drwxr-xr-x 1 root root 30 2009-03-16 21:28 structure
drwxr-xr-x 1 root root 8 2009-03-16 21:28 system
drwxr-xr-x 1 root root 8 2009-03-16 21:28 uncached Nice if you need to share your 1-wire data over the network but what i want is to have my temperature sensors values available in misterhouse that runs on the router as well.
So let’s go on to the next solution.
Digitemp is another command line tool to interface a 1-wire network. To install type opkg -d usb install digitemp Let’s do a first test : root@OpenWrt:~# digitemp_DS2490 -w
DigiTemp v3.5.0 Copyright 1996-2007 by Brian C. Lane
GNU Public License v2.0 – http://www.digitemp.com
Found DS2490 device #1 at 003/004
Turning off all DS2409 Couplers
…….
Devices on the Main LAN
10A09B9401080052 : DS1820/DS18S20/DS1920 Temperature Sensor
105853940108009D : DS1820/DS18S20/DS1920 Temperature Sensor
106A6E9401080076 : DS1820/DS18S20/DS1920 Temperature Sensor
10096994010800BD : DS1820/DS18S20/DS1920 Temperature Sensor
10A77594010800AF : DS1820/DS18S20/DS1920 Temperature Sensor
10F7709401080053 : DS1820/DS18S20/DS1920 Temperature Sensor
81E74C2A000000A5 : Unknown Family Code That’s good ! Next create a conf file. digitemp -i Now you can read a value like this digitemp_DS2490 -t 2 -q -c /root/.digitemprc
Feb 08 22:09:23 Sensor 2 C: 21.00 F: 69.80 All that we need now is some perl code to read the sensors values and store them in a misterhouse variable. I came up with the following code. use vars ‘$tempsensor1′;
if ($New_Minute){
$_=`digitemp_DS2490 -t 5 -q -c /root/.digitemprc`;
/\sC:\s(.*)\sF/;
$tempsensor1 = $1;
print_log “Temperatuur is nu $tempsensor1″;
} This is just some test code but it proofs that it works so I am happy for now.
image:http://www.designnotes.com/Merchant2/graphics/00000001/K8055.JPG width="163" height="123"The next device I added to my misterhouse proxy running on my router is the Velleman K8055 IO board. This is a USB powered experimental IO board with 8 outputs, 5 inputs, 2 DAC outputs and 2 analog inputs. I used the k8055 OpenWrt kernel module from the sourceforge project homepage. I have compiled the module myself because there was no package available for the OpenWrt Kamikaze 8.09 release, if you need it you can download it here so you don’t need to install the buildroot etc.or you can install the package directly. opkg install http://blog.export.be/downloads/kmod-k8055d_0.1.2_2.4.35.4-brcm-2.4-1_mipsel.ipk
opkg install kmod-usb-uhci-iv Like you can see I also installed the kmod-usb-uhci-iv package which was needed for the module to work. If all went well you now a /proc/k8055/0 directory with a file for every input and output. By reading or writing to these files you can read or write values to the board.
Next I wrote some misterhouse code to create misterhouse items for all the IO and the read and write commands to interface the files. Here is my code :
//$k8055_out1 = new Generic_Item;//
//$k8055_out2 = new Generic_Item;//
//$k8055_out3 = new Generic_Item;//
//$k8055_out4 = new Generic_Item;//
//$k8055_out5 = new Generic_Item;//
//$k8055_out6 = new Generic_Item;//
//$k8055_out7 = new Generic_Item;//
//$k8055_out8 = new Generic_Item;//
//$k8055_in1 = new Generic_Item;//
//$k8055_in2 = new Generic_Item;//
//$k8055_in3 = new Generic_Item;//
//$k8055_in4 = new Generic_Item;//
//$k8055_in5 = new Generic_Item;//
//$k8055_out1 -> set_states (‘aan’,'uit’);//
//$k8055_out2 -> set_states (‘aan’,'uit’);//
//$k8055_out3 -> set_states (‘aan’,'uit’);//
//$k8055_out4 -> set_states (‘aan’,'uit’);//
//$k8055_out5 -> set_states (‘aan’,'uit’);//
//$k8055_out6 -> set_states (‘aan’,'uit’);//
//$k8055_out7 -> set_states (‘aan’,'uit’);//
//$k8055_out8 -> set_states (‘aan’,'uit’);//
//if ($state = state_changed $k8055_out1){//
//if ($state eq ‘aan’) {//
//file_write(‘/proc/k8055/0/out1′,1);//
//}//
//else {//
//file_write(‘/proc/k8055/0/out1′,0);//
//}//
//}// //if ($state = state_changed $k8055_out2){//
//if ($state eq ‘aan’) {//
//file_write(‘/proc/k8055/0/out2′,1);//
//}//
//else {//
//file_write(‘/proc/k8055/0/out2′,0);//
//}//
//}// //if ($state = state_changed $k8055_out3){//
//if ($state eq ‘aan’) {//
//file_write(‘/proc/k8055/0/out3′,1);//
//}//
//else {//
//file_write(‘/proc/k8055/0/out3′,0);//
//}//
//}// if ($state = state_changed $k8055_out4){
if ($state eq ‘aan’) {
file_write(‘/proc/k8055/0/out4′,1);
}
else {
file_write(‘/proc/k8055/0/out4′,0);
}
} //if ($state = state_changed $k8055_out5){//
//if ($state eq ‘aan’) {//
//file_write(‘/proc/k8055/0/out5′,1);//
//}//
//else {//
//file_write(‘/proc/k8055/0/out5′,0);//
//}//
//}// //if ($state = state_changed $k8055_out6){//
//if ($state eq ‘aan’) {//
//file_write(‘/proc/k8055/0/out6′,1);//
//}//
//else {//
//file_write(‘/proc/k8055/0/out6′,0);//
//}//
//}// //if ($state = state_changed $k8055_out7){//
//if ($state eq ‘aan’) {//
//file_write(‘/proc/k8055/0/out7′,1);//
//}//
//else {//
//file_write(‘/proc/k8055/0/out7′,0);//
//}//
//}//
//if ($state = state_changed $k8055_out8){//
//if ($state eq ‘aan’) {//
//file_write(‘/proc/k8055/0/out8′,1);//
//}//
//else {//
//file_write(‘/proc/k8055/0/out8′,0);//
//}//
//}//
//my $input;//
//if ($New_Second){//
//$input = file_read(‘/proc/k8055/0/in1′);//
//set $k8055_in1 $input;//
//$input = file_read(‘/proc/k8055/0/in2′);//
//set $k8055_in2 $input;//
//$input = file_read(‘/proc/k8055/0/in3′);//
//set $k8055_in3 $input;//
//$input = file_read(‘/proc/k8055/0/in4′);//
//set $k8055_in4 $input;//
//$input = file_read(‘/proc/k8055/0/in5′);//
//set $k8055_in5 $input;//
//#print_log “Input 1 is now $input1″;//
//}// Handles for the DA and AD ports are not yet implemented because I don’t use them for the moment. Update : I just finished doing the same setup on a NSLU2 . I compiled the k8055 module via the buildroot for the ixp4xx harware. The only difference was that I had to use the kmod-usb-ohci_2.6.28.10-1_ixp4xx.ipk module instead of the uhci one. If anyone needs tha packages for the Linux OpenWrt 2.6.28.10 #2 armv5teb GNU/Linux NSLU2 harware let me know.