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
@@ -61,6 +61,20 @@ You can add a "repeat" key/value to the MQTTto433 JSON message to override the d
|
||||
Example:
|
||||
`home/OpenMQTTGateway/commands/MQTTto433 {"value":1315156,"protocol":1,"length":24,"delay":317, "repeat":10}`
|
||||
|
||||
### Set Transmit and Receive Frequency of CC1101 Transceiver Module
|
||||
|
||||
Default transmit frequency of the CC1101 module is 433.92 Mhz, and this can be can changed by including the frequency in the transmit message. Parameter is `mhz` and valid values are 300-348 Mhz, 387-464Mhz and 779-928Mhz. Actual frequency support will depend on your CC1101 board.
|
||||
|
||||
`home/OpenMQTTGateway/commands/MQTTto433 {"value":1150,"protocol":6,"length":12,"delay":450,"repeat":8,"mhz":303.732}`
|
||||
|
||||
Default receive frequency of the CC1101 module is 433.92 Mhz, and this can be can changed by sending a message with the frequency. Parameter is `mhz` and valid values are 300-348 Mhz, 387-464Mhz and 779-928Mhz. Actual frequency support will depend on your CC1101 board
|
||||
|
||||
`home/OpenMQTTGateway/commands/MQTTto433 {"mhz":315.026}`
|
||||
|
||||
Messages received will include the frequency, and when transmitting on a different frequency the module return to the receive frequency afterwards. ie transmit messages on 303.732 Mhz then receive messages on 433.92 Mhz
|
||||
|
||||
`{"value":4534142,"protocol":6,"length":26,"delay":356,"mhz":315.026}`
|
||||
|
||||
## Pilight gateway
|
||||
|
||||
### Receiving data from RF signal
|
||||
|
||||
+4
-2
@@ -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
|
||||
@@ -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
@@ -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
@@ -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
@@ -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
|
||||
|
||||
+1
-1
@@ -111,7 +111,7 @@ dallastemperature = DallasTemperature
|
||||
m5stickc = M5StickC@0.2.0
|
||||
m5stickcp = https://github.com/m5stack/M5StickC-Plus.git
|
||||
m5stack = M5Stack@0.3.0
|
||||
smartrc-cc1101-driver-lib = SmartRC-CC1101-Driver-Lib@2.3.5
|
||||
smartrc-cc1101-driver-lib = SmartRC-CC1101-Driver-Lib@2.5.2
|
||||
stl = https://github.com/mike-matera/ArduinoSTL.git#7411816
|
||||
shtc3 = https://github.com/sparkfun/SparkFun_SHTC3_Arduino_Library
|
||||
somfy_remote=Somfy_Remote_Lib@0.2.0
|
||||
|
||||
Reference in new issue
Block a user