[RF] Added Pilight RAW packet return support (#1604)

* Added Pilight RAW packet return support - can be enabled in User_config.h
This commit is contained in:
Tamas DAJKA authored and GitHub committed 2023-04-25 17:13:01 -05:00
1 parent 5927259db6
commit e3e700449b
3 files changed
+62 -1

No files matched your search

+42
View File
@@ -36,6 +36,11 @@
# include <ESPiLight.h>
ESPiLight rf(RF_EMITTER_GPIO); // use -1 to disable transmitter
# ifdef Pilight_rawEnabled
// raw output support
bool pilightRawEnabled = 0;
# endif
void pilightCallback(const String& protocol, const String& message, int status,
size_t repeats, const String& deviceID) {
if (status == VALID) {
@@ -78,6 +83,28 @@ void pilightCallback(const String& protocol, const String& message, int status,
}
}
# ifdef Pilight_rawEnabled
void pilightRawCallback(const uint16_t* pulses, size_t length) {
uint16_t pulse;
if (!pilightRawEnabled) {
Log.trace(F("Pilight RAW not enabled" CR));
return;
}
Log.trace(F("Creating RF PiLight buffer" CR));
StaticJsonDocument<JSON_MSG_BUFFER> jsonBuffer;
JsonObject RFPiLightdata = jsonBuffer.to<JsonObject>();
RFPiLightdata["format"] = "RAW";
RFPiLightdata["rawlen"] = length;
RFPiLightdata["pulsesString"] = rf.pulseTrainToString(pulses, length); // c=pulse_array_key;p=pulse_types
// publish data
pub(subjectPilighttoMQTT, RFPiLightdata);
}
# endif
void setupPilight() {
# ifdef ZradioCC1101 //receiving with CC1101
ELECHOUSE_cc1101.Init();
@@ -157,6 +184,16 @@ void MQTTtoPilight(char* topicOri, JsonObject& Pilightdata) {
Log.notice(F("PiLight protocols available: %s" CR), rf.availableProtocols().c_str());
success = true;
}
# ifdef Pilight_rawEnabled
if (Pilightdata.containsKey("rawEnabled")) {
Log.notice(F("Setting PiLight raw output enabled: %s" CR), Pilightdata["rawEnabled"]);
pilightRawEnabled = (bool)Pilightdata["rawEnabled"];
disablePilightReceive();
delay(1);
enablePilightReceive();
success = true;
}
# endif
if (success) {
pub(subjectGTWPilighttoMQTT, Pilightdata); // 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
@@ -297,6 +334,11 @@ extern void enablePilightReceive() {
ELECHOUSE_cc1101.SetRx(receiveMhz); // set Receive on
# endif
rf.setCallback(pilightCallback);
# ifdef Pilight_rawEnabled
if (pilightRawEnabled) {
rf.setPulseTrainCallBack(pilightRawCallback);
}
# endif
rf.initReceiver(RF_RECEIVER_GPIO);
pinMode(RF_EMITTER_GPIO, OUTPUT); // Set this here, because if this is the RX pin it was reset to INPUT by Serial.end();
rf.enableReceiver();
+1
View File
@@ -167,6 +167,7 @@ const char parameters[40][4][24] = {
#define subjectPilighttoMQTT "/PilighttoMQTT"
#define subjectGTWPilighttoMQTT "/PilighttoMQTT"
#define repeatPilightwMQTT false // do we repeat a received signal by using MQTT with Pilight gateway
//#define Pilight_rawEnabled true // enables Pilight RAW return - switchable via MQTT
/*-------------------RTL_433 topics & parameters----------------------*/
//433Mhz RTL_433 MQTT Subjects and keys