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:
1 parent
d84f64b23f
commit
25ea909c08
7 files changed
+79
-16
No files matched your search
+50
-10
@@ -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
|
||||
Reference in new issue
Block a user