Skip to content

Commit

Permalink
Merge pull request #4 from arek125/beta
Browse files Browse the repository at this point in the history
Beta
  • Loading branch information
arek125 committed Sep 15, 2019
2 parents a1cc20a + 19671eb commit b037e19
Show file tree
Hide file tree
Showing 88 changed files with 3,333 additions and 985 deletions.
19 changes: 19 additions & 0 deletions 433Utils/RPi_utils/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@

# Defines the RPI variable which is needed by rc-switch/RCSwitch.h
CXXFLAGS=-DRPI

all: send codesend RFSniffer

send: ../rc-switch/RCSwitch.o send.o
$(CXX) $(CXXFLAGS) $(LDFLAGS) $+ -o $@ -lwiringPi -lwiringPiDev -lcrypt

codesend: ../rc-switch/RCSwitch.o codesend.o
$(CXX) $(CXXFLAGS) $(LDFLAGS) $+ -o $@ -lwiringPi -lwiringPiDev -lcrypt

RFSniffer: ../rc-switch/RCSwitch.o RFSniffer.o
$(CXX) $(CXXFLAGS) $(LDFLAGS) $+ -o $@ -lwiringPi -lwiringPiDev -lcrypt


clean:
$(RM) ../rc-switch/*.o *.o send codesend servo RFSniffer

Binary file added 433Utils/RPi_utils/RFSniffer
Binary file not shown.
67 changes: 67 additions & 0 deletions 433Utils/RPi_utils/RFSniffer.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/*
RFSniffer
Usage: ./RFSniffer bcm_pin [tolerance] [<pulseLength>]
[] = optional
Printf: Received code | Protocol | Pulse lenght | BitLength
Hacked from http://code.google.com/p/rc-switch/
by @justy to provide a handy RF code sniffer
*/

#include "../rc-switch/RCSwitch.h"
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>

RCSwitch mySwitch;

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

if (argc == 1) {
printf("Usage: %s bcm_pin [<pulseLength>]\n", argv[0]);
return 0;
}
if(wiringPiSetupGpio() == -1) {
printf("wiringPiSetup failed, exiting...");
return 0;
}
int PIN = atoi(argv[1]);
int pulseLength = 0;
int tolerance = 60;
if (argv[2] != NULL) tolerance = atoi(argv[2]);
if (argv[3] != NULL) pulseLength = atoi(argv[3]);

mySwitch = RCSwitch();
if (tolerance != 60) mySwitch.setReceiveTolerance(tolerance);
if (pulseLength != 0) mySwitch.setPulseLength(pulseLength);
mySwitch.enableReceive(PIN);


while(1) {

if (mySwitch.available()) {
int value = mySwitch.getReceivedValue();
if (value == 0) {
printf("Unknown encoding\n");
} else {
printf("%i|%i|%i|%i\n", mySwitch.getReceivedValue(),mySwitch.getReceivedProtocol(),mySwitch.getReceivedDelay(),mySwitch.getReceivedBitlength() );
// printf("Received %i\n", mySwitch.getReceivedValue() );
// printf("Bit lenght %i\n", mySwitch.getReceivedBitlength() );
// printf("Protocol %i\n", mySwitch.getReceivedProtocol() );
// printf("Delaye %i\n", mySwitch.getReceivedDelay() );
// printf("Raw data %i\n", mySwitch.getReceivedRawdata() );
}

fflush(stdout);
mySwitch.resetAvailable();
}
usleep(10000);

}

exit(0);


}

Binary file added 433Utils/RPi_utils/RFSniffer.o
Binary file not shown.
Binary file added 433Utils/RPi_utils/codesend
Binary file not shown.
59 changes: 59 additions & 0 deletions 433Utils/RPi_utils/codesend.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
Usage: ./codesend decimalcode bcm_pin [protocol] [pulselength] [repeattransmit] [bitlength]
decimalcode - As decoded by RFSniffer
bcm_pin - BCM GPIO PIN of connected transmiter
protocol - According to rc-switch definitions
pulselength - pulselength in microseconds
repeattransmit - number of transmit repeat
'codesend' hacked from 'send' by @justy
- The provided rc_switch 'send' command uses the form systemCode, unitCode, command
which is not suitable for our purposes. Instead, we call
send(code, length); // where length is always 24 and code is simply the code
we find using the RF_sniffer.ino Arduino sketch.
*/
#include "../rc-switch/RCSwitch.h"
#include <stdlib.h>
#include <stdio.h>


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

int protocol = 1; // A value of 0 will use rc-switch's default value
int pulseLength = 0;
int repeatTransmit = 10;
int bitlength = 24;

// If no command line argument is given, print the help text
if (argc <= 2) {
printf("Usage: %s decimalcode bcm_pin [protocol] [pulselength] [repeattransmit]\n", argv[0]);
printf("decimalcode\t- As decoded by RFSniffer\n");
printf("bcm_pin\t- BCM GPIO PIN of connected transmiter\n");
printf("protocol\t- According to rc-switch definitions\n");
printf("pulselength\t- pulselength in microseconds\n");
printf("repeattransmit\t- number of transmit repeat\n");
return -1;
}

// Change protocol and pulse length accroding to parameters
int code = atoi(argv[1]);
int PIN = atoi(argv[2]);
if (argc >= 4) protocol = atoi(argv[3]);
if (argc >= 5) pulseLength = atoi(argv[4]);
if (argc >= 6) repeatTransmit = atoi(argv[5]);
if (argc >= 7) bitlength = atoi(argv[6]);

if (wiringPiSetupGpio() == -1) return 1;
RCSwitch mySwitch = RCSwitch();
printf("%i|%i|%i\n", code,protocol,pulseLength);
if (protocol != 1) mySwitch.setProtocol(protocol);
if (pulseLength != 0) mySwitch.setPulseLength(pulseLength);
if (repeatTransmit != 10) mySwitch.setRepeatTransmit(repeatTransmit);
mySwitch.enableTransmit(PIN);
mySwitch.send(code, bitlength);

return 0;

}
Binary file added 433Utils/RPi_utils/codesend.o
Binary file not shown.
Binary file added 433Utils/RPi_utils/send
Binary file not shown.
60 changes: 60 additions & 0 deletions 433Utils/RPi_utils/send.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*
Usage: ./send <systemCode> <unitCode> <command>
Command is 0 for OFF and 1 for ON
*/

#include "../rc-switch/RCSwitch.h"
#include <stdlib.h>
#include <stdio.h>

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

/*
output PIN is hardcoded for testing purposes
see https://projects.drogon.net/raspberry-pi/wiringpi/pins/
for pin mapping of the raspberry pi GPIO connector
*/
int PIN = 0;
const char* code[6] = { "00000", "10000", "01000", "00100", "00010", "00001" };

if (argc < 4) {
printf("Sending 433 MHz remote plug control codes, hardcoded on wiringpi pin %d.\n", PIN);
printf("Usage: %s <systemCode> <unitCode> <command> [pulseLength]\n", argv[0]);
printf("systemCode - First five settings of Type A 10 pole DIP switch, e.g. 11111\n");
printf("unitCode - Switch number [1 .. 5] or [10000 .. 00001]\n");
printf("command - 0 for OFF and 1 for ON\n");
printf("pulseLength - optional pulse length\n");
return -1;
}

char* systemCode = argv[1];
const char* unitCode;
if (strlen(argv[2]) == 5) {
unitCode = argv[2];
} else if (atoi(argv[2]) > 0 and atoi(argv[2]) < 6) {
unitCode = code[atoi(argv[2])];
} else {
return -1;
}
int command = atoi(argv[3]);

if (wiringPiSetup () == -1) return 1;
printf("sending systemCode[%s] unitCode[%s] command[%i]\n", systemCode, unitCode, command);
RCSwitch mySwitch = RCSwitch();
if (argv[4] != NULL)
mySwitch.setPulseLength(atoi(argv[4]));
mySwitch.enableTransmit(PIN);

switch(command) {
case 1:
mySwitch.switchOn(systemCode, unitCode);
break;
case 0:
mySwitch.switchOff(systemCode, unitCode);
break;
default:
printf("command[%i] is unsupported\n", command);
return -1;
}
return 0;
}
Binary file added 433Utils/RPi_utils/send.o
Binary file not shown.
19 changes: 19 additions & 0 deletions 433Utils/RPi_utilsdef/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@

# Defines the RPI variable which is needed by rc-switch/RCSwitch.h
CXXFLAGS=-DRPI

all: send codesend RFSniffer

send: ../rc-switch/RCSwitch.o send.o
$(CXX) $(CXXFLAGS) $(LDFLAGS) $+ -o $@ -lwiringPi -lwiringPiDev -lcrypt

codesend: ../rc-switch/RCSwitch.o codesend.o
$(CXX) $(CXXFLAGS) $(LDFLAGS) $+ -o $@ -lwiringPi -lwiringPiDev -lcrypt

RFSniffer: ../rc-switch/RCSwitch.o RFSniffer.o
$(CXX) $(CXXFLAGS) $(LDFLAGS) $+ -o $@ -lwiringPi -lwiringPiDev -lcrypt


clean:
$(RM) ../rc-switch/*.o *.o send codesend servo RFSniffer

17 changes: 17 additions & 0 deletions 433Utils/RPi_utilsdef/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# About

rcswitch-pi is for controlling rc remote controlled power sockets
with the raspberry pi. Kudos to the projects [rc-switch](http://code.google.com/p/rc-switch)
and [wiringpi](https://projects.drogon.net/raspberry-pi/wiringpi).
I just adapted the rc-switch code to use the wiringpi library instead of
the library provided by the arduino.


## Usage

First you have to install the [wiringpi](https://projects.drogon.net/raspberry-pi/wiringpi/download-and-install/) library.
After that you can compile the example program *send* by executing *make*.
It uses wiringPi pin no 2 by default. You may want to change the used GPIO pin before compilation of the codesend.cpp source file. (Good Resource for Pin Details https://pinout.xyz/pinout/wiringpi)

## Note
The 'RF\_Sniffer' code is as yet untested. It _should_ work, but it is still being tested thoroughly. It's provided to allow you to start playing with it now.
Binary file added 433Utils/RPi_utilsdef/RFSniffer
Binary file not shown.
65 changes: 65 additions & 0 deletions 433Utils/RPi_utilsdef/RFSniffer.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/*
RFSniffer
Usage: ./RFSniffer [<pulseLength>]
[] = optional
Hacked from http://code.google.com/p/rc-switch/
by @justy to provide a handy RF code sniffer
*/

#include "../rc-switch/RCSwitch.h"
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>


RCSwitch mySwitch;



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

// This pin is not the first pin on the RPi GPIO header!
// Consult https://projects.drogon.net/raspberry-pi/wiringpi/pins/
// for more information.
int PIN = 2;

if(wiringPiSetup() == -1) {
printf("wiringPiSetup failed, exiting...");
return 0;
}

int pulseLength = 0;
if (argv[1] != NULL) pulseLength = atoi(argv[1]);

mySwitch = RCSwitch();
if (pulseLength != 0) mySwitch.setPulseLength(pulseLength);
mySwitch.enableReceive(PIN); // Receiver on interrupt 0 => that is pin #2


while(1) {

if (mySwitch.available()) {

int value = mySwitch.getReceivedValue();

if (value == 0) {
printf("Unknown encoding\n");
} else {

printf("Received %i\n", mySwitch.getReceivedValue() );
}

fflush(stdout);
mySwitch.resetAvailable();
}
usleep(100);

}

exit(0);


}

Binary file added 433Utils/RPi_utilsdef/RFSniffer.o
Binary file not shown.
Binary file added 433Utils/RPi_utilsdef/codesend
Binary file not shown.
58 changes: 58 additions & 0 deletions 433Utils/RPi_utilsdef/codesend.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*
Usage: ./codesend decimalcode [protocol] [pulselength]
decimalcode - As decoded by RFSniffer
protocol - According to rc-switch definitions
pulselength - pulselength in microseconds
'codesend' hacked from 'send' by @justy
- The provided rc_switch 'send' command uses the form systemCode, unitCode, command
which is not suitable for our purposes. Instead, we call
send(code, length); // where length is always 24 and code is simply the code
we find using the RF_sniffer.ino Arduino sketch.
(Use RF_Sniffer.ino to check that RF signals are being produced by the RPi's transmitter
or your remote control)
*/
#include "../rc-switch/RCSwitch.h"
#include <stdlib.h>
#include <stdio.h>


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

// This pin is not the first pin on the RPi GPIO header!
// Consult https://projects.drogon.net/raspberry-pi/wiringpi/pins/
// for more information.
int PIN = 0;

// Parse the first parameter to this command as an integer
int protocol = 0; // A value of 0 will use rc-switch's default value
int pulseLength = 0;

// If no command line argument is given, print the help text
if (argc == 1) {
printf("Usage: %s decimalcode [protocol] [pulselength]\n", argv[0]);
printf("decimalcode\t- As decoded by RFSniffer\n");
printf("protocol\t- According to rc-switch definitions\n");
printf("pulselength\t- pulselength in microseconds\n");
return -1;
}

// Change protocol and pulse length accroding to parameters
int code = atoi(argv[1]);
if (argc >= 3) protocol = atoi(argv[2]);
if (argc >= 4) pulseLength = atoi(argv[3]);

if (wiringPiSetup () == -1) return 1;
printf("sending code[%i]\n", code);
RCSwitch mySwitch = RCSwitch();
if (protocol != 0) mySwitch.setProtocol(protocol);
if (pulseLength != 0) mySwitch.setPulseLength(pulseLength);
mySwitch.enableTransmit(PIN);

mySwitch.send(code, 24);

return 0;

}
Binary file added 433Utils/RPi_utilsdef/codesend.o
Binary file not shown.
Binary file added 433Utils/RPi_utilsdef/send
Binary file not shown.

0 comments on commit b037e19

Please sign in to comment.