{"id":721,"date":"2017-11-04T19:45:06","date_gmt":"2017-11-04T19:45:06","guid":{"rendered":"https:\/\/test.warrensoft.co.uk\/wp-test\/home-hub\/?p=721"},"modified":"2018-12-08T07:29:27","modified_gmt":"2018-12-08T07:29:27","slug":"voice-interface-home-hub-rest","status":"publish","type":"post","link":"https:\/\/test.warrensoft.co.uk\/wp-test\/2017\/11\/04\/voice-interface-home-hub-rest\/","title":{"rendered":"Voice Interface &#8211; Home Hub REST"},"content":{"rendered":"<p>In a previous post we developed a simple api facility for home-hub slaves to enable remote control. The voice interface will use this api for controlling actuators, but it requires a much richer interface to provide a full interactive voice service.<\/p>\n<p>The following instructions will detail how to modify your home-hub to add a full REST api. This will allow us to read data from any table or view in the hub&#8217;s database.<\/p>\n<p>Our REST commands will be of the form:<\/p>\n<p style=\"padding-left: 30px;\">http:\/\/home-hub\/rest\/zones<\/p>\n<p>Normally, the apache web server would throw a page not found error, but with some additional configuration we can direct all such requests to a specific service page.<\/p>\n<p>The first step is to enable the apache rewrite module:<\/p>\n<pre>sudo a2enmod rewrite<\/pre>\n<p>Then we need to edit the configuration:<\/p>\n<pre>sudo nano \/etc\/apache2\/apache2.conf<\/pre>\n<p>and find the document root spec:<\/p>\n<pre>&lt;Directory \/var\/www\/&gt;\r\n Options Indexes FollowSymLinks\r\n AllowOverride <strong>None<\/strong>\r\n Require all granted\r\n&lt;\/Directory&gt;<\/pre>\n<p>and change AllowOverride from None to All.<\/p>\n<p>Restart apache&#8230;<\/p>\n<pre>sudo service apache2 restart<\/pre>\n<p>Then we can add the following .htaccess file to our document root at \/var\/www:<\/p>\n<pre>&lt;IfModule mod_rewrite.c&gt;\r\n RewriteEngine On\r\n RewriteBase \/\r\n RewriteCond %{REQUEST_FILENAME} !-f\r\n RewriteCond %{REQUEST_FILENAME} !-d\r\n RewriteRule . \/rest.php [L]\r\n&lt;\/IfModule&gt;<\/pre>\n<p>and this will send any unfound page requests to rest.php<\/p>\n<p>Now we can fetch the rest php script from the project repository with the following command:<\/p>\n<pre>wget -P \/var\/www\/html http:\/\/www.warrensoft.co.uk\/home-hub\/code\/website\/html\/rest.php<\/pre>\n<p>The same warning about security applies here. The rest api has no authentication built in. It provides an access-most-areas pass to inspect (but not change) all the hub&#8217;s database contents, so if your hub is internet-facing you are strongly advised to add your own security measures.<\/p>\n<p>Finally we can test our rest interface:<\/p>\n<p><a href=\"http:\/\/home-hub\/rest\/zones\" target=\"_blank\" rel=\"noopener\">http:\/\/home-hub\/rest\/zones<\/a><\/p>\n<p>In the next post we will setup a new Raspberry Pi in the role of Voice Assistant.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In a previous post we developed a simple api facility for home-hub slaves to enable remote control. The voice interface will use this api for controlling actuators, but it requires a much richer interface to provide a full interactive voice service. The following instructions will detail how to modify your home-hub to add a full &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/test.warrensoft.co.uk\/wp-test\/2017\/11\/04\/voice-interface-home-hub-rest\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Voice Interface &#8211; Home Hub REST&#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":[15],"tags":[],"class_list":["post-721","post","type-post","status-publish","format-standard","hentry","category-hub-software-website"],"_links":{"self":[{"href":"https:\/\/test.warrensoft.co.uk\/wp-test\/wp-json\/wp\/v2\/posts\/721","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=721"}],"version-history":[{"count":8,"href":"https:\/\/test.warrensoft.co.uk\/wp-test\/wp-json\/wp\/v2\/posts\/721\/revisions"}],"predecessor-version":[{"id":729,"href":"https:\/\/test.warrensoft.co.uk\/wp-test\/wp-json\/wp\/v2\/posts\/721\/revisions\/729"}],"wp:attachment":[{"href":"https:\/\/test.warrensoft.co.uk\/wp-test\/wp-json\/wp\/v2\/media?parent=721"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/test.warrensoft.co.uk\/wp-test\/wp-json\/wp\/v2\/categories?post=721"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/test.warrensoft.co.uk\/wp-test\/wp-json\/wp\/v2\/tags?post=721"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}