{"id":208,"date":"2017-05-14T07:09:24","date_gmt":"2017-05-14T07:09:24","guid":{"rendered":"https:\/\/test.warrensoft.co.uk\/wp-test\/home-hub\/?p=208"},"modified":"2018-12-08T07:32:18","modified_gmt":"2018-12-08T07:32:18","slug":"controller-main-loop","status":"publish","type":"post","link":"https:\/\/test.warrensoft.co.uk\/wp-test\/2017\/05\/14\/controller-main-loop\/","title":{"rendered":"Controller &#8211; Main Loop"},"content":{"rendered":"<p>The main controller program is\u00a0<a href=\"http:\/\/www.warrensoft.co.uk\/home-hub\/code\/controller\/main_sched.py\">main_sched.py<\/a>. It consists of:<\/p>\n<ul>\n<li>a continuous loop which performs periodic routine activities e.g. reading sensors<\/li>\n<li>a thread that controls\u00a0time-sensitive functions e.g. updating timers<\/li>\n<li>a thread that does high-priority work e.g. responding to user instruction<\/li>\n<li>logging initialisation<\/li>\n<\/ul>\n<p>This program needs to run when the pi is started, so it is placed in the rc.local script:<\/p>\n<pre>sudo nano \/etc\/rc.local<\/pre>\n<p>Add the following between the section that prints the IP Address, and the exit statement:<\/p>\n<pre># Run the Hub Program in a seperate process (&amp;)\r\ncd \/usr\/local\/bin\/code\/controller\r\nsudo python main_sched.py --log=INFO --slave=false &gt;&gt; hub.log &amp;\r\n\r\n<\/pre>\n<p>Save the file.<\/p>\n<p>The parameters set the logging level and the slave status. This will be our master node, so slave is false.<\/p>\n<p>To assist with the staged implementation of the controller code, as per the project plan, I have commented out a number of lines in the main scheduler with the double hash # #. This enables the controller to run, and future modules to be added later, with their required dependencies.<\/p>\n<p>The following command will fetch the files for this first stage&#8230;<\/p>\n<pre>wget -nH -x --cut-dirs=3 -P \/usr\/local\/bin\/code\/controller\/ -i \/usr\/local\/bin\/code\/controller\/manifest1.txt http:\/\/www.warrensoft.co.uk\/home-hub\/manifests\/controller\/manifest1.txt<\/pre>\n<p>&nbsp;<\/p>\n<p>The next post will cover reading values from sensors.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The main controller program is\u00a0main_sched.py. It consists of: a continuous loop which performs periodic routine activities e.g. reading sensors a thread that controls\u00a0time-sensitive functions e.g. updating timers a thread that does high-priority work e.g. responding to user instruction logging initialisation This program needs to run when the pi is started, so it is placed in &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/test.warrensoft.co.uk\/wp-test\/2017\/05\/14\/controller-main-loop\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Controller &#8211; Main Loop&#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-208","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\/208","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=208"}],"version-history":[{"count":23,"href":"https:\/\/test.warrensoft.co.uk\/wp-test\/wp-json\/wp\/v2\/posts\/208\/revisions"}],"predecessor-version":[{"id":692,"href":"https:\/\/test.warrensoft.co.uk\/wp-test\/wp-json\/wp\/v2\/posts\/208\/revisions\/692"}],"wp:attachment":[{"href":"https:\/\/test.warrensoft.co.uk\/wp-test\/wp-json\/wp\/v2\/media?parent=208"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/test.warrensoft.co.uk\/wp-test\/wp-json\/wp\/v2\/categories?post=208"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/test.warrensoft.co.uk\/wp-test\/wp-json\/wp\/v2\/tags?post=208"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}