[SERIAL] Enable SERIAL to X communication (#2068)

Add Serial as a communication layer so as to transmit data to/from serial
Enable discovery of BT sensors through serial
Add serial heartbeat

Change discovery principle for interval and intervalacts, keep them always discovered and deactivate adaptivescan when changed. Instead of removing their discovery when adaptive scan is activated

Increase JSON_MSG_BUFFER_MAX as we are now using const char* and it requires more memory for Arduino Json Deserialization

Co-authored-by: Florian <1technophile@users.noreply.github.com>
This commit is contained in:
FlorianandFlorian authored and GitHub committed 2024-09-26 06:55:26 -05:00
1 parent a89ff43900
commit 3187ed6154
52 files changed
+588 -459

No files matched your search

+254 -215
View File
@@ -56,12 +56,15 @@ ReceivedSignal receivedSignal[] = {{0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0
# define struct_size (sizeof(receivedSignal) / sizeof(ReceivedSignal))
#endif
//Time used to wait for an interval before checking system measures
//Time used to wait for an interval before measures
unsigned long timer_sys_measures = 0;
// Time used to wait before system checkings
unsigned long timer_sys_checks = 0;
// First Start of offline mode modules
bool firstStart = true;
#define ARDUINOJSON_USE_LONG_LONG 1
#define ARDUINOJSON_ENABLE_STD_STRING 1
@@ -247,12 +250,12 @@ char ota_hostname[MAC_NAME_MAX_LEN];
int failure_number_ntwk = 0; // number of failure connecting to network
int failure_number_mqtt = 0; // number of failure connecting to MQTT
unsigned long timer_led_measures = 0;
static unsigned long last_ota_activity_millis = 0;
// Global struct to store live SYS configuration data
SYSConfig_s SYSConfig;
bool failSafeMode = false;
bool ProcessLock = true; // Process lock when we want to use a critical function like OTA for example
static bool mqttSetupPending = true;
static int cnt_index = CNT_DEFAULT_INDEX;
@@ -265,7 +268,6 @@ static int cnt_index = CNT_DEFAULT_INDEX;
# include <nvs_flash.h>
bool BTProcessLock = true; // Process lock when we want to use a critical function like OTA for example, at start to true so as to wait for critical functions to be performed before BLE start
bool ProcessLock = false; // Process lock when we want to use a critical function like OTA for example
# if !defined(NO_INT_TEMP_READING)
// ESP32 internal temperature reading
@@ -372,9 +374,9 @@ void Config_update(JsonObject& data, const char* key, T& var) {
if (data.containsKey(key)) {
if (var != data[key].as<T>()) {
var = data[key].as<T>();
Log.notice(F("Config %s changed: %T" CR), key, data[key].as<T>());
Log.notice(F("Config %s changed to: %T" CR), key, data[key].as<T>());
} else {
Log.notice(F("Config %s unchanged: %T" CR), key, data[key].as<T>());
Log.notice(F("Config %s unchanged, currently: %T" CR), key, data[key].as<T>());
}
}
}
@@ -385,7 +387,7 @@ void Config_update(JsonObject& data, const char* key, T& var) {
*/
bool jsonDispatch(JsonObject& data) {
bool res = false;
if (data.containsKey("origin")) {
if (data.containsKey("origin") || data.containsKey("topic")) {
GatewayState previousGatewayState = gatewayState;
gatewayState = GatewayState::PROCESSING;
#if message_UTCtimestamp == true
@@ -394,26 +396,23 @@ bool jsonDispatch(JsonObject& data) {
#if message_unixtimestamp == true
data["unixtime"] = TheengsUtils::unixtimestamp();
#endif
pubWebUI((char*)data["origin"].as<const char*>(), data);
if (data.containsKey("origin")) {
pubWebUI((char*)data["origin"].as<const char*>(), data);
}
if (SYSConfig.mqtt && !SYSConfig.offline) {
res = pub((char*)data["origin"].as<const char*>(), data);
#ifdef ZgatewayBT
if (data.containsKey("distance")) {
String topic = String(mqtt_topic) + BTConfig.presenceTopic + String(gateway_name);
Log.trace(F("Pub HA Presence %s" CR), topic.c_str());
res = pub_custom_topic((char*)topic.c_str(), data, false);
}
#endif
res = pub(data);
}
#ifdef ZgatewaySERIAL
if (SYSConfig.serial) {
XtoSERIAL("", data);
res = true;
char jsonStr[JSON_MSG_BUFFER_MAX];
serializeJson(data, jsonStr);
receivingDATA("", jsonStr);
res = true; // Return the state from receivingDATA
}
#endif
gatewayState = previousGatewayState; // restore the previous state
} else {
Log.error(F("No origin in JSON filtered" CR));
Log.error(F("No origin or topic in JSON filtered" CR));
gatewayState = GatewayState::ERROR;
}
return res;
@@ -568,22 +567,31 @@ bool pub(const char* topicori, const char* payload, bool retainFlag) {
* @param topicori suffix to add on default MQTT Topic
* @param data The Json Object that represents the message
*/
bool pub(const char* topicori, JsonObject& data) {
bool pub(JsonObject& data) {
bool res = false;
bool ret = sensor_Retain;
if (data.containsKey("retain") && data["retain"].is<bool>()) {
ret = data["retain"];
data.remove("retain");
}
if (data.containsKey("origin")) { // temporary, in the future use this instead of topicori
data.remove("origin");
}
if (data.size() == 0) {
Log.error(F("Empty JSON, not published" CR));
gatewayState = GatewayState::ERROR;
return res;
}
String topic = String(mqtt_topic) + String(gateway_name) + String(topicori);
String topic;
if (data.containsKey("origin") && data["origin"].is<const char*>()) {
topic = String(mqtt_topic) + String(gateway_name) + String(data["origin"].as<const char*>());
data.remove("origin");
} else if (data.containsKey("topic") && data["topic"].is<const char*>()) {
topic = data["topic"].as<const char*>();
data.remove("topic");
} else {
Log.error(F("No topic or origin in JSON, not published" CR));
gatewayState = GatewayState::ERROR;
return res;
}
#if valueAsATopic
# ifdef ZgatewayPilight
String value = data["value"];
@@ -641,19 +649,6 @@ bool pub(const char* topicori, const char* payload) {
return pubMQTT(topic, payload);
}
/**
* @brief Publish the payload on the topic with a retention
*
* @param topic The topic where to publish
* @param data The Json Object that represents the message
* @param retain true if you what a retain
*/
bool pub_custom_topic(const char* topic, JsonObject& data, boolean retain) {
String buffer = "";
serializeJson(data, buffer);
return pubMQTT(topic, buffer.c_str(), retain);
}
/**
* @brief Low level MQTT functions without retain
*
@@ -855,6 +850,8 @@ void SYSConfig_save() {}
#endif
bool cmpToMainTopic(const char* topicOri, const char* toAdd) {
if (strcmp(topicOri, toAdd) == 0)
return true;
// Is string "<mqtt_topic><gateway_name><toAdd>" equal to "<topicOri>"?
// Compare first part with first chunk
if (strncmp(topicOri, mqtt_topic, strlen(mqtt_topic)) != 0)
@@ -1019,7 +1016,10 @@ void setupMQTT() {
}
}
# endif
# ifdef ZgatewayBT
BTProcessLock = !BTConfig.enabled; // Release BLE processes at start if enabled
# endif
ProcessLock = false; // Release the loop process
displayPrint("MQTT connected");
Log.notice(F("Connected to broker" CR));
gatewayState = GatewayState::BROKER_CONNECTED;
@@ -1041,7 +1041,6 @@ void setupMQTT() {
cnt_parameters_backup.reset();
ESPRestart(7);
}
handle_autodiscovery();
};
@@ -1113,16 +1112,16 @@ void setupMQTT() {
}
};
mqtt->subscribe(String(mqtt_topic) + gateway_name + subjectMQTTtoX, receivingMQTT, mqtt_max_payload_size);
mqtt->subscribe(String(mqtt_topic) + gateway_name + subjectMQTTtoX, receivingDATA, mqtt_max_payload_size);
# ifdef ZgatewayRF
// 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
mqtt->subscribe(subjectMultiGTWRF, receivingMQTT, mqtt_max_payload_size);
mqtt->subscribe(subjectMultiGTWRF, receivingDATA, mqtt_max_payload_size);
# endif
# ifdef ZgatewayIR
// 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
mqtt->subscribe(subjectMultiGTWIR, receivingMQTT, mqtt_max_payload_size);
mqtt->subscribe(subjectMultiGTWIR, receivingDATA, mqtt_max_payload_size);
# endif
mqtt->begin();
@@ -1314,8 +1313,9 @@ void setup() {
SYSConfig_init();
SYSConfig_load();
if (SYSConfig.offline)
if (SYSConfig.offline) {
gatewayState = GatewayState::OFFLINE;
}
#ifdef LED_ADDRESSABLE
# ifdef LED_ADDRESSABLE_PIN1
@@ -1369,11 +1369,7 @@ void setup() {
gatewayState = GatewayState::ERROR;
}
#endif
#ifdef ESP32
//esp_task_wdt_init(GeneralTimeOut, true); //enable panic so ESP32 restarts
#endif
/*
The 2 modules below are not connection dependent so start them before the connectivity functions
Note that the ONOFF module need to start after the RN8209 so that the overCurrent function is launched after the setup of the sensor
*/
#ifdef ZsensorRN8209
@@ -1384,6 +1380,10 @@ void setup() {
setupONOFF();
modules.add(ZactuatorONOFF);
#endif
#ifdef ZgatewaySERIAL
setupSERIAL();
modules.add(ZgatewaySERIAL);
#endif
#if defined(ESP32) && defined(USE_BLUFI)
if (SYSConfig.blufi)
@@ -1580,10 +1580,6 @@ void setup() {
setupDHT();
modules.add(ZsensorDHT);
#endif
#ifdef ZgatewaySERIAL
setupSERIAL();
modules.add(ZgatewaySERIAL);
#endif
#ifdef ZsensorSHTC3
setupSHTC3();
#endif
@@ -1774,7 +1770,8 @@ void ESPRestart(byte reason) {
jsondata["reason"] = reason;
jsondata["retain"] = true;
jsondata["uptime"] = uptime();
pub(subjectLOGtoMQTT, jsondata);
jsondata["origin"] = subjectLOGtoMQTT;
pub(jsondata); // We go to MQTT bypassing the queue to ensure the message is sent
// Clean queue
while (!jsonQueue.empty()) {
jsonQueue.pop();
@@ -2472,19 +2469,34 @@ void loop() {
#ifdef ESP8266
updateAndHandleLEDsTask(); // With ESP8266 we need to update the LEDs in the loop
#endif
if (!SYSConfig.offline) {
if (!SYSConfig.offline) { // Online mode
if (mqttSetupPending) {
setupMQTT();
mqttSetupPending = false;
}
// When online the MQTT connection callback release the processes
} else { // Offline mode
if (firstStart) {
#ifdef ZgatewaySERIAL
if (SYSConfig.serial && isSerialReady()) {
# ifdef ZgatewayBT
BTProcessLock = !BTConfig.enabled;
# endif
ProcessLock = false;
firstStart = false;
}
#else
ProcessLock = false;
firstStart = false;
#endif
}
}
unsigned long now = millis();
// Switch off of the LED after TimeLedON
if (now > (timer_led_measures + (TimeLedON * 1000))) {
timer_led_measures = millis();
}
#ifdef ZgatewaySERIAL // Serial is a module and a communication layer so it's always processed
SERIALtoX();
#endif
if (ethConnected || WiFi.status() == WL_CONNECTED) {
if (ethConnected && WiFi.status() == WL_CONNECTED) {
@@ -2492,6 +2504,17 @@ void loop() {
}
ArduinoOTA.handle();
failure_number_ntwk = 0;
if (now > (timer_sys_checks + (TimeBetweenCheckingSYS * 1000)) || !timer_sys_checks) {
#if message_UTCtimestamp || message_unixtimestamp
TheengsUtils::syncNTP();
#endif
if (!timer_sys_checks) { // Update check at start up only
#if defined(ESP32) && defined(MQTT_HTTPS_FW_UPDATE)
checkForUpdates();
#endif
}
timer_sys_checks = millis();
}
#if defined(ZwebUI) && defined(ESP32)
WebUILoop();
#endif
@@ -2505,43 +2528,6 @@ void loop() {
if (!discovery_republish_on_reconnect && SYSConfig.discovery && (now > lastDiscovery + DiscoveryAutoOffTimer))
SYSConfig.discovery = false;
#endif
if (now > (timer_sys_measures + (TimeBetweenReadingSYS * 1000)) || !timer_sys_measures) {
timer_sys_measures = millis();
stateMeasures();
#ifdef ZgatewayBT
stateBTMeasures(false);
#endif
#ifdef ZactuatorONOFF
stateONOFFMeasures();
#endif
#ifdef ZdisplaySSD1306
stateSSD1306Display();
#endif
#ifdef ZgatewayLORA
stateLORAMeasures();
#endif
#if defined(ZgatewayRTL_433) || defined(ZgatewayPilight) || defined(ZgatewayRF) || defined(ZgatewayRF2) || defined(ZactuatorSomfy)
stateRFMeasures();
#endif
#if defined(ZwebUI) && defined(ESP32)
stateWebUIStatus();
#endif
}
if (now > (timer_sys_checks + (TimeBetweenCheckingSYS * 1000)) || !timer_sys_checks) {
#if message_UTCtimestamp || message_unixtimestamp
TheengsUtils::syncNTP();
#endif
if (!timer_sys_checks) { // Update check at start up only
#if defined(ESP32) && defined(MQTT_HTTPS_FW_UPDATE)
checkForUpdates();
#endif
#ifdef ZgatewayBT
BTProcessLock = !BTConfig.enabled; // Release BLE processes at start if enabled
#endif
}
timer_sys_checks = millis();
}
}
} else if (!SYSConfig.offline) { // disconnected from network
Log.warning(F("Network disconnected" CR));
@@ -2552,128 +2538,149 @@ void loop() {
gatewayState = GatewayState::NTWK_CONNECTED;
}
}
// Function that doesn't need an active connection
#if defined(ZboardM5STICKC) || defined(ZboardM5STICKCP) || defined(ZboardM5STACK) || defined(ZboardM5TOUGH)
loopM5();
if (!ProcessLock) {
if (now > (timer_sys_measures + (TimeBetweenReadingSYS * 1000)) || !timer_sys_measures) {
timer_sys_measures = millis();
stateMeasures();
#ifdef ZgatewayBT
stateBTMeasures(false);
#endif
#if defined(ZdisplaySSD1306)
loopSSD1306();
#ifdef ZactuatorONOFF
stateONOFFMeasures();
#endif
#ifdef ZsensorBME280
MeasureTempHumAndPressure(); //Addon to measure Temperature, Humidity, Pressure and Altitude with a Bosch BME280/BMP280
#endif
#ifdef ZsensorHTU21
MeasureTempHum(); //Addon to measure Temperature, Humidity, of a HTU21 sensor
#endif
#ifdef ZsensorLM75
MeasureTemp(); //Addon to measure Temperature of an LM75 sensor
#endif
#ifdef ZsensorAHTx0
MeasureAHTTempHum(); //Addon to measure Temperature, Humidity, of an 'AHTx0' sensor
#endif
#ifdef ZsensorHCSR04
MeasureDistance(); //Addon to measure distance with a HC-SR04
#endif
#ifdef ZsensorBH1750
MeasureLightIntensity(); //Addon to measure Light Intensity with a BH1750
#endif
#ifdef ZsensorMQ2
MeasureGasMQ2();
#endif
#ifdef ZsensorTEMT6000
MeasureLightIntensityTEMT6000();
#endif
#ifdef ZsensorTSL2561
MeasureLightIntensityTSL2561();
#endif
#ifdef ZsensorC37_YL83_HMRD
MeasureC37_YL83_HMRDWater(); //Addon for leak detection with a C-37 YL-83 H-MRD
#endif
#ifdef ZsensorDHT
MeasureTempAndHum(); //Addon to measure the temperature with a DHT
#endif
#ifdef ZsensorSHTC3
MeasureTempAndHum(); //Addon to measure the temperature with a DHT
#endif
#ifdef ZsensorDS1820
MeasureDS1820Temp(); //Addon to measure the temperature with DS1820 sensor(s)
#endif
#ifdef ZsensorINA226
MeasureINA226();
#endif
#ifdef ZsensorHCSR501
MeasureHCSR501();
#endif
#ifdef ZsensorGPIOInput
MeasureGPIOInput();
#endif
#ifdef ZsensorGPIOKeyCode
MeasureGPIOKeyCode();
#endif
#ifdef ZsensorADC
MeasureADC(); //Addon to measure the analog value of analog pin
#endif
#ifdef ZsensorTouch
MeasureTouch();
#ifdef ZdisplaySSD1306
stateSSD1306Display();
#endif
#ifdef ZgatewayLORA
LORAtoMQTT();
stateLORAMeasures();
#endif
#if defined(ZgatewayRTL_433) || defined(ZgatewayPilight) || defined(ZgatewayRF) || defined(ZgatewayRF2) || defined(ZactuatorSomfy)
stateRFMeasures();
#endif
#if defined(ZwebUI) && defined(ESP32)
stateWebUIStatus();
#endif
}
// Function that doesn't need an active connection
#if defined(ZboardM5STICKC) || defined(ZboardM5STICKCP) || defined(ZboardM5STACK) || defined(ZboardM5TOUGH)
loopM5();
#endif
#if defined(ZdisplaySSD1306)
loopSSD1306();
#endif
#ifdef ZsensorBME280
MeasureTempHumAndPressure(); //Addon to measure Temperature, Humidity, Pressure and Altitude with a Bosch BME280/BMP280
#endif
#ifdef ZsensorHTU21
MeasureTempHum(); //Addon to measure Temperature, Humidity, of a HTU21 sensor
#endif
#ifdef ZsensorLM75
MeasureTemp(); //Addon to measure Temperature of an LM75 sensor
#endif
#ifdef ZsensorAHTx0
MeasureAHTTempHum(); //Addon to measure Temperature, Humidity, of an 'AHTx0' sensor
#endif
#ifdef ZsensorHCSR04
MeasureDistance(); //Addon to measure distance with a HC-SR04
#endif
#ifdef ZsensorBH1750
MeasureLightIntensity(); //Addon to measure Light Intensity with a BH1750
#endif
#ifdef ZsensorMQ2
MeasureGasMQ2();
#endif
#ifdef ZsensorTEMT6000
MeasureLightIntensityTEMT6000();
#endif
#ifdef ZsensorTSL2561
MeasureLightIntensityTSL2561();
#endif
#ifdef ZsensorC37_YL83_HMRD
MeasureC37_YL83_HMRDWater(); //Addon for leak detection with a C-37 YL-83 H-MRD
#endif
#ifdef ZsensorDHT
MeasureTempAndHum(); //Addon to measure the temperature with a DHT
#endif
#ifdef ZsensorSHTC3
MeasureTempAndHum(); //Addon to measure the temperature with a DHT
#endif
#ifdef ZsensorDS1820
MeasureDS1820Temp(); //Addon to measure the temperature with DS1820 sensor(s)
#endif
#ifdef ZsensorINA226
MeasureINA226();
#endif
#ifdef ZsensorHCSR501
MeasureHCSR501();
#endif
#ifdef ZsensorGPIOInput
MeasureGPIOInput();
#endif
#ifdef ZsensorGPIOKeyCode
MeasureGPIOKeyCode();
#endif
#ifdef ZsensorADC
MeasureADC(); //Addon to measure the analog value of analog pin
#endif
#ifdef ZsensorTouch
MeasureTouch();
#endif
#ifdef ZgatewayLORA
LORAtoX();
# ifdef ZmqttDiscovery
if (SYSConfig.discovery)
launchLORADiscovery(false);
if (SYSConfig.discovery)
launchLORADiscovery(false);
# endif
#endif
#ifdef ZgatewayRF
RFtoMQTT();
RFtoX();
#endif
#ifdef ZgatewayRF2
RF2toMQTT();
RF2toX();
#endif
#ifdef ZgatewayWeatherStation
ZgatewayWeatherStationtoMQTT();
ZgatewayWeatherStationtoX();
#endif
#ifdef ZgatewayGFSunInverter
ZgatewayGFSunInverterMQTT();
ZgatewayGFSunInverterMQTT();
#endif
#ifdef ZgatewayPilight
PilighttoMQTT();
PilighttoX();
#endif
#ifdef ZgatewayBT
# ifdef ZmqttDiscovery
if (SYSConfig.discovery)
launchBTDiscovery(false);
if (SYSConfig.discovery)
launchBTDiscovery(false);
# endif
#endif
#ifdef ZgatewaySRFB
SRFBtoMQTT();
SRFBtoX();
#endif
#ifdef ZgatewayIR
IRtoMQTT();
IRtoX();
#endif
#ifdef Zgateway2G
if (_2GtoMQTT())
Log.trace(F("2GtoMQTT OK" CR));
if (_2GtoX())
Log.trace(F("2GtoMQTT OK" CR));
#endif
#ifdef ZgatewayRFM69
if (RFM69toMQTT())
Log.trace(F("RFM69toMQTT OK" CR));
#endif
#ifdef ZgatewaySERIAL
SERIALtoMQTT();
if (RFM69toX())
Log.trace(F("RFM69toMQTT OK" CR));
#endif
#ifdef ZactuatorFASTLED
FASTLEDLoop();
FASTLEDLoop();
#endif
#ifdef ZactuatorPWM
PWMLoop();
PWMLoop();
#endif
#ifdef ZgatewayRTL_433
RTL_433Loop();
RTL_433Loop();
# ifdef ZmqttDiscovery
if (SYSConfig.discovery)
launchRTL_433Discovery(false);
if (SYSConfig.discovery)
launchRTL_433Discovery(false);
# endif
#endif
}
// Empty the queue
emptyQueue();
// Sleep if ready
@@ -2749,6 +2756,8 @@ String stateMeasures() {
#if USE_BLUFI
SYSdata["blufi"] = SYSConfig.blufi;
#endif
SYSdata["mqtt"] = SYSConfig.mqtt;
SYSdata["serial"] = SYSConfig.serial;
#ifdef ZmqttDiscovery
SYSdata["disc"] = SYSConfig.discovery;
SYSdata["ohdisc"] = SYSConfig.ohdiscovery;
@@ -2839,6 +2848,7 @@ String stateMeasures() {
String output;
serializeJson(SYSdata, output);
Log.notice(F("SYS json: %s" CR), output.c_str());
return output;
}
@@ -2896,18 +2906,47 @@ bool isAduplicateSignal(uint64_t value) {
}
#endif
void receivingMQTT(char* topicOri, char* datacallback) {
void receivingDATA(const char* topicOri, const char* datacallback) {
std::string strTopicOri = topicOri;
StaticJsonDocument<JSON_MSG_BUFFER_MAX> jsonBuffer;
JsonObject jsondata = jsonBuffer.to<JsonObject>();
auto error = deserializeJson(jsonBuffer, datacallback);
if (error) {
DeserializationError error = deserializeJson(jsonBuffer, datacallback);
if (error || jsondata.isNull()) {
Log.error(F("deserialize MQTT data failed: %s" CR), error.c_str());
gatewayState = GatewayState::ERROR;
return;
}
if (topicOri == nullptr || strcmp(topicOri, "") == 0) {
if (jsondata.containsKey("target") && jsondata["target"].is<const char*>()) {
strTopicOri = jsondata["target"].as<const char*>();
Log.trace(F("BUS Msg target: %s" CR), strTopicOri.c_str());
} else if (jsondata.containsKey("origin") && jsondata["origin"].is<const char*>()) {
strTopicOri = jsondata["origin"].as<const char*>();
Log.trace(F("BUS Msg origin: %s" CR), strTopicOri.c_str());
}
} else {
#if defined(SecondaryModule) // Redirect certain commands to Serial
String topicSerial = String(mqtt_topic) + String(gateway_name) + subjectMQTTtoSERIAL;
const char* cSecondaryModule = SecondaryModule;
if (strcmp(cSecondaryModule, "BT") == 0) {
if (cmpToMainTopic(topicOri, subjectMQTTtoBTset)) {
strTopicOri = topicSerial.c_str();
jsondata["target"] = subjectMQTTtoBTset;
} else if (cmpToMainTopic(topicOri, subjectMQTTtoBT)) {
strTopicOri = topicSerial.c_str();
jsondata["target"] = subjectMQTTtoBT;
}
}
if (cmpToMainTopic(topicOri, subjectMQTTtoSYSsetSecondaryModule)) {
strTopicOri = topicSerial.c_str();
jsondata["target"] = subjectMQTTtoSYSsetSecondaryModule;
}
#endif
Log.trace(F("MQTT Msg topic: %s" CR), strTopicOri.c_str());
}
#if defined(ZgatewayRF) || defined(ZgatewayIR) || defined(ZgatewaySRFB) || defined(ZgatewayWeatherStation)
if (strstr(topicOri, subjectMultiGTWKey) != NULL) { // storing received value so as to avoid publishing this value if it has been already sent by this or another OpenMQTTGateway
if (strstr(strTopicOri.c_str(), subjectMultiGTWKey) != NULL) { // storing received value so as to avoid publishing this value if it has been already sent by this or another OpenMQTTGateway
uint64_t data = jsondata.isNull() ? strtoull(datacallback, NULL, 10) : jsondata["value"];
if (data != 0 && !isAduplicateSignal(data)) {
storeSignalValue(data);
@@ -2922,95 +2961,95 @@ void receivingMQTT(char* topicOri, char* datacallback) {
//Log.notice(F("[ MQTT->OMG ]: %s" CR), buffer.c_str());
#ifdef ZgatewayPilight // ZgatewayPilight is only defined with json publishing due to its numerous parameters
MQTTtoPilight(topicOri, jsondata);
XtoPilight(strTopicOri.c_str(), jsondata);
#endif
#if defined(ZgatewayRTL_433) || defined(ZgatewayPilight) || defined(ZgatewayRF) || defined(ZgatewayRF2) || defined(ZactuatorSomfy)
MQTTtoRFset(topicOri, jsondata);
XtoRFset(strTopicOri.c_str(), jsondata);
#endif
#if jsonReceiving
# ifdef ZgatewayLORA
MQTTtoLORA(topicOri, jsondata);
XtoLORA(strTopicOri.c_str(), jsondata);
# endif
# ifdef ZgatewayRF
MQTTtoRF(topicOri, jsondata);
XtoRF(strTopicOri.c_str(), jsondata);
# endif
# ifdef ZgatewayRF2
MQTTtoRF2(topicOri, jsondata);
XtoRF2(strTopicOri.c_str(), jsondata);
# endif
# ifdef Zgateway2G
MQTTto2G(topicOri, jsondata);
Xto2G(strTopicOri.c_str(), jsondata);
# endif
# ifdef ZgatewaySRFB
MQTTtoSRFB(topicOri, jsondata);
XtoSRFB(strTopicOri.c_str(), jsondata);
# endif
# ifdef ZgatewayIR
MQTTtoIR(topicOri, jsondata);
XtoIR(strTopicOri.c_str(), jsondata);
# endif
# ifdef ZgatewayRFM69
MQTTtoRFM69(topicOri, jsondata);
XtoRFM69(strTopicOri.c_str(), jsondata);
# endif
# ifdef ZgatewayBT
MQTTtoBT(topicOri, jsondata);
XtoBT(strTopicOri.c_str(), jsondata);
# endif
# ifdef ZactuatorFASTLED
MQTTtoFASTLED(topicOri, jsondata);
XtoFASTLED(strTopicOri.c_str(), jsondata);
# endif
# ifdef ZactuatorPWM
MQTTtoPWM(topicOri, jsondata);
XtoPWM(strTopicOri.c_str(), jsondata);
# endif
# if defined(ZboardM5STICKC) || defined(ZboardM5STICKCP) || defined(ZboardM5STACK) || defined(ZboardM5TOUGH)
MQTTtoM5(topicOri, jsondata);
XtoM5(strTopicOri.c_str(), jsondata);
# endif
# if defined(ZdisplaySSD1306)
MQTTtoSSD1306(topicOri, jsondata);
XtoSSD1306(strTopicOri.c_str(), jsondata);
# endif
# ifdef ZactuatorONOFF
MQTTtoONOFF(topicOri, jsondata);
XtoONOFF(strTopicOri.c_str(), jsondata);
# endif
# ifdef ZactuatorSomfy
MQTTtoSomfy(topicOri, jsondata);
XtoSomfy(strTopicOri.c_str(), jsondata);
# endif
# ifdef ZgatewaySERIAL
XtoSERIAL(topicOri, jsondata);
XtoSERIAL(strTopicOri.c_str(), jsondata);
# endif
# ifdef MQTT_HTTPS_FW_UPDATE
MQTTHttpsFWUpdate(topicOri, jsondata);
MQTTHttpsFWUpdate(strTopicOri.c_str(), jsondata);
# endif
# if defined(ZwebUI) && defined(ESP32)
MQTTtoWebUI(topicOri, jsondata);
XtoWebUI(strTopicOri.c_str(), jsondata);
# endif
#endif
MQTTtoSYS(topicOri, jsondata);
XtoSYS(strTopicOri.c_str(), jsondata);
} else { // not a json object --> simple decoding
#if simpleReceiving
# ifdef ZgatewayLORA
MQTTtoLORA(topicOri, datacallback);
XtoLORA(strTopicOri.c_str(), datacallback);
# endif
# ifdef ZgatewayRF
MQTTtoRF(topicOri, datacallback);
XtoRF(strTopicOri.c_str(), datacallback);
# endif
# ifdef ZgatewayRF315
MQTTtoRF315(topicOri, datacallback);
XtoRF315(strTopicOri.c_str(), datacallback);
# endif
# ifdef ZgatewayRF2
MQTTtoRF2(topicOri, datacallback);
XtoRF2(strTopicOri.c_str(), datacallback);
# endif
# ifdef Zgateway2G
MQTTto2G(topicOri, datacallback);
Xto2G(strTopicOri.c_str(), datacallback);
# endif
# ifdef ZgatewaySRFB
MQTTtoSRFB(topicOri, datacallback);
XtoSRFB(strTopicOri.c_str(), datacallback);
# endif
# ifdef ZgatewayRFM69
MQTTtoRFM69(topicOri, datacallback);
XtoRFM69(strTopicOri.c_str(), datacallback);
# endif
# ifdef ZactuatorFASTLED
MQTTtoFASTLED(topicOri, datacallback);
XtoFASTLED(strTopicOri.c_str(), datacallback);
# endif
#endif
#ifdef ZactuatorONOFF
MQTTtoONOFF(topicOri, datacallback);
XtoONOFF(strTopicOri.c_str(), datacallback);
#endif
}
}
@@ -3093,7 +3132,7 @@ bool checkForUpdates() {
# include <ESP8266httpUpdate.h>
# endif
void MQTTHttpsFWUpdate(char* topicOri, JsonObject& HttpsFwUpdateData) {
void MQTTHttpsFWUpdate(const char* topicOri, JsonObject& HttpsFwUpdateData) {
if (strstr(topicOri, subjectMQTTtoSYSupdate) != NULL) {
const char* version = HttpsFwUpdateData["version"] | "latest";
if (version && ((strlen(version) != strlen(OMG_VERSION)) || strcmp(version, OMG_VERSION) != 0)) {
@@ -3276,12 +3315,12 @@ void readCntParameters(int index) {
jsondata["mqtt_pass"] = generateHash(cnt_parameters_array[index].mqtt_pass);
jsondata["mqtt_secure"] = cnt_parameters_array[index].isConnectionSecure;
jsondata["mqtt_validate"] = cnt_parameters_array[index].isCertValidate;
pub(subjectSYStoMQTT, jsondata);
jsondata["origin"] = subjectSYStoMQTT;
enqueueJsonObject(jsondata);
}
#endif
void MQTTtoSYS(char* topicOri, JsonObject& SYSdata) { // json object decoding
void XtoSYS(const char* topicOri, JsonObject& SYSdata) { // json object decoding
if (cmpToMainTopic(topicOri, subjectMQTTtoSYSset)) {
bool restartESP = false;
bool publishState = false;