[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

+19 -1
View File
@@ -263,6 +263,24 @@ Generate your RF signals by pressing a remote button or other and you will see :
![](../img/OpenMQTTGateway_Pilight_Digoo-DG-R8S.png)
#### Enabling RAW packet return support
First, you need to compile a binary with `Pilight_rawEnabled true` uncommented in config_RF.h.
Once the device is online, you can turn on the RAW packet return support with the following MQTT command:
`mosquitto_pub -t "home/OpenMQTTGateway/commands/MQTTtoPilight/protocols" -m '{"rawEnabled":true}'`
The returned JSON looks like this:
`Client (null) received PUBLISH (d0, q0, r0, m0, 'home/OpenMQTTGateway/PilighttoMQTT', ... (176 bytes))
{"format":"RAW","rawlen":106,"pulsesString":"c:0102010102020202020101010101010102020201020102020202020201010101010101010101010102010102010201020201010203;p:521,944,1924,3845@"}`
The pulseString format is Pilight's native. For those who are not familiar with it:
c:* are the indexes for the p:* array, which are the different pulse length. (e.g. pulse[0] = 521ms, pulse[1]=944ms..., so c[0], which is a '0' = 521ms pulse, c[1], which is a '1' =944ms pulse etc)
After gathering all the packets you need, simply turn off the RAW packet support via MQTT:
`mosquitto_pub -t "home/OpenMQTTGateway/commands/MQTTtoPilight/protocols" -m '{"rawEnabled":false}'`
### Limit Protocols
It is possible to limit the protocols that Pilight will respond to, this can help reduce noise from unwanted devices and in some cases disable conflicting protocols.
@@ -279,7 +297,7 @@ eg: `mosquitto_pub -t "home/OpenMQTTGateway/commands/MQTTtoPilight/protocols" -m
#### Reset protocols
To reset and listen to all protocols -
`mosquitto_pub -t "home/OpenMQTTGateway/commands/MQTTtoPilight/protocols -m '{"reset": true}`'
`mosquitto_pub -t "home/OpenMQTTGateway/commands/MQTTtoPilight/protocols -m '{"reset": true}'`
#### Enabled protocols
To list the enabled protocols on the Serial -
+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