<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Maartendamen&#039;s blog &#187; Home automation</title>
	<atom:link href="http://www.maartendamen.com/category/home-automation/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.maartendamen.com</link>
	<description>Blogging on various IT subjects</description>
	<lastBuildDate>Tue, 22 Nov 2011 21:27:03 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Horstmann HRT4-ZW Thermostat &#8211; open ends</title>
		<link>http://www.maartendamen.com/2011/06/horstmann-hrt4-zw-thermostat-open-ends/</link>
		<comments>http://www.maartendamen.com/2011/06/horstmann-hrt4-zw-thermostat-open-ends/#comments</comments>
		<pubDate>Mon, 13 Jun 2011 18:53:40 +0000</pubDate>
		<dc:creator>Maarten</dc:creator>
				<category><![CDATA[Home automation]]></category>
		<category><![CDATA[horstmann]]></category>
		<category><![CDATA[hrt4-zw]]></category>
		<category><![CDATA[thermostat]]></category>
		<category><![CDATA[wireless]]></category>
		<category><![CDATA[z-wave]]></category>

		<guid isPermaLink="false">http://www.maartendamen.com/?p=775</guid>
		<description><![CDATA[A few weeks ago I received an e-mail from a guy who rather stays anonymous, but had some really great additional/detailed information about the HRT4-ZW thermostat. There&#8217;s some things I missed out, or did configure along the way while tinkering with this device but forgot to mention. So here&#8217;s a post about these &#8220;open ends&#8221;. [...]]]></description>
			<content:encoded><![CDATA[<p>A few weeks ago I received an e-mail from a guy who rather stays anonymous, but had some really great additional/detailed information about the HRT4-ZW thermostat.<br />
There&#8217;s some things I missed out, or did configure along the way while tinkering with this device but forgot to mention. So here&#8217;s a post about these &#8220;open ends&#8221;.</p>
<ul>
<li>Previously I mentioned an &#8220;ERASE&#8221; mode, this is actually &#8220;EXCLUDE&#8221; mode. This mode should only be used if your thermostat was previously installed in a z-wave network, I guess this was the case when I first set-up my thermostat. The protocol reset does more or less the same but is more extensive. It removes any network information from the HRT4-ZW and returns it to the factory default state (The double press of the dial is to avoid accidental operation)</li>
<p></p>
<li>The way incorporate the devices with a controller (in my case the Aeon Labs Z-Stick) is to start with both in an unassigned state. Install each device separately on to your controller. The Association between the two devices may be done using the ‘A’ command on the HRT4-ZW and pressing the install button on the ASR. This does not require knowledge of the node numbers. The install (network) button is required for installation. You need to hold the button down for over a second.</li>
<p></p>
<li>I forgot to mention about the wake-up time, I changed the wake-up time while it was in the LI (listen) mode. The default wake-up time is around 23 hours, which is a bit long when you want your thermostat changed. I changed it to 256 seconds or in other words 4 minutes and 16 seconds (the bare minimum value), but I might change it to a higher value again later on.. please see the point below why..</li>
<p></p>
<li>The 2 year battery life (as reported by Horstmann) is based on normal use as a stand-alone thermostat. Use in a network where the HRT4-ZW is woken up regularly will reduce this time. That’s why there is a minimum wake-up interval. Battery life should not be a problem in practice, but please note that when the HRT4-ZW is in installer mode (switch 1 up) the Z-Wave module is permanently powered and takes much more power. This is why my battery life reported 90% after some tests. 0% is 2V and 100% is 3V or above. A new set of batteries will normally give just over 3V (2xAAA, 1.5v each)</li>
<p></p>
<li>There is actually a second and third configuration parameter I forgot to mention about. The second one allows you to change to Fahrenheit messages. The third one allows you to set a delta t for reporting temperature changes. A message will be sent to associated nodes if the temperature changes by delta t. This parameter defaults to 1°C.</li>
<p></p>
<li>When controlled by Z-Wave messages rather than turning the dial, you can actually set the setpoint to 0.1°C steps. This will not show up on the display as it’s only 2 digits, but it will attempt to control to it. For example you could set the setpoint to 20.6°C if you wished. 21°C will be shown on the display as the demand temperature is rounded up. Fahrenheit temperatures are converted internally to the nearest 0.1°C so will not give you more accuracy.</li>
</ul>
<p>Some really valuable additional information, thanks a lot Mr.Anonymous ! :-)</p>
]]></content:encoded>
			<wfw:commentRss>http://www.maartendamen.com/2011/06/horstmann-hrt4-zw-thermostat-open-ends/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>The power of open source and social coding</title>
		<link>http://www.maartendamen.com/2011/05/the-power-of-open-source-and-social-coding/</link>
		<comments>http://www.maartendamen.com/2011/05/the-power-of-open-source-and-social-coding/#comments</comments>
		<pubDate>Fri, 20 May 2011 18:00:18 +0000</pubDate>
		<dc:creator>Maarten</dc:creator>
				<category><![CDATA[Home automation]]></category>
		<category><![CDATA[github]]></category>
		<category><![CDATA[open-zwave]]></category>
		<category><![CDATA[opensource]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[z-wave]]></category>

		<guid isPermaLink="false">http://www.maartendamen.com/?p=752</guid>
		<description><![CDATA[A few weeks ago I published the open-zwave Python wrapper. I basically started with a small wrapper suiting my personal needs. After a couple of days I was asked to share the code on Github. Until then I never used Github before. I did not expect anything from that whole social coding thing. But then [...]]]></description>
			<content:encoded><![CDATA[<p>A few weeks ago I published the open-zwave Python wrapper. I basically started with a small wrapper suiting my personal needs. After a couple of days I was asked to share the code on Github. Until then I never used Github before.</p>
<p>I did not expect anything from that whole social coding thing. But then after a couple of days two guys (Steve Davidson and Drew Perttula) started commiting code (a lot of code!) to the project. Here&#8217;s the result of 3 weeks on Github:</p>
<p>52 commits with 5,421 additions and 510 deletions </p>
<p>Really impressive, thanks a lot guys!<br />
Steve even made a really nice curses interface to it, here are some screenshots (click for full view):</p>
<p><a href="http://www.maartendamen.com/wp-content/uploads/2011/05/19-5-2011-21-55-38.png"><img src="http://www.maartendamen.com/wp-content/uploads/2011/05/19-5-2011-21-55-38-300x181.png" alt="" title="19-5-2011 21-55-38" width="300" height="181" class="alignnone size-medium wp-image-766" /></a></p>
<p><a href="http://www.maartendamen.com/wp-content/uploads/2011/05/19-5-2011-21-56-05.png"><img src="http://www.maartendamen.com/wp-content/uploads/2011/05/19-5-2011-21-56-05-300x181.png" alt="" title="19-5-2011 21-56-05" width="300" height="181" class="alignnone size-medium wp-image-767" /></a></p>
<p>This interface available on <a href="https://github.com/maartendamen/py-openzwave">Github</a> as well.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.maartendamen.com/2011/05/the-power-of-open-source-and-social-coding/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Horstmann HRT4-ZW Thermostat</title>
		<link>http://www.maartendamen.com/2011/05/horstmann-hrt4-zw-thermostat/</link>
		<comments>http://www.maartendamen.com/2011/05/horstmann-hrt4-zw-thermostat/#comments</comments>
		<pubDate>Thu, 19 May 2011 18:20:37 +0000</pubDate>
		<dc:creator>Maarten</dc:creator>
				<category><![CDATA[Electronics]]></category>
		<category><![CDATA[Home automation]]></category>
		<category><![CDATA[open-zwave]]></category>
		<category><![CDATA[thermostat]]></category>
		<category><![CDATA[wireless]]></category>
		<category><![CDATA[z-wave]]></category>

		<guid isPermaLink="false">http://www.maartendamen.com/?p=734</guid>
		<description><![CDATA[About one month ago I ordered a Horstmann HRT4-ZW thermostat. I came across this z-wave thermostat while I was surfing across the web. As far as I know this is the only EU thermostat available right now. Some of the features I like and I was looking for in a z-wave thermostat: Control the setpoint [...]]]></description>
			<content:encoded><![CDATA[<p>About one month ago I ordered a <a href="http://www.horstmann.co.uk/downloads/ElectronicDocuments/Central-Heating/HRT4-ZWdataweb.pdf">Horstmann HRT4-ZW</a> thermostat. I came across this z-wave thermostat while I was surfing across the web. As far as I know this is the only EU thermostat available right now. Some of the features I like and I was looking for in a z-wave thermostat:</p>
<ul>
<li>Control the setpoint</li>
<li>Get a setpoint report when it is manually changed (also notifications of battery levels and the room temperature)</li>
<li>Get the actual room temperature</li>
</ul>
<p>There are several posts on the Micasa Verde and Homeseer forums that device is not working in their software, despite this fact I decided to take the risk and order this device. The total cost including shipping costs was just under €100.<br />
The HRT4-ZW is a thermostat system that consists of two devices, one controller (the user side of the system, where you control the set point etc.) and a receiver (this one needs to be attached to your HVAC system). Here&#8217;s a picture of both devices:<br />
<span id="more-734"></span></p>
<p><a href="http://www.maartendamen.com/wp-content/uploads/2011/05/HRT4-ZW-montage.jpg"><img src="http://www.maartendamen.com/wp-content/uploads/2011/05/HRT4-ZW-montage.jpg" alt="" title="HRT4-ZW-montage" width="370" height="380" class="alignnone size-full wp-image-735" /></a></p>
<p><strong>Getting my feet wet: the first steps</strong></p>
<p>The first step I took when I got the device was creating a test setup, I connected an old PC power supply cable to the receiver (it needs 230v). Put in the batteries of the controller device and I was good to go! I decided the first step I had to take was getting values from the device (temperature, current set point and battery level as a bonus). Horstmann has provided detailed z-wave information in a separate document, available <a href="http://www.pepper1.net/zwavedb/uploads/resources/c9a9e2f0a21623166ddfc437c4f842c34020aa45.pdf">here</a>.<br />
One of the requirements for me was to include the controller device into my existing z-wave network, that appears to be a pretty trivial task. But, it turned out it was one of the most difficult tasks.<br />
I completely read through the z-wave document over and over again, but after 2 evenings of playing around with I was about to give up. The L mode as described in the document does include the controller within an existing z-wave network, but that loses the connection with the device that you attach to your HVAC.<br />
Separately re-associating that unit is not an option as the network button on the device does not do anything. Or, maybe it can be used?<br />
I figured out that once you put the controller unit into ERASE mode, the receiver network LED will blink as if it is ready for association. This turned out to be the key to getting both nodes included within my existing z-wave network! Here are the steps in detail:</p>
<p>1) Put the thermostat into program mode (dip switch 1 into position ON)<br />
2) Select the P option, double click the rotary wheel until PP appears on the display.<br />
3) Now go to the E, for ERASE mode. Click the rotary wheel once again until the E starts blinking.<br />
4) At this point the receiver network LED should be blinking, this means the node is ready for inclusion.<br />
5) Now, remove the batteries from the controller! Yes, just do it :-)<br />
6) Include the receiver by pushing the include button on your z-wave network stick (in my case an Aeon Labs z-stick), after that press the network button on the receiver until the ON led starts to blink.<br />
7) The receiver is now included!<br />
8) Include the controller by using the L function as described in the z-wave documentation.</p>
<p>You should now end up with two thermostat devices in your z-wave network. Here&#8217;s a screenshot from <a href="http://projects.maartendamen.com/projects/houseagent">HouseAgent</a>:</p>
<p><a href="http://www.maartendamen.com/wp-content/uploads/2011/05/17-5-2011-23-45-16.png"><img src="http://www.maartendamen.com/wp-content/uploads/2011/05/17-5-2011-23-45-16.png" alt="" title="17-5-2011 23-45-16" width="584" height="106" class="alignnone size-full wp-image-739" /></a></p>
<p>Node number 3 is the receiver and node 4 is the controller. Node 3 is quite useless (it doesn&#8217;t report any z-wave classes, except basic) but it needs to be included within the same network in order to work with the controller. Here are the z-wave classes reported by the controller, again a screenshot from HouseAgent:</p>
<p><a href="http://www.maartendamen.com/wp-content/uploads/2011/05/17-5-2011-23-48-52.png"><img src="http://www.maartendamen.com/wp-content/uploads/2011/05/17-5-2011-23-48-52.png" alt="" title="17-5-2011 23-48-52" width="727" height="411" class="alignnone size-full wp-image-741" /></a></p>
<p>Please note that the controller is a sleeping z-wave device, requests for this device need to be queued until the device comes available. The device will send a wakeup notification once it comes online. You can queue commands to the controller, and when it gets online send these commands.</p>
<p><strong>Associations</strong></p>
<p>In order to receive updates from the controller once a value changes you need to set associations. The thermostat supports associations for unsollicited room temperature, setpoint and battery reports. I set associations for each of these reports to my z-wave stick. Here&#8217;s an overview of my configuration (more information of the specifications of these groups can be found in the Horstmann document):</p>
<p><a href="http://www.maartendamen.com/wp-content/uploads/2011/05/associations.png"><img src="http://www.maartendamen.com/wp-content/uploads/2011/05/associations.png" alt="" title="associations" width="671" height="337" class="alignnone size-full wp-image-757" /></a></p>
<p><strong>Setting the setpoint</strong></p>
<p>This was my final task to be actually able to control the thermostat. Because this is a sleepjng device commands need to be queued, this was an easy thing to do in open-zwave. The problem was however that my Python z-wave wrapper had no support for setting values.. yet. I commited a new version of my open-zwave python wrapper, with setvalue support to github!</p>
<p>Here&#8217;s an example of the setvalue command being executed after the device woke up:</p>
<p><code><br />
2011-05-19 20:10:01:771 Received Wakeup Notification from node 4<br />
2011-05-19 20:10:01:772   Node 4 has been marked as awake<br />
2011-05-19 20:10:01:774 Queuing command: Set Thermostat Setpoint (Node=4): 0x01, 0x0c, 0x00, 0x13, 0x04, 0x05, 0x43, 0x01, 0x01, 0x01, 0x0f, 0x05, 0x09, 0xa0<br />
2011-05-19 20:10:01:817 Sending command (Callback ID=0x09, Expected Reply=0x13) - Set Thermostat Setpoint (Node=4): 0x01, 0x0c, 0x00, 0x13, 0x04, 0x05, 0x43, 0x01, 0x01, 0x01, 0x0f, 0x05, 0x09, 0xa0<br />
2011-05-19 20:10:01:822   ACK received CallbackId 0x09 Reply 0x13<br />
2011-05-19 20:10:01:825   Received: 0x01, 0x04, 0x01, 0x13, 0x01, 0xe8<br />
2011-05-19 20:10:01:828   ZW_SEND_DATA delivered to Z-Wave stack<br />
2011-05-19 20:10:01:838   Received: 0x01, 0x05, 0x00, 0x13, 0x09, 0x00, 0xe0<br />
2011-05-19 20:10:01:840   ZW_SEND_DATA Request with callback ID 0x09 received (expected 0x09)<br />
2011-05-19 20:10:01:845   Expected reply was received<br />
2011-05-19 20:10:01:869   Message transaction complete<br />
</code></p>
<p><strong>Physical/electrical connections</strong></p>
<p>I was unsure about the electrical connections required from the receiver to my HVAC, so I decided to hook up two wires to the points I expected to be the required connections. After that I tested it with the continuity function of my multimeter. Here&#8217;s a video of my test setup:</p>
<p><iframe width="425" height="349" src="http://www.youtube.com/embed/9ldwge_3fJc" frameborder="0" allowfullscreen></iframe></p>
<p><strong>Parameters</strong></p>
<p>One more sidenote, there are two configuration parameters available. Configuration parameter 1 must be set in order for room temperature reporting to work! This does not work out of the box..</p>
<p>This concludes my long post about this thermostat, next up for me is creating a nice GUI for it&#8230; now that I got everything figured out.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.maartendamen.com/2011/05/horstmann-hrt4-zw-thermostat/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>From Python module to GUI, software evolution</title>
		<link>http://www.maartendamen.com/2011/04/from-python-module-to-gui-software-evolution/</link>
		<comments>http://www.maartendamen.com/2011/04/from-python-module-to-gui-software-evolution/#comments</comments>
		<pubDate>Sat, 16 Apr 2011 09:59:18 +0000</pubDate>
		<dc:creator>Maarten</dc:creator>
				<category><![CDATA[Home automation]]></category>
		<category><![CDATA[evolution]]></category>
		<category><![CDATA[gui]]></category>
		<category><![CDATA[HouseAgent]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[software]]></category>
		<category><![CDATA[z-wave]]></category>

		<guid isPermaLink="false">http://www.maartendamen.com/?p=684</guid>
		<description><![CDATA[Having a Python module to control a z-wave network is great, but not really directly useful in practice. I can&#8217;t imagine myself switching lamps on and off everyday using a Python script. However, with a nice GUI it will become much more useful. Today I created a GUI around the py-openzwave module, for use within [...]]]></description>
			<content:encoded><![CDATA[<p>Having a Python module to control a z-wave network is great, but not really directly useful in practice. I can&#8217;t imagine myself switching lamps on and off everyday using a Python script.<br />
However, with a nice GUI it will become much more useful. Today I created a GUI around the py-openzwave module, for use within my home automation software (<a href="http://projects.maartendamen.com/projects/houseagent">HouseAgent</a>)<br />
HouseAgent uses a plugin structure so I can easily add new plugins in a few basic steps:</p>
<ul>
<li>Add the needed HTML templates for the GUI interface</li>
<li>Create some Python code to query the right information from the specific plugin</li>
<li>Add some device types to the database</li>
</ul>
<p><span id="more-684"></span></p>
<p>So after two/three hours of work I created the following:</p>
<p><a href="http://www.maartendamen.com/wp-content/uploads/2011/04/zwave_networkinfo.png"><img src="http://www.maartendamen.com/wp-content/uploads/2011/04/zwave_networkinfo.png" alt="" title="zwave_networkinfo" width="726" height="308" class="alignnone size-full wp-image-686" /></a></p>
<p>This screenshot shows general information about the z-wave network, I want to expand that overview with more network parameters later on. HouseAgent also includes a control page, which now allows me to switch z-wave modules on or off. That is shown in the following screenshot:</p>
<p><a href="http://www.maartendamen.com/wp-content/uploads/2011/04/zwave_onoff.png"><img src="http://www.maartendamen.com/wp-content/uploads/2011/04/zwave_onoff.png" alt="" title="zwave_onoff" width="950" height="539" class="alignnone size-full wp-image-688" /></a></p>
<p>(click for a better view)<br />
So there you have it, software evolution: from a somewhat hacky Python module up to a usable GUI.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.maartendamen.com/2011/04/from-python-module-to-gui-software-evolution/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>py-openzwave, a python wrapper for open-zwave released!</title>
		<link>http://www.maartendamen.com/2011/04/py-openzwave-a-python-wrapper-for-open-zwave-released/</link>
		<comments>http://www.maartendamen.com/2011/04/py-openzwave-a-python-wrapper-for-open-zwave-released/#comments</comments>
		<pubDate>Tue, 12 Apr 2011 18:11:00 +0000</pubDate>
		<dc:creator>Maarten</dc:creator>
				<category><![CDATA[Home automation]]></category>
		<category><![CDATA[cython]]></category>
		<category><![CDATA[projects]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[redmine]]></category>
		<category><![CDATA[wrapper]]></category>
		<category><![CDATA[z-wave]]></category>

		<guid isPermaLink="false">http://www.maartendamen.com/?p=681</guid>
		<description><![CDATA[Today I am releasing py-openzwave, which is a python wrapper around the open-zwave project. The wrapper allows you to control a z-wave network from python. This wrapper is still a work in progress, but the basic skeleton is in place (network scanning, and turning a device on or off). At the same time I am [...]]]></description>
			<content:encoded><![CDATA[<p>Today I am releasing py-openzwave, which is a python wrapper around the <a href="http://code.google.com/p/open-zwave/">open-zwave</a> project. The wrapper allows you to control a z-wave network from python.<br />
This wrapper is still a work in progress, but the basic skeleton is in place (network scanning, and turning a device on or off). At the same time I am presenting my new project workspace, based on <a href="http://www.redmine.org/">Redmine</a>.<br />
All my projects, can be found on this page from now on: <a href="http://projects.maartendamen.com">http://projects.maartendamen.com</a></p>
<p>Enough talking, py-openzwave can be found here: <a href="http://projects.maartendamen.com/projects/pyopenzwave/">http://projects.maartendamen.com/projects/pyopenzwave/</a><br />
There are some usage notes on the wiki page. </p>
<p>Any help with the project is greatly appreciated. </p>
]]></content:encoded>
			<wfw:commentRss>http://www.maartendamen.com/2011/04/py-openzwave-a-python-wrapper-for-open-zwave-released/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Compiling open-zwave with MinGW</title>
		<link>http://www.maartendamen.com/2011/04/compiling-open-zwave-with-mingw/</link>
		<comments>http://www.maartendamen.com/2011/04/compiling-open-zwave-with-mingw/#comments</comments>
		<pubDate>Tue, 05 Apr 2011 18:00:32 +0000</pubDate>
		<dc:creator>Maarten</dc:creator>
				<category><![CDATA[Home automation]]></category>
		<category><![CDATA[c++]]></category>
		<category><![CDATA[mingw]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[z-wave]]></category>

		<guid isPermaLink="false">http://www.maartendamen.com/?p=667</guid>
		<description><![CDATA[Open-zwave is a great project, it provides a software interface to z-wave networks. Z-wave is a popular home automation protocol. With more and more devices coming I was interested in adding z-wave support to my own home automation software. Being a python fanatic, I wanted to use open-zwave from within python. The first step in [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://code.google.com/p/open-zwave/">Open-zwave</a> is a great project, it provides a software interface to z-wave networks. Z-wave is a popular home automation protocol.<br />
With more and more devices coming I was interested in adding z-wave support to my own home automation software.<br />
Being a python fanatic, I wanted to use open-zwave from within python. The first step in this process was getting open-zwave to compile with <a href="http://www.mingw.org/">MingW</a>, which I can then use to create a python wrapper later on (hint, some more posts coming soon :-) )<br />
MinGW is a minimalist GNU implementation for Windows, and it&#8217;s widely used for several python modules.</p>
<p>MinGW also uses a make command, to built and maintain c/c++ programs. So the first step I had to take was to create a Makefile for MinGW.<br />
This was actually quite easy, I took the Linux Makefile and modified it accordingly:<br />
<span id="more-667"></span></p>
<pre class="brush: cpp; title: ; notranslate">
#
# Makefile for OpenZWave Linux build
# Greg Satz
# Modified for use with MinGW by Maarten Damen

# Requires libudev-dev

.SUFFIXES:	.d .cpp .o .a
.PHONY:	default clean

CC     := $(CROSS_COMPILE)gcc
CXX    := $(CROSS_COMPILE)g++
LD     := $(CROSS_COMPILE)g++
AR     := $(CROSS_COMPILE)ar rc
RANLIB := $(CROSS_COMPILE)ranlib

DEBUG_CFLAGS    := -Wall -Wno-format -g -DDEBUG -DLOG_STDERR
RELEASE_CFLAGS  := -Wall -Wno-unknown-pragmas -Wno-format -O3

DEBUG_LDFLAGS	:= -g

# Change for DEBUG or RELEASE
CFLAGS	:= -c $(DEBUG_CFLAGS)
LDFLAGS	:= $(DEBUG_LDFLAGS)

LIBDIR	:= ../../lib/windows-mingw32

INCLUDES	:= -I ../../src -I ../../src/command_classes/ -I ../../src/value_classes/ \
	-I ../../src/platform/ -I ../../src/platform/windows -I ../../tinyxml/ -I ../../hidapi/hidapi/
SOURCES		:= ../../src ../../src/command_classes ../../tinyxml ../../hidapi/windows \
	../../src/value_classes ../../src/platform ../../src/platform/windows

VPATH = ../../src:../../src/command_classes:../../tinyxml:../../hidapi/windows:\
	../../src/value_classes:../../src/platform:../../src/platform/windows

%.d : %.cpp
	@set -e; rm -f $@; \
	$(CXX) -MM $(INCLUDES) $&lt; &gt; $@.$$$$; \
	sed 's,\($*\)\.o[ :]*,\1.o $@ : ,g' &lt; $@.$$$$ &gt; $@; \
	rm -f $@.$$$$

tinyxml := $(notdir $(wildcard ../../tinyxml/*.cpp))
hidapi := $(notdir $(wildcard ../../hidapi/linux/hid.c)) # we do not want the libusb version
cclasses := $(notdir $(wildcard ../../src/command_classes/*.cpp))
vclasses := $(notdir $(wildcard ../../src/value_classes/*.cpp))
pform := $(notdir $(wildcard ../../src/platform/*.cpp)) \
	$(notdir $(wildcard ../../src/platform/windows/*.cpp))
indep := $(notdir $(wildcard ../../src/*.cpp))

%.o : %.cpp
	$(CXX) $(CFLAGS) $(INCLUDES) -o $@ $&lt;

%.o : %.c
	$(CC) $(CFLAGS) $(INCLUDES) -o $@ $&lt;

default:	$(LIBDIR)/openzwave.a

clean:
	rm -f *.d *.o

-include $(tinyxml:.cpp=.d)
-include $(hidapi:.c=.d)
-include $(cclasses:.cpp=.d)
-include $(vclasses:.cpp=.d)
-include $(pform:.cpp=.d)
-include $(indep:.cpp=.d)

vers.c:
	echo 'char ozw_vers[] = &quot;OpenZWave version 1.0.'`svnversion ../..`'&quot;;' &gt; vers.c

vers.o:	vers.c

$(LIBDIR)/openzwave.a:	$(patsubst %.cpp,%.o,$(tinyxml)) \
			$(patsubst %.c,%.o,$(hidapi)) \
			$(patsubst %.cpp,%.o,$(cclasses)) \
			$(patsubst %.cpp,%.o,$(vclasses)) \
			$(patsubst %.cpp,%.o,$(pform)) \
			$(patsubst %.cpp,%.o,$(indep)) vers.o
	$(AR) $@ $?
</pre>
<p>For the sake of maintainability I created the following folders in the open-zwave folder structure:</p>
<p>- openzwave/cpp/build/windows-mingw32 <- for the custom Makefile<br />
- openzwave/cpp/lib/windows-mingw32 <- for the output library file</p>
<p>After setting all of this up, I was ready to run the 'make' command.<br />
Uh oh, troubles:</p>
<p><a href="http://www.maartendamen.com/wp-content/uploads/2011/04/5-4-2011-17-08-54.png"><img src="http://www.maartendamen.com/wp-content/uploads/2011/04/5-4-2011-17-08-54.png" alt="" title="5-4-2011 17-08-54" width="612" height="56" class="alignnone size-full wp-image-670" /></a></p>
<p>This is caused because a non c++ standard function &#8220;sprintf_s&#8221; is used within some of open-zwave&#8217;s files.<br />
Fortunately there is a similar standard c++ function called snprintf, the fix was easy (put this on top of the cpp/src/platform/windows/HidControllerImpl.cpp file):</p>
<pre class="brush: cpp; title: ; notranslate">
#define sprintf_s snprintf
</pre>
<p>Will it build now? No, way..</p>
<p><a href="http://www.maartendamen.com/wp-content/uploads/2011/04/5-4-2011-17-14-121.png"><img src="http://www.maartendamen.com/wp-content/uploads/2011/04/5-4-2011-17-14-121.png" alt="" title="5-4-2011 17-14-12" width="566" height="86" class="alignnone size-full wp-image-674" /></a></p>
<p>This is again caused by use of non-standard functions: fprint_s and fopen_s. The fix is to put this in the head section of the cpp/src/platform/windows/LogImpl.cpp file:</p>
<pre class="brush: cpp; title: ; notranslate">
#define sprintf_s snprintf
</pre>
<p>The fix for the fopen_s command is a bit trickier, I replaced it with the standard fopen command. Replace all parts in the LogImpl.cpp file where opening of files takes place:</p>
<pre class="brush: cpp; title: ; notranslate">
FILE* pFile = NULL;
if( !fopen_s( &amp;pFile, m_filename.c_str(), &quot;a&quot; ) )
</pre>
<p>Replace it with the fopen equivalent:</p>
<pre class="brush: cpp; title: ; notranslate">
FILE* pFile = fopen( m_filename.c_str(), &quot;a&quot; );
if ( pFile != NULL )
</pre>
<p>Rerun the &#8216;make&#8217; command and open-zwave should now compile correctly with MinGW! The output library is roughly 31MB.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.maartendamen.com/2011/04/compiling-open-zwave-with-mingw/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Z-wave and python node discovery, more bitwise trickery</title>
		<link>http://www.maartendamen.com/2010/11/z-wave-and-python-node-discovery-more-bitwise-trickery/</link>
		<comments>http://www.maartendamen.com/2010/11/z-wave-and-python-node-discovery-more-bitwise-trickery/#comments</comments>
		<pubDate>Sun, 07 Nov 2010 14:00:42 +0000</pubDate>
		<dc:creator>Maarten</dc:creator>
				<category><![CDATA[Home automation]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[Reverse engineering]]></category>
		<category><![CDATA[z-wave]]></category>

		<guid isPermaLink="false">http://www.maartendamen.com/?p=467</guid>
		<description><![CDATA[This post continues upon the last blog post, in the last post we looked at some z-wave protocol basics. At the same time we had a look at a bitwise operation (XOR), in this post some more bitwise tricks will be used to do z-wave node discovery. Node discovery is essential to get information about [...]]]></description>
			<content:encoded><![CDATA[<p>This post continues upon the last blog post, in the last post we looked at some z-wave protocol basics.<br />
At the same time we had a look at a bitwise operation (XOR), in this post some more bitwise tricks will be used to do z-wave node discovery.<br />
Node discovery is essential to get information about the members of a z-wave network.<br />
The serial port sniff in the previous post, showed the FUNC_ID_SERIAL_API_GET_INIT_DATA command. Let&#8217;s dive into this packet&#8230;<br />
Here&#8217;s the packet response again:<br />
#06#01#25#01#02#05#00#1D#03#00#00#00#00#00#00#00#00#<br />
00#00#00#00#00#00#00#00#00#00#00#00#00#00#00#00#00#00#00#00#03#01#C0<br />
<span id="more-467"></span><br />
The first 4 bytes are not relevant for this post, I have to look into them later on. The fun starts at byte &#8220;02&#8243;, this byte represents the function response code (in this case FUNC_ID_SERIAL_API_GET_INIT_DATA). The byte following (05) is the z-wave protocol version, in this case v5. Next byte is &#8220;00&#8243; which is the controller type (primary or secondary)<br />
&#8220;1D&#8221; indicates the amount of node bytes. 1D is 29 decimal.<br />
Z-wave uses these node bytes to indicate whether or not a node is in use within the network (the bytes are bit masked). For example the first node byte value 03, is as follows in binary:<br />
0000 0011 </p>
<p>This means node 1 and 2 are in use, another example:</p>
<p>0000 1011</p>
<p>This would indicate node 4, 2 and 1 being used. So, how do we figure this out from code? This is where bitwise AND comes into play. A bitwise AND takes two binary representations of equal length and performs the logical AND operation on each pair of corresponding bits. In each pair, the result is 1 if the first bit is 1 AND the second bit is 1. Otherwise, the result is 0.<br />
We can use this from our python code in the following matter:</p>
<pre class="brush: python; title: ; notranslate">
    length = ord(response[7]) - 1
    index = 1

    for i in range(0, length):
        buffer_index = response[8+i]
        num = 1
        j = 0

        while j &lt;= 7:
            if (ord(buffer_index) &amp; num &gt; 0):
                print &quot;node exists!&quot;, index
            else:
                print &quot;node does not exist&quot;, index

            index = index+1

            if j &lt; 7:
                num = num * 2 

            j = j+1
</pre>
<p>And does it work?</p>
<p><a href="http://www.maartendamen.com/wp-content/uploads/2010/11/node_discovery.png"><img src="http://www.maartendamen.com/wp-content/uploads/2010/11/node_discovery.png" alt="" title="node_discovery" width="475" height="247" class="alignnone size-full wp-image-473" /></a></p>
<p>Looks fine!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.maartendamen.com/2010/11/z-wave-and-python-node-discovery-more-bitwise-trickery/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Getting started with z-wave and python</title>
		<link>http://www.maartendamen.com/2010/11/getting-started-with-z-wave-and-python/</link>
		<comments>http://www.maartendamen.com/2010/11/getting-started-with-z-wave-and-python/#comments</comments>
		<pubDate>Sat, 06 Nov 2010 10:30:20 +0000</pubDate>
		<dc:creator>Maarten</dc:creator>
				<category><![CDATA[Home automation]]></category>
		<category><![CDATA[bitwise operations]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[Reverse engineering]]></category>
		<category><![CDATA[z-wave]]></category>
		<category><![CDATA[zwave]]></category>

		<guid isPermaLink="false">http://www.maartendamen.com/?p=438</guid>
		<description><![CDATA[I started playing around with my new z-wave kit. I ordered an Aeon-Labs Z-stick (series 2) and a Duwi dimmer module to start with. Here are some images of both devices: After playing around a bit with a demo Homeseer license to test whether the stick and module worked (setup was really easy), I quickly [...]]]></description>
			<content:encoded><![CDATA[<p>I started playing around with my new z-wave kit. I ordered an Aeon-Labs Z-stick (series 2) and a Duwi dimmer module to start with.<br />
Here are some images of both devices:</p>
<p><a href="http://www.maartendamen.com/wp-content/uploads/2010/11/duwi.jpg"><img src="http://www.maartendamen.com/wp-content/uploads/2010/11/duwi-300x300.jpg" alt="" title="duwi" width="300" height="300" class="alignnone size-medium wp-image-439" /></a><a href="http://www.maartendamen.com/wp-content/uploads/2010/11/aeo_usb.jpg"><img src="http://www.maartendamen.com/wp-content/uploads/2010/11/aeo_usb-300x300.jpg" alt="" title="aeo_usb" width="300" height="300" class="alignleft size-medium wp-image-440" /></a><br />
<span id="more-438"></span><br />
After playing around a bit with a demo Homeseer license to test whether the stick and module worked (setup was really easy), I quickly switched over to my &#8216;bits and bytes view&#8217;..<br />
Here&#8217;s a log of the Aeon-Labs stick initializing:</p>
<p><a href="http://www.maartendamen.com/wp-content/uploads/2010/11/zwave_log1.png"><img src="http://www.maartendamen.com/wp-content/uploads/2010/11/zwave_log1.png" alt="" title="zwave_log" width="635" height="207" class="alignnone size-full wp-image-450" /></a></p>
<p>The yellow text is the command that get&#8217;s transmitted from the PC to the controller. This article will focus just on the sending command (my first starting point with python and z-wave)<br />
So let&#8217;s have a look at the basics, these are the 5 bytes that get send to the controller: #01#03#00#02#FE<br />
Let&#8217;s translate these bytes to bits (a lot of people still seem to have trouble to distinct between the two of them):</p>
<p>01 = 0000 0001<br />
03 = 0000 0011<br />
00 = 0000 0000<br />
02 = 0000 0010<br />
FE = 1111 1110</p>
<p>From some z-wave documentation publicly available, I figured out that the checksum is the last byte of the command. In most documents they referred to the checksum as a CRC checksum, I actually think it&#8217;s an LRC (Longitudinal Redundancy Check). A LRC is computed by XOR all the byte values of the packet together. XOR stands for a bitwise eXclusive OR. A bitwise exclusive or takes two bit patterns of equal length and performs the logical XOR operation on each pair of corresponding bits. The result in each position is 1 if the two bits are different, and 0 if they are the same. For example:</p>
<pre>
    0101
XOR 0011
  = 0110
</pre>
<p>So how does our calculation look at bit level? (remember that we skip the first byte):</p>
<p>00000011 (03) XOR 00000000 (00) = 00000011 (03) (Nothing happens on this operation)<br />
00000011 (03) XOR 00000010 (02) = 00000001 (01) (See how one + one is 0 here?)</p>
<p>So the outcome is 01.. hmm, not quite the LRC value we&#8217;d expected. We expected &#8216;FE&#8217; (last byte in our command). This is because the LRC calculation z-wave uses starts with a starter value, which is &#8220;FF&#8221; or 1111 1111. So let&#8217;s try our calculation again, now with three steps:</p>
<p>11111111 (FF) XOR 00000011 (03) = 11111100 (FC) (Note the last two bits as a result of our XOR operation)<br />
11111100 (FC) XOR 00000000 (00) = 11111100 (FC) (Nothing happens on this operation)<br />
11111100 (FC) XOR 00000010 (02) = 11111110 (FE) (Aha! There&#8217;s our value!)</p>
<p>So, there we go.. through some calculations we figured out the checksum algorithm that z-wave uses. This is an important first step in understanding the protocol.<br />
Now for the python part, here&#8217;s the code I used to test the checksum:</p>
<pre class="brush: python; title: ; notranslate">
def generateChecksum(message):
    lrc = 0xFF
    for b in message:
        lrc ^= ord(b)
    message += chr(lrc)
    return message

testmessage = &quot;\x03\x00\x02&quot;
generateChecksum(testmessage)
</pre>
<p>And this is me, testing the code :-)</p>
<p><a href="http://www.maartendamen.com/wp-content/uploads/2010/11/python_lrc.png"><img src="http://www.maartendamen.com/wp-content/uploads/2010/11/python_lrc.png" alt="" title="python_lrc" width="635" height="324" class="alignleft size-full wp-image-454" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.maartendamen.com/2010/11/getting-started-with-z-wave-and-python/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Jeenode infrared project part 5: extending IR range</title>
		<link>http://www.maartendamen.com/2010/08/jeenode-infrared-project-part-5-extending-ir-range/</link>
		<comments>http://www.maartendamen.com/2010/08/jeenode-infrared-project-part-5-extending-ir-range/#comments</comments>
		<pubDate>Tue, 10 Aug 2010 13:21:55 +0000</pubDate>
		<dc:creator>Maarten</dc:creator>
				<category><![CDATA[Home automation]]></category>
		<category><![CDATA[infrared]]></category>
		<category><![CDATA[jeenode]]></category>

		<guid isPermaLink="false">http://www.maartendamen.com/?p=353</guid>
		<description><![CDATA[Ok, so my IR controller has been running for a while. Though I was only using it for receiving for now. The range of the IR LED was not sufficient enough to control my devices. Today I had a look into the hardware schematics. I increased the transmitting power by using a NPN transistor (BC549). [...]]]></description>
			<content:encoded><![CDATA[<p>Ok, so my IR controller has been running for a while. Though I was only using it for receiving for now.<br />
The range of the IR LED was not sufficient enough to control my devices. Today I had a look into the hardware schematics.<br />
I increased the transmitting power by using a NPN transistor (BC549).<br />
<span id="more-353"></span></p>
<p>Here&#8217;s the schematic I used (all at 5V, USB power):</p>
<p><a href="http://www.maartendamen.com/wp-content/uploads/2010/08/ir_transmitter.png"><img src="http://www.maartendamen.com/wp-content/uploads/2010/08/ir_transmitter.png" alt="" title="ir_transmitter" width="343" height="360" class="alignnone size-full wp-image-354" /></a></p>
<p>Using this schematic I doubled the range of my IR LED, the power drawn in the circuit is now 37mA. My former circuit, without using a NPN transistor drew 20mA (JeeNode max per digital pin). So that&#8217;s almost twice the power.<br />
You could increase this even further using smaller valued resistors, but that would push the boundaries of the LED and transistor. I didn&#8217;t need any bigger range anyway as I use IR emitter cables attached to my devices.<br />
Now that I&#8217;m satisfied with the hardware part of sending I can start looking at the software side! </p>
<p>p.s: here&#8217;s a picture of the box right now.. cables anyone?</p>
<p><a href="http://www.maartendamen.com/wp-content/uploads/2010/08/2010-08-10_14-04-35_13_Doetinchem.jpg"><img src="http://www.maartendamen.com/wp-content/uploads/2010/08/2010-08-10_14-04-35_13_Doetinchem-1024x575.jpg" alt="" title="2010-08-10_14-04-35_13_Doetinchem" width="1024" height="575" class="alignnone size-large wp-image-356" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.maartendamen.com/2010/08/jeenode-infrared-project-part-5-extending-ir-range/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Jeenode infrared project part 4: a better home&#8230;</title>
		<link>http://www.maartendamen.com/2010/06/jeenode-infrared-project-part-4-a-better-home/</link>
		<comments>http://www.maartendamen.com/2010/06/jeenode-infrared-project-part-4-a-better-home/#comments</comments>
		<pubDate>Tue, 22 Jun 2010 20:10:03 +0000</pubDate>
		<dc:creator>Maarten</dc:creator>
				<category><![CDATA[Home automation]]></category>
		<category><![CDATA[arduino]]></category>
		<category><![CDATA[hotglue]]></category>
		<category><![CDATA[infrared]]></category>
		<category><![CDATA[jeenode]]></category>

		<guid isPermaLink="false">http://www.maartendamen.com/?p=321</guid>
		<description><![CDATA[Agreed, a breadboard looks nice and &#8220;hacky&#8221;. But, it doesn&#8217;t really fit nicely into my interior :-) It&#8217;s time to give the Jeenode infrared sender/receiver a better home! The main ingredients to get this going are: Hot glue (love that stuff) Solder Some wires A Jeelabs carrier board with case A drill A lot of [...]]]></description>
			<content:encoded><![CDATA[<p>Agreed, a breadboard looks nice and &#8220;hacky&#8221;. But, it doesn&#8217;t really fit nicely into my interior :-)<br />
It&#8217;s time to give the Jeenode infrared sender/receiver a better home!</p>
<p>The main ingredients to get this going are: </p>
<ul>
<li>Hot glue (love that stuff)</li>
<li>Solder</li>
<li>Some wires</li>
<li><a href="http://cafe.jeelabs.net/lab/cb1/">A Jeelabs carrier board with case</a></li>
<li>A drill</li>
<li>A lot of patience&#8230;</li>
</ul>
<p><span id="more-321"></span></p>
<p>I started out drilling a hole for the power supply. I used an USB cable to power the Jeenode (I cut the unused wires). USB is on a lot of devices nowadays (media boxes, media tanks, sat receivers you name it) so this is an ideal power source for my IR box.</p>
<p>Here is the hole in place (one part of the box is shown):<br />
<a href="http://www.maartendamen.com/wp-content/uploads/2010/06/box1.jpg"><img src="http://www.maartendamen.com/wp-content/uploads/2010/06/box1-300x168.jpg" alt="" title="box1" width="300" height="168" class="alignnone size-medium wp-image-323" /></a></p>
<p>And here is the result of the closed box:<br />
<a href="http://www.maartendamen.com/wp-content/uploads/2010/06/box2.jpg"><img src="http://www.maartendamen.com/wp-content/uploads/2010/06/box2-300x168.jpg" alt="" title="box2" width="300" height="168" class="alignnone size-medium wp-image-326" /></a></p>
<p>The next step I took was to give the IR receiver a nice position, I choose the opposite of the power connector. I did this because I want the power connector, and other connectors out of sight.<br />
Once again I drilled a hole, inside the box I had to make a little piece of plastic tube to lift the IR sensor (I soldered it to a little hobby print board)</p>
<p>Here&#8217;s a picture of the plastic tube, and the IR sensor soldered on the hobby print board:<br />
<a href="http://www.maartendamen.com/wp-content/uploads/2010/06/box3.jpg"><img src="http://www.maartendamen.com/wp-content/uploads/2010/06/box3-300x168.jpg" alt="" title="box3" width="300" height="168" class="alignnone size-medium wp-image-327" /></a></p>
<p>And here is it glued to the box (I am a sloppy solderer, but hey it&#8217;s inside a box anyway :-) )</p>
<p><a href="http://www.maartendamen.com/wp-content/uploads/2010/06/box4.jpg"><img src="http://www.maartendamen.com/wp-content/uploads/2010/06/box4-300x168.jpg" alt="" title="box4" width="300" height="168" class="alignnone size-medium wp-image-328" /></a></p>
<p>And this is how it looks on the outside:</p>
<p><a href="http://www.maartendamen.com/wp-content/uploads/2010/06/box5.jpg"><img src="http://www.maartendamen.com/wp-content/uploads/2010/06/box5-300x168.jpg" alt="" title="box5" width="300" height="168" class="alignnone size-medium wp-image-329" /></a></p>
<p>Next up was wiring the cables the same way as on the breadboard, this was more work then I expected it to be. Took me quite a while to get everything wired up.<br />
Here&#8217;s the result of the wiring inside the box:</p>
<p><a href="http://www.maartendamen.com/wp-content/uploads/2010/06/box6.jpg"><img src="http://www.maartendamen.com/wp-content/uploads/2010/06/box6-300x168.jpg" alt="" title="box6" width="300" height="168" class="alignnone size-medium wp-image-332" /></a></p>
<p>And this is how it looks from the outside:</p>
<p><a href="http://www.maartendamen.com/wp-content/uploads/2010/06/box8.jpg"><img src="http://www.maartendamen.com/wp-content/uploads/2010/06/box8-300x168.jpg" alt="" title="box8" width="300" height="168" class="alignnone size-medium wp-image-336" /></a></p>
<p>That&#8217;s it! The receiver has been put inside the box, I need some more time to fit the sender inside the box. I have some different idea&#8217;s for that instead of drilling holes.<br />
This step in the project required quite some different skills (drilling, glue&#8217;ing, soldering etc)</p>
]]></content:encoded>
			<wfw:commentRss>http://www.maartendamen.com/2010/06/jeenode-infrared-project-part-4-a-better-home/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

