[SYS] Add save option to discovery and ohdiscovery key and remove discovery for Arduino boards (#1696)
Enabling to keep discovery off if required Remove Mqtt discovery for Arduino UNO and ATMEGA
This commit is contained in:
1 parent
7405499f15
commit
a6c0a3b1d4
10 files changed
+110
-26
No files matched your search
+5
-1
@@ -27,7 +27,8 @@ You can deactivate the MQTT auto discovery function, this function enables to au
|
|||||||
### Activate
|
### Activate
|
||||||
`mosquitto_pub -t "home/OpenMQTTGateway/commands/MQTTtoSYS/config" -m '{"discovery":true}'`
|
`mosquitto_pub -t "home/OpenMQTTGateway/commands/MQTTtoSYS/config" -m '{"discovery":true}'`
|
||||||
|
|
||||||
If you want the settings to be kept upon gateway restart, you can publish the command with the retain flag.
|
If you want the settings to be kept upon gateway restart, you can save the state by adding `"save":true` (ESP32 only).
|
||||||
|
`mosquitto_pub -t "home/OpenMQTTGateway/commands/MQTTtoSYS/config" -m '{"discovery":false, "save":true}'`
|
||||||
|
|
||||||
::: tip
|
::: tip
|
||||||
Auto discovery is enable by default on release binaries, on platformio (except for UNO). With Arduino IDE please read the [advanced configuration section](../upload/advanced-configuration#auto-discovery) of the documentation.
|
Auto discovery is enable by default on release binaries, on platformio (except for UNO). With Arduino IDE please read the [advanced configuration section](../upload/advanced-configuration#auto-discovery) of the documentation.
|
||||||
@@ -38,6 +39,9 @@ OpenHAB does not support the key `is_defined` in the json template, to remove it
|
|||||||
|
|
||||||
`mosquitto_pub -t "home/OpenMQTTGateway/commands/MQTTtoSYS/config" -m '{"ohdiscovery":true}'`
|
`mosquitto_pub -t "home/OpenMQTTGateway/commands/MQTTtoSYS/config" -m '{"ohdiscovery":true}'`
|
||||||
|
|
||||||
|
If you want the settings to be kept upon gateway restart, you can save the state by adding `"save":true` (ESP32 only).
|
||||||
|
`mosquitto_pub -t "home/OpenMQTTGateway/commands/MQTTtoSYS/config" -m '{"ohdiscovery":true, "save":true}'`
|
||||||
|
|
||||||
::: tip
|
::: tip
|
||||||
This command can also be used with other controllers that does not support the is_defined key.
|
This command can also be used with other controllers that does not support the is_defined key.
|
||||||
:::
|
:::
|
||||||
|
|||||||
@@ -1397,6 +1397,7 @@ build_flags =
|
|||||||
'-DZmqttDiscovery="HADiscovery"'
|
'-DZmqttDiscovery="HADiscovery"'
|
||||||
'-DsimplePublishing=true'
|
'-DsimplePublishing=true'
|
||||||
'-DGateway_Name="OMG_ATMEGA_ALL"'
|
'-DGateway_Name="OMG_ATMEGA_ALL"'
|
||||||
|
'-UZmqttDiscovery="HADiscovery"'
|
||||||
|
|
||||||
[env:uno-rf]
|
[env:uno-rf]
|
||||||
platform = ${com.atmelavr_platform}
|
platform = ${com.atmelavr_platform}
|
||||||
@@ -1406,6 +1407,7 @@ lib_deps =
|
|||||||
${libraries.rc-switch}
|
${libraries.rc-switch}
|
||||||
build_flags =
|
build_flags =
|
||||||
${com-arduino-low-memory.build_flags}
|
${com-arduino-low-memory.build_flags}
|
||||||
|
'-UZmqttDiscovery="HADiscovery"'
|
||||||
'-DZgatewayRF="RF"'
|
'-DZgatewayRF="RF"'
|
||||||
'-DGateway_Name="OMG_1_RF"'
|
'-DGateway_Name="OMG_1_RF"'
|
||||||
'-DDISABLE_LOGGING'
|
'-DDISABLE_LOGGING'
|
||||||
@@ -1421,6 +1423,7 @@ build_flags =
|
|||||||
${com-arduino-low-memory.build_flags}
|
${com-arduino-low-memory.build_flags}
|
||||||
'-DGateway_Name="OMG_1_FL"'
|
'-DGateway_Name="OMG_1_FL"'
|
||||||
'-DZactuatorFASTLED="FASTLED"'
|
'-DZactuatorFASTLED="FASTLED"'
|
||||||
|
'-UZmqttDiscovery="HADiscovery"'
|
||||||
custom_description = FastLed control
|
custom_description = FastLed control
|
||||||
|
|
||||||
[env:esp32dev-ble-datatest]
|
[env:esp32dev-ble-datatest]
|
||||||
|
|||||||
+7
-1
@@ -733,7 +733,6 @@ Preferences preferences;
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef ZmqttDiscovery
|
#ifdef ZmqttDiscovery
|
||||||
bool disc = true; // Auto discovery with Home Assistant convention
|
|
||||||
unsigned long lastDiscovery = 0; // Time of the last discovery to trigger automaticaly to off after DiscoveryAutoOffTimer
|
unsigned long lastDiscovery = 0; // Time of the last discovery to trigger automaticaly to off after DiscoveryAutoOffTimer
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -748,6 +747,13 @@ unsigned long lastDiscovery = 0; // Time of the last discovery to trigger automa
|
|||||||
# define isWhite(device) device->isWhtL
|
# define isWhite(device) device->isWhtL
|
||||||
# define isBlack(device) device->isBlkL
|
# define isBlack(device) device->isBlkL
|
||||||
# define isDiscovered(device) device->isDisc
|
# define isDiscovered(device) device->isDisc
|
||||||
|
|
||||||
|
/*----------------CONFIGURABLE PARAMETERS-----------------*/
|
||||||
|
struct SYSConfig_s {
|
||||||
|
bool discovery; // HA discovery convention
|
||||||
|
bool ohdiscovery; // OH discovery specificities
|
||||||
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(ZgatewayRF) || defined(ZgatewayIR) || defined(ZgatewaySRFB) || defined(ZgatewayWeatherStation) || defined(ZgatewayRTL_433)
|
#if defined(ZgatewayRF) || defined(ZgatewayIR) || defined(ZgatewaySRFB) || defined(ZgatewayWeatherStation) || defined(ZgatewayRTL_433)
|
||||||
|
|||||||
+1
-1
@@ -164,7 +164,7 @@ void RFtoMQTT() {
|
|||||||
|
|
||||||
if (!isAduplicateSignal(MQTTvalue) && MQTTvalue != 0) { // conditions to avoid duplications of RF -->MQTT
|
if (!isAduplicateSignal(MQTTvalue) && MQTTvalue != 0) { // conditions to avoid duplications of RF -->MQTT
|
||||||
# if defined(ZmqttDiscovery) && !defined(RF_DISABLE_TRANSMIT) && defined(RFmqttDiscovery) //component creation for HA
|
# if defined(ZmqttDiscovery) && !defined(RF_DISABLE_TRANSMIT) && defined(RFmqttDiscovery) //component creation for HA
|
||||||
if (disc)
|
if (SYSConfig.discovery)
|
||||||
RFtoMQTTdiscovery(MQTTvalue);
|
RFtoMQTTdiscovery(MQTTvalue);
|
||||||
# endif
|
# endif
|
||||||
pub(subjectRFtoMQTT, RFdata);
|
pub(subjectRFtoMQTT, RFdata);
|
||||||
|
|||||||
@@ -131,7 +131,7 @@ void RF2toMQTT() {
|
|||||||
RF2data["address"] = (unsigned long)rf2rd.address;
|
RF2data["address"] = (unsigned long)rf2rd.address;
|
||||||
RF2data["switchType"] = (int)rf2rd.switchType;
|
RF2data["switchType"] = (int)rf2rd.switchType;
|
||||||
# ifdef ZmqttDiscovery //component creation for HA
|
# ifdef ZmqttDiscovery //component creation for HA
|
||||||
if (disc)
|
if (SYSConfig.discovery)
|
||||||
RF2toMQTTdiscovery(RF2data);
|
RF2toMQTTdiscovery(RF2data);
|
||||||
# endif
|
# endif
|
||||||
|
|
||||||
|
|||||||
@@ -129,7 +129,7 @@ void launchRTL_433Discovery(bool overrideDiscovery) {
|
|||||||
DISCOVERY_TRACE_LOG(F("idWoKey %s" CR), idWoKey.c_str());
|
DISCOVERY_TRACE_LOG(F("idWoKey %s" CR), idWoKey.c_str());
|
||||||
String value_template = "{{ value_json." + String(parameters[i][0]) + " | is_defined }}";
|
String value_template = "{{ value_json." + String(parameters[i][0]) + " | is_defined }}";
|
||||||
if (strcmp(parameters[i][0], "battery_ok") == 0) {
|
if (strcmp(parameters[i][0], "battery_ok") == 0) {
|
||||||
if (OpenHABDisc) {
|
if (SYSConfig.ohdiscovery) {
|
||||||
value_template = "{{ value_json." + String(parameters[i][0]) + " * 99 + 1 }}"; // https://github.com/merbanan/rtl_433/blob/93f0f30c28cfb6b82b8cc3753415b01a85bee91d/examples/rtl_433_mqtt_hass.py#L187
|
value_template = "{{ value_json." + String(parameters[i][0]) + " * 99 + 1 }}"; // https://github.com/merbanan/rtl_433/blob/93f0f30c28cfb6b82b8cc3753415b01a85bee91d/examples/rtl_433_mqtt_hass.py#L187
|
||||||
} else {
|
} else {
|
||||||
value_template = "{{ float(value_json." + String(parameters[i][0]) + ") * 99 + 1 | is_defined }}"; // https://github.com/merbanan/rtl_433/blob/93f0f30c28cfb6b82b8cc3753415b01a85bee91d/examples/rtl_433_mqtt_hass.py#L187
|
value_template = "{{ float(value_json." + String(parameters[i][0]) + ") * 99 + 1 | is_defined }}"; // https://github.com/merbanan/rtl_433/blob/93f0f30c28cfb6b82b8cc3753415b01a85bee91d/examples/rtl_433_mqtt_hass.py#L187
|
||||||
@@ -254,7 +254,7 @@ void rtl_433_Callback(char* message) {
|
|||||||
// Log.notice(F("uniqueid: %s" CR), uniqueid.c_str());
|
// Log.notice(F("uniqueid: %s" CR), uniqueid.c_str());
|
||||||
if (!isAduplicateSignal(MQTTvalue)) {
|
if (!isAduplicateSignal(MQTTvalue)) {
|
||||||
# ifdef ZmqttDiscovery
|
# ifdef ZmqttDiscovery
|
||||||
if (disc)
|
if (SYSConfig.discovery)
|
||||||
storeRTL_433Discovery(RFrtl_433_ESPdata, (char*)model.c_str(), (char*)uniqueid.c_str());
|
storeRTL_433Discovery(RFrtl_433_ESPdata, (char*)model.c_str(), (char*)uniqueid.c_str());
|
||||||
# endif
|
# endif
|
||||||
pub((char*)topic.c_str(), RFrtl_433_ESPdata);
|
pub((char*)topic.c_str(), RFrtl_433_ESPdata);
|
||||||
|
|||||||
+12
-2
@@ -295,7 +295,7 @@ void createDiscovery(const char* sensor_type,
|
|||||||
if (retainCmd)
|
if (retainCmd)
|
||||||
sensor["retain"] = retainCmd; // Retain command
|
sensor["retain"] = retainCmd; // Retain command
|
||||||
if (value_template[0]) {
|
if (value_template[0]) {
|
||||||
if (strstr(value_template, " | is_defined") != NULL && OpenHABDisc) {
|
if (strstr(value_template, " | is_defined") != NULL && SYSConfig.ohdiscovery) {
|
||||||
sensor["val_tpl"] = remove_substring(value_template, " | is_defined"); //OpenHAB compatible HA auto discovery
|
sensor["val_tpl"] = remove_substring(value_template, " | is_defined"); //OpenHAB compatible HA auto discovery
|
||||||
} else {
|
} else {
|
||||||
sensor["val_tpl"] = value_template; //HA Auto discovery
|
sensor["val_tpl"] = value_template; //HA Auto discovery
|
||||||
@@ -487,7 +487,17 @@ void pubMqttDiscovery() {
|
|||||||
createDiscovery("switch", //set Type
|
createDiscovery("switch", //set Type
|
||||||
subjectSYStoMQTT, "SYS: Auto discovery", (char*)getUniqueId("discovery", "").c_str(), //set state_topic,name,uniqueId
|
subjectSYStoMQTT, "SYS: Auto discovery", (char*)getUniqueId("discovery", "").c_str(), //set state_topic,name,uniqueId
|
||||||
will_Topic, "", "{{ value_json.discovery }}", //set availability_topic,device_class,value_template,
|
will_Topic, "", "{{ value_json.discovery }}", //set availability_topic,device_class,value_template,
|
||||||
"{\"discovery\":true}", "{\"discovery\":false}", "", //set,payload_on,payload_off,unit_of_meas,
|
"{\"discovery\":true,\"save\":true}", "{\"discovery\":false,\"save\":true}", "", //set,payload_on,payload_off,unit_of_meas,
|
||||||
|
0, //set off_delay
|
||||||
|
Gateway_AnnouncementMsg, will_Message, true, subjectMQTTtoSYSset, //set,payload_avalaible,payload_not avalaible ,is a gateway entity, command topic
|
||||||
|
"", "", "", "", true, // device name, device manufacturer, device model, device MAC, retain,
|
||||||
|
stateClassNone, //State Class
|
||||||
|
"false", "true" //state_off, state_on
|
||||||
|
);
|
||||||
|
createDiscovery("switch", //set Type
|
||||||
|
subjectSYStoMQTT, "SYS: OpenHAB discovery", (char*)getUniqueId("ohdiscovery", "").c_str(), //set state_topic,name,uniqueId
|
||||||
|
will_Topic, "", "{{ value_json.ohdiscovery }}", //set availability_topic,device_class,value_template,
|
||||||
|
"{\"ohdiscovery\":true,\"save\":true}", "{\"ohdiscovery\":false,\"save\":true}", "", //set,payload_on,payload_off,unit_of_meas,
|
||||||
0, //set off_delay
|
0, //set off_delay
|
||||||
Gateway_AnnouncementMsg, will_Message, true, subjectMQTTtoSYSset, //set,payload_avalaible,payload_not avalaible ,is a gateway entity, command topic
|
Gateway_AnnouncementMsg, will_Message, true, subjectMQTTtoSYSset, //set,payload_avalaible,payload_not avalaible ,is a gateway entity, command topic
|
||||||
"", "", "", "", true, // device name, device manufacturer, device model, device MAC, retain,
|
"", "", "", "", true, // device name, device manufacturer, device model, device MAC, retain,
|
||||||
|
|||||||
@@ -101,7 +101,7 @@ void pubOneWire_HADiscovery() {
|
|||||||
// If zmqttDiscovery is enabled, create a sensor topic for each DS18b20 sensor found on the bus, using addr as uniqueID
|
// If zmqttDiscovery is enabled, create a sensor topic for each DS18b20 sensor found on the bus, using addr as uniqueID
|
||||||
# ifdef ZmqttDiscovery
|
# ifdef ZmqttDiscovery
|
||||||
// If zmqtt discovery is enabled, create a sensor topic for each DS18b20 sensor found on the bus, using addr as uniqueID
|
// If zmqtt discovery is enabled, create a sensor topic for each DS18b20 sensor found on the bus, using addr as uniqueID
|
||||||
if (disc) {
|
if (SYSConfig.discovery) {
|
||||||
for (int index = 0; index < ds1820_count; index++) {
|
for (int index = 0; index < ds1820_count; index++) {
|
||||||
createDiscovery("sensor",
|
createDiscovery("sensor",
|
||||||
(char*)(String(OW_TOPIC) + "/" + ds1820_addr[index]).c_str(),
|
(char*)(String(OW_TOPIC) + "/" + ds1820_addr[index]).c_str(),
|
||||||
|
|||||||
@@ -135,8 +135,6 @@ void announceDeviceTrigger(bool use_gateway_info,
|
|||||||
# define OpenHABDiscovery false
|
# define OpenHABDiscovery false
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
boolean OpenHABDisc = OpenHABDiscovery;
|
|
||||||
|
|
||||||
// Home assistant autodiscovery value key definition
|
// Home assistant autodiscovery value key definition
|
||||||
#define jsonBatt "{{ value_json.batt | is_defined }}"
|
#define jsonBatt "{{ value_json.batt | is_defined }}"
|
||||||
#define jsonLux "{{ value_json.lux | is_defined }}"
|
#define jsonLux "{{ value_json.lux | is_defined }}"
|
||||||
|
|||||||
+78
-15
@@ -224,6 +224,9 @@ unsigned long timer_led_measures = 0;
|
|||||||
static void* eClient = nullptr;
|
static void* eClient = nullptr;
|
||||||
static unsigned long last_ota_activity_millis = 0;
|
static unsigned long last_ota_activity_millis = 0;
|
||||||
#if defined(ESP8266) || defined(ESP32)
|
#if defined(ESP8266) || defined(ESP32)
|
||||||
|
// Global struct to store live SYS configuration data
|
||||||
|
SYSConfig_s SYSConfig;
|
||||||
|
|
||||||
bool failSafeMode = false;
|
bool failSafeMode = false;
|
||||||
static bool mqtt_secure = MQTT_SECURE_DEFAULT;
|
static bool mqtt_secure = MQTT_SECURE_DEFAULT;
|
||||||
static bool mqtt_cert_validate = MQTT_CERT_VALIDATE_DEFAULT;
|
static bool mqtt_cert_validate = MQTT_CERT_VALIDATE_DEFAULT;
|
||||||
@@ -294,9 +297,9 @@ void Config_update(JsonObject& data, const char* key, T& var) {
|
|||||||
if (data.containsKey(key)) {
|
if (data.containsKey(key)) {
|
||||||
if (var != data[key].as<T>()) {
|
if (var != data[key].as<T>()) {
|
||||||
var = data[key].as<T>();
|
var = data[key].as<T>();
|
||||||
Log.notice(F("Config %s changed: %s" CR), key, data[key].as<String>());
|
Log.notice(F("Config %s changed: %T" CR), key, data[key].as<T>());
|
||||||
} else {
|
} else {
|
||||||
Log.notice(F("Config %s unchanged: %s" CR), key, data[key].as<String>());
|
Log.notice(F("Config %s unchanged: %T" CR), key, data[key].as<T>());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -623,6 +626,48 @@ void delayWithOTA(long waitMillis) {
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef ZmqttDiscovery
|
||||||
|
void SYSConfig_init() {
|
||||||
|
SYSConfig.discovery = true;
|
||||||
|
SYSConfig.ohdiscovery = OpenHABDiscovery;
|
||||||
|
}
|
||||||
|
|
||||||
|
void SYSConfig_fromJson(JsonObject& SYSdata) {
|
||||||
|
Config_update(SYSdata, "discovery", SYSConfig.discovery);
|
||||||
|
Config_update(SYSdata, "ohdiscovery", SYSConfig.ohdiscovery);
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
void SYSConfig_init() {}
|
||||||
|
void SYSConfig_fromJson(JsonObject& SYSdata) {}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(ESP32) && defined(ZmqttDiscovery)
|
||||||
|
void SYSConfig_load() {
|
||||||
|
StaticJsonDocument<JSON_MSG_BUFFER> jsonBuffer;
|
||||||
|
preferences.begin(Gateway_Short_Name, true);
|
||||||
|
if (preferences.isKey("SYSConfig")) {
|
||||||
|
auto error = deserializeJson(jsonBuffer, preferences.getString("SYSConfig", "{}"));
|
||||||
|
preferences.end();
|
||||||
|
if (error) {
|
||||||
|
Log.error(F("SYS config deserialization failed: %s, buffer capacity: %u" CR), error.c_str(), jsonBuffer.capacity());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (jsonBuffer.isNull()) {
|
||||||
|
Log.warning(F("SYS config is null" CR));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
JsonObject jo = jsonBuffer.as<JsonObject>();
|
||||||
|
SYSConfig_fromJson(jo);
|
||||||
|
Log.notice(F("SYS config loaded" CR));
|
||||||
|
} else {
|
||||||
|
preferences.end();
|
||||||
|
Log.notice(F("SYS config not found" CR));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#else // Function not available for ESP8266
|
||||||
|
void SYSConfig_load() {}
|
||||||
|
#endif
|
||||||
|
|
||||||
void connectMQTT() {
|
void connectMQTT() {
|
||||||
#ifndef ESPWifiManualSetup
|
#ifndef ESPWifiManualSetup
|
||||||
# if defined(ESP8266) || defined(ESP32)
|
# if defined(ESP8266) || defined(ESP32)
|
||||||
@@ -916,6 +961,9 @@ void setup() {
|
|||||||
modules.add(ZwebUI);
|
modules.add(ZwebUI);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
SYSConfig_init();
|
||||||
|
SYSConfig_load();
|
||||||
|
|
||||||
#if defined(ESP8266) || defined(ESP32)
|
#if defined(ESP8266) || defined(ESP32)
|
||||||
if (mqtt_secure) {
|
if (mqtt_secure) {
|
||||||
eClient = new WiFiClientSecure;
|
eClient = new WiFiClientSecure;
|
||||||
@@ -1736,11 +1784,11 @@ void loop() {
|
|||||||
|
|
||||||
#ifdef ZmqttDiscovery
|
#ifdef ZmqttDiscovery
|
||||||
// Deactivate autodiscovery after DiscoveryAutoOffTimer
|
// Deactivate autodiscovery after DiscoveryAutoOffTimer
|
||||||
if (disc && (now > lastDiscovery + DiscoveryAutoOffTimer))
|
if (SYSConfig.discovery && (now > lastDiscovery + DiscoveryAutoOffTimer))
|
||||||
disc = false;
|
SYSConfig.discovery = false;
|
||||||
// at first connection we publish the discovery payloads
|
// at first connection we publish the discovery payloads
|
||||||
// or, when we have just re-connected (only when discovery_republish_on_reconnect is enabled)
|
// or, when we have just re-connected (only when discovery_republish_on_reconnect is enabled)
|
||||||
bool publishDiscovery = disc && (!connectedOnce || (discovery_republish_on_reconnect && justReconnected));
|
bool publishDiscovery = SYSConfig.discovery && (!connectedOnce || (discovery_republish_on_reconnect && justReconnected));
|
||||||
if (publishDiscovery) {
|
if (publishDiscovery) {
|
||||||
pubMqttDiscovery();
|
pubMqttDiscovery();
|
||||||
}
|
}
|
||||||
@@ -1854,7 +1902,7 @@ void loop() {
|
|||||||
#endif
|
#endif
|
||||||
#ifdef ZgatewayBT
|
#ifdef ZgatewayBT
|
||||||
# ifdef ZmqttDiscovery
|
# ifdef ZmqttDiscovery
|
||||||
if (disc)
|
if (SYSConfig.discovery)
|
||||||
launchBTDiscovery(publishDiscovery);
|
launchBTDiscovery(publishDiscovery);
|
||||||
# endif
|
# endif
|
||||||
emptyBTQueue();
|
emptyBTQueue();
|
||||||
@@ -1885,7 +1933,7 @@ void loop() {
|
|||||||
#ifdef ZgatewayRTL_433
|
#ifdef ZgatewayRTL_433
|
||||||
RTL_433Loop();
|
RTL_433Loop();
|
||||||
# ifdef ZmqttDiscovery
|
# ifdef ZmqttDiscovery
|
||||||
if (disc)
|
if (SYSConfig.discovery)
|
||||||
launchRTL_433Discovery(publishDiscovery);
|
launchRTL_433Discovery(publishDiscovery);
|
||||||
# endif
|
# endif
|
||||||
#endif
|
#endif
|
||||||
@@ -2035,8 +2083,8 @@ String stateMeasures() {
|
|||||||
|
|
||||||
SYSdata["version"] = OMG_VERSION;
|
SYSdata["version"] = OMG_VERSION;
|
||||||
# ifdef ZmqttDiscovery
|
# ifdef ZmqttDiscovery
|
||||||
SYSdata["discovery"] = disc;
|
SYSdata["discovery"] = SYSConfig.discovery;
|
||||||
SYSdata["ohdiscovery"] = OpenHABDisc;
|
SYSdata["ohdiscovery"] = SYSConfig.ohdiscovery;
|
||||||
# endif
|
# endif
|
||||||
# if defined(ESP8266) || defined(ESP32)
|
# if defined(ESP8266) || defined(ESP32)
|
||||||
SYSdata["env"] = ENV_NAME;
|
SYSdata["env"] = ENV_NAME;
|
||||||
@@ -2521,8 +2569,8 @@ void MQTTtoSYS(char* topicOri, JsonObject& SYSdata) { // json object decoding
|
|||||||
}
|
}
|
||||||
# ifdef ZmqttDiscovery
|
# ifdef ZmqttDiscovery
|
||||||
if (SYSdata.containsKey("ohdiscovery") && SYSdata["ohdiscovery"].is<bool>()) {
|
if (SYSdata.containsKey("ohdiscovery") && SYSdata["ohdiscovery"].is<bool>()) {
|
||||||
OpenHABDisc = SYSdata["ohdiscovery"];
|
SYSConfig.ohdiscovery = SYSdata["ohdiscovery"];
|
||||||
Log.notice(F("OpenHAB discovery: %T" CR), OpenHABDisc);
|
Log.notice(F("OpenHAB discovery: %T" CR), SYSConfig.ohdiscovery);
|
||||||
stateMeasures();
|
stateMeasures();
|
||||||
}
|
}
|
||||||
# endif
|
# endif
|
||||||
@@ -2671,17 +2719,32 @@ void MQTTtoSYS(char* topicOri, JsonObject& SYSdata) { // json object decoding
|
|||||||
#ifdef ZmqttDiscovery
|
#ifdef ZmqttDiscovery
|
||||||
if (SYSdata.containsKey("discovery")) {
|
if (SYSdata.containsKey("discovery")) {
|
||||||
if (SYSdata["discovery"].is<bool>()) {
|
if (SYSdata["discovery"].is<bool>()) {
|
||||||
if (SYSdata["discovery"] == true && disc == false)
|
if (SYSdata["discovery"] == true && SYSConfig.discovery == false)
|
||||||
lastDiscovery = millis();
|
lastDiscovery = millis();
|
||||||
disc = SYSdata["discovery"];
|
SYSConfig.discovery = SYSdata["discovery"];
|
||||||
stateMeasures();
|
stateMeasures();
|
||||||
if (disc)
|
if (SYSConfig.discovery)
|
||||||
pubMqttDiscovery();
|
pubMqttDiscovery();
|
||||||
} else {
|
} else {
|
||||||
Log.error(F("Discovery command not a boolean" CR));
|
Log.error(F("Discovery command not a boolean" CR));
|
||||||
}
|
}
|
||||||
Log.notice(F("Discovery state: %T" CR), disc);
|
Log.notice(F("Discovery state: %T" CR), SYSConfig.discovery);
|
||||||
}
|
}
|
||||||
|
# ifdef ESP32
|
||||||
|
if (SYSdata.containsKey("save") && SYSdata["save"].as<bool>()) {
|
||||||
|
StaticJsonDocument<JSON_MSG_BUFFER> jsonBuffer;
|
||||||
|
JsonObject jo = jsonBuffer.to<JsonObject>();
|
||||||
|
jo["discovery"] = SYSConfig.discovery;
|
||||||
|
jo["ohdiscovery"] = SYSConfig.ohdiscovery;
|
||||||
|
// Save config into NVS (non-volatile storage)
|
||||||
|
String conf = "";
|
||||||
|
serializeJson(jsonBuffer, conf);
|
||||||
|
preferences.begin(Gateway_Short_Name, false);
|
||||||
|
int result = preferences.putString("SYSConfig", conf);
|
||||||
|
preferences.end();
|
||||||
|
Log.notice(F("SYS Config_save: %s, result: %d" CR), conf.c_str(), result);
|
||||||
|
}
|
||||||
|
# endif
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user