{"id":489,"date":"2013-07-06T16:17:01","date_gmt":"2013-07-06T14:17:01","guid":{"rendered":"http:\/\/www.jensd.de\/wordpress\/?p=489"},"modified":"2013-12-19T12:46:41","modified_gmt":"2013-12-19T11:46:41","slug":"raspi-does-the-home-automation-part-ii-crossing-the-bridge-to-javafx","status":"publish","type":"post","link":"https:\/\/www.jensd.de\/wordpress\/?p=489","title":{"rendered":"RasPi does the Home Automation (Part II): Crossing the bridge to JavaFX"},"content":{"rendered":"<p>Hi,<\/p>\n<p>before JavaFX can take over, I need some bottom-up stuff to control my <a href=\"http:\/\/www.intertechno.at\" title=\"Intertechno\" target=\"_blank\">Intertechno<\/a>-Devices.<\/p>\n<p><strong>Basically this is the schema:<\/strong><br \/>\n<a href=\"http:\/\/www.jensd.de\/wordpress\/wp-content\/uploads\/2013\/07\/RaspiSendSetup3.png\"><img decoding=\"async\" data-attachment-id=\"580\" data-permalink=\"https:\/\/www.jensd.de\/wordpress\/?attachment_id=580\" data-orig-file=\"https:\/\/www.jensd.de\/wordpress\/wp-content\/uploads\/2013\/07\/RaspiSendSetup3.png\" data-orig-size=\"\" data-comments-opened=\"0\" data-image-meta=\"[]\" data-image-title=\"RaspiSendSetup\" data-image-description=\"\" data-image-caption=\"\" data-medium-file=\"https:\/\/www.jensd.de\/wordpress\/wp-content\/uploads\/2013\/07\/RaspiSendSetup3.png\" data-large-file=\"https:\/\/www.jensd.de\/wordpress\/wp-content\/uploads\/2013\/07\/RaspiSendSetup3.png\" tabindex=\"0\" role=\"button\" src=\"http:\/\/www.jensd.de\/wordpress\/wp-content\/uploads\/2013\/07\/RaspiSendSetup3.png\" alt=\"RaspiSendSetup\" class=\"aligncenter size-full wp-image-580\" \/><\/a><\/p>\n<p>Right now I have 2 <a href=\"http:\/\/intertechno.at\/produkte\/zwischenstecker\/schalter\/ITR-3500.html\" title=\"radio intermediate adapters\" target=\"_blank\">radio intermediate adapters<\/a> to switch the lights of my terrace\/garden and the fountain. And one of these to control the lights in front of my house (cool: can be combined with existing light switch) :<br \/>\n<a href=\"http:\/\/intertechno.at\/produkte\/empfaenger\/schalter\/ITL-230.html\" target=\"_blank\"><img loading=\"lazy\" decoding=\"async\" data-attachment-id=\"572\" data-permalink=\"https:\/\/www.jensd.de\/wordpress\/?attachment_id=572\" data-orig-file=\"https:\/\/www.jensd.de\/wordpress\/wp-content\/uploads\/2013\/07\/ITL-230_assembly.png\" data-orig-size=\"482,181\" 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=\"ITL-230_assembly\" data-image-description=\"\" data-image-caption=\"\" data-medium-file=\"https:\/\/www.jensd.de\/wordpress\/wp-content\/uploads\/2013\/07\/ITL-230_assembly-300x112.png\" data-large-file=\"https:\/\/www.jensd.de\/wordpress\/wp-content\/uploads\/2013\/07\/ITL-230_assembly.png\" tabindex=\"0\" role=\"button\" src=\"http:\/\/www.jensd.de\/wordpress\/wp-content\/uploads\/2013\/07\/ITL-230_assembly.png\" alt=\"ITL-230_assembly\" width=\"482\" height=\"181\" class=\"aligncenter size-full wp-image-572\" srcset=\"https:\/\/www.jensd.de\/wordpress\/wp-content\/uploads\/2013\/07\/ITL-230_assembly.png 482w, https:\/\/www.jensd.de\/wordpress\/wp-content\/uploads\/2013\/07\/ITL-230_assembly-300x112.png 300w\" sizes=\"(max-width: 482px) 100vw, 482px\" \/><\/a><\/p>\n<p><strong>Some Details:<\/strong><\/p>\n<p><strong>Pragmatic approach: &#8220;<code>Runtime.getRuntime().exec(...)<\/code>&#8220;<\/strong><br \/>\nClearly to pipe the data to the C implementation via a JNI call would be nice, but to get ahead in time by now for me it&#8217;s ok to use <code>Runtime.getRuntime().exec(...)<\/code> to run my &#8220;send&#8221; CLI command:<\/p>\n<p>[java]<br \/>\n public class Send {<\/p>\n<p>  public enum Command {<br \/>\n    TURN_OFF, TURN_ON;<br \/>\n  }<\/p>\n<p>  public static final String SEND_COMMAND = &#8220;\/home\/pi\/rcswitch-pi\/send&#8221;;<br \/>\n  private static final Logger logger = Logger.getLogger(Send.class.getName());<\/p>\n<p>  public void send(String deviveCode, Command command) {<br \/>\n    try {<br \/>\n      String commandLine = String.<br \/>\n              format(&#8220;%s %s %s&#8221;, SEND_COMMAND, deviveCode, command.ordinal());<br \/>\n      logger.log(Level.INFO, &#8220;send: {0}&#8221;, commandLine);<\/p>\n<p>      Runtime rt = Runtime.getRuntime();<br \/>\n      Process pr = rt.exec(commandLine);<br \/>\n      BufferedReader rd = new BufferedReader(new InputStreamReader(pr.<br \/>\n              getInputStream()));<br \/>\n      String line;<br \/>\n      while ((line = rd.readLine()) != null) {<br \/>\n        logger.log(Level.INFO, line);<br \/>\n      }<\/p>\n<p>    } catch (IOException ex) {<br \/>\n      Logger.getLogger(Send.class.getName()).<br \/>\n              log(Level.SEVERE, null, ex);<br \/>\n    }<br \/>\n  }<\/p>\n<p>  public boolean isSendCommandExecutable(){<br \/>\n      return Files.isExecutable(Paths.get(SEND_COMMAND));<br \/>\n  }<br \/>\n}<br \/>\n[\/java]<\/p>\n<p>The Java-<code>Send<\/code> is used by <code>DeviceControl<\/code>: <\/p>\n<p>[java]<br \/>\npublic class DeviceControl {<\/p>\n<p>    private Send send = new Send();<br \/>\n    private static final Logger logger = Logger.getLogger(DeviceLoader.class.getName());<br \/>\n    private static DeviceControl me;<\/p>\n<p>    private DeviceControl() {<br \/>\n    }<\/p>\n<p>    public static DeviceControl get() {<br \/>\n        if (me == null) {<br \/>\n            me = new DeviceControl();<br \/>\n        }<br \/>\n        return me;<br \/>\n    }<\/p>\n<p>    public void turnOn(Device device) {<br \/>\n        logger.log(Level.INFO, &#8220;About to {0} {1} ({2})&#8221;, new Object[]{Send.Command.TURN_ON, device.getName(), device.getId()});<br \/>\n        if (send.isSendCommandExecutable()) {<br \/>\n            send.send(device.getId(), Send.Command.TURN_ON);<br \/>\n        } else {<br \/>\n            logger.log(Level.SEVERE, &#8220;{0} could not be executed!&#8221;, Send.SEND_COMMAND);<br \/>\n        }<br \/>\n    }<\/p>\n<p>    public void turnOff(Device device) {<br \/>\n        logger.log(Level.INFO, &#8220;About to {0} {1} ({2})&#8221;, new Object[]{Send.Command.TURN_OFF, device.getName(), device.getId()});<br \/>\n        if (send.isSendCommandExecutable()) {<br \/>\n            send.send(device.getId(), Send.Command.TURN_OFF);<br \/>\n        } else {<br \/>\n            logger.log(Level.SEVERE, &#8220;{0} could not be executed!&#8221;, Send.SEND_COMMAND);<br \/>\n        }<br \/>\n    }<br \/>\n}<br \/>\n[\/java]<\/p>\n<p>A <a href=\"http:\/\/www.intertechno.at\" title=\"Intertechno\" target=\"_blank\">Intertechno<\/a>-appliance is represented by <code>Device<\/code>:<\/p>\n<p>[java]<br \/>\npublic class Device {<\/p>\n<p>  private String name;<br \/>\n  private String houseCode;<br \/>\n  private String group;<br \/>\n  private String device;<\/p>\n<p>  public Device() {<br \/>\n  }<\/p>\n<p>  public Device(String name, String houseCode, String group, String device) {<br \/>\n    this.name = name;<br \/>\n    this.houseCode = houseCode;<br \/>\n    this.group = group;<br \/>\n    this.device = device;<br \/>\n  }<\/p>\n<p>  public String getId() {<br \/>\n    return String.format(&#8220;%s %s %s&#8221;, houseCode, group, device);<br \/>\n  }<\/p>\n<p> [&#8230;. getter &#038; setter &#8230;.]<\/p>\n<p>}<br \/>\n[\/java] <\/p>\n<p>The available <code>Devices<\/code> are defined via a configuration-file:  <\/p>\n<p>[xml]<br \/>\n<?xml version=\"1.0\" encoding=\"UTF-8\"?><br \/>\n<home-configuration><br \/>\n    <devices><br \/>\n        <device name=\"Haust\u00fcr\" houseCode=\"a\" group=\"1\" device=\"1\"\/><br \/>\n        <device name=\"Terrasse\" houseCode=\"a\" group=\"1\" device=\"2\"\/><br \/>\n        <device name=\"Springbrunnen\" houseCode=\"a\" group=\"1\" device=\"3\"\/><br \/>\n    <\/devices><br \/>\n<\/home-configuration><br \/>\n[\/xml]<\/p>\n<p>Finally utility class <code>DeviceLoader.load();<\/code> loads the configuration and provides a <code>List<\/code> of <code>Devices<\/code>.<br \/>\nThe <code>HomeControlBoardController<\/code> dynamically creates <code>DevicePanes<\/code> according to the configured devices.<\/p>\n<p>That&#8217;s it for now.<\/p>\n<p>Next:<br \/>\n<a href=\"http:\/\/www.jensd.de\/wordpress\/?p=591\" title=\"RasPi does the Home Automation (Part III): \u2018Let\u2019s Put It All Together\u2019\">RasPi does the Home Automation (Part III): \u2018Let\u2019s Put It All Together\u2019<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hi, before JavaFX can take over, I need some bottom-up stuff to control my Intertechno-Devices. Basically this is the schema: Right now I have 2 radio intermediate adapters to switch the lights of my terrace\/garden and the fountain. And one of these to control the lights in front of my house (cool: can be combined&hellip; <span class=\"clear\"><\/span><a href=\"https:\/\/www.jensd.de\/wordpress\/?p=489\" class=\"more-link read-more\" rel=\"bookmark\">Continue Reading <span class=\"screen-reader-text\">RasPi does the Home Automation (Part II): Crossing the bridge to JavaFX<\/span><i class=\"fa fa-arrow-right\"><\/i><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","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":"#RaspberryPi does the #HomeAutomation (Part II): Crossing the bridge to #JavaFX http:\/\/wp.me\/p38FCL-7T","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","enabled":false},"version":2}},"categories":[21,22,30,4,18],"tags":[87,88,91,76,86],"jetpack_publicize_connections":[],"aioseo_notices":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p38FCL-7T","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.jensd.de\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/489"}],"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=489"}],"version-history":[{"count":31,"href":"https:\/\/www.jensd.de\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/489\/revisions"}],"predecessor-version":[{"id":773,"href":"https:\/\/www.jensd.de\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/489\/revisions\/773"}],"wp:attachment":[{"href":"https:\/\/www.jensd.de\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=489"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.jensd.de\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=489"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.jensd.de\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=489"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}