{"id":522,"date":"2017-06-22T13:56:45","date_gmt":"2017-06-22T13:56:45","guid":{"rendered":"https:\/\/test.warrensoft.co.uk\/wp-test\/home-hub\/?p=522"},"modified":"2018-12-08T07:29:28","modified_gmt":"2018-12-08T07:29:28","slug":"controller-slave-hub","status":"publish","type":"post","link":"https:\/\/test.warrensoft.co.uk\/wp-test\/2017\/06\/22\/controller-slave-hub\/","title":{"rendered":"Controller &#8211; Slave Hub"},"content":{"rendered":"<p>You will have seen references to the slave flag in the main scheduler program. This is a boolean value passed in when the controller is first started up. We have set it to false for all operations to date, as we have been building our <em>master<\/em> hub, but if we set this flag to true then we would launch the hub in slave mode.<\/p>\n<p>A Slave hub is a cut-down appliance that is focused on reading sensors and driving actuators. It still has all of the software installation of a master hub, but some routines are not used. I will be publishing an installation script and SD image file in the resources section soon, so you don&#8217;t have to manually construct another hub. The master hub will\u00a0<em>talk<\/em> to the slave over the network, giving you the extended reach for your sensors and actuators. The Pi Zero W is the ideal candidate for implementing a slave hub.<\/p>\n<p>Once you have your second pi up and running, all that is required to make it a <strong>slave<\/strong> is the following:<\/p>\n<p style=\"padding-left: 30px;\">1. Install the api:<\/p>\n<pre>wget -P \/var\/www\/html http:\/\/www.warrensoft.co.uk\/home-hub\/code\/website\/html\/api.php<\/pre>\n<p style=\"padding-left: 30px;\">2. Change the slave hostname &#8211; to distinguish master and slave when configuring<\/p>\n<p style=\"padding-left: 30px;\">3. Edit \/etc\/rc.local and change the &#8211;slave=false to &#8211;slave=true in the line launching main_sched.py and optionally reduce the logging level to just errors &#8211;log=ERROR or no logging &#8211;log=CRITICAL<\/p>\n<p style=\"padding-left: 30px;\">4. Reboot the slave<\/p>\n<p style=\"padding-left: 30px;\">5. Test the api:<\/p>\n<p style=\"padding-left: 60px;\">http:\/\/slave-hub\/api.php?sensor=1<\/p>\n<p>Now we need to add some software to our <strong>master<\/strong> hub to equip it to talk to slaves. \u00a0This comes in the form of a <em>remote<\/em> sensor helper and a\u00a0<em>remote<\/em> actuator helper.<\/p>\n<pre>wget -nH -x --cut-dirs=3 -P \/usr\/local\/bin\/code\/controller\/ -i \/usr\/local\/bin\/code\/controller\/manifest5.txt http:\/\/www.warrensoft.co.uk\/home-hub\/manifests\/controller\/manifest5.txt<\/pre>\n<p>These helpers need to be un-commented in their respective __init__.py files.<\/p>\n<p>We also need the python requests module, via pip:<\/p>\n<pre>sudo apt-get install python-pip<\/pre>\n<pre>sudo pip install requests\r\nsudo pip install --upgrade requests-cache\r\n\r\n<\/pre>\n<p>Restart the controller and add a new sensor, this time with the Sensor Function of the form:<\/p>\n<p style=\"padding-left: 30px;\">remote.x.y<\/p>\n<p>where x represents the least significant part of the ip address of the slave, and y represents the remote sensor number. For example, if we had a master hub on 170.30.90.40, and a slave on\u00a0170.30.90.41 with a Sensor S3, \u00a0then the sensor function in the master would be:<\/p>\n<p style=\"padding-left: 30px;\">remote.41.3<\/p>\n<p>Once configured the remote sensor is identical to a local sensor, and can be sampled, alerted, monitored, etc.<\/p>\n<p>An identical \u00a0approach applies to remote actuators, so the actuator function <em>remote.41.4<\/em> would control actuator 4 on the slave hub.<\/p>\n<p>Just a note about security. Remote access to the api page is not secure, unlike the normal website functions. Rather than publish details on a public blog, it is left to the reader to implement whatever mechanism they feel is appropriate. One possible setup is to make just the master hub website accessible over the internet, on a different port, but not the slave hub(s). Consult your router documentation for details.<\/p>\n<p>Next we will look at fetching our readings from slightly further afield.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>You will have seen references to the slave flag in the main scheduler program. This is a boolean value passed in when the controller is first started up. We have set it to false for all operations to date, as we have been building our master hub, but if we set this flag to true &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/test.warrensoft.co.uk\/wp-test\/2017\/06\/22\/controller-slave-hub\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Controller &#8211; Slave Hub&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7],"tags":[],"class_list":["post-522","post","type-post","status-publish","format-standard","hentry","category-hub-software"],"_links":{"self":[{"href":"https:\/\/test.warrensoft.co.uk\/wp-test\/wp-json\/wp\/v2\/posts\/522","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=522"}],"version-history":[{"count":23,"href":"https:\/\/test.warrensoft.co.uk\/wp-test\/wp-json\/wp\/v2\/posts\/522\/revisions"}],"predecessor-version":[{"id":701,"href":"https:\/\/test.warrensoft.co.uk\/wp-test\/wp-json\/wp\/v2\/posts\/522\/revisions\/701"}],"wp:attachment":[{"href":"https:\/\/test.warrensoft.co.uk\/wp-test\/wp-json\/wp\/v2\/media?parent=522"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/test.warrensoft.co.uk\/wp-test\/wp-json\/wp\/v2\/categories?post=522"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/test.warrensoft.co.uk\/wp-test\/wp-json\/wp\/v2\/tags?post=522"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}