Created
March 3, 2018 09:37
-
-
Save h3po/4d7052f147988a1f7b9173b6e272f7a7 to your computer and use it in GitHub Desktop.
WiringPi code for sending signals to my 433MHz remote controlled wall sockets labeled with "unitec EIM-209 48111". The protocol is quite different from other remotes, the remote unit sends each code in multiple different ways and also cycles between 4 different codes for each button. I have not spent the time to figure out how/if the address and…
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <wiringPi.h> | |
#include <stdio.h> | |
#include <stdlib.h> | |
#define PIN 8 | |
#define PERIOD 1500 | |
#define SHORT 440 //short pulse == 1 in rtl_433 output | |
#define LONG 940 | |
#define LONGLOW 1140 | |
#define LONGHIGH 2940 | |
#define PAUSE 7080 | |
#define CORRECTION -70 | |
//values received with rtl_433 -p 75 -R0 -X "unitec:OOK_PWM:440:940:1400:2000" | |
static unsigned int codes[32] = { | |
0x1aa373, 0x18ca43, 0x1d8583, 0x156cd3, //A OFF | |
0x1bd153, 0x165f93, 0x11b4e3, 0x1ee7a3, //A ON | |
0x1f7d6a, 0x19282a, 0x1406ba, 0x139b3a, //B OFF | |
0x1c301a, 0x1212fa, 0x1749ca, 0x10fe0a, //B ON | |
0x11b4e1, 0x1ee7a1, 0x1bd151, 0x165f91, //C OFF | |
0x1d8581, 0x156cd1, 0x1aa371, 0x18ca41, //C ON | |
0x1212f8, 0x1749c8, 0x10fe08, 0x1c3018, //D OFF | |
0x1f7d68, 0x192828, 0x1406b8, 0x139b38 //D ON | |
}; | |
void delayUs(unsigned int us) { | |
delayMicroseconds(us + CORRECTION); | |
} | |
void sendBit(unsigned int bit) { | |
digitalWrite(PIN, HIGH); | |
delayUs((bit & 1) ? SHORT : LONG); | |
digitalWrite(PIN, LOW); | |
delayUs((bit & 1) ? (PERIOD - SHORT) : (PERIOD - LONG)); | |
} | |
//send 24 bits, MSB first | |
void sendCommand(unsigned int command) { | |
for (int j = 23; j>=0; j--) { | |
sendBit(command >> j); | |
} | |
} | |
void sendPacket(unsigned int command) { | |
sendBit(1); | |
delayUs(LONGLOW); | |
sendCommand(command); | |
sendBit(1); | |
delayUs(LONGLOW); | |
sendCommand(command); | |
sendBit(1); | |
delayUs(LONGLOW); | |
sendCommand(command); | |
sendBit(1); | |
delayUs(LONGLOW); | |
sendCommand(command); | |
digitalWrite(PIN, HIGH); | |
delayUs(LONGHIGH); | |
digitalWrite(PIN, LOW); | |
delayUs(PAUSE); | |
sendCommand(command); | |
digitalWrite(PIN, HIGH); | |
delayUs(LONGHIGH); | |
digitalWrite(PIN, LOW); | |
delayUs(PAUSE); | |
sendCommand(command); | |
digitalWrite(PIN, HIGH); | |
delayUs(LONGHIGH); | |
digitalWrite(PIN, LOW); | |
delayUs(PAUSE); | |
sendCommand(command); | |
digitalWrite(PIN, HIGH); | |
delayUs(LONGHIGH); | |
digitalWrite(PIN, LOW); | |
delayUs(PAUSE); | |
sendCommand(command); | |
delay(50); | |
} | |
int main (int argc, char *argv[]) { | |
wiringPiSetup(); | |
pinMode(PIN, OUTPUT); | |
if (argc == 3) { | |
unsigned long channel = strtoul(argv[1], NULL, 10); | |
unsigned long value = strtoul(argv[2], NULL, 10); | |
printf("channel %lu %s\n", channel, value == 1 ? "on" : "off"); | |
sendPacket(codes[(channel * 8) + (4*value)]); | |
sendPacket(codes[(channel * 8) + 1 + (4*value)]); | |
sendPacket(codes[(channel * 8) + 2 + (4*value)]); | |
sendPacket(codes[(channel * 8) + 3 + (4*value)]); | |
return 0; | |
} | |
printf("Usage: %s [0|1|2|3] [0|1] to turn channel 0-3 off or on\n", argv[0]); | |
return 1; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment