Add Pilight limitProtocols support (#1223)
* Add ability to limit protocols * Make serial feedback notice Co-authored-by: Paul <steadramon@local>
This commit is contained in:
1 parent
23351226ea
commit
5b697e0306
3 files changed
+96
-5
No files matched your search
@@ -122,6 +122,29 @@ Generate your RF signals by pressing a remote button or other and you will see :
|
||||
|
||||

|
||||
|
||||
### 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.
|
||||
|
||||
#### Available protocols
|
||||
To list the available protocols on the Serial -
|
||||
|
||||
`mosquitto_pub -t "home/OpenMQTTGateway/commands/MQTTtoPilight/protocols" -m '{"available":true}'`
|
||||
#### Limit protocols
|
||||
To limit the protocols, send a JSON array of protocols as below -
|
||||
|
||||
`mosquitto_pub -t "home/OpenMQTTGateway/commands/MQTTtoPilight/protocols -m '{"limit": ["array", "of", "protocols"]}'`
|
||||
|
||||
eg: `mosquitto_pub -t "home/OpenMQTTGateway/commands/MQTTtoPilight/protocols" -m '{"limit":["tfa", "ev1527"}'`
|
||||
|
||||
#### Reset protocols
|
||||
To reset and listen to all protocols -
|
||||
`mosquitto_pub -t "home/OpenMQTTGateway/commands/MQTTtoPilight/protocols -m '{"reset": true}`'
|
||||
|
||||
#### Enabled protocols
|
||||
To list the enabled protocols on the Serial -
|
||||
|
||||
`mosquitto_pub -t "home/OpenMQTTGateway/commands/MQTTtoPilight/protocols" -m '{"enabled":true}'`
|
||||
|
||||
### Send data by MQTT to transmit a RF signal
|
||||
|
||||
#### Using a known protocol
|
||||
|
||||
@@ -93,12 +93,78 @@ void setupPilight() {
|
||||
Log.trace(F("ZgatewayPilight setup done " CR));
|
||||
}
|
||||
|
||||
void savePilightConfig() {
|
||||
Log.trace(F("saving Pilight config" CR));
|
||||
DynamicJsonDocument json(4096);
|
||||
deserializeJson(json, rf.enabledProtocols());
|
||||
|
||||
File configFile = SPIFFS.open("/pilight.json", "w");
|
||||
if (!configFile) {
|
||||
Log.error(F("failed to open config file for writing" CR));
|
||||
}
|
||||
|
||||
serializeJsonPretty(json, Serial);
|
||||
serializeJson(json, configFile);
|
||||
configFile.close();
|
||||
}
|
||||
|
||||
void loadPilightConfig() {
|
||||
Log.trace(F("reading Pilight config file" CR));
|
||||
File configFile = SPIFFS.open("/pilight.json", "r");
|
||||
if (configFile) {
|
||||
Log.trace(F("opened Pilight config file" CR));
|
||||
DynamicJsonDocument json(configFile.size() * 4);
|
||||
auto error = deserializeJson(json, configFile);
|
||||
if (error) {
|
||||
Log.error(F("deserialize config failed: %s, buffer capacity: %u" CR), error.c_str(), json.capacity());
|
||||
}
|
||||
serializeJson(json, Serial);
|
||||
if (!json.isNull()) {
|
||||
String rflimit;
|
||||
serializeJson(json, rflimit);
|
||||
rf.limitProtocols(rflimit);
|
||||
} else {
|
||||
Log.warning(F("failed to load json config" CR));
|
||||
}
|
||||
configFile.close();
|
||||
}
|
||||
}
|
||||
|
||||
void PilighttoMQTT() {
|
||||
rf.loop();
|
||||
}
|
||||
|
||||
void MQTTtoPilight(char* topicOri, JsonObject& Pilightdata) {
|
||||
if (cmpToMainTopic(topicOri, subjectMQTTtoPilight)) {
|
||||
if (cmpToMainTopic(topicOri, subjectMQTTtoPilightProtocol)) {
|
||||
bool success = false;
|
||||
if (Pilightdata.containsKey("reset")) {
|
||||
rf.limitProtocols(rf.availableProtocols());
|
||||
savePilightConfig();
|
||||
success = true;
|
||||
}
|
||||
if (Pilightdata.containsKey("limit")) {
|
||||
String output;
|
||||
serializeJson(Pilightdata["limit"], output);
|
||||
rf.limitProtocols(output);
|
||||
savePilightConfig();
|
||||
success = true;
|
||||
}
|
||||
if (Pilightdata.containsKey("enabled")) {
|
||||
Log.notice(F("PiLight protocols enabled: %s" CR), rf.enabledProtocols().c_str());
|
||||
success = true;
|
||||
}
|
||||
if (Pilightdata.containsKey("available")) {
|
||||
Log.notice(F("PiLight protocols available: %s" CR), rf.availableProtocols().c_str());
|
||||
success = true;
|
||||
}
|
||||
|
||||
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
|
||||
} else {
|
||||
pub(subjectGTWPilighttoMQTT, "{\"Status\": \"Error\"}"); // Fail feedback
|
||||
Log.error(F("MQTTtoPilightProtocol Fail json" CR));
|
||||
}
|
||||
} else if (cmpToMainTopic(topicOri, subjectMQTTtoPilight)) {
|
||||
const char* message = Pilightdata["message"];
|
||||
const char* protocol = Pilightdata["protocol"];
|
||||
const char* raw = Pilightdata["raw"];
|
||||
@@ -227,5 +293,6 @@ extern void enablePilightReceive() {
|
||||
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();
|
||||
loadPilightConfig();
|
||||
};
|
||||
#endif
|
||||
+5
-4
@@ -101,10 +101,11 @@ int minimumRssi = 0;
|
||||
|
||||
/*-------------------ESPPiLight topics & parameters----------------------*/
|
||||
//433Mhz Pilight MQTT Subjects and keys
|
||||
#define subjectMQTTtoPilight "/commands/MQTTtoPilight"
|
||||
#define subjectPilighttoMQTT "/PilighttoMQTT"
|
||||
#define subjectGTWPilighttoMQTT "/PilighttoMQTT"
|
||||
#define repeatPilightwMQTT false // do we repeat a received signal by using mqtt with Pilight gateway
|
||||
#define subjectMQTTtoPilight "/commands/MQTTtoPilight"
|
||||
#define subjectMQTTtoPilightProtocol "/commands/MQTTtoPilight/protocols"
|
||||
#define subjectPilighttoMQTT "/PilighttoMQTT"
|
||||
#define subjectGTWPilighttoMQTT "/PilighttoMQTT"
|
||||
#define repeatPilightwMQTT false // do we repeat a received signal by using mqtt with Pilight gateway
|
||||
|
||||
/*-------------------RTL_433 topics & parameters----------------------*/
|
||||
//433Mhz RTL_433 MQTT Subjects and keys
|
||||
|
||||
Reference in new issue
Block a user