Misterhouse CBUS Gateway Code V2.0
Running RUN_BUILDER and RELOAD
Running C-BUS Monitor & Talker
·
Special
Thanks to Greg McCall for his valuable effort in testing for Windows, TK and
his valuable documentation help. Thanks
Greg.
·
Updates will be available at http://www.killara.net/mh/ or from time to time in the MH release kit.
·
Please send all comments, complaints, praises to the author
at richard@webcom.com.au
The distribution package should contain the following files
Is the output file created by cgate_builder(). It is a proper MH perl file, and contains
all the objects and properties for all the CBUS units. NEVER EVER edit this
file. Make changes to cbus_dat.csv, and then run cgate_builder. Put this file in your code directory.
Is the input file for cgate_builder(). It is a simple CSV file that defines all the CBUS units and there
names, properties etc. You will need to edit this for your own site, remember
that CBUS used the GROUP addresses not the unit ID’s. Put this file in your
code directory.
This is a simple file that creates the Cbus_Item object, which is
just an inheritance of the Generic_Item.
Put this file in your code directory.
This file contains all the main CBUS interface routines to talk to
the Clipsal cgate server. Put this file
in your code directory.
It contains;
This sample file contains my own houses lighting controls, it
demonstrates well how to use the CBUS objects.
This sample file contains some examples of how my own houses uses
Radio Control key fobs, connected via the CBUS. Irrelevant application I know, but a good example of using CBUS
input triggers.
Is the MH private config file, it contains all the required config
parameters. Add these directives to
your own config file.
This is a working, tested safe version of cbus.pl. Rename this file to cbus.pl, if the one you have built with cgate_builder() has
corruptions or is causing MH to crash.
All CBUS objects are defined in a standard CSV file
(cbus_dat.csv), this file is read in at
$Reload, and a large Hash-of-Hash is created to store the CBUS objects for
MH. To ensure that MH can use the CBUS
objects properly, they are mapped into a MH object called Cbus_Item (actually
an alias for a Generic_Item) This
allows all the good stuff in MH to work on CBUS items, as if they were an X10
(sort off). (I tried to map the CBUS devices into the existing X10 support
in MH, but the X10 support is just too limited, and CBUS has too many new
features. Eventually I hope to migrate
cbus_dat.csv into a XML specification.)
To do this mapping, that is create the CBUS $objects and matching
tied Voice_cmds a sub in this file make_cbus_file() reads through the CBUS hash
and creates the Perl directive We are in effect using MH to write its own code,
this was inspired from the X!0 methods. The output file of the builder, cbus.pl
is a valid MH code module and is then read in at the next reload.
So.. Remember to
RUN_BUILDER, then RELOAD code, to make a CBUS object change. (see following
chapters for information on how to run
RUN_BUILDER and RELOAD)
The $v_objects are all voice commands and they are used to control
a CBUS device from the web. Each
$v_object is tied to its respective $object. In program control (testing the
state of an $object, or setting a $object) are all performed against the
$object, although you can set the $v_object, its state will not reflect any
updates from the actual CBUS.
Remember, the CBUS is interactive, it can receive as well as issue
commands, at the same time. So, its
best to always use the $object in your code.
Moving on. Each $object is
tied to an event trigger that calls the cgate_set subroutines,, notice how the
last 'set_by' directive was also
passed, this is to ensure that we do not create endless message loops.
When the cgate_set() sub is called the actual CBUS device is set
to that state assuming it was not the CBUS that actually initiated this set in
the first place, get it ?
As Cgate itself repeats all commands received to it, back to MH,
via cgate_monitor.pl MH listens for
these commands and then sets the appropriate non $object, but this is ignore if
MH was in fact the source of the set.
If you understand this you are now an expert on MH objects, and a
true CBUS wizard.
Instructions assume a Misterhouse directory structure as follows:
(adjust depending on your own environment and operating system)
c:--+
+--misterhouse--+ <---
mh.private.ini lives here
+--code
<--- my code
+--data
<--- my data
+--sounds
<--- my sounds
+--mh----+
<--- mh installed here
+--bin
+--code
+--data
+--docs
+--lib
+--sounds
+--web
(for info on
the above directory layout, see “Coding your own events” at the end of the
install.html included in MH docs at c:\misterhouse\mh\docs)
# Category = C-Bus
Cbus_Item_module = Cbus_Item
cgate_mon_address = 192.168.200.5:20024
cgate_talk_address = 192.168.200.5:20023
cbus_dat_file = cbus_dat.csv
cbus_categories_prefix = cbus_
cbus_ramp_speed = 0
These
commands can either be run from the MH web interface or the MH TK interface.
CommandsCGATEcgate_builder: cgate Builder RUN_BUILDER
Note: If the TK Interface is not running, you might not have all
the code. Include the following lines in a script and run it while connected to
the internet:
c:
cd \perl\bin
perl ppm.bat install Win32-API
perl ppm.bat install Tk
perl ppm.bat install Tk-JPEG
perl ppm.bat install DB_File
perl ppm.bat install GD
These commands can either be run from the MH web interface or the
MH TK interface.
CommandsCGATEcgate_monitor: CBUS Monitor START
CommandsCGATEcgate_talker: C-Gate Talker START
Note: If the TK Interface is not running on a Windows machine, you
might not have all the code. Include the following lines in a script and run it
while connected to the internet:
c:
cd \perl\bin
perl ppm.bat install Win32-API
perl ppm.bat install Tk
perl ppm.bat install Tk-JPEG
perl ppm.bat install DB_File
perl ppm.bat install GD
This chart can be useful when editing the cbus_dat.csv
0 1 2 3 4
5 6 7 8 9
A B C D E
F.
0
000 001 002 003 004 005 006 007 008 009 010 011 012 013 014 015
1
016 017 018 019 020 021 022 023 024 025 026 027 028 029 030 031
2
032 033 034 035 036 037 038 039 040 041 042 043 044 045 046 047
3
048 049 050 051 052 053 054 055 056 057 058 059 060 061 062 063
4
064 065 066 067 068 069 070 071 072 073 074 075 076 077 078 079
5
080 081 082 083 084 085 086 087 088 089 090 091 092 093 094 095
6
096 097 098 099 100 101 102 103 104 105 106 107 108 109 110 111
7
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127
8
128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143
9
144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159
A
160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175
B
176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191
C
192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207
D
208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223
E
224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239
F
240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255
Hex 41 (written as 0x41 ) is equivalent to
decimal 65