{"id":802,"date":"2013-09-09T23:39:36","date_gmt":"2013-09-09T21:39:36","guid":{"rendered":"http:\/\/www.jensd.de\/wordpress\/?p=802"},"modified":"2013-10-28T21:55:36","modified_gmt":"2013-10-28T20:55:36","slug":"raspi-does-the-home-automation-part-v-just-around-the-corner","status":"publish","type":"post","link":"https:\/\/www.jensd.de\/wordpress\/?p=802","title":{"rendered":"RasPi does the Home Automation (Part V): Just around the corner"},"content":{"rendered":"<p>Looking for a lightweight Java-based solution to run REST services on embedded systems I already had an eye on the <a href=\"http:\/\/vertx.io\" title=\"Vert.x\" target=\"_blank\">Vert.x project<\/a>. I was excited to see there is a talk about it on the agenda of the <a href=\"http:\/\/www.herbstcampus.de\" title=\"Herbstcampus\" target=\"_blank\">Herbstcampus<\/a> in Nuremberg last week (I <a href=\"http:\/\/www.herbstcampus.de\/hc13\/program\/sessions.html#68\" title=\"Herbstcampus session\" target=\"_blank\">talked<\/a> about my RasPi projects).<\/p>\n<p>It was a pleasure to attend the talk with <a href=\"http:\/\/www.herbstcampus.de\/hc13\/program\/speakers.html#R37\" title=\"Eberhard Wolff\" target=\"_blank\">Eberhard Wolff<\/a> about Vert.x!<\/p>\n<p>Inspired by Eberhards presentation I was thrilled to give it a try and I created my first &#8220;Vertical&#8221; as a REST service for <a href=\"https:\/\/bitbucket.org\/Jerady\/sweethome\/overview\" title=\"Sweethome Source\" target=\"_blank\">my little home automation project<\/a> (as an alternative to my custom HttpServer).<br \/>\nClearly I will only need a very small fraction of the provided power! <\/p>\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_61 counter-hierarchy ez-toc-counter ez-toc-grey ez-toc-container-direction\">\n<p class=\"ez-toc-title\">Table of Contents<\/p>\n<label for=\"ez-toc-cssicon-toggle-item-69d956fc736e3\" class=\"ez-toc-cssicon-toggle-label\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #999;color:#999\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #999;color:#999\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/label><input type=\"checkbox\"  id=\"ez-toc-cssicon-toggle-item-69d956fc736e3\"  aria-label=\"Toggle\" \/><nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-1'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/www.jensd.de\/wordpress\/?p=802\/#Setup_Vertx_on_RasPi\" title=\"Setup Vert.x on RasPi\">Setup Vert.x on RasPi<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-1'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/www.jensd.de\/wordpress\/?p=802\/#Check_installation\" title=\"Check installation\">Check installation<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-1'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/www.jensd.de\/wordpress\/?p=802\/#Implementing_the_service\" title=\"Implementing the service\">Implementing the service<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-1'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/www.jensd.de\/wordpress\/?p=802\/#Deploy_and_run_vertx\" title=\"Deploy and run vertx\">Deploy and run vertx<\/a><\/li><\/ul><\/nav><\/div>\n<h1><span class=\"ez-toc-section\" id=\"Setup_Vertx_on_RasPi\"><\/span>Setup Vert.x on RasPi<span class=\"ez-toc-section-end\"><\/span><\/h1>\n<ul>\n<li><a href=\"http:\/\/vertx.io\/downloads.html\" title=\"download\" target=\"_blank\">Download<\/a> and <a href=\"http:\/\/vertx.io\/install.html\" title=\"install\" target=\"_blank\">Install<\/a> Vert.x<br \/>\ne.g. extract the package to <code><strong>\/opt<\/strong><\/code><\/li>\n<li>put &#8216;<strong>vert.x-2.0.1-final\/bin<\/strong>&#8216; on path:<br \/>\ne.g. add <code><strong>'export PATH=\/opt\/vert.x-2.0.1-final\/bin:$PATH'<\/strong><\/code> at the and of <code><strong>~\/.bashrc.<\/strong><\/code><\/li>\n<\/ul>\n<h1><span class=\"ez-toc-section\" id=\"Check_installation\"><\/span>Check installation<span class=\"ez-toc-section-end\"><\/span><\/h1>\n<p><a href=\"http:\/\/www.jensd.de\/wordpress\/wp-content\/uploads\/2013\/09\/vertx-version.png\"><img loading=\"lazy\" decoding=\"async\" data-attachment-id=\"805\" data-permalink=\"https:\/\/www.jensd.de\/wordpress\/?attachment_id=805\" data-orig-file=\"https:\/\/www.jensd.de\/wordpress\/wp-content\/uploads\/2013\/09\/vertx-version.png\" data-orig-size=\"629,96\" data-comments-opened=\"0\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;}\" data-image-title=\"vertx-version\" data-image-description=\"\" data-image-caption=\"\" data-medium-file=\"https:\/\/www.jensd.de\/wordpress\/wp-content\/uploads\/2013\/09\/vertx-version-300x45.png\" data-large-file=\"https:\/\/www.jensd.de\/wordpress\/wp-content\/uploads\/2013\/09\/vertx-version.png\" tabindex=\"0\" role=\"button\" src=\"http:\/\/www.jensd.de\/wordpress\/wp-content\/uploads\/2013\/09\/vertx-version.png\" alt=\"vertx-version\" width=\"629\" height=\"96\" class=\"aligncenter size-full wp-image-805\" srcset=\"https:\/\/www.jensd.de\/wordpress\/wp-content\/uploads\/2013\/09\/vertx-version.png 629w, https:\/\/www.jensd.de\/wordpress\/wp-content\/uploads\/2013\/09\/vertx-version-300x45.png 300w\" sizes=\"(max-width: 629px) 100vw, 629px\" \/><\/a><\/p>\n<h1><span class=\"ez-toc-section\" id=\"Implementing_the_service\"><\/span>Implementing the service<span class=\"ez-toc-section-end\"><\/span><\/h1>\n<p>I added <code><strong>vertx-core<\/strong><\/code> &#038; <code><strong>vertx-platform<\/strong><\/code> as maven dependency to my Sweethome project.<br \/>\n<strong>Note the &#8216;provided&#8217; scope:<\/strong> the dependencies are just used at compile time. At runtime the needed libs will be provided by the <code><strong>vertx<\/strong><\/code> environment.<\/p>\n<p>[xml]<br \/>\n<dependency><br \/>\n    <groupId>io.vertx<\/groupId><br \/>\n    <artifactId>vertx-core<\/artifactId><br \/>\n    <version>2.0.1-final<\/version><br \/>\n    <scope>provided<\/scope><br \/>\n<\/dependency><br \/>\n<dependency><br \/>\n    <groupId>io.vertx<\/groupId><br \/>\n    <artifactId>vertx-platform<\/artifactId><br \/>\n    <version>2.0.1-final<\/version><br \/>\n    <scope>provided<\/scope><br \/>\n<\/dependency><br \/>\n[\/xml]<\/p>\n<p>Now I am prepared to give it a try with a very simple so called &#8216;<strong>Verticle<\/strong>&#8216; implementing a request handler which is called in case the REST call signature is matching.<\/p>\n<p>Basically the URL contains the parameter for my Send-command mentioned in a <a href=\"http:\/\/www.jensd.de\/wordpress\/?p=489\" title=\"RasPi does the Home Automation (Part II): Crossing the bridge to JavaFX\">previous post<\/a>:<\/p>\n<p><code><strong>http:\/\/IP:PORT\/intertechno\/send\/HOUSE_CODE\/GROUP\/DEVICE>\/COMMAND<\/strong><\/code><\/p>\n<p>[java]<br \/>\npublic class IntertechnoVerticle extends Verticle {<\/p>\n<p>    @Override<br \/>\n    public void start() {<br \/>\n        RouteMatcher routeMatcher = new RouteMatcher();<br \/>\n        routeMatcher.get(&#8220;\/intertechno\/send\/:houseCode\/:group\/:device\/:command&#8221;, new Handler<HttpServerRequest>() {<br \/>\n            @Override<br \/>\n            public void handle(HttpServerRequest req) {<br \/>\n                container.logger().info(&#8220;received request from: &#8221; + req.remoteAddress());<\/p>\n<p>                String deviceCode = String.format(&#8220;%s %s %s&#8221;, req.params().get(&#8220;houseCode&#8221;), req.params().get(&#8220;group&#8221;), req.params().get(&#8220;device&#8221;));<br \/>\n                String commandParam = (String) req.params().get(&#8220;command&#8221;);<br \/>\n                Send.Command command = &#8220;0&#8221;.equals(commandParam) ? Send.Command.TURN_OFF : Send.Command.TURN_ON;<\/p>\n<p>                container.logger().info(&#8220;Send: &#8221; + deviceCode + &#8221; &#8221; + command.name());<br \/>\n                new Send().send(deviceCode, command);<br \/>\n                container.logger().info(&#8220;OK&#8221;);<\/p>\n<p>                req.response().setStatusCode(200);<br \/>\n                req.response().end(&#8220;<b>Send: &#8221; + deviceCode + &#8221; &#8221; + command.name() + &#8220;<\/b>&#8220;);<br \/>\n            }<br \/>\n        });<\/p>\n<p>        int port = 14880;<br \/>\n        HttpServer server = vertx.createHttpServer();<br \/>\n        server.requestHandler(routeMatcher)<br \/>\n                .listen(port);<\/p>\n<p>        container.logger().info(&#8220;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8220;);<br \/>\n        container.logger().info(&#8220;-                                     -&#8220;);<br \/>\n        container.logger().info(&#8220;-      S W E E T H O M E  SERVER      -&#8220;);<br \/>\n        container.logger().info(&#8220;-                                     -&#8220;);<br \/>\n        container.logger().info(&#8220;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8220;);<br \/>\n        container.logger().info(&#8220;Server started.&#8221;);<br \/>\n        container.logger().info(&#8220;Listening on port &#8221; + port);<br \/>\n        container.logger().info(&#8220;Waiting for incoming requests&#8230;&#8221;);<br \/>\n    }<br \/>\n}<br \/>\n[\/java]<\/p>\n<h1><span class=\"ez-toc-section\" id=\"Deploy_and_run_vertx\"><\/span>Deploy and run vertx<span class=\"ez-toc-section-end\"><\/span><\/h1>\n<p>Start the server&#8230;<\/p>\n<p><code><strong>vertx run de.jensd.sweethome.server.vertx.IntertechnoVerticle -cp \/opt\/lib\/sweethome-1.0.4-SNAPSHOT.jar<\/strong><\/code><\/p>\n<p><a href=\"http:\/\/www.jensd.de\/wordpress\/wp-content\/uploads\/2013\/09\/vertx-intertechno-verticle.png\"><img loading=\"lazy\" decoding=\"async\" data-attachment-id=\"820\" data-permalink=\"https:\/\/www.jensd.de\/wordpress\/?attachment_id=820\" data-orig-file=\"https:\/\/www.jensd.de\/wordpress\/wp-content\/uploads\/2013\/09\/vertx-intertechno-verticle.png\" data-orig-size=\"931,556\" data-comments-opened=\"0\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;}\" data-image-title=\"vertx-intertechno-verticle\" data-image-description=\"\" data-image-caption=\"\" data-medium-file=\"https:\/\/www.jensd.de\/wordpress\/wp-content\/uploads\/2013\/09\/vertx-intertechno-verticle-300x179.png\" data-large-file=\"https:\/\/www.jensd.de\/wordpress\/wp-content\/uploads\/2013\/09\/vertx-intertechno-verticle.png\" tabindex=\"0\" role=\"button\" src=\"http:\/\/www.jensd.de\/wordpress\/wp-content\/uploads\/2013\/09\/vertx-intertechno-verticle.png\" alt=\"vertx-intertechno-verticle\" width=\"931\" height=\"556\" class=\"aligncenter size-full wp-image-820\" srcset=\"https:\/\/www.jensd.de\/wordpress\/wp-content\/uploads\/2013\/09\/vertx-intertechno-verticle.png 931w, https:\/\/www.jensd.de\/wordpress\/wp-content\/uploads\/2013\/09\/vertx-intertechno-verticle-300x179.png 300w\" sizes=\"(max-width: 931px) 100vw, 931px\" \/><\/a><\/p>\n<p>&#8230; and call the service:<\/p>\n<p><a href=\"http:\/\/www.jensd.de\/wordpress\/wp-content\/uploads\/2013\/09\/vertx-intertechno-url.png\"><img loading=\"lazy\" decoding=\"async\" data-attachment-id=\"825\" data-permalink=\"https:\/\/www.jensd.de\/wordpress\/?attachment_id=825\" data-orig-file=\"https:\/\/www.jensd.de\/wordpress\/wp-content\/uploads\/2013\/09\/vertx-intertechno-url.png\" data-orig-size=\"902,198\" data-comments-opened=\"0\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;}\" data-image-title=\"vertx-intertechno-url\" data-image-description=\"\" data-image-caption=\"\" data-medium-file=\"https:\/\/www.jensd.de\/wordpress\/wp-content\/uploads\/2013\/09\/vertx-intertechno-url-300x65.png\" data-large-file=\"https:\/\/www.jensd.de\/wordpress\/wp-content\/uploads\/2013\/09\/vertx-intertechno-url.png\" tabindex=\"0\" role=\"button\" src=\"http:\/\/www.jensd.de\/wordpress\/wp-content\/uploads\/2013\/09\/vertx-intertechno-url.png\" alt=\"vertx-intertechno-url\" width=\"902\" height=\"198\" class=\"aligncenter size-full wp-image-825\" srcset=\"https:\/\/www.jensd.de\/wordpress\/wp-content\/uploads\/2013\/09\/vertx-intertechno-url.png 902w, https:\/\/www.jensd.de\/wordpress\/wp-content\/uploads\/2013\/09\/vertx-intertechno-url-300x65.png 300w\" sizes=\"(max-width: 902px) 100vw, 902px\" \/><\/a><\/p>\n<p>You can get the code <a href=\"https:\/\/bitbucket.org\/Jerady\/sweethome\/overview\" title=\"Sweethome Source\" target=\"_blank\">here<\/a>.<\/p>\n<p>[EOM]<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Looking for a lightweight Java-based solution to run REST services on embedded systems I already had an eye on the Vert.x project. I was excited to see there is a talk about it on the agenda of the Herbstcampus in Nuremberg last week (I talked about my RasPi projects). It was a pleasure to attend&hellip; <span class=\"clear\"><\/span><a href=\"https:\/\/www.jensd.de\/wordpress\/?p=802\" class=\"more-link read-more\" rel=\"bookmark\">Continue Reading <span class=\"screen-reader-text\">RasPi does the Home Automation (Part V): Just around the corner<\/span><i class=\"fa fa-arrow-right\"><\/i><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"footnotes":"","_jetpack_memberships_contains_paid_content":false,"jetpack_publicize_message":"RasPi does the Home Automation (Part V): Just around the corner http:\/\/wp.me\/p38FCL-cW","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","enabled":false},"version":2}},"categories":[22,30,18,27],"tags":[91],"jetpack_publicize_connections":[],"aioseo_notices":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p38FCL-cW","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.jensd.de\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/802"}],"collection":[{"href":"https:\/\/www.jensd.de\/wordpress\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.jensd.de\/wordpress\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.jensd.de\/wordpress\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.jensd.de\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=802"}],"version-history":[{"count":36,"href":"https:\/\/www.jensd.de\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/802\/revisions"}],"predecessor-version":[{"id":842,"href":"https:\/\/www.jensd.de\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/802\/revisions\/842"}],"wp:attachment":[{"href":"https:\/\/www.jensd.de\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=802"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.jensd.de\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=802"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.jensd.de\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=802"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}