Tutorials

Home Automation with the Raspberry Pi controlling a Kambrook Powerpoint RF3399

By: Edgar Pisani

I found this tutorial: Reverse engineering the RF protocol on a Kambrook Power Point Controller. The tutorial has the source code to make it work with a Microchip PIC32MX440F512H.

I was curious if a Raspberry Pi could also control it.

I headed down to Bunnings and bought myself a set like this:

Kambrook RF3672 Remote Control

 

I created a little program, connected a 433.92MHz transmitter to the Pi, tried to control one of the power points and it didn't work.

I was a bit disappointed so I got a 433.92MHz receiver to check what the remote control was transmitting.

I don't have an oscilloscope, so I decided to use the poor people's oscilloscope: Audacity  a free audio editor and recorder.

So I connected the data output of the 433.92MHz receiver to the microphone input of my computer and set Audacity to record.

  • The first image shows the commands are sent 5 times.
  • The second image shows one of the command
  • The third image shows the first bits even closer
Kambrook RF3672 Secuence Code 1
Kambrook RF3672 Secuence Code Closer
Kambrook RF3672 Secuence Code First Bits

The sequence my transmitter was sending when pressing A-1-On was:

  • 01010101-00000000-00110110-01101000-00000001-11111111

It was very similar to the one in the reverse engineering tutorial which for A-1-On was:

  • 01010101-00000000-01101101-11111101-00000001-11111111

First and second byte, represent the start bits, third and fourth byte represent the code of the remote control, fifth byte identify the power point (A-1-On, A-1-Off, A-2-On, A-2-Off and so on) and the sixth byte is the end bits.

Concentrating in the power point byte we get:

  • A-1-On: 00000001 - Decimal: 1
  • A-1-Off: 00000010 - Decimal: 2
  • A-2-On: 00000011 - Decimal: 3
  • A-2-Off: 00000100 - Decimal: 4
  • A-3-On: 00000101 - Decimal: 5
  • A-3-Off: 00000110 - Decimal: 6
  • A-4-On: 00000111 - Decimal: 7
  • A-4-Off: 00001000 - Decimal: 8
  • A-5-On: 00001001 - Decimal: 9
  • A-5-Off: 00001010 - Decimal: 10
  • B-1-On: 00010001 - Decimal: 17
  • C-1-On: 00100001 - Decimal: 33
  • D-1-On: 00110001 - Decimal: 49

These numbers are only relevant if you still want to use the remote control at the same time as the Raspberry Pi, but if you don't it seems like odd numbers mean on and the following even number means off.

After having a closer look to the waves generated in Audacity I came up with the following numbers:

  • A digital zero: is an on pulse of 280ms followed with an off pulse for 300ms
  • A digital one: is an on pulse of 650ms followed with an off pulse for 300ms
  • The gap in-between the 5 messages is 9850ms

Having all that information I wrote a little C program for the Raspberry Pi, which is listed below.

Required Materials to Complete this Project:

A Raspberry Pi, a power supply for the Raspberry Pi, a SD card with Raspbian, a network cable, a router to connect the Raspberry Pi to and a 433.92Mhz transmitter.

You can check the Raspberry Pi Accessories Shopping Guide if you're not sure about which materials to get. The recommended materials are listed below. You might already have most of them available.

Raspberry Pi Model B+ 512MB
  • 700MHz Broadcom BCM2835 CPU with 512MB RAM
  • 40pin extended GPIO
  • 4 x USB 2 ports
  • 4 pole Stereo output and Composite video port
  • Full size HDMI
  • 5V micro USB power input jack
$52.80 In stock.
Network Cable RJ45 Cat 5E 2m - Black
  • Network Cable CAT 5E, 2m Black
  • Connector Type A: RJ45 Plug
  • Connector Type B: RJ45 Plug
  • Cable Length: 2m
  • Conductor Size: 24AWG
$5.00 In stock.
433.92 MHz RF Transmitter and Receiver

433.92MHz transmitter and receiver. Transmitter is compatible with Raspberry Pi (Connected to 3.3 V). If the receiver  will be connected to a Raspberry Pi, it will need a TTL to 3.3V convertor in the data ouput, otherwise it might damage your Pi.

Not in stock, please contact us for more info

Before you can compile the power point controller, you have to install the wiringPi libraries.

The Wiring Pi installation instructions and and be found here: http://wiringpi.com/download-and-install/

In short, you need to upgrade the pi to the latest version of Raspbian:

sudo apt-get update
sudo apt-get upgrade

To install wiring pi you need git:

sudo apt-get install git-core

If you don't have wiringPi installed use this command:

git clone git://git.drogon.net/wiringPi

If you do:

cd wiringPi
git pull origin

Then to build:

cd wiringPi
./build

Now create a folder called kambrook_rf3399 and cd into it:

mkdir kambrook_rf3399
cd kambrook_rf3399

Create a file called kambrook_rf3399_send.c and insert the contents listed below:

/*
 kambrook_rf3399_send.c

 Send commands from the Raspberry PI to the Kambrook RF3399 Power Point
 The data output is GPIO0, pin 11 of the Raspberry Pi GPIO Connector

 Use of this application is solely at your own risk!
 Original project: www.openmediacentre.com.au/index.php
 Edgar Pisani, 2014
*/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <wiringPi.h>

#define PIN 0  // pin 11 of the Raspberry Pi GPIO Connector

#define LOW 0
#define HIGH 1

int parse_bin(char *string, int repeat) {
       char fullstring[50];
       char *endstring = "11111111";
       strcpy (fullstring,"01010101000000000011011001101000");
       strcat(fullstring,string);
       strcat(fullstring,endstring);



   int len = strlen(fullstring);
   int i;

   printf("code: %s \n", fullstring);

    while(repeat) {

        for(i=0; i < len; i ++) {
       //printf("Bit: %d ",i);

            switch(fullstring[i]) {
                case '0':
                    digitalWrite( PIN, HIGH );
                    delayMicroseconds(280);
                  digitalWrite( PIN, LOW );
            delayMicroseconds(300);

                break;
                case '1':
                    digitalWrite( PIN, HIGH );
                    delayMicroseconds(650);
                  digitalWrite( PIN, LOW );
                  delayMicroseconds(300);

                break;
            }
      }
    delayMicroseconds(9580);
    repeat --;
    }
   printf("\n");
   return 0;
}

int reset_pin(void) {
    printf("reset pin to low\n");
    digitalWrite( PIN, LOW );
    return 0;
}

int main(int argc, char** argv) {

        if(argc < 2) {
                printf("[bin]\n");
        return -1;
        }

    wiringPiSetup ();
    pinMode (PIN, OUTPUT);

   reset_pin();
   // 5 is the number of repeats
   parse_bin(argv[1], 5);

   reset_pin();
return 0;
}
 

To compile do the following command:

gcc -Wall -o kambrook_rf3399_send kambrook_rf3399_send.c -lwiringPi

This will create the binary kambrook_rf3399_send

Now you can connect the 433.92MHz module as shown in the image below

Raspberry Pi with 433MHz Transmitter

As you can see the pins in the transmitter are connected as follows:

  • Data (white cable) in the transmitter is connected to pin 11 in the Raspberry Pi
  • Vcc (red cable) in the transmitter is connected to pin 1 (3.3V) in the Raspberry Pi. You can also connect this cable to pin 2 or pin 4 (5V) in the Raspberry Pi.
  • GND (black cable) in the transmitter is connected to pin 14 of the Paspberry Pi

You can check this page for a diagram of pins: https://projects.drogon.net/raspberry-pi/wiringpi/pins/

The even though the Raspberry Pi model B+ has more GPIO pins. The pins are backward compatible, so this should still work.

Finally to send a command to the Kambrook RF3399 Power Point Outlets, type in the following command and press enter:

sudo ./kambrook_rf3399_send 00000001

First you will have to "teach" the power point which code you want to use in them. To do so, plug the power point in a wall socket and press the on button for 5 seconds until it starts blinking.

Then type in the following command in your Raspberry Pi and press enter:

sudo ./kambrook_rf3399_send 00000001

If the power point "understands" the command it will stop blinking.

To test send 00000001 and 00000010. It should switch it on and off.

sudo ./kambrook_rf3399_send 00000001
sudo ./kambrook_rf3399_send 00000010

 

What to do next?

The possibilities are endless, you could:

  • Write a web application to control the power points to switch on or off at different hours of the day.
  • Connect remotely from anywhere on the Internet to your Raspberry Pi and make the power points go on or off.

Restrictions

Unfortunately the power points don't seem to be able to send back if they are on or off, so even though you might send a command to a power point, you don't have a way of figure out if the command was successful or not.

Comments

Chris, 03-08-16 17:56
Can you point me in the the libraries for the program please. i.e wiringPi.h
Add comment

* - required field

*




CAPTCHA image for SPAM prevention If you can't read the word, click here.

*
*
Continue Shoppping View Cart
Continue Shoppping View Wishlist