Skip to content
This repository has been archived by the owner on Oct 15, 2021. It is now read-only.

Implement a client for "Bauhn" brand 433Mhz radio-control switches, #22

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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
25 changes: 25 additions & 0 deletions bauhn_codes.h
Original file line number Diff line number Diff line change
@@ -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
// }
};

87 changes: 87 additions & 0 deletions send_bauhn.cpp
Original file line number Diff line number Diff line change
@@ -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> <unit> <set>
*
* 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 <stdlib.h>
#include <stdio.h>
#include <string.h>

/*
* 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;
}