{"id":262,"date":"2017-05-14T07:10:41","date_gmt":"2017-05-14T07:10:41","guid":{"rendered":"https:\/\/test.warrensoft.co.uk\/wp-test\/home-hub\/?p=262"},"modified":"2018-12-08T07:32:18","modified_gmt":"2018-12-08T07:32:18","slug":"controller-sensor-software","status":"publish","type":"post","link":"https:\/\/test.warrensoft.co.uk\/wp-test\/2017\/05\/14\/controller-sensor-software\/","title":{"rendered":"Controller &#8211; Sensor Software"},"content":{"rendered":"<p>Fortunately, there is a fantastic library available from Adafruit which interfaces with our temperature sensor. Use the following command to install the necessary pre-requisites&#8230;<\/p>\n<pre>sudo apt-get install git python-dev python-openssl<\/pre>\n<p>and then fetch and install the library.<\/p>\n<pre>cd ~\r\ngit clone https:\/\/github.com\/adafruit\/Adafruit_Python_DHT.git\r\ncd Adafruit_Python_DHT\r\nsudo python setup.py install\r\n\r\n<\/pre>\n<p>Next we need the sensor helper module for this sensor type, from the project code repository:<\/p>\n<pre>wget -P \/usr\/local\/bin\/code\/controller\/sensor_helpers http:\/\/www.warrensoft.co.uk\/home-hub\/code\/controller\/sensor_helpers\/am2302.py<\/pre>\n<p>and then we need to make the controller aware of the type by uncommenting the following line in \/usr\/local\/bin\/code\/controller\/sensor_helpers\/__init__.py<\/p>\n<pre>from sensor_helpers.am2302 import am2302<\/pre>\n<p>Stop the current controller thread, and start a new one&#8230;<\/p>\n<pre>sudo killall python\r\nsudo su - -c \/etc\/rc.local\r\n\r\n<\/pre>\n<p>and then we are tantalisingly close to taking a measurement. But we haven&#8217;t configured the hub to tell it about our sensor, so this is a quick hack to prove our sensor is working. In the next post we will enhance our website with the forms needed to manage all this stuff, like adding sensors, setting up zones and measurands, etc. but I can&#8217;t wait that long, so lets use pgAdmin to edit the database and change the existing sensor in the <em>Sensor<\/em> table.<\/p>\n<p>The inaugural sensor S50 was a virtual sensor. It had an expression in its <em>SensorFunction<\/em> column rather than details of a real sensor. Save this expression somewhere if you want to restore after the test, and replace it with the following:<\/p>\n<p style=\"padding-left: 30px;\">am2302.nn.0.2<\/p>\n<p>This is shorthand for:<\/p>\n<p style=\"padding-left: 30px;\">call the am2302 function with the parameters bcm_pin, channel, sample_count<\/p>\n<p>You will need to replace nn with the bcm pin number that your sensor is connected to. The channel specifies the measurand: 0 for temperature or 1 for relative humidity. The sample_count sets the number of readings which will be simultaneously compared for error detection. Different sensor types will support different parameters as we will see later.<\/p>\n<p>In my development system the sensor function is:<\/p>\n<pre>am2302.23.0.2<\/pre>\n<p>While editing the sensor, change the <em>MeasurandID<\/em> from 1 Angle to 2 Temperature. Otherwise the reading will exceed the limits set for the measurand, and an error will occur.<\/p>\n<p>Once you have updated your sensor function and measurand in the database you should be able to visit the Statistics website page and see the temperature reading.<\/p>\n<p>Enough of hacking, let&#8217;s sort out the website facilities for editing sensors.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Fortunately, there is a fantastic library available from Adafruit which interfaces with our temperature sensor. Use the following command to install the necessary pre-requisites&#8230; sudo apt-get install git python-dev python-openssl and then fetch and install the library. cd ~ git clone https:\/\/github.com\/adafruit\/Adafruit_Python_DHT.git cd Adafruit_Python_DHT sudo python setup.py install Next we need the sensor helper module &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/test.warrensoft.co.uk\/wp-test\/2017\/05\/14\/controller-sensor-software\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Controller &#8211; Sensor Software&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-262","post","type-post","status-publish","format-standard","hentry","category-hub-software-controller"],"_links":{"self":[{"href":"https:\/\/test.warrensoft.co.uk\/wp-test\/wp-json\/wp\/v2\/posts\/262","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/test.warrensoft.co.uk\/wp-test\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/test.warrensoft.co.uk\/wp-test\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/test.warrensoft.co.uk\/wp-test\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/test.warrensoft.co.uk\/wp-test\/wp-json\/wp\/v2\/comments?post=262"}],"version-history":[{"count":14,"href":"https:\/\/test.warrensoft.co.uk\/wp-test\/wp-json\/wp\/v2\/posts\/262\/revisions"}],"predecessor-version":[{"id":455,"href":"https:\/\/test.warrensoft.co.uk\/wp-test\/wp-json\/wp\/v2\/posts\/262\/revisions\/455"}],"wp:attachment":[{"href":"https:\/\/test.warrensoft.co.uk\/wp-test\/wp-json\/wp\/v2\/media?parent=262"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/test.warrensoft.co.uk\/wp-test\/wp-json\/wp\/v2\/categories?post=262"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/test.warrensoft.co.uk\/wp-test\/wp-json\/wp\/v2\/tags?post=262"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}