first commit
This commit is contained in:
@@ -0,0 +1,131 @@
|
||||
/*
|
||||
Example for analyzing and proposing unknown new protocols
|
||||
|
||||
Requires modified rc-switch branch "protocollessreceiver"
|
||||
with ReceivedInverted() function exposed.
|
||||
|
||||
https://github.com/Martin-Laclaustra/rc-switch/tree/protocollessreceiver
|
||||
https://github.com/LSatan/SmartRC-CC1101-Driver-Lib
|
||||
|
||||
----------------------------------------------------------
|
||||
CC1101 Mod by Little Satan. Have Fun!
|
||||
----------------------------------------------------------
|
||||
*/
|
||||
|
||||
#include <ELECHOUSE_CC1101_SRC_DRV.h>
|
||||
#include <RCSwitch.h>
|
||||
|
||||
int pin; // int for Receive pin.
|
||||
|
||||
RCSwitch mySwitch = RCSwitch();
|
||||
|
||||
void setup() {
|
||||
Serial.begin(9600);
|
||||
|
||||
#ifdef ESP32
|
||||
pin = 4; // for esp32! Receiver on GPIO pin 4.
|
||||
#elif ESP8266
|
||||
pin = 4; // for esp8266! Receiver on pin 4 = D2.
|
||||
#else
|
||||
pin = 0; // for Arduino! Receiver on interrupt 0 => that is pin #2
|
||||
#endif
|
||||
|
||||
if (ELECHOUSE_cc1101.getCC1101()){ // Check the CC1101 Spi connection.
|
||||
Serial.println("Connection OK");
|
||||
}else{
|
||||
Serial.println("Connection Error");
|
||||
}
|
||||
|
||||
//CC1101 Settings: (Settings with "//" are optional!)
|
||||
ELECHOUSE_cc1101.Init(); // must be set to initialize the cc1101!
|
||||
//ELECHOUSE_cc1101.setRxBW(812.50); // Set the Receive Bandwidth in kHz. Value from 58.03 to 812.50. Default is 812.50 kHz.
|
||||
//ELECHOUSE_cc1101.setPA(10); // set TxPower. The following settings are possible depending on the frequency band. (-30 -20 -15 -10 -6 0 5 7 10 11 12) Default is max!
|
||||
ELECHOUSE_cc1101.setMHZ(433.92); // Here you can set your basic frequency. The lib calculates the frequency automatically (default = 433.92).The cc1101 can: 300-348 MHZ, 387-464MHZ and 779-928MHZ. Read More info from datasheet.
|
||||
|
||||
mySwitch.enableReceive(pin); // Receiver on
|
||||
|
||||
ELECHOUSE_cc1101.SetRx(); // set Receive on
|
||||
|
||||
}
|
||||
|
||||
void loop() {
|
||||
if (mySwitch.available()) {
|
||||
|
||||
int value = mySwitch.getReceivedValue();
|
||||
|
||||
if (value == 0) {
|
||||
Serial.print("Unknown encoding");
|
||||
} else {
|
||||
|
||||
int databuffer[64]; // get a copy of the received timings before they are overwritten
|
||||
int numberoftimings = 2 * mySwitch.getReceivedBitlength() + 2;
|
||||
if(numberoftimings > 64) numberoftimings = 64;
|
||||
for (int i = 0; i < numberoftimings; i++) {
|
||||
databuffer[i] = mySwitch.getReceivedRawdata()[i];
|
||||
}
|
||||
|
||||
Serial.print("Received ");
|
||||
Serial.print( mySwitch.getReceivedValue() );
|
||||
Serial.print(" / ");
|
||||
Serial.print( mySwitch.getReceivedBitlength() );
|
||||
Serial.print("bit ");
|
||||
Serial.print("Protocol: ");
|
||||
Serial.println( mySwitch.getReceivedProtocol() );
|
||||
|
||||
unsigned int databitsoffset = abs( (int)mySwitch.getReceivedLevelInFirstTiming() - (int)mySwitch.getReceivedInverted());
|
||||
//Serial.println( mySwitch.getReceivedLevelInFirstTiming() );
|
||||
//Serial.println( mySwitch.getReceivedInverted() );
|
||||
//Serial.println( databitsoffset );
|
||||
unsigned long dataduration = 0;
|
||||
for (unsigned int i = 1 + databitsoffset; i < numberoftimings - 1 + databitsoffset; i++) {
|
||||
dataduration += databuffer[i];
|
||||
}
|
||||
Serial.print("data bits of pulse train duration: ");
|
||||
Serial.println( dataduration );
|
||||
unsigned int averagebitduration = (int)(0.5 + ((double)dataduration)/mySwitch.getReceivedBitlength());
|
||||
unsigned int protocolratio = (unsigned int)(0.5 + ((double)(averagebitduration - mySwitch.getReceivedDelay())) / (double)mySwitch.getReceivedDelay());
|
||||
Serial.print("proposed protocol: { ");
|
||||
Serial.print(mySwitch.getReceivedDelay());
|
||||
Serial.print(", { ");
|
||||
Serial.print( (databitsoffset==0) ?
|
||||
(int) (0.5 + (double)databuffer[2*mySwitch.getReceivedBitlength()+1]/(double)mySwitch.getReceivedDelay())
|
||||
:
|
||||
(int) (0.5 + (double)databuffer[0]/(double)mySwitch.getReceivedDelay())
|
||||
);
|
||||
Serial.print(", ");
|
||||
Serial.print( (databitsoffset==0) ?
|
||||
(int) (0.5 + (double)databuffer[0]/(double)mySwitch.getReceivedDelay())
|
||||
:
|
||||
(int) (0.5 + (double)databuffer[1]/(double)mySwitch.getReceivedDelay())
|
||||
);
|
||||
Serial.print(" }, { ");
|
||||
Serial.print("1");
|
||||
Serial.print(", ");
|
||||
Serial.print(protocolratio);
|
||||
Serial.print(" }, { ");
|
||||
Serial.print(protocolratio);
|
||||
Serial.print(", ");
|
||||
Serial.print("1");
|
||||
Serial.print(" }, ");
|
||||
Serial.print((mySwitch.getReceivedInverted()) ? "true" : "false" );
|
||||
Serial.println(" }");
|
||||
|
||||
// raw signal
|
||||
Serial.println("====");
|
||||
Serial.print("first level ");
|
||||
Serial.println((mySwitch.getReceivedLevelInFirstTiming() == 0) ? "down" : "up" );
|
||||
for (int i = 0; i < 2*mySwitch.getReceivedBitlength()+2 - 1 + databitsoffset; i++) {
|
||||
Serial.print(databuffer[i]);
|
||||
Serial.print(" ");
|
||||
if((i - databitsoffset) % 16 == 0) Serial.println("");
|
||||
}
|
||||
if ((2*mySwitch.getReceivedBitlength()+2 - 1 + databitsoffset - 1) % 16 != 0) Serial.println("");
|
||||
if (databitsoffset != 1) Serial.println(databuffer[2*mySwitch.getReceivedBitlength()+1]);
|
||||
// plot signal in spreadsheet
|
||||
Serial.println("====");
|
||||
|
||||
}
|
||||
|
||||
mySwitch.resetAvailable();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
/*
|
||||
Example for receiving
|
||||
|
||||
https://github.com/sui77/rc-switch/
|
||||
https://github.com/LSatan/SmartRC-CC1101-Driver-Lib
|
||||
If you want to visualize a telegram copy the raw data and
|
||||
paste it into http://test.sui.li/oszi/
|
||||
----------------------------------------------------------
|
||||
Mod by Little Satan. Have Fun!
|
||||
----------------------------------------------------------
|
||||
*/
|
||||
#include <ELECHOUSE_CC1101_SRC_DRV.h>
|
||||
#include <RCSwitch.h>
|
||||
|
||||
int pin; // int for Receive pin.
|
||||
|
||||
RCSwitch mySwitch = RCSwitch();
|
||||
|
||||
void setup() {
|
||||
Serial.begin(9600);
|
||||
|
||||
#ifdef ESP32
|
||||
pin = 4; // for esp32! Receiver on GPIO pin 4.
|
||||
#elif ESP8266
|
||||
pin = 4; // for esp8266! Receiver on pin 4 = D2.
|
||||
#else
|
||||
pin = 0; // for Arduino! Receiver on interrupt 0 => that is pin #2
|
||||
#endif
|
||||
|
||||
if (ELECHOUSE_cc1101.getCC1101()){ // Check the CC1101 Spi connection.
|
||||
Serial.println("Connection OK");
|
||||
}else{
|
||||
Serial.println("Connection Error");
|
||||
}
|
||||
|
||||
//CC1101 Settings: (Settings with "//" are optional!)
|
||||
ELECHOUSE_cc1101.Init(); // must be set to initialize the cc1101!
|
||||
//ELECHOUSE_cc1101.setRxBW(812.50); // Set the Receive Bandwidth in kHz. Value from 58.03 to 812.50. Default is 812.50 kHz.
|
||||
//ELECHOUSE_cc1101.setPA(10); // set TxPower. The following settings are possible depending on the frequency band. (-30 -20 -15 -10 -6 0 5 7 10 11 12) Default is max!
|
||||
ELECHOUSE_cc1101.setMHZ(433.92); // Here you can set your basic frequency. The lib calculates the frequency automatically (default = 433.92).The cc1101 can: 300-348 MHZ, 387-464MHZ and 779-928MHZ. Read More info from datasheet.
|
||||
|
||||
mySwitch.enableReceive(pin); // Receiver on interrupt 0 => that is pin #2
|
||||
|
||||
ELECHOUSE_cc1101.SetRx(); // set Receive on
|
||||
}
|
||||
|
||||
void loop() {
|
||||
if (mySwitch.available()) {
|
||||
output(mySwitch.getReceivedValue(), mySwitch.getReceivedBitlength(), mySwitch.getReceivedDelay(), mySwitch.getReceivedRawdata(),mySwitch.getReceivedProtocol());
|
||||
mySwitch.resetAvailable();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
static const char* bin2tristate(const char* bin);
|
||||
static char * dec2binWzerofill(unsigned long Dec, unsigned int bitLength);
|
||||
|
||||
void output(unsigned long decimal, unsigned int length, unsigned int delay, unsigned int* raw, unsigned int protocol) {
|
||||
|
||||
const char* b = dec2binWzerofill(decimal, length);
|
||||
Serial.print("Decimal: ");
|
||||
Serial.print(decimal);
|
||||
Serial.print(" (");
|
||||
Serial.print( length );
|
||||
Serial.print("Bit) Binary: ");
|
||||
Serial.print( b );
|
||||
Serial.print(" Tri-State: ");
|
||||
Serial.print( bin2tristate( b) );
|
||||
Serial.print(" PulseLength: ");
|
||||
Serial.print(delay);
|
||||
Serial.print(" microseconds");
|
||||
Serial.print(" Protocol: ");
|
||||
Serial.println(protocol);
|
||||
|
||||
Serial.print("Raw data: ");
|
||||
for (unsigned int i=0; i<= length*2; i++) {
|
||||
Serial.print(raw[i]);
|
||||
Serial.print(",");
|
||||
}
|
||||
Serial.println();
|
||||
Serial.println();
|
||||
}
|
||||
|
||||
static const char* bin2tristate(const char* bin) {
|
||||
static char returnValue[50];
|
||||
int pos = 0;
|
||||
int pos2 = 0;
|
||||
while (bin[pos]!='\0' && bin[pos+1]!='\0') {
|
||||
if (bin[pos]=='0' && bin[pos+1]=='0') {
|
||||
returnValue[pos2] = '0';
|
||||
} else if (bin[pos]=='1' && bin[pos+1]=='1') {
|
||||
returnValue[pos2] = '1';
|
||||
} else if (bin[pos]=='0' && bin[pos+1]=='1') {
|
||||
returnValue[pos2] = 'F';
|
||||
} else {
|
||||
return "not applicable";
|
||||
}
|
||||
pos = pos+2;
|
||||
pos2++;
|
||||
}
|
||||
returnValue[pos2] = '\0';
|
||||
return returnValue;
|
||||
}
|
||||
|
||||
static char * dec2binWzerofill(unsigned long Dec, unsigned int bitLength) {
|
||||
static char bin[64];
|
||||
unsigned int i=0;
|
||||
|
||||
while (Dec > 0) {
|
||||
bin[32+i++] = ((Dec & 1) > 0) ? '1' : '0';
|
||||
Dec = Dec >> 1;
|
||||
}
|
||||
|
||||
for (unsigned int j = 0; j< bitLength; j++) {
|
||||
if (j >= bitLength - i) {
|
||||
bin[j] = bin[ 31 + i - (j - (bitLength - i)) ];
|
||||
} else {
|
||||
bin[j] = '0';
|
||||
}
|
||||
}
|
||||
bin[bitLength] = '\0';
|
||||
|
||||
return bin;
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
/*
|
||||
Simple example for receiving
|
||||
|
||||
https://github.com/sui77/rc-switch/
|
||||
https://github.com/LSatan/SmartRC-CC1101-Driver-Lib
|
||||
----------------------------------------------------------
|
||||
Mod by Little Satan. Have Fun!
|
||||
----------------------------------------------------------
|
||||
*/
|
||||
#include <ELECHOUSE_CC1101_SRC_DRV.h>
|
||||
#include <RCSwitch.h>
|
||||
|
||||
int pin; // int for Receive pin.
|
||||
|
||||
RCSwitch mySwitch = RCSwitch();
|
||||
|
||||
void setup() {
|
||||
Serial.begin(9600);
|
||||
|
||||
#ifdef ESP32
|
||||
pin = 4; // for esp32! Receiver on GPIO pin 4.
|
||||
#elif ESP8266
|
||||
pin = 4; // for esp8266! Receiver on pin 4 = D2.
|
||||
#else
|
||||
pin = 0; // for Arduino! Receiver on interrupt 0 => that is pin #2
|
||||
#endif
|
||||
|
||||
if (ELECHOUSE_cc1101.getCC1101()){ // Check the CC1101 Spi connection.
|
||||
Serial.println("Connection OK");
|
||||
}else{
|
||||
Serial.println("Connection Error");
|
||||
}
|
||||
|
||||
//CC1101 Settings: (Settings with "//" are optional!)
|
||||
ELECHOUSE_cc1101.Init(); // must be set to initialize the cc1101!
|
||||
//ELECHOUSE_cc1101.setRxBW(812.50); // Set the Receive Bandwidth in kHz. Value from 58.03 to 812.50. Default is 812.50 kHz.
|
||||
//ELECHOUSE_cc1101.setPA(10); // set TxPower. The following settings are possible depending on the frequency band. (-30 -20 -15 -10 -6 0 5 7 10 11 12) Default is max!
|
||||
ELECHOUSE_cc1101.setMHZ(433.92); // Here you can set your basic frequency. The lib calculates the frequency automatically (default = 433.92).The cc1101 can: 300-348 MHZ, 387-464MHZ and 779-928MHZ. Read More info from datasheet.
|
||||
|
||||
|
||||
mySwitch.enableReceive(pin); // Receiver on
|
||||
|
||||
ELECHOUSE_cc1101.SetRx(); // set Receive on
|
||||
|
||||
}
|
||||
void loop() {
|
||||
|
||||
if (mySwitch.available()){
|
||||
|
||||
Serial.print("Received ");
|
||||
Serial.print( mySwitch.getReceivedValue() );
|
||||
Serial.print(" / ");
|
||||
Serial.print( mySwitch.getReceivedBitlength() );
|
||||
Serial.print("bit ");
|
||||
Serial.print("Protocol: ");
|
||||
Serial.println( mySwitch.getReceivedProtocol() );
|
||||
|
||||
mySwitch.resetAvailable();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
/*
|
||||
Simple example for receiving with Rssi output.
|
||||
|
||||
https://github.com/sui77/rc-switch/
|
||||
https://github.com/LSatan/SmartRC-CC1101-Driver-Lib
|
||||
----------------------------------------------------------
|
||||
Mod by Little Satan. Have Fun!
|
||||
----------------------------------------------------------
|
||||
*/
|
||||
#include <ELECHOUSE_CC1101_SRC_DRV.h>
|
||||
#include <RCSwitch.h>
|
||||
|
||||
int pin; // int for Receive pin.
|
||||
|
||||
RCSwitch mySwitch = RCSwitch();
|
||||
|
||||
void setup() {
|
||||
Serial.begin(9600);
|
||||
|
||||
#ifdef ESP32
|
||||
pin = 4; // for esp32! Receiver on GPIO pin 4.
|
||||
#elif ESP8266
|
||||
pin = 4; // for esp8266! Receiver on pin 4 = D2.
|
||||
#else
|
||||
pin = 0; // for Arduino! Receiver on interrupt 0 => that is pin #2
|
||||
#endif
|
||||
|
||||
if (ELECHOUSE_cc1101.getCC1101()){ // Check the CC1101 Spi connection.
|
||||
Serial.println("Connection OK");
|
||||
}else{
|
||||
Serial.println("Connection Error");
|
||||
}
|
||||
|
||||
//CC1101 Settings: (Settings with "//" are optional!)
|
||||
ELECHOUSE_cc1101.Init(); // must be set to initialize the cc1101!
|
||||
//ELECHOUSE_cc1101.setRxBW(812.50); // Set the Receive Bandwidth in kHz. Value from 58.03 to 812.50. Default is 812.50 kHz.
|
||||
//ELECHOUSE_cc1101.setPA(10); // set TxPower. The following settings are possible depending on the frequency band. (-30 -20 -15 -10 -6 0 5 7 10 11 12) Default is max!
|
||||
ELECHOUSE_cc1101.setMHZ(433.92); // Here you can set your basic frequency. The lib calculates the frequency automatically (default = 433.92).The cc1101 can: 300-348 MHZ, 387-464MHZ and 779-928MHZ. Read More info from datasheet.
|
||||
|
||||
mySwitch.enableReceive(pin); // Receiver on
|
||||
|
||||
ELECHOUSE_cc1101.SetRx(); // set Receive on
|
||||
|
||||
}
|
||||
void loop() {
|
||||
|
||||
if (mySwitch.available()){
|
||||
|
||||
Serial.print("Received ");
|
||||
Serial.print( mySwitch.getReceivedValue() );
|
||||
Serial.print(" / ");
|
||||
Serial.print( mySwitch.getReceivedBitlength() );
|
||||
Serial.print("bit ");
|
||||
Serial.print("Protocol: ");
|
||||
Serial.println( mySwitch.getReceivedProtocol() );
|
||||
|
||||
Serial.print("RSSI: ");
|
||||
Serial.println(ELECHOUSE_cc1101.getRssi());
|
||||
|
||||
mySwitch.resetAvailable();
|
||||
}
|
||||
}
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 119 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 125 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 127 KiB |
@@ -0,0 +1,118 @@
|
||||
/*
|
||||
Simple example for Receiving and Transmit decimal code for cc1101
|
||||
|
||||
https://github.com/sui77/rc-switch/
|
||||
https://github.com/LSatan/SmartRC-CC1101-Driver-Lib
|
||||
----------------------------------------------------------
|
||||
Mod by Little Satan. Have Fun!
|
||||
----------------------------------------------------------
|
||||
*/
|
||||
#include <ELECHOUSE_CC1101_SRC_DRV.h>
|
||||
#include <RCSwitch.h>
|
||||
|
||||
int pinRx; // int for Receive pin.
|
||||
int pinTx; // int for Transmit pin.
|
||||
|
||||
RCSwitch mySwitch = RCSwitch();
|
||||
|
||||
int buttonPin; // for button pin.
|
||||
int buttonState = 0; // button state
|
||||
int ccSetRx = 0; // reset state for Receive
|
||||
int long value = 5393; // int to save value
|
||||
int bits = 24; // int to save bit number
|
||||
int prot = 1; // int to save Protocol number
|
||||
int puls = 320; // int to save pulse length
|
||||
|
||||
void setup() {
|
||||
Serial.begin(9600);
|
||||
|
||||
#ifdef ESP32
|
||||
pinRx = 4; pinTx = 2; // for esp32! Receiver on GPIO pin 4. Transmit on GPIO pin 2.
|
||||
buttonPin = 34; // set button on GPIO pin 34.
|
||||
#elif ESP8266
|
||||
pinRx = 4; pinTx = 5; // for esp8266! Receiver on pin 4 = D2. Transmit on pin 5 = D1.
|
||||
buttonPin = 16; // set button on pin 16 = D0.
|
||||
#else
|
||||
pinRx = 0; pinTx = 6; // for Arduino! Receiver on interrupt 0 => that is pin #2. Transmit on pin 6.
|
||||
buttonPin = 4; // set button on pin D4.
|
||||
#endif
|
||||
|
||||
if (ELECHOUSE_cc1101.getCC1101()){ // Check the CC1101 Spi connection.
|
||||
Serial.println("Connection OK");
|
||||
}else{
|
||||
Serial.println("Connection Error");
|
||||
}
|
||||
|
||||
//CC1101 Settings: (Settings with "//" are optional!)
|
||||
ELECHOUSE_cc1101.Init(); // must be set to initialize the cc1101!
|
||||
//ELECHOUSE_cc1101.setRxBW(812.50); // Set the Receive Bandwidth in kHz. Value from 58.03 to 812.50. Default is 812.50 kHz.
|
||||
//ELECHOUSE_cc1101.setPA(10); // set TxPower. The following settings are possible depending on the frequency band. (-30 -20 -15 -10 -6 0 5 7 10 11 12) Default is max!
|
||||
ELECHOUSE_cc1101.setMHZ(433.92); // Here you can set your basic frequency. The lib calculates the frequency automatically (default = 433.92).The cc1101 can: 300-348 MHZ, 387-464MHZ and 779-928MHZ. Read More info from datasheet.
|
||||
|
||||
pinMode(buttonPin, INPUT); // set pin4 as input
|
||||
|
||||
}
|
||||
void loop() {
|
||||
|
||||
buttonState = digitalRead(buttonPin); // read digital pin and save the state to int
|
||||
|
||||
|
||||
if (buttonState == HIGH) { // the button is pressed. Set transmit on.
|
||||
|
||||
ccSetRx = 0; // set resetstate to 0 for next reinit to Recive
|
||||
ELECHOUSE_cc1101.SetTx(); // set Transmit on
|
||||
mySwitch.disableReceive(); // Receiver off
|
||||
mySwitch.enableTransmit(pinTx); // Transmit on
|
||||
|
||||
mySwitch.setRepeatTransmit(3); // transmission repetitions.
|
||||
mySwitch.setProtocol(prot); // send Received Protocol
|
||||
mySwitch.setPulseLength(puls);// send Received Delay
|
||||
mySwitch.send(value, bits); // send Received value/bits
|
||||
|
||||
Serial.print("Transmit ");
|
||||
Serial.print( value );
|
||||
Serial.print(" / ");
|
||||
Serial.print( bits );
|
||||
Serial.print("bit ");
|
||||
Serial.print("Protocol: ");
|
||||
Serial.print( prot );
|
||||
Serial.print(" Delay: ");
|
||||
Serial.println( puls );
|
||||
}
|
||||
|
||||
|
||||
if (buttonState == LOW && ccSetRx == 0){ //the button is not pressed. set cc1101 to Receive.
|
||||
|
||||
ELECHOUSE_cc1101.SetRx(); // set Receive on
|
||||
mySwitch.disableTransmit(); // set Transmit off
|
||||
mySwitch.enableReceive(pinRx); // Receiver on
|
||||
ccSetRx = 1;
|
||||
}
|
||||
|
||||
if (buttonState == LOW && ccSetRx == 1) { //the button is not pressed and set receive is finish. Receive values.
|
||||
|
||||
|
||||
|
||||
if (mySwitch.available()){
|
||||
|
||||
Serial.print("Received ");
|
||||
Serial.print( mySwitch.getReceivedValue() );
|
||||
Serial.print(" / ");
|
||||
Serial.print( mySwitch.getReceivedBitlength() );
|
||||
Serial.print("bit ");
|
||||
Serial.print("Protocol: ");
|
||||
Serial.print( mySwitch.getReceivedProtocol() );
|
||||
Serial.print(" Delay: ");
|
||||
Serial.println( mySwitch.getReceivedDelay() );
|
||||
|
||||
value = mySwitch.getReceivedValue(); // save received Value
|
||||
bits = mySwitch.getReceivedBitlength(); // save received Bitlength
|
||||
prot = mySwitch.getReceivedProtocol(); // save received Protocol
|
||||
puls = mySwitch.getReceivedDelay(); // save received pulse length
|
||||
|
||||
mySwitch.resetAvailable();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
/*
|
||||
Simple example for repeating decimal code for cc1101
|
||||
|
||||
https://github.com/sui77/rc-switch/
|
||||
https://github.com/LSatan/SmartRC-CC1101-Driver-Lib
|
||||
----------------------------------------------------------
|
||||
Mod by Little Satan. Have Fun!
|
||||
----------------------------------------------------------
|
||||
*/
|
||||
#include <ELECHOUSE_CC1101_SRC_DRV.h>
|
||||
#include <RCSwitch.h>
|
||||
|
||||
int pinRx; // int for Receive pin.
|
||||
int pinTx; // int for Transmit pin.
|
||||
|
||||
RCSwitch mySwitch = RCSwitch();
|
||||
|
||||
int number = 15; // set number of transmission repetitions.
|
||||
int TIME = 3000; // set delay befor repeat. For direct repetition after receive set 0.
|
||||
|
||||
void setup() {
|
||||
Serial.begin(9600);
|
||||
|
||||
#ifdef ESP32
|
||||
pinRx = 4; pinTx = 2; // for esp32! Receiver on GPIO pin 4. Transmit on GPIO pin 2.
|
||||
#elif ESP8266
|
||||
pinRx = 4; pinTx = 5; // for esp8266! Receiver on pin 4 = D2. Transmit on pin 5 = D1.
|
||||
#else
|
||||
pinRx = 0; pinTx = 6; // for Arduino! Receiver on interrupt 0 => that is pin #2. Transmit on pin 6.
|
||||
#endif
|
||||
|
||||
if (ELECHOUSE_cc1101.getCC1101()){ // Check the CC1101 Spi connection.
|
||||
Serial.println("Connection OK");
|
||||
}else{
|
||||
Serial.println("Connection Error");
|
||||
}
|
||||
|
||||
//CC1101 Settings: (Settings with "//" are optional!)
|
||||
ELECHOUSE_cc1101.Init(); // must be set to initialize the cc1101!
|
||||
//ELECHOUSE_cc1101.setRxBW(812.50); // Set the Receive Bandwidth in kHz. Value from 58.03 to 812.50. Default is 812.50 kHz.
|
||||
//ELECHOUSE_cc1101.setPA(10); // set TxPower. The following settings are possible depending on the frequency band. (-30 -20 -15 -10 -6 0 5 7 10 11 12) Default is max!
|
||||
ELECHOUSE_cc1101.setMHZ(433.92); // Here you can set your basic frequency. The lib calculates the frequency automatically (default = 433.92).The cc1101 can: 300-348 MHZ, 387-464MHZ and 779-928MHZ. Read More info from datasheet.
|
||||
|
||||
ELECHOUSE_cc1101.SetRx(); // set Receive on
|
||||
mySwitch.enableReceive(pinRx); // Receiver on
|
||||
|
||||
}
|
||||
void loop() {
|
||||
|
||||
if (mySwitch.available()){
|
||||
|
||||
Serial.print("Received ");
|
||||
Serial.print( mySwitch.getReceivedValue() );
|
||||
Serial.print(" / ");
|
||||
Serial.print( mySwitch.getReceivedBitlength() );
|
||||
Serial.print("bit ");
|
||||
Serial.print("Protocol: ");
|
||||
Serial.print( mySwitch.getReceivedProtocol() );
|
||||
Serial.print(" Delay: ");
|
||||
Serial.println( mySwitch.getReceivedDelay() );
|
||||
|
||||
delay(TIME);
|
||||
mySwitch.disableReceive(); // Receiver off
|
||||
mySwitch.enableTransmit(pinTx); // Transmit on
|
||||
ELECHOUSE_cc1101.SetTx(); // set Transmit on
|
||||
|
||||
Serial.println("Transmit");
|
||||
|
||||
mySwitch.setRepeatTransmit(number); // transmission repetitions.
|
||||
mySwitch.setProtocol(mySwitch.getReceivedProtocol()); // send Received Protocol
|
||||
mySwitch.setPulseLength(mySwitch.getReceivedDelay()); // send Received Delay
|
||||
mySwitch.send(mySwitch.getReceivedValue(), mySwitch.getReceivedBitlength()); // send Received value/bits
|
||||
|
||||
ELECHOUSE_cc1101.SetRx(); // set Receive on
|
||||
mySwitch.disableTransmit(); // set Transmit off
|
||||
mySwitch.enableReceive(pinRx); // Receiver on
|
||||
|
||||
Serial.println("Receive");
|
||||
|
||||
mySwitch.resetAvailable();
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,84 @@
|
||||
/*
|
||||
Example for different sending methods
|
||||
|
||||
https://github.com/sui77/rc-switch/
|
||||
https://github.com/LSatan/SmartRC-CC1101-Driver-Lib
|
||||
----------------------------------------------------------
|
||||
Mod by Little Satan. Have Fun!
|
||||
----------------------------------------------------------
|
||||
*/
|
||||
#include <ELECHOUSE_CC1101_SRC_DRV.h>
|
||||
#include <RCSwitch.h>
|
||||
|
||||
int pin; // int for Transmit pin.
|
||||
|
||||
RCSwitch mySwitch = RCSwitch();
|
||||
|
||||
void setup() {
|
||||
Serial.begin(9600);
|
||||
|
||||
#ifdef ESP32
|
||||
pin = 2; // for esp32! Transmit on GPIO pin 2.
|
||||
#elif ESP8266
|
||||
pin = 5; // for esp8266! Transmit on pin 5 = D1
|
||||
#else
|
||||
pin = 6; // for Arduino! Transmit on pin 6.
|
||||
#endif
|
||||
|
||||
if (ELECHOUSE_cc1101.getCC1101()){ // Check the CC1101 Spi connection.
|
||||
Serial.println("Connection OK");
|
||||
}else{
|
||||
Serial.println("Connection Error");
|
||||
}
|
||||
|
||||
//CC1101 Settings: (Settings with "//" are optional!)
|
||||
ELECHOUSE_cc1101.Init(); // must be set to initialize the cc1101!
|
||||
//ELECHOUSE_cc1101.setRxBW(812.50); // Set the Receive Bandwidth in kHz. Value from 58.03 to 812.50. Default is 812.50 kHz.
|
||||
//ELECHOUSE_cc1101.setPA(10); // set TxPower. The following settings are possible depending on the frequency band. (-30 -20 -15 -10 -6 0 5 7 10 11 12) Default is max!
|
||||
ELECHOUSE_cc1101.setMHZ(433.92); // Here you can set your basic frequency. The lib calculates the frequency automatically (default = 433.92).The cc1101 can: 300-348 MHZ, 387-464MHZ and 779-928MHZ. Read More info from datasheet.
|
||||
|
||||
// Transmitter on
|
||||
mySwitch.enableTransmit(pin);
|
||||
|
||||
// cc1101 set Transmit on
|
||||
ELECHOUSE_cc1101.SetTx();
|
||||
|
||||
// Optional set protocol (default is 1, will work for most outlets)
|
||||
// mySwitch.setProtocol(2);
|
||||
|
||||
// Optional set pulse length.
|
||||
// mySwitch.setPulseLength(320);
|
||||
|
||||
// Optional set number of transmission repetitions.
|
||||
// mySwitch.setRepeatTransmit(15);
|
||||
|
||||
}
|
||||
|
||||
void loop() {
|
||||
|
||||
/* See Example: TypeA_WithDIPSwitches */
|
||||
mySwitch.switchOn("11111", "00010");
|
||||
delay(1000);
|
||||
mySwitch.switchOff("11111", "00010");
|
||||
delay(1000);
|
||||
|
||||
/* Same switch as above, but using decimal code */
|
||||
mySwitch.send(5393, 24);
|
||||
delay(1000);
|
||||
mySwitch.send(5396, 24);
|
||||
delay(1000);
|
||||
|
||||
/* Same switch as above, but using binary code */
|
||||
mySwitch.send("000000000001010100010001");
|
||||
delay(1000);
|
||||
mySwitch.send("000000000001010100010100");
|
||||
delay(1000);
|
||||
|
||||
/* Same switch as above, but tri-state code */
|
||||
mySwitch.sendTriState("00000FFF0F0F");
|
||||
delay(1000);
|
||||
mySwitch.sendTriState("00000FFF0FF0");
|
||||
delay(1000);
|
||||
|
||||
delay(20000);
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
/*
|
||||
Example for outlets which are configured with a 10 pole DIP switch.
|
||||
|
||||
https://github.com/sui77/rc-switch/
|
||||
https://github.com/LSatan/SmartRC-CC1101-Driver-Lib
|
||||
----------------------------------------------------------
|
||||
Mod by Little Satan. Have Fun!
|
||||
----------------------------------------------------------
|
||||
*/
|
||||
#include <ELECHOUSE_CC1101_SRC_DRV.h>
|
||||
#include <RCSwitch.h>
|
||||
|
||||
int pin; // int for Transmit pin.
|
||||
|
||||
RCSwitch mySwitch = RCSwitch();
|
||||
|
||||
void setup() {
|
||||
Serial.begin(9600);
|
||||
|
||||
#ifdef ESP32
|
||||
pin = 2; // for esp32! Transmit on GPIO pin 2.
|
||||
#elif ESP8266
|
||||
pin = 5; // for esp8266! Transmit on pin 5 = D1
|
||||
#else
|
||||
pin = 6; // for Arduino! Transmit on pin 6.
|
||||
#endif
|
||||
|
||||
if (ELECHOUSE_cc1101.getCC1101()){ // Check the CC1101 Spi connection.
|
||||
Serial.println("Connection OK");
|
||||
}else{
|
||||
Serial.println("Connection Error");
|
||||
}
|
||||
|
||||
//CC1101 Settings: (Settings with "//" are optional!)
|
||||
ELECHOUSE_cc1101.Init(); // must be set to initialize the cc1101!
|
||||
//ELECHOUSE_cc1101.setRxBW(812.50); // Set the Receive Bandwidth in kHz. Value from 58.03 to 812.50. Default is 812.50 kHz.
|
||||
//ELECHOUSE_cc1101.setPA(10); // set TxPower. The following settings are possible depending on the frequency band. (-30 -20 -15 -10 -6 0 5 7 10 11 12) Default is max!
|
||||
ELECHOUSE_cc1101.setMHZ(433.92); // Here you can set your basic frequency. The lib calculates the frequency automatically (default = 433.92).The cc1101 can: 300-348 MHZ, 387-464MHZ and 779-928MHZ. Read More info from datasheet.
|
||||
|
||||
// Transmitter on
|
||||
mySwitch.enableTransmit(pin);
|
||||
|
||||
// cc1101 set Transmit on
|
||||
ELECHOUSE_cc1101.SetTx();
|
||||
|
||||
|
||||
// Optional set pulse length.
|
||||
// mySwitch.setPulseLength(320);
|
||||
|
||||
}
|
||||
|
||||
void loop() {
|
||||
|
||||
// Switch on:
|
||||
// The first parameter represents the setting of the first 5 DIP switches.
|
||||
// In this example it's ON-ON-OFF-OFF-ON.
|
||||
//
|
||||
// The second parameter represents the setting of the last 5 DIP switches.
|
||||
// In this example the last 5 DIP switches are OFF-ON-OFF-ON-OFF.
|
||||
mySwitch.switchOn("11001", "01010");
|
||||
|
||||
// Wait a second
|
||||
delay(1000);
|
||||
|
||||
// Switch off
|
||||
mySwitch.switchOff("11001", "01010");
|
||||
|
||||
// Wait another second
|
||||
delay(1000);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
/*
|
||||
Example for outlets which are configured with two rotary/sliding switches.
|
||||
|
||||
https://github.com/sui77/rc-switch/
|
||||
https://github.com/LSatan/SmartRC-CC1101-Driver-Lib
|
||||
----------------------------------------------------------
|
||||
Mod by Little Satan. Have Fun!
|
||||
----------------------------------------------------------
|
||||
*/
|
||||
#include <ELECHOUSE_CC1101_SRC_DRV.h>
|
||||
#include <RCSwitch.h>
|
||||
|
||||
int pin; // int for Transmit pin.
|
||||
|
||||
RCSwitch mySwitch = RCSwitch();
|
||||
|
||||
void setup() {
|
||||
Serial.begin(9600);
|
||||
|
||||
#ifdef ESP32
|
||||
pin = 2; // for esp32! Transmit on GPIO pin 2.
|
||||
#elif ESP8266
|
||||
pin = 5; // for esp8266! Transmit on pin 5 = D1
|
||||
#else
|
||||
pin = 6; // for Arduino! Transmit on pin 6.
|
||||
#endif
|
||||
|
||||
if (ELECHOUSE_cc1101.getCC1101()){ // Check the CC1101 Spi connection.
|
||||
Serial.println("Connection OK");
|
||||
}else{
|
||||
Serial.println("Connection Error");
|
||||
}
|
||||
|
||||
//CC1101 Settings: (Settings with "//" are optional!)
|
||||
ELECHOUSE_cc1101.Init(); // must be set to initialize the cc1101!
|
||||
//ELECHOUSE_cc1101.setRxBW(812.50); // Set the Receive Bandwidth in kHz. Value from 58.03 to 812.50. Default is 812.50 kHz.
|
||||
//ELECHOUSE_cc1101.setPA(10); // set TxPower. The following settings are possible depending on the frequency band. (-30 -20 -15 -10 -6 0 5 7 10 11 12) Default is max!
|
||||
ELECHOUSE_cc1101.setMHZ(433.92); // Here you can set your basic frequency. The lib calculates the frequency automatically (default = 433.92).The cc1101 can: 300-348 MHZ, 387-464MHZ and 779-928MHZ. Read More info from datasheet.
|
||||
|
||||
// Transmitter on
|
||||
mySwitch.enableTransmit(pin);
|
||||
|
||||
// cc1101 set Transmit on
|
||||
ELECHOUSE_cc1101.SetTx();
|
||||
|
||||
// Optional set pulse length.
|
||||
// mySwitch.setPulseLength(320);
|
||||
|
||||
}
|
||||
|
||||
void loop() {
|
||||
|
||||
// Switch on:
|
||||
// The first parameter represents the setting of the first rotary switch.
|
||||
// In this example it's switched to "1" or "A" or "I".
|
||||
//
|
||||
// The second parameter represents the setting of the second rotary switch.
|
||||
// In this example it's switched to "4" or "D" or "IV".
|
||||
mySwitch.switchOn(1, 4);
|
||||
|
||||
// Wait a second
|
||||
delay(1000);
|
||||
|
||||
// Switch off
|
||||
mySwitch.switchOff(1, 4);
|
||||
|
||||
// Wait another second
|
||||
delay(1000);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
/*
|
||||
Example for Intertechno outlets
|
||||
|
||||
https://github.com/sui77/rc-switch/
|
||||
https://github.com/LSatan/SmartRC-CC1101-Driver-Lib
|
||||
----------------------------------------------------------
|
||||
Mod by Little Satan. Have Fun!
|
||||
----------------------------------------------------------
|
||||
*/
|
||||
#include <ELECHOUSE_CC1101_SRC_DRV.h>
|
||||
#include <RCSwitch.h>
|
||||
|
||||
int pin; // int for Transmit pin.
|
||||
|
||||
RCSwitch mySwitch = RCSwitch();
|
||||
|
||||
void setup() {
|
||||
Serial.begin(9600);
|
||||
|
||||
#ifdef ESP32
|
||||
pin = 2; // for esp32! Transmit on GPIO pin 2.
|
||||
#elif ESP8266
|
||||
pin = 5; // for esp8266! Transmit on pin 5 = D1
|
||||
#else
|
||||
pin = 6; // for Arduino! Transmit on pin 6.
|
||||
#endif
|
||||
|
||||
if (ELECHOUSE_cc1101.getCC1101()){ // Check the CC1101 Spi connection.
|
||||
Serial.println("Connection OK");
|
||||
}else{
|
||||
Serial.println("Connection Error");
|
||||
}
|
||||
|
||||
//CC1101 Settings: (Settings with "//" are optional!)
|
||||
ELECHOUSE_cc1101.Init(); // must be set to initialize the cc1101!
|
||||
//ELECHOUSE_cc1101.setRxBW(812.50); // Set the Receive Bandwidth in kHz. Value from 58.03 to 812.50. Default is 812.50 kHz.
|
||||
//ELECHOUSE_cc1101.setPA(10); // set TxPower. The following settings are possible depending on the frequency band. (-30 -20 -15 -10 -6 0 5 7 10 11 12) Default is max!
|
||||
ELECHOUSE_cc1101.setMHZ(433.92); // Here you can set your basic frequency. The lib calculates the frequency automatically (default = 433.92).The cc1101 can: 300-348 MHZ, 387-464MHZ and 779-928MHZ. Read More info from datasheet.
|
||||
|
||||
// Transmitter on
|
||||
mySwitch.enableTransmit(pin);
|
||||
|
||||
// cc1101 set Transmit on
|
||||
ELECHOUSE_cc1101.SetTx();
|
||||
|
||||
// Optional set pulse length.
|
||||
// mySwitch.setPulseLength(320);
|
||||
|
||||
}
|
||||
|
||||
void loop() {
|
||||
|
||||
// Switch on:
|
||||
// The first parameter represents the familycode (a, b, c, ... f)
|
||||
// The second parameter represents the group number
|
||||
// The third parameter represents the device number
|
||||
//
|
||||
// In this example it's family 'b', group #3, device #2
|
||||
mySwitch.switchOn('b', 3, 2);
|
||||
|
||||
// Wait a second
|
||||
delay(1000);
|
||||
|
||||
// Switch off
|
||||
mySwitch.switchOff('b', 3, 2);
|
||||
|
||||
// Wait another second
|
||||
delay(1000);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
/*
|
||||
Example for REV outlets (e.g. 8342L)
|
||||
|
||||
https://github.com/sui77/rc-switch/
|
||||
https://github.com/LSatan/SmartRC-CC1101-Driver-Lib
|
||||
|
||||
Need help? http://forum.ardumote.com
|
||||
----------------------------------------------------------
|
||||
Mod by Little Satan. Have Fun!
|
||||
----------------------------------------------------------
|
||||
*/
|
||||
#include <ELECHOUSE_CC1101_SRC_DRV.h>
|
||||
#include <RCSwitch.h>
|
||||
|
||||
int pin; // int for Transmit pin.
|
||||
|
||||
RCSwitch mySwitch = RCSwitch();
|
||||
|
||||
void setup() {
|
||||
Serial.begin(9600);
|
||||
|
||||
#ifdef ESP32
|
||||
pin = 2; // for esp32! Transmit on GPIO pin 2.
|
||||
#elif ESP8266
|
||||
pin = 5; // for esp8266! Transmit on pin 5 = D1
|
||||
#else
|
||||
pin = 6; // for Arduino! Transmit on pin 6.
|
||||
#endif
|
||||
|
||||
if (ELECHOUSE_cc1101.getCC1101()){ // Check the CC1101 Spi connection.
|
||||
Serial.println("Connection OK");
|
||||
}else{
|
||||
Serial.println("Connection Error");
|
||||
}
|
||||
|
||||
//CC1101 Settings: (Settings with "//" are optional!)
|
||||
ELECHOUSE_cc1101.Init(); // must be set to initialize the cc1101!
|
||||
//ELECHOUSE_cc1101.setRxBW(812.50); // Set the Receive Bandwidth in kHz. Value from 58.03 to 812.50. Default is 812.50 kHz.
|
||||
//ELECHOUSE_cc1101.setPA(10); // set TxPower. The following settings are possible depending on the frequency band. (-30 -20 -15 -10 -6 0 5 7 10 11 12) Default is max!
|
||||
ELECHOUSE_cc1101.setMHZ(433.92); // Here you can set your basic frequency. The lib calculates the frequency automatically (default = 433.92).The cc1101 can: 300-348 MHZ, 387-464MHZ and 779-928MHZ. Read More info from datasheet.
|
||||
|
||||
// Transmitter on
|
||||
mySwitch.enableTransmit(pin);
|
||||
|
||||
// cc1101 set Transmit on
|
||||
ELECHOUSE_cc1101.SetTx();
|
||||
|
||||
// set pulse length.
|
||||
mySwitch.setPulseLength(360);
|
||||
|
||||
}
|
||||
|
||||
void loop() {
|
||||
|
||||
// Switch on:
|
||||
// The first parameter represents the channel (a, b, c, d)
|
||||
// The second parameter represents the device number
|
||||
//
|
||||
// In this example it's family 'd', device #2
|
||||
mySwitch.switchOn('d', 2);
|
||||
|
||||
// Wait a second
|
||||
delay(1000);
|
||||
|
||||
// Switch off
|
||||
mySwitch.switchOff('d', 2);
|
||||
|
||||
// Wait another second
|
||||
delay(1000);
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user