{"id":720,"date":"2010-03-19T22:13:55","date_gmt":"2010-03-19T20:13:55","guid":{"rendered":"http:\/\/lika.be\/wp\/?p=720"},"modified":"2011-03-22T22:00:38","modified_gmt":"2011-03-22T20:00:38","slug":"xpl-enabled-utility-meter-monitor","status":"publish","type":"post","link":"https:\/\/lika.be\/wp\/2010\/03\/xpl-enabled-utility-meter-monitor\/","title":{"rendered":"xPL enabled utility meter monitor"},"content":{"rendered":"<p>When built our house, we took measures to ensure that we would consume little energy to keep our place to live warm and cosy. For this, we added extra insulation, we kept the number of air leaks as small as possible, and added a ventilation system that recycles the energy from the extracted air into the fresh air that is brought into our home.<br \/>\n<!--more--><\/p>\n<p>Since the proof of the pudding is in the eating, I need a way to monitor the resources used. A logical way to go is to tap into the existing utility grid meters. The meters are already in place, they are nicely calibrated (I hope), and they can easily be interfaced without having to fiddle with the interior of the meter itself.<\/p>\n<p>What do I want to monitor: gas usage and water usage. Interfacing to the electricity meter is a bit more difficult, as it can spin in both directions in our situation (we also produce electricity). In the end, our yearly electricity consumption is covered by what we produce. I already monitor the production, so I feel little need in monitoring the main electricity meter.<\/p>\n<p>Next question: how to interface with the meters? Several sensor types are available.<\/p>\n<ul>\n<li>Optical (the lowest digit of the meter has a reflective part) is not cool, as the interface will be influenced by lights being switched on.<\/li>\n<li>Infrared might be an option, but is like the optical a bit ugly. I can imagine that the meter-man is not keen on seeing some electronics glued in front of the meter readouts.<\/li>\n<li>Magnetic: closer inspection of the gas and water meter discloses some clues on the fact that the meters are prepared for electronic readout. For the gas meter, this is visible as a small rectangular indent in the meter housing right above the meter digits. For the water meter, a drilling is made in the side of the meter that is sealed with a removable rubber plug.<\/li>\n<\/ul>\n<p>Aha, maybe a Hall sensor will do? In fact, both meters contain a magnet that is strong enough to trigger a Hall effect sensor. The sensor I use is a A3214EUA-T from Allegro Microsystems (Farnell order code: 1651972).<\/p>\n<figure id=\"attachment_738\" aria-describedby=\"caption-attachment-738\" style=\"width: 461px\" class=\"wp-caption aligncenter\"><a rel=\"attachment wp-att-738\" href=\"http:\/\/lika.be\/wp\/2010\/03\/xpl-enabled-utility-meter-monitor\/tellers1\/\"><img loading=\"lazy\" decoding=\"async\" class=\"size-large wp-image-738 \" title=\"Water meter\" src=\"http:\/\/lika.be\/wp\/wp-content\/uploads\/2010\/03\/tellers1-512x401.jpg\" alt=\"\" width=\"461\" height=\"361\" srcset=\"https:\/\/lika.be\/wp\/wp-content\/uploads\/2010\/03\/tellers1-512x401.jpg 512w, https:\/\/lika.be\/wp\/wp-content\/uploads\/2010\/03\/tellers1-300x235.jpg 300w, https:\/\/lika.be\/wp\/wp-content\/uploads\/2010\/03\/tellers1.jpg 640w\" sizes=\"auto, (max-width: 461px) 100vw, 461px\" \/><\/a><figcaption id=\"caption-attachment-738\" class=\"wp-caption-text\">Water meter with Hall sensor inserted<\/figcaption><\/figure>\n<figure id=\"attachment_739\" aria-describedby=\"caption-attachment-739\" style=\"width: 461px\" class=\"wp-caption aligncenter\"><a rel=\"attachment wp-att-739\" href=\"http:\/\/lika.be\/wp\/2010\/03\/xpl-enabled-utility-meter-monitor\/tellers2\/\"><img loading=\"lazy\" decoding=\"async\" class=\"size-large wp-image-739 \" title=\"Gas meter\" src=\"http:\/\/lika.be\/wp\/wp-content\/uploads\/2010\/03\/tellers2-512x402.jpg\" alt=\"\" width=\"461\" height=\"362\" srcset=\"https:\/\/lika.be\/wp\/wp-content\/uploads\/2010\/03\/tellers2-512x402.jpg 512w, https:\/\/lika.be\/wp\/wp-content\/uploads\/2010\/03\/tellers2-300x235.jpg 300w, https:\/\/lika.be\/wp\/wp-content\/uploads\/2010\/03\/tellers2.jpg 640w\" sizes=\"auto, (max-width: 461px) 100vw, 461px\" \/><\/a><figcaption id=\"caption-attachment-739\" class=\"wp-caption-text\">Gas meter with Hall sensor glued into place<\/figcaption><\/figure>\n<p>A test circuit is quickly built and shows that both sensors produce pulses when the meters are rotating. For the gas meter, I get a single pulse per .01 m3. The water meter generates a pulse for every .5 liter of water that is used.<\/p>\n<p>Time to build a more robust circuit to measure the pulses. I decided to build an <a href=\"http:\/\/xplproject.org.uk\/\" target=\"_blank\">xPL enabled<\/a> sensor node that can report sensor readings over the local network to my home server. The sensor node reports the readings through the <a href=\"http:\/\/xplproject.org.uk\/wiki\/index.php?title=Schema_-_SENSOR.BASIC\" target=\"_blank\">sensor.basic message scheme<\/a> and uses the type &#8216;count&#8217;.<\/p>\n<h1>Hardware<\/h1>\n<p>The node is built around a PIC18F2520 and an XPORT. Both are mounted on the <a href=\"http:\/\/lika.be\/wp\/2006\/07\/ethernet-connected-pic\/\" target=\"_blank\">netnode PCB<\/a> that I designed previously. PCB and schematics are available <a href=\"http:\/\/code.google.com\/p\/hasy\/source\/browse\/#svn\/trunk\/netnode\/hardware\/v1\" target=\"_blank\">here<\/a>.<\/p>\n<h1>Firmware<\/h1>\n<p>The software is written in MPLAB and can be compiled with the free version of the Microchip C18 compiler.<\/p>\n<p>The basic idea of the software is to continuously run the function &#8216;xpl_handler&#8217; from the xPL lib that was written by me and Dirk. All events (sensor triggers, serial IO) are handled through interrupts. To offload the storage of received characters to the receive buffers of the XPORT (that device has 2k buffers built in) a software handshaking is implemented in the firmware.<\/p>\n<p>The sensornode keeps track of the number of pulses that are produced by the Hall sensors and transmits an xpl-trig message when a pulse is detected. The server software can interrogate the accumulated pulses with an cmnd.basic message, after which the sensornode responds with a status message.<br \/>\nThe device presents itself to the xPL network as  &#8216;hollie-utilmon&#8217;.<br \/>\nThe next screenshot shows the basic communication between the server software and the netnode for a single sensor readout.<\/p>\n<p><a rel=\"attachment wp-att-721\" href=\"http:\/\/lika.be\/wp\/2010\/03\/xpl-enabled-utility-meter-monitor\/dcm\/\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-large wp-image-721\" title=\"dcm\" src=\"http:\/\/lika.be\/wp\/wp-content\/uploads\/2010\/03\/dcm-512x276.png\" alt=\"\" width=\"512\" height=\"276\" srcset=\"https:\/\/lika.be\/wp\/wp-content\/uploads\/2010\/03\/dcm-512x276.png 512w, https:\/\/lika.be\/wp\/wp-content\/uploads\/2010\/03\/dcm-300x161.png 300w, https:\/\/lika.be\/wp\/wp-content\/uploads\/2010\/03\/dcm.png 626w\" sizes=\"auto, (max-width: 512px) 100vw, 512px\" \/><\/a><br \/>\nNext to sensor reporting, the firmware of the netnode also supports initial configuration of the name of the netnode in the xPL network. Filters and group membership is currently not supported.<\/p>\n<p>Code is available <a href=\"http:\/\/code.google.com\/p\/hasy\/source\/browse\/#svn\/trunk\/netnode\/firmware\/utility_monitor\" target=\"_blank\">in SVN<\/a>.<\/p>\n<h1>Software<\/h1>\n<p>On the PC side, we need a script to poll the sensornode are regular intervals. This is done with software of choice, and an example Perl script built on the excellent <a href=\"http:\/\/www.xpl-perl.org.uk\/\" target=\"_blank\">xpl-perl library<\/a> is located <a href=\"http:\/\/code.google.com\/p\/hasy\/source\/browse\/#svn\/trunk\/netnode\/software\/utility_monitor\">here<\/a>. This script pulls the values from the sensornodes and stores them in an RRD database for archiving and graph generation.<\/p>\n<h1>Results<\/h1>\n<p>The data stored in the RRD database is then graphed. The daily usage statistics look like this:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter\" title=\"Gas usage\" src=\"http:\/\/lika.be\/uushuus_stats\/gas_month.png\" alt=\"Gas usage per day the last month\" width=\"497\" height=\"178\" \/><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter\" title=\"Water usage per day\" src=\"http:\/\/lika.be\/uushuus_stats\/water_month.png\" alt=\"Water usage per day\" width=\"497\" height=\"178\" \/><\/p>\n<h1>XPORT configuration<\/h1>\n<p>I have not found a way to include the configuration of the XPORT in the SVN repo. Relevant settings are shown below.<\/p>\n<p><a rel=\"attachment wp-att-722\" href=\"http:\/\/lika.be\/wp\/2010\/03\/xpl-enabled-utility-meter-monitor\/schermafbeelding-2010-03-19-om-20-52-25\/\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-large wp-image-722\" title=\"Schermafbeelding 2010-03-19 om 20.52.25\" src=\"http:\/\/lika.be\/wp\/wp-content\/uploads\/2010\/03\/Schermafbeelding-2010-03-19-om-20.52.25-512x323.png\" alt=\"\" width=\"512\" height=\"323\" srcset=\"https:\/\/lika.be\/wp\/wp-content\/uploads\/2010\/03\/Schermafbeelding-2010-03-19-om-20.52.25-512x323.png 512w, https:\/\/lika.be\/wp\/wp-content\/uploads\/2010\/03\/Schermafbeelding-2010-03-19-om-20.52.25-300x189.png 300w, https:\/\/lika.be\/wp\/wp-content\/uploads\/2010\/03\/Schermafbeelding-2010-03-19-om-20.52.25.png 738w\" sizes=\"auto, (max-width: 512px) 100vw, 512px\" \/><\/a><\/p>\n<p><a rel=\"attachment wp-att-722\" href=\"http:\/\/lika.be\/wp\/2010\/03\/xpl-enabled-utility-meter-monitor\/schermafbeelding-2010-03-19-om-20-52-25\/\"><\/a><a rel=\"attachment wp-att-723\" href=\"http:\/\/lika.be\/wp\/2010\/03\/xpl-enabled-utility-meter-monitor\/schermafbeelding-2010-03-19-om-20-52-40\/\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-large wp-image-723\" title=\"Schermafbeelding 2010-03-19 om 20.52.40\" src=\"http:\/\/lika.be\/wp\/wp-content\/uploads\/2010\/03\/Schermafbeelding-2010-03-19-om-20.52.40-512x309.png\" alt=\"\" width=\"512\" height=\"309\" srcset=\"https:\/\/lika.be\/wp\/wp-content\/uploads\/2010\/03\/Schermafbeelding-2010-03-19-om-20.52.40-512x309.png 512w, https:\/\/lika.be\/wp\/wp-content\/uploads\/2010\/03\/Schermafbeelding-2010-03-19-om-20.52.40-300x181.png 300w, https:\/\/lika.be\/wp\/wp-content\/uploads\/2010\/03\/Schermafbeelding-2010-03-19-om-20.52.40.png 740w\" sizes=\"auto, (max-width: 512px) 100vw, 512px\" \/><\/a><\/p>\n<p><a rel=\"attachment wp-att-723\" href=\"http:\/\/lika.be\/wp\/2010\/03\/xpl-enabled-utility-meter-monitor\/schermafbeelding-2010-03-19-om-20-52-40\/\"><\/a><a rel=\"attachment wp-att-724\" href=\"http:\/\/lika.be\/wp\/2010\/03\/xpl-enabled-utility-meter-monitor\/schermafbeelding-2010-03-19-om-20-52-58\/\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-large wp-image-724\" title=\"Schermafbeelding 2010-03-19 om 20.52.58\" src=\"http:\/\/lika.be\/wp\/wp-content\/uploads\/2010\/03\/Schermafbeelding-2010-03-19-om-20.52.58-512x155.png\" alt=\"\" width=\"512\" height=\"155\" srcset=\"https:\/\/lika.be\/wp\/wp-content\/uploads\/2010\/03\/Schermafbeelding-2010-03-19-om-20.52.58-512x155.png 512w, https:\/\/lika.be\/wp\/wp-content\/uploads\/2010\/03\/Schermafbeelding-2010-03-19-om-20.52.58-300x91.png 300w, https:\/\/lika.be\/wp\/wp-content\/uploads\/2010\/03\/Schermafbeelding-2010-03-19-om-20.52.58.png 740w\" sizes=\"auto, (max-width: 512px) 100vw, 512px\" \/><\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>When built our house, we took measures to ensure that we would consume little energy to keep our place to live warm and cosy. For this, we added extra insulation, we kept the number of air leaks as small as possible, and added a ventilation system that recycles the energy from the extracted air into [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5,35],"tags":[],"class_list":["post-720","post","type-post","status-publish","format-standard","hentry","category-embedded","category-xpl"],"_links":{"self":[{"href":"https:\/\/lika.be\/wp\/wp-json\/wp\/v2\/posts\/720","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lika.be\/wp\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lika.be\/wp\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lika.be\/wp\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/lika.be\/wp\/wp-json\/wp\/v2\/comments?post=720"}],"version-history":[{"count":23,"href":"https:\/\/lika.be\/wp\/wp-json\/wp\/v2\/posts\/720\/revisions"}],"predecessor-version":[{"id":735,"href":"https:\/\/lika.be\/wp\/wp-json\/wp\/v2\/posts\/720\/revisions\/735"}],"wp:attachment":[{"href":"https:\/\/lika.be\/wp\/wp-json\/wp\/v2\/media?parent=720"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lika.be\/wp\/wp-json\/wp\/v2\/categories?post=720"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lika.be\/wp\/wp-json\/wp\/v2\/tags?post=720"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}