CC1101 433.92MHz support for pilight, rf and rf2 (#585)

* adds CC1101 (433mhz) support esp32 and esp8266
This commit is contained in:
orrpan authored and GitHub committed 2020-04-23 14:23:47 -05:00
1 parent 1385ddfa8d
commit ac743ed350
7 files changed
+137 -3

No files matched your search

+1
View File
@@ -153,6 +153,7 @@ char gateway_name[parameters_size * 2] = Gateway_Name;
//#define ZsensorGPIOInput "GPIOInput" //ESP8266, Arduino, ESP32
//#define ZmqttDiscovery "HADiscovery"//ESP8266, Arduino, ESP32, Sonoff RF Bridge
//#define ZactuatorFASTLED "FASTLED" //ESP8266, Arduino, ESP32, Sonoff RF Bridge
//#define ZradioCC1101 "CC1101" //ESP8266, ESP32
/*-------------DEFINE YOUR MQTT ADVANCED PARAMETERS BELOW----------------*/
#define version_Topic "/version"
+19 -1
View File
@@ -28,6 +28,11 @@
#include "User_config.h"
#ifdef ZgatewayPilight
#ifdef ZradioCC1101
#include <ELECHOUSE_CC1101_SRC_DRV.h>
#endif
#include <ESPiLight.h>
ESPiLight rf(RF_EMITTER_PIN); // use -1 to disable transmitter
@@ -58,6 +63,12 @@ void pilightCallback(const String &protocol, const String &message, int status,
void setupPilight()
{
#ifndef ZgatewayRF &&ZgatewayRF2 //receiving with Pilight is not compatible with ZgatewayRF or RF2 or RF315 as far as I can tell
#ifdef ZradioCC1101 //receiving with CC1101
ELECHOUSE_cc1101.Init();
ELECHOUSE_cc1101.setMHZ(CC1101_FREQUENCY);
ELECHOUSE_cc1101.SetRx(CC1101_FREQUENCY);
rf.enableReceiver();
#endif
rf.setCallback(pilightCallback);
rf.initReceiver(RF_RECEIVER_PIN);
pinMode(RF_EMITTER_PIN, OUTPUT); // Set this here, because if this is the RX pin it was reset to INPUT by Serial.end();
@@ -76,7 +87,10 @@ void PilighttoMQTT()
void MQTTtoPilight(char *topicOri, JsonObject &Pilightdata)
{
#ifdef ZradioCC1101
ELECHOUSE_cc1101.SetTx(CC1101_FREQUENCY); // set Transmit on
rf.disableReceiver();
#endif
int result = 0;
if (cmpToMainTopic(topicOri, subjectMQTTtoPilight))
@@ -155,5 +169,9 @@ void MQTTtoPilight(char *topicOri, JsonObject &Pilightdata)
}
}
}
#ifdef ZradioCC1101
ELECHOUSE_cc1101.SetRx(CC1101_FREQUENCY); // set Receive on
rf.enableReceiver();
#endif
}
#endif
+29
View File
@@ -29,6 +29,10 @@
#ifdef ZgatewayRF
#ifdef ZradioCC1101
#include <ELECHOUSE_CC1101_SRC_DRV.h>
#endif
#include <RCSwitch.h> // library for controling Radio frequency switch
RCSwitch mySwitch = RCSwitch();
@@ -57,6 +61,11 @@ void setupRF()
//RF init parameters
Log.notice(F("RF_EMITTER_PIN: %d " CR), RF_EMITTER_PIN);
Log.notice(F("RF_RECEIVER_PIN: %d " CR), RF_RECEIVER_PIN);
#ifdef ZradioCC1101 //receiving with CC1101
ELECHOUSE_cc1101.Init();
ELECHOUSE_cc1101.setMHZ(CC1101_FREQUENCY);
ELECHOUSE_cc1101.SetRx(CC1101_FREQUENCY);
#endif
mySwitch.enableTransmit(RF_EMITTER_PIN);
mySwitch.setRepeatTransmit(RF_EMITTER_REPEAT);
mySwitch.enableReceive(RF_RECEIVER_PIN);
@@ -103,6 +112,11 @@ void RFtoMQTT()
void MQTTtoRF(char *topicOri, char *datacallback)
{
#ifdef ZradioCC1101 // set Receive off and Transmitt on
ELECHOUSE_cc1101.SetTx(CC1101_FREQUENCY);
mySwitch.disableReceive();
mySwitch.enableTransmit(RF_EMITTER_PIN);
#endif
unsigned long data = strtoul(datacallback, NULL, 10); // we will not be able to pass values > 4294967295
// RF DATA ANALYSIS
@@ -156,12 +170,22 @@ void MQTTtoRF(char *topicOri, char *datacallback)
// Acknowledgement to the GTWRF topic
pub(subjectGTWRFtoMQTT, datacallback); // we acknowledge the sending by publishing the value to an acknowledgement topic, for the moment even if it is a signal repetition we acknowledge also
}
#ifdef ZradioCC1101 // set Receive on and Transmitt off
ELECHOUSE_cc1101.SetRx(CC1101_FREQUENCY);
mySwitch.disableTransmit();
mySwitch.enableReceive(RF_RECEIVER_PIN);
#endif
}
#endif
#ifdef jsonReceiving
void MQTTtoRF(char *topicOri, JsonObject &RFdata)
{ // json object decoding
#ifdef ZradioCC1101 // set Receive off and Transmitt on
ELECHOUSE_cc1101.SetTx(CC1101_FREQUENCY);
mySwitch.disableReceive();
mySwitch.enableTransmit(RF_EMITTER_PIN);
#endif
if (cmpToMainTopic(topicOri, subjectMQTTtoRF))
{
Log.trace(F("MQTTtoRF json" CR));
@@ -187,6 +211,11 @@ void MQTTtoRF(char *topicOri, JsonObject &RFdata)
Log.error(F("MQTTtoRF Fail json" CR));
}
}
#ifdef ZradioCC1101 // set Receive on and Transmitt off
ELECHOUSE_cc1101.SetRx(CC1101_FREQUENCY);
mySwitch.disableTransmit();
mySwitch.enableReceive(RF_RECEIVER_PIN);
#endif
}
#endif
#endif
+25
View File
@@ -37,6 +37,10 @@ sudo mosquitto_pub -t home/commands/MQTTtoRF2/CODE_8233372/UNIT_0/PERIOD_272 -m/
#ifdef ZgatewayRF2
#ifdef ZradioCC1101
#include <ELECHOUSE_CC1101_SRC_DRV.h>
#endif
#include <NewRemoteTransmitter.h>
#include <NewRemoteReceiver.h>
@@ -55,6 +59,11 @@ RF2rxd rf2rd;
void setupRF2()
{
#ifndef ZgatewayRF //receiving with RF2 is not compatible with ZgatewayRF
#ifdef ZradioCC1101 //receiving with CC1101
ELECHOUSE_cc1101.Init();
ELECHOUSE_cc1101.setMHZ(CC1101_FREQUENCY);
ELECHOUSE_cc1101.SetRx(CC1101_FREQUENCY);
#endif
NewRemoteReceiver::init(RF_RECEIVER_PIN, 2, rf2Callback);
Log.notice(F("RF_EMITTER_PIN: %d " CR), RF_EMITTER_PIN);
Log.notice(F("RF_RECEIVER_PIN: %d " CR), RF_RECEIVER_PIN);
@@ -101,6 +110,10 @@ void rf2Callback(unsigned int period, unsigned long address, unsigned long group
#ifdef simpleReceiving
void MQTTtoRF2(char *topicOri, char *datacallback)
{
#ifdef ZradioCC1101
NewRemoteReceiver::disable();
ELECHOUSE_cc1101.SetTx(CC1101_FREQUENCY); // set Transmit on
#endif
// RF DATA ANALYSIS
//We look into the subject to see if a special RF protocol is defined
@@ -216,12 +229,20 @@ void MQTTtoRF2(char *topicOri, char *datacallback)
pub((char *)MQTTRF2string.c_str(), (char *)MQTTswitchType.c_str());
}
}
#ifdef ZradioCC1101
ELECHOUSE_cc1101.SetRx(CC1101_FREQUENCY); // set Receive on
NewRemoteReceiver::enable();
#endif
}
#endif
#ifdef jsonReceiving
void MQTTtoRF2(char *topicOri, JsonObject &RF2data)
{ // json object decoding
#ifdef ZradioCC1101
NewRemoteReceiver::disable();
ELECHOUSE_cc1101.SetTx(CC1101_FREQUENCY); // set Transmit on
#endif
if (cmpToMainTopic(topicOri, subjectMQTTtoRF2))
{
@@ -282,6 +303,10 @@ void MQTTtoRF2(char *topicOri, JsonObject &RF2data)
Log.error(F("MQTTtoRF2 failed json read" CR));
}
}
#ifdef ZradioCC1101
ELECHOUSE_cc1101.SetRx(CC1101_FREQUENCY); // set Receive on
NewRemoteReceiver::enable();
#endif
}
#endif
#endif
+4
View File
@@ -90,6 +90,10 @@ RF supported protocols
#define PilightRAW "RAW"
#define repeatPilightwMQTT false // do we repeat a received signal by using mqtt with Pilight gateway
/*-------------------CC1101 frequency----------------------*/
//Match frequency to the hardware version of the radio if ZradioCC1101 is used.
#define CC1101_FREQUENCY 433.92
/*-------------------PIN DEFINITIONS----------------------*/
#ifndef RF_RECEIVER_PIN
#ifdef ESP8266