RasPi does the Home Automation (Part I): Setting up the Pi

Hi all,

it’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€ (incl. shipping!) for 5 pairs of receiver/transmitter is quite unbeatable ;-)):

DSC_5210

Next: connect the transmitter to PIN 0, +5V and GND:

DSC_5214

The software

To “talk” to the radio-controlled sockets you have to send serial data to a generic GPIO pin to be send by the transmitter, keyword: “bit-banging”.

Sadly by now Pi4J 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 Robert Savage from Pi4J for support)

OK then, down-to-earth: install required stuff on the Rasperry

  1. GPIO access library: wiringpi
  2. and the RaspPi adaption of RCSwitch (Arduino): rcswitch-pi

Then I replaced send.cpp from rcswitch-pi by my own version:


#include "RCSwitch.h"
#include <stdlib.h>
#include <stdio.h>

int main(int argc, char *argv[])
{
  int PIN = 0;

  if (wiringPiSetup() == -1) return 1;
  RCSwitch mySwitch = RCSwitch();
  mySwitch.enableTransmit(PIN);

  if (argc==5)
  {
    char* houseCode = argv[1];
    int group = atoi(argv[2]);
    int device = atoi(argv[3]);
    int command  = atoi(argv[4]);
    printf("sending: houseCode:%c group:%i device:%i command: %i\n", houseCode[0], group, device, command);
    switch(command) {
    case 1:
        mySwitch.switchOn(houseCode[0], group, device);
        break;
    case 0:
        mySwitch.switchOff(houseCode[0], group, device);
        break;
    default:
        printf("command[%i] is unsupported\n", command);
        return -1;
    }
  }
  else
  {
    printf(" Usage: ./send <houseCode> <groupCode> <deviceCode> <command>\n");
    printf(" Command is 0 for OFF and 1 for ON\n");
  }

  return 0;
}

For convenience, I allow send to run as root:

sudo chown root ./send
sudo chmod 4711 ./send

My Intertechno devices can now be controlled from the prompt with my “send”-command:

./send [houseCode] [group] [device] [command]

Here we go:

pi@raspberrypi ~/rcswitch-pi $ ./send a 1 3 1
sending: houseCode:a group:1 device:3 command: 1
pi@raspberrypi ~/rcswitch-pi $

And the fountain in the garden ripples…

Next: “I need a UI” or Crossing the bridge to JavaFX

Leave a Reply to Minnie Reinhard Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

2 thoughts on “RasPi does the Home Automation (Part I): Setting up the Pi”

  1. Happy New Year !!

    Welcome to SourcingIC.com and we are seeking your RFQ or Bom Listing for us to price estimate.

    We are Hong Kong supplier of the complying with IC brand names for 15 years:

    TOSHIBA
    ALTERA
    ANALOG TOOLS
    TEXAS INSTRUMENTS
    ST
    FAIRCHILD
    ATMEL
    XILINX
    MICROCHIP
    SAMSUNG.
    SAYING
    NEC
    NXP
    ON SEMI
    PHILIPS
    FREESCALE
    INFINEON
    INTERSIL
    DIRECT INNOVATION
    MOTOROLA

    I know you may need to locate ICs.

    The significant mission for us is sourcing ICs. As you know greater than 99% ICs available in this earth could be discovered in China, but it is time-costly to locate or send out questions to countless distributors or firms one by one to locate that got stocks as well as get good quote!

    Step 1: Skype or email our teammate: sales@sourcingic.com

    Action 2: Inform us component number as well as the quantity or other needs

    Step 3: I will certainly resource from vendors as well as our colleague will certainly select the reliable supplier to estimate

    Tip 4: Our skilled IC technicans will check the ICs to verify they are genius and working well

    Step 5: Well packed as well as delivered

    Settlement Technique:
    Paypal/ Western Uniuon/ TT

    See you!

    Best Regards,
    Sourcing IC

    To supply every unusual ICs

    Firm History:

    Souring IC Ltd is a Hong Kong based business with China workplaces in various provinces. We supply a wide variety of digital elements, concentrated on IC consisting of Sound IC, Power Administration IC, Customer Electronic IC, and so on. Our aim is to supply any components which are challenging to be sourced in the electronic market, especially the one discountinued by manufacturing facilities. With the assistance of latest A.I system as well as the elite colleagues we owned, we have the ability to source every ICs that is not typically made use of by the co-operation with thousands manufacturing facilities and companies in China. We have the ability to offer the most affordable cost without MOQ.