Project

General

Profile

Using RFM12B for OOK 433mhz power sockets

Added by cpfeil81 over 1 year ago

Hi,

I have an Arduino Pro Mini with a RFM12B 433 Mhz connected to it. I bought a couple of RFM12B from the jeelabs shop.
The RFM12B works fine with the RFM12Demo sketch from jeelib.

No I want to generate an OOK signal with it to switch a 433 Mhz power socket.
There is a script which is able to send OOK signals here: https://github.com/mharizanov/new\_Funky/blob/master/examples/\_433Mhz\_OOK\_with\_RFM2b/\_433Mhz\_OOK\_with\_RFM2b.ino

I want to adapt this script to my Brennenstuhl power sockets (http://www.amazon.de/Brennenstuhl-Funkschalt-Set-1000-Comfort-1507450/dp/B001AX8QUM).

My first idea was to find out the Binary signal of the remote control, to add it to the example sketch.

So I did another setup with an Arduino Pro mini an an cheap 433 Mhz reciever (not RFM12B) to get the signal from the remote control (RFM12B does not received the signal).
And I used the rc-switch library (https://code.google.com/p/rc-switch/) to record the signal from the remote control (of the power sockets).

So for ON/OFF signal I got the following output:

ON:

Decimal: 1361 (24Bit) Binary: 000000000000010101010001 Tri-State: 000000FFFF0F PulseLength: 320 microseconds Protocol: 1
Raw data: 9932,336,952,332,952,328,952,328,960,324,956,324,960,324,956,324,964,320,964,316,960,324,960,320,168,60,220,136,324,316,968,956,332,48,316,144,1884,132,1008,252,64,508,124,332,100,36,272,72,248

OFF:

Decimal: 1364 (24Bit) Binary: 000000000000010101010100 Tri-State: 000000FFFFF0 PulseLength: 320 microseconds Protocol: 1
Raw data: 9940,332,952,332,956,324,956,328,960,320,956,324,964,320,964,316,964,76,2128,32,3728,132,372,96,276,84,2260,80,4948,288,352,772,108,196,40,56,108,140,52,428,156,132,380,68,336,172,160,216,140,

Putting the Binary code from this result to the script above does not switch the power socket as I expected.
I think it may be an issue with the PulseLength!? I hope anyone can help me to adapt the sketch.

Here is the full sketch I use:

// This example is based in JCW's KAKU RF sockets control code
// 2009-02-21 jc@wippler.nl http://opensource.org/licenses/mit-license.php

// Note that 868 MHz RFM12B's can send 433 MHz just fine, even though the RF
// circuitry is presumably not optimized for that band. Maybe the range will
// be limited, or maybe it's just because 868 is nearly a multiple of 433 ?

#include 
#include 

// Turn transmitter on or off, but also apply asymmetric correction and account
// for 25 us SPI overhead to end up with the proper on-the-air pulse widths.
// With thanks to JGJ Veken for his help in getting these values right.
static void ookPulse(int on, int off) {
    rf12_onOff(1);
    delayMicroseconds(on + 150);
    rf12_onOff(0);
    delayMicroseconds(off - 200);
}

static void OOKSend(unsigned long cmd) {
    for (byte i = 0; i < 10; ++i) {
        for (byte bit = 0; bit < 25; ++bit) {
            int on = bitRead(cmd, bit) ? 1056 : 395;
            ookPulse(on, 1313 - on);
        }
        delay(10); // approximate
    }
}

void setup() {
    Serial.begin(9600);
    Serial.println("\n[OOK_RF sockets]");

    pinMode(A5,OUTPUT);  //Start RFM12b
    digitalWrite(A5,LOW);
    delay(100);

    rf12_initialize(0, RF12_433MHZ);
}

void loop() {
    Serial.println("off");
    OOKSend(0b0001010101010100010101000);
    delay(1000);
    Serial.println("on");
//    OOKSend(0b0111010101010100010101000);
    OOKSend(0b0101010101010100010101000);
    delay(1000);
}

Best regards,
Christian


Replies (5)

RE: Using RFM12B for OOK 433mhz power sockets - Added by martynj over 1 year ago

@Christian,

How does that output look using the same Arduino Pro mini debug tool ?

RE: Using RFM12B for OOK 433mhz power sockets - Added by cpfeil81 over 1 year ago

Hi,

the output looks like this:

OFF:
~~~
Decimal: 133152 (24Bit) Binary: 000000100000100000100000 Tri-State: not applicable PulseLength: 334 microseconds Protocol: 1
Raw data: 10364,404,932,396,940,384,924,404,928,384,948,384,924,1032,304,368,964,364,944,376,956,376,960,376,956,1008,324,368,940,396,964,360,972,368,964,372,960,1012,324,372,960,384,948,380,980,364,968,376,956,
~~~

ON:
~~~
Decimal: 8390688 (24Bit) Binary: 100000000000100000100000 Tri-State: not applicable PulseLength: 334 microseconds Protocol: 1
Raw data: 10364,1040,296,396,936,388,920,392,940,388,920,408,928,388,944,376,932,400,932,384,952,380,952,384,948,1016,316,384,948,388,944,384,976,360,948,392,968,1004,328,364,968,376,956,376,984,356,976,372,960,
~~~

So compared to the values above my sketch seems to be wrong!
But I cant find the problem in my sketch.

Christian

RE: Using RFM12B for OOK 433mhz power sockets - Added by martynj over 1 year ago

@Christian,

If you look at the driver source code you extracted for the OOK transmit section, you will see that there are corrections made to the ON/OFF times given to the radio chip to allow for the Tx startup delay and the SPI transaction overhead. Assuming the polarity of your trace is correct (the '1' meaning Tx on), then the Tx seems to be ON for too short a period to register correctly. I'd check around that area for correct operation of the delays.

Note that code snippette is for Manchester encoded data - is that the default setting for your sniffer?

RE: Using RFM12B for OOK 433mhz power sockets - Added by cpfeil81 over 1 year ago

Hi,

thank you for your answer!

That's my problem, I have no idea how to set encoding for receiving and sending OOK signals.

When I use the rc-switch library (https://code.google.com/p/rc-switch/wiki) receiving and sending is no problem! I can switch the power socket using this library and a cheap 433 mhz sender/receiver. I don't know the encoding format of the sniffer and I can't find a way to change the encoding format in the sketch. Details for receiving can be found here https://code.google.com/p/rc-switch/wiki/HowTo_Receive

I want to use the RFM12B to switch the power sockets because I also have other RFM12B sensor nodes.

Unfortunately I have no idea how to analyze frequency and how to build a RFM12B sketch on the Arduino Pro Mini to communicate with my power sockets.
There are a few examples that can be found on the internet but nothing works for me.

Best regards,
Christian

RE: Using RFM12B for OOK 433mhz power sockets - Added by jcw over 1 year ago

OOK means turning the transmitter on and off. If you have working code which turns a cheap 433 MHz transmitter on and off via a digitalWrite to some pin, then you need to replace those with calls to rf12_onOff instead. Call rf12_onOff(1) to turn the RFM12 on and rf12_onOff(0) to turn it off. There may be some issues due to internal SPI delays as Martyn pointed out, but if this is a reasonably slow protocol, then it should still work - at least up to a certain range.

    (1-5/5)