{"id":456,"date":"2013-06-29T20:22:24","date_gmt":"2013-06-29T18:22:24","guid":{"rendered":"http:\/\/www.jensd.de\/wordpress\/?p=456"},"modified":"2015-02-10T09:12:51","modified_gmt":"2015-02-10T08:12:51","slug":"raspi-does-the-home-automation-part-i-setup-the-pi","status":"publish","type":"post","link":"https:\/\/www.jensd.de\/wordpress\/?p=456","title":{"rendered":"RasPi does the Home Automation (Part I): Setting up the Pi"},"content":{"rendered":"<p>Hi all,<\/p>\n<p>it&#8217;s some time ago since my last post as I was very busy due to other projects.<br \/>\nBut I still intent to control my wireless power outlets with the Raspberry.<\/p>\n<p><strong>The hardware<\/strong><\/p>\n<p>In the meantime the receiver\/transmitter components arrived from Hong Kong (took some weeks, but 8\u20ac (incl.  shipping!) for 5 pairs of receiver\/transmitter is quite unbeatable ;-)):<\/p>\n<p><a href=\"http:\/\/www.jensd.de\/wordpress\/wp-content\/uploads\/2013\/06\/DSC_5210.jpg\"><img decoding=\"async\" data-attachment-id=\"463\" data-permalink=\"https:\/\/www.jensd.de\/wordpress\/?attachment_id=463\" data-orig-file=\"https:\/\/www.jensd.de\/wordpress\/wp-content\/uploads\/2013\/06\/DSC_5210.jpg\" data-orig-size=\"\" data-comments-opened=\"0\" data-image-meta=\"[]\" data-image-title=\"DSC_5210\" data-image-description=\"\" data-image-caption=\"\" data-medium-file=\"https:\/\/www.jensd.de\/wordpress\/wp-content\/uploads\/2013\/06\/DSC_5210.jpg\" data-large-file=\"https:\/\/www.jensd.de\/wordpress\/wp-content\/uploads\/2013\/06\/DSC_5210.jpg\" tabindex=\"0\" role=\"button\" src=\"http:\/\/www.jensd.de\/wordpress\/wp-content\/uploads\/2013\/06\/DSC_5210.jpg\" alt=\"DSC_5210\" class=\"aligncenter size-large wp-image-463\" \/><\/a><\/p>\n<p>Next: connect the transmitter to PIN 0, +5V and GND:<\/p>\n<p><a href=\"http:\/\/www.jensd.de\/wordpress\/wp-content\/uploads\/2013\/06\/DSC_5214.jpg\"><img decoding=\"async\" data-attachment-id=\"458\" data-permalink=\"https:\/\/www.jensd.de\/wordpress\/?attachment_id=458\" data-orig-file=\"https:\/\/www.jensd.de\/wordpress\/wp-content\/uploads\/2013\/06\/DSC_5214.jpg\" data-orig-size=\"\" data-comments-opened=\"0\" data-image-meta=\"[]\" data-image-title=\"DSC_5214\" data-image-description=\"\" data-image-caption=\"\" data-medium-file=\"https:\/\/www.jensd.de\/wordpress\/wp-content\/uploads\/2013\/06\/DSC_5214.jpg\" data-large-file=\"https:\/\/www.jensd.de\/wordpress\/wp-content\/uploads\/2013\/06\/DSC_5214.jpg\" tabindex=\"0\" role=\"button\" src=\"http:\/\/www.jensd.de\/wordpress\/wp-content\/uploads\/2013\/06\/DSC_5214.jpg\" alt=\"DSC_5214\" class=\"aligncenter size-large wp-image-458\" target=\"_blank\"\/><\/a><\/p>\n<p><strong>The software<\/strong><\/p>\n<p>To &#8220;talk&#8221; to the radio-controlled sockets you have to send serial data to a generic GPIO pin to be send by the transmitter, keyword: <a href=\"http:\/\/en.wikipedia.org\/wiki\/Bit_banging\" title=\"bit-banging\" target=\"_blank\">&#8220;bit-banging&#8221;<\/a>.<\/p>\n<p>Sadly by now <a href=\"http:\/\/www.pi4j.com\" title=\"Pi4J\" target=\"_blank\">Pi4J<\/a> does not include any bit-banging techniques or built in support. Anyway bit-banging in Java may not be the best solution since timing cannot be guaranteed. (Thanks to <a href=\"https:\/\/twitter.com\/savageautomate\" title=\"Robert Savage\" target=\"_blank\">Robert Savage<\/a> from <a href=\"http:\/\/www.pi4j.com\" title=\"Pi4J\" target=\"_blank\"> Pi4J<\/a> for support)   <\/p>\n<p><strong>OK then, down-to-earth: install required stuff on the Rasperry<\/strong><\/p>\n<ol>\n<li>GPIO access library: <a href=\"https:\/\/www.wiringpi.com\" target=\"_blank\" title=\"https:\/\/projects.drogon.net\/raspberry-pi\/wiringpi\/\">wiringpi<\/a><\/li>\n<li>and the RaspPi adaption of <a href=\"https:\/\/code.google.com\/p\/rc-switch\/\" title=\"RCSwitch\" target=\"_blank\">RCSwitch<\/a> (Arduino): <a href=\"https:\/\/github.com\/r10r\/rcswitch-pi\" target=\"_blank\" title=\"https:\/\/github.com\/r10r\/rcswitch-pi\">rcswitch-pi<\/a><\/li>\n<\/ol>\n<p>Then I replaced <code>send.cpp<\/code> from rcswitch-pi by my own version:<\/p>\n<p>[cpp]<\/p>\n<p>#include &#8220;RCSwitch.h&#8221;<br \/>\n#include <stdlib.h><br \/>\n#include <stdio.h><\/p>\n<p>int main(int argc, char *argv[])<br \/>\n{<br \/>\n  int PIN = 0;<\/p>\n<p>  if (wiringPiSetup() == -1) return 1;<br \/>\n  RCSwitch mySwitch = RCSwitch();<br \/>\n  mySwitch.enableTransmit(PIN);<\/p>\n<p>  if (argc==5)<br \/>\n  {<br \/>\n    char* houseCode = argv[1];<br \/>\n    int group = atoi(argv[2]);<br \/>\n    int device = atoi(argv[3]);<br \/>\n    int command  = atoi(argv[4]);<br \/>\n    printf(&#8220;sending: houseCode:%c group:%i device:%i command: %i\\n&#8221;, houseCode[0], group, device, command);<br \/>\n    switch(command) {<br \/>\n    case 1:<br \/>\n        mySwitch.switchOn(houseCode[0], group, device);<br \/>\n        break;<br \/>\n    case 0:<br \/>\n        mySwitch.switchOff(houseCode[0], group, device);<br \/>\n        break;<br \/>\n    default:<br \/>\n        printf(&#8220;command[%i] is unsupported\\n&#8221;, command);<br \/>\n        return -1;<br \/>\n    }<br \/>\n  }<br \/>\n  else<br \/>\n  {<br \/>\n    printf(&#8221; Usage: .\/send <houseCode> <groupCode> <deviceCode> <command>\\n&#8221;);<br \/>\n    printf(&#8221; Command is 0 for OFF and 1 for ON\\n&#8221;);<br \/>\n  }<\/p>\n<p>  return 0;<br \/>\n}<\/p>\n<p>[\/cpp]<\/p>\n<p>For convenience, I allow <code>send<\/code> to run as root:<br \/>\n<code><br \/>\nsudo chown root .\/send<br \/>\nsudo chmod 4711 .\/send<br \/>\n<\/code><\/p>\n<p>My Intertechno devices can now be controlled from the prompt with my &#8220;send&#8221;-command:<\/p>\n<p><code>.\/send [houseCode] [group] [device] [command]<\/code> <\/p>\n<p><strong>Here we go:<\/strong><br \/>\n<code><br \/>\npi@raspberrypi ~\/rcswitch-pi $ .\/send a 1 3 1<br \/>\nsending: houseCode:a group:1 device:3 command: 1<br \/>\npi@raspberrypi ~\/rcswitch-pi $<br \/>\n<\/code><\/p>\n<p>And the fountain in the garden ripples&#8230;<\/p>\n<p>Next: &#8220;I need a UI&#8221; or <a href=\"http:\/\/www.jensd.de\/wordpress\/?p=489\">Crossing the bridge to JavaFX<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hi all, it&#8217;s some time ago since my last post as I was very busy due to other projects. But I still intent to control my wireless power outlets with the Raspberry. The hardware In the meantime the receiver\/transmitter components arrived from Hong Kong (took some weeks, but 8\u20ac (incl. shipping!) for 5 pairs of&hellip; <span class=\"clear\"><\/span><a href=\"https:\/\/www.jensd.de\/wordpress\/?p=456\" class=\"more-link read-more\" rel=\"bookmark\">Continue Reading <span class=\"screen-reader-text\">RasPi does the Home Automation (Part I): Setting up the Pi<\/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":"","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-7m","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.jensd.de\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/456"}],"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=456"}],"version-history":[{"count":46,"href":"https:\/\/www.jensd.de\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/456\/revisions"}],"predecessor-version":[{"id":1930,"href":"https:\/\/www.jensd.de\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/456\/revisions\/1930"}],"wp:attachment":[{"href":"https:\/\/www.jensd.de\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=456"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.jensd.de\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=456"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.jensd.de\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=456"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}