diff --git a/Makefile b/Makefile index 28fe0f3..287922b 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,10 @@ -all: send +all: send send_bauhn send: RCSwitch.o send.o - $(CXX) $(CXXFLAGS) $(LDFLAGS) $+ -o $@ -lwiringPi + $(CXX) $(CXXFLAGS) $(LDFLAGS) $+ -o $@ -lwiringPi -lpthread + +send_bauhn: RCSwitch.o send_bauhn.o + $(CXX) $(CXXFLAGS) $(LDFLAGS) $+ -o $@ -lwiringPi -lpthread clean: $(RM) *.o send diff --git a/bauhn_codes.h b/bauhn_codes.h new file mode 100644 index 0000000..b3c1e73 --- /dev/null +++ b/bauhn_codes.h @@ -0,0 +1,25 @@ +/* + * Off and On codes for Bauhn (Aldi) remote power sockets + * + * The units auto-pair to the remote on first use. + * Use the arduino rc-switch ReceiveDemo program to + * find out the codes that your individual remotes send, + * then edit bauhn_codes.h to set the codes for your units. + * + */ + +#define NUM_SETS 1 + +unsigned long bauhn_codes[NUM_SETS][5][2] = { + { // first set + { 3831040116UL, 3831039096UL }, // all-off all-on + { 3831039866UL, 3831041906UL }, // 1-off 1-on + { 3831038846UL, 3831040886UL }, // 2-off 2-on + { 3831039353UL, 3831041393UL }, // 3-off 3-on + { 3831039611UL, 3831041651UL } // 4-off 4-on + } + // ,{ // second set here if any + // { code, code }, etc + // } +}; + diff --git a/send_bauhn.cpp b/send_bauhn.cpp new file mode 100644 index 0000000..011fbfb --- /dev/null +++ b/send_bauhn.cpp @@ -0,0 +1,87 @@ +/* + * Bauhn (aldi) wireless power switch control. + * + * This program sends on/off codes for an inexpensive 4-unit remote power + * switch set sold by Aldi, replicating the ability of the supplied remote which + * has separate on and off buttons for each of 4 units, + * and a 5th pair for all-on/all-off. + * + * Usage: sudo ./send_bauhn + * + * Command is 0 for turn-off and 1 for turn-on (or the words 'off' or 'on') + * Unit is 0 for all units (or 'all'), or 1-4 for individual unit + * Set is needed if you have more than one set of outlets. + * + * If arguments are omitted, the defaults are + * command=ON unit=ALL set=1 + * + */ + +#include "RCSwitch.h" +#include +#include +#include + +/* + * Set the TRANSMIT_PIN here + * see https://projects.drogon.net/raspberry-pi/wiringpi/pins/ + * for pin mapping of the raspberry pi GPIO connector + */ +#define TRANSMIT_PIN 0 + +/* + * edit bauhn_codes.h to set the codes for your remote(s) + */ +#include "bauhn_codes.h" + +int main(int argc, char *argv[]) { + + int command = 1; + int unit = 0; + int set = 1; + unsigned long code; + + if (wiringPiSetup () == -1) { + printf("WiringPi setup failed\n"); + exit(1); + } + + if (argc > 1) { + if (strcasecmp(argv[1], "on") == 0) command = 1; + else if (strcasecmp(argv[1], "off") == 0) command = 0; + else command = atoi(argv[1]); + } + if ((command < 0) || (command > 1)) { + printf("Invalid command value, expected [0,off,1,on]\n"); + exit(1); + } + if (argc > 2) { + if (strcasecmp(argv[2], "all") == 0) unit = 0; + else unit = atoi(argv[2]); + } + if ((unit < 0) || (unit > 4)) { + printf("Invalid unit value, expected [0,4]\n"); + exit(1); + } + if (argc > 3) { + set = atoi(argv[3]); + } + if ((set < 1) || (set > NUM_SETS)) { + printf("Invalid set value, expected [0,4]\n"); + exit(1); + } + + printf("sending command %d to unit %d of set %d\n", command, unit, set); + + RCSwitch mySwitch = RCSwitch(); + mySwitch.enableTransmit(TRANSMIT_PIN); + + code = bauhn_codes[set-1][unit][command]; + printf(" transmit code %lu\n", code); + + mySwitch.setProtocol(1); + mySwitch.setRepeatTransmit(14); + mySwitch.send(code, 32); + + return 0; +}