Support for changing CC1101 Receive and Transmit Frequency (#847)

* Support for changing CC1101 Receive and Transmit Frequency

* Docs

* Resolve feedback

* Update Somfy module to use Global receiveMhz

ELECHOUSE_cc1101.SpiStrobe(CC1101_SIDLE); // Idle receiver prior to
setting a new frequency
This commit is contained in:
Northern Man authored and GitHub committed 2021-01-22 05:53:39 -06:00
1 parent d84f64b23f
commit 25ea909c08
7 files changed
+79 -16

No files matched your search

+4 -2
View File
@@ -384,6 +384,8 @@ uint8_t wifiProtocol = 0; // default mode, automatic selection
#define subjectMQTTtoSYSset "/commands/MQTTtoSYS/config"
/*-------------------DEFINE LOG LEVEL----------------------*/
#define LOG_LEVEL LOG_LEVEL_NOTICE
#ifndef LOG_LEVEL
# define LOG_LEVEL LOG_LEVEL_NOTICE
#endif
#endif
+2 -1
View File
@@ -71,7 +71,8 @@ void MQTTtoSomfy(char* topicOri, JsonObject& jsonData) {
SomfyRemote somfyRemote(RF_EMITTER_GPIO, somfyRemotes[remoteIndex], &rollingCodeStorage);
somfyRemote.sendCommand(command);
# ifdef ZradioCC1101
ELECHOUSE_cc1101.SetRx(CC1101_FREQUENCY); // set Receive on
ELECHOUSE_cc1101.SpiStrobe(CC1101_SIDLE); // Idle receiver prior to setting a new frequency
ELECHOUSE_cc1101.SetRx(receiveMhz); // set Receive on
# endif
}
}
+50 -10
View File
@@ -61,8 +61,7 @@ void setupRF() {
Log.notice(F("RF_RECEIVER_GPIO: %d " CR), RF_RECEIVER_GPIO);
# ifdef ZradioCC1101 //receiving with CC1101
ELECHOUSE_cc1101.Init();
ELECHOUSE_cc1101.setMHZ(CC1101_FREQUENCY);
ELECHOUSE_cc1101.SetRx(CC1101_FREQUENCY);
ELECHOUSE_cc1101.SetRx(receiveMhz);
# endif
# ifdef RF_DISABLE_TRANSMIT
mySwitch.disableTransmit();
@@ -76,7 +75,11 @@ void setupRF() {
void RFtoMQTT() {
if (mySwitch.available()) {
# ifdef ZradioCC1101 //receiving with CC1101
const int JSON_MSG_CALC_BUFFER = JSON_OBJECT_SIZE(5);
# else
const int JSON_MSG_CALC_BUFFER = JSON_OBJECT_SIZE(4);
# endif
StaticJsonBuffer<JSON_MSG_CALC_BUFFER> jsonBuffer;
JsonObject& RFdata = jsonBuffer.createObject();
Log.trace(F("Rcv. RF" CR));
@@ -88,6 +91,9 @@ void RFtoMQTT() {
RFdata.set("protocol", (int)mySwitch.getReceivedProtocol());
RFdata.set("length", (int)mySwitch.getReceivedBitlength());
RFdata.set("delay", (int)mySwitch.getReceivedDelay());
# ifdef ZradioCC1101 // set Receive off and Transmitt on
RFdata.set("mhz", receiveMhz);
# endif
mySwitch.resetAvailable();
if (!isAduplicateSignal(MQTTvalue) && MQTTvalue != 0) { // conditions to avoid duplications of RF -->MQTT
@@ -109,7 +115,7 @@ void RFtoMQTT() {
# ifdef simpleReceiving
void MQTTtoRF(char* topicOri, char* datacallback) {
# ifdef ZradioCC1101 // set Receive off and Transmitt on
ELECHOUSE_cc1101.SetTx(CC1101_FREQUENCY);
ELECHOUSE_cc1101.SetTx(receiveMhz);
mySwitch.disableReceive();
mySwitch.enableTransmit(RF_EMITTER_GPIO);
# endif
@@ -161,7 +167,8 @@ void MQTTtoRF(char* topicOri, char* datacallback) {
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);
ELECHOUSE_cc1101.SpiStrobe(CC1101_SIDLE); // Idle receiver prior to setting a new frequency
ELECHOUSE_cc1101.SetRx(receiveMhz);
mySwitch.disableTransmit();
mySwitch.enableReceive(RF_RECEIVER_GPIO);
# endif
@@ -170,11 +177,6 @@ void MQTTtoRF(char* topicOri, char* datacallback) {
# 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_GPIO);
# endif
if (cmpToMainTopic(topicOri, subjectMQTTtoRF)) {
Log.trace(F("MQTTtoRF json" CR));
SIGNAL_SIZE_UL_ULL data = RFdata["value"];
@@ -186,6 +188,15 @@ void MQTTtoRF(char* topicOri, JsonObject& RFdata) { // json object decoding
Log.notice(F("RF Protocol:%d" CR), valuePRT);
Log.notice(F("RF Pulse Lgth: %d" CR), valuePLSL);
Log.notice(F("Bits nb: %d" CR), valueBITS);
# ifdef ZradioCC1101 // set Receive off and Transmitt on
float trMhz = RFdata["mhz"] | CC1101_FREQUENCY;
if (validFrequency((int)trMhz)) {
ELECHOUSE_cc1101.SetTx(trMhz);
Log.notice(F("Transmit mhz: %F" CR), trMhz);
mySwitch.disableReceive();
mySwitch.enableTransmit(RF_EMITTER_GPIO);
}
# endif
mySwitch.setRepeatTransmit(valueRPT);
mySwitch.setProtocol(valuePRT, valuePLSL);
mySwitch.send(data, valueBITS);
@@ -193,14 +204,43 @@ void MQTTtoRF(char* topicOri, JsonObject& RFdata) { // json object decoding
pub(subjectGTWRFtoMQTT, RFdata); // 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
mySwitch.setRepeatTransmit(RF_EMITTER_REPEAT); // Restore the default value
} else {
# ifdef ZradioCC1101 // set Receive on and Transmitt off
float tempMhz = RFdata["mhz"];
if (tempMhz != 0 && validFrequency((int)tempMhz)) {
receiveMhz = tempMhz;
Log.notice(F("Receive mhz: %F" CR), receiveMhz);
pub(subjectGTWRFtoMQTT, RFdata); // 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
} else {
pub(subjectGTWRFtoMQTT, "{\"Status\": \"Error\"}"); // Fail feedback
Log.error(F("MQTTtoRF Fail json" CR));
}
# else
# ifndef ARDUINO_AVR_UNO // Space issues with the UNO
pub(subjectGTWRFtoMQTT, "{\"Status\": \"error\"}"); // Fail feedback
# endif
Log.error(F("MQTTtoRF Fail json" CR));
# endif
}
}
# ifdef ZradioCC1101 // set Receive on and Transmitt off
ELECHOUSE_cc1101.SetRx(CC1101_FREQUENCY);
ELECHOUSE_cc1101.SpiStrobe(CC1101_SIDLE); // Idle receiver prior to setting a new frequency
ELECHOUSE_cc1101.SetRx(receiveMhz);
mySwitch.disableTransmit();
mySwitch.enableReceive(RF_RECEIVER_GPIO);
# endif
}
# endif
#endif
#ifdef ZradioCC1101
bool validFrequency(int mhz) {
// CC1101 valid frequencies 300-348 MHZ, 387-464MHZ and 779-928MHZ.
if (mhz >= 300 && mhz <= 348)
return true;
if (mhz >= 387 && mhz <= 464)
return true;
if (mhz >= 779 && mhz <= 928)
return true;
return false;
}
#endif
+7 -1
View File
@@ -82,7 +82,13 @@ extern void MQTTtoPilight(char* topicOri, JsonObject& RFdata);
/*-------------------CC1101 frequency----------------------*/
//Match frequency to the hardware version of the radio if ZradioCC1101 is used.
#define CC1101_FREQUENCY 433.92
#ifndef CC1101_FREQUENCY
# define CC1101_FREQUENCY 433.92
#endif
// Allow ZGatewayRF Module to change receive frequency of CC1101 Transceiver module
#ifdef ZradioCC1101
float receiveMhz = CC1101_FREQUENCY;
#endif
/*-------------------PIN DEFINITIONS----------------------*/
#ifndef RF_RECEIVER_GPIO
+1 -1
View File
@@ -493,7 +493,7 @@ void connectMQTT() {
#ifdef ZgatewayIR
client.subscribe(subjectMultiGTWIR); // subject on which other OMG will publish, this OMG will store these msg and by the way don't republish them if they have been already published
#endif
Log.trace(F("Subscription OK to the subjects" CR));
Log.trace(F("Subscription OK to the subjects %s" CR), topic2);
}
} else {
failure_number_mqtt++; // we count the failure