How to setup a misterhouse proxy on openwrt
If you have followed my guide to install misterhouse on an openwrt router you may use it as proxy. 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 build 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
no_log=serial_unmatch
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
export mh_parms=/mnt/usb/my_mh/mh.private.ini
./mhl “$@”
And this is the mhl script that actually starts and monitors the misterhouse process
#!/bin/sh
while [ 1 = 1 ]; do
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 = 1 ]; then
echo mh exited normally
exit
fi
if [ -f mh.startup ]; 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 .
The Xap setup
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.
Have a look at my 1-wire and K8055 code files for some working examples.
April 15th, 2009 at 10:46
thanks !! very helpful post!