Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions docs/use/rf.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 4 additions & 2 deletions main/User_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 3 additions & 1 deletion main/ZactuatorSomfy.ino
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,9 @@ 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
if (CC1101_FREQUENCY_SOMFY != receiveMhz)
ELECHOUSE_cc1101.Init();
ELECHOUSE_cc1101.SetRx(receiveMhz); // set Receive on
# endif
}
}
Expand Down
63 changes: 53 additions & 10 deletions main/ZgatewayRF.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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));
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -161,7 +167,7 @@ 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.SetRx(receiveMhz);
mySwitch.disableTransmit();
mySwitch.enableReceive(RF_RECEIVER_GPIO);
# endif
Expand All @@ -170,11 +176,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"];
Expand All @@ -186,21 +187,63 @@ 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);
Log.notice(F("MQTTtoRF OK" CR));
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
# ifdef ZradioCC1101 // set Receive off and Transmitt on
if (trMhz != receiveMhz)
ELECHOUSE_cc1101.Init();
# endif
} else {
# ifdef ZradioCC1101 // set Receive on and Transmitt off
float tempMhz = RFdata["mhz"];
if (tempMhz != 0 && validFrequency((int)tempMhz)) {
receiveMhz = tempMhz;
ELECHOUSE_cc1101.Init();
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.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
10 changes: 9 additions & 1 deletion main/config_RF.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,15 @@ 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
Expand Down
2 changes: 1 addition & 1 deletion main/main.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down