diff --git a/lib/TheengsUtils/TheengsUtils.cpp b/lib/TheengsUtils/TheengsUtils.cpp index 272d420..bb96be2 100644 --- a/lib/TheengsUtils/TheengsUtils.cpp +++ b/lib/TheengsUtils/TheengsUtils.cpp @@ -53,17 +53,25 @@ std::string TheengsUtils::processCert(const char* cert) { return certStr; } -std::string TheengsUtils::generateHash(const std::string& input) { - // Implementation depends on your hash function - // This is a placeholder - return "hash_placeholder"; -} +#ifdef ESP32 +# include "mbedtls/sha256.h" -bool TheengsUtils::cmpToMainTopic(const char* topicOri, const char* toAdd) { - // Implementation depends on mqtt_topic and gateway_name - // You might need to pass these as parameters or make them class members - return false; +std::string TheengsUtils::generateHash(const std::string& input) { + unsigned char hash[32]; + mbedtls_sha256((unsigned char*)input.c_str(), input.length(), hash, 0); + + char hashString[65]; // Room for null terminator + for (int i = 0; i < 32; ++i) { + sprintf(&hashString[i * 2], "%02x", hash[i]); + } + + return std::string(hashString); } +#else +std::string TheengsUtils::generateHash(const std::string& input) { + return "Not implemented for ESP8266"; +} +#endif unsigned long TheengsUtils::uptime() { static unsigned long lastUptime = 0; diff --git a/lib/TheengsUtils/TheengsUtils.h b/lib/TheengsUtils/TheengsUtils.h index e4f857e..90b520e 100644 --- a/lib/TheengsUtils/TheengsUtils.h +++ b/lib/TheengsUtils/TheengsUtils.h @@ -32,7 +32,6 @@ public: static String toString(uint64_t input); static std::string processCert(const char* cert); static std::string generateHash(const std::string& input); - static bool cmpToMainTopic(const char* topicOri, const char* toAdd); static unsigned long uptime(); static void syncNTP(); static int unixtimestamp(); diff --git a/main/ZactuatorFASTLED.ino b/main/ZactuatorFASTLED.ino index abb38a8..e7bfa50 100644 --- a/main/ZactuatorFASTLED.ino +++ b/main/ZactuatorFASTLED.ino @@ -103,7 +103,7 @@ void MQTTtoFASTLED(char* topicOri, JsonObject& jsonData) { //trc(topicOri); //number = (long)strtol(&datacallback[1], NULL, 16); - if (TheengsUtils::cmpToMainTopic(topicOri, subjectMQTTtoFASTLEDsetled)) { + if (cmpToMainTopic(topicOri, subjectMQTTtoFASTLEDsetled)) { Log.trace(F("MQTTtoFASTLED JSON analysis" CR)); int ledNr = jsonData["led"]; Log.notice(F("Led numero: %d" CR), ledNr); @@ -126,19 +126,19 @@ void MQTTtoFASTLED(char* topicOri, char* datacallback) { Log.trace(F("MQTTtoFASTLED: " CR)); currentLEDState = GENERAL; long number = 0; - if (TheengsUtils::cmpToMainTopic(topicOri, subjectMQTTtoFASTLED)) { + if (cmpToMainTopic(topicOri, subjectMQTTtoFASTLED)) { number = (long)strtol(&datacallback[1], NULL, 16); Log.notice(F("Number: %l" CR), number); for (int i = 0; i < FASTLED_NUM_LEDS; i++) { leds[i] = number; } FastLED.show(); - } else if (TheengsUtils::cmpToMainTopic(topicOri, subjectMQTTtoFASTLEDsetbrightness)) { + } else if (cmpToMainTopic(topicOri, subjectMQTTtoFASTLEDsetbrightness)) { number = (long)strtol(&datacallback[1], NULL, 16); Log.notice(F("Number: %l" CR), number); FastLED.setBrightness(number); FastLED.show(); - } else if (TheengsUtils::cmpToMainTopic(topicOri, subjectMQTTtoFASTLEDsetanimation)) { + } else if (cmpToMainTopic(topicOri, subjectMQTTtoFASTLEDsetanimation)) { String payload = datacallback; Log.notice(F("Datacallback: %s" CR), datacallback); if (strstr(datacallback, "fire") != NULL) { diff --git a/main/ZactuatorONOFF.ino b/main/ZactuatorONOFF.ino index 54a945a..7696de6 100644 --- a/main/ZactuatorONOFF.ino +++ b/main/ZactuatorONOFF.ino @@ -133,7 +133,7 @@ void setupONOFF() { # if jsonReceiving void MQTTtoONOFF(char* topicOri, JsonObject& ONOFFdata) { - if (TheengsUtils::cmpToMainTopic(topicOri, subjectMQTTtoONOFF)) { + if (cmpToMainTopic(topicOri, subjectMQTTtoONOFF)) { Log.trace(F("MQTTtoONOFF json data analysis" CR)); int boolSWITCHTYPE = ONOFFdata["cmd"] | 99; int gpio = ONOFFdata["gpio"] | ACTUATOR_ONOFF_GPIO; @@ -179,7 +179,7 @@ void MQTTtoONOFF(char* topicOri, JsonObject& ONOFFdata) { } } } - if (TheengsUtils::cmpToMainTopic(topicOri, subjectMQTTtoONOFFset)) { + if (cmpToMainTopic(topicOri, subjectMQTTtoONOFFset)) { Log.trace(F("MQTTtoONOFF json set" CR)); /* * Configuration modifications priorities: @@ -204,7 +204,7 @@ void MQTTtoONOFF(char* topicOri, JsonObject& ONOFFdata) { # if simpleReceiving void MQTTtoONOFF(char* topicOri, char* datacallback) { - if ((TheengsUtils::cmpToMainTopic(topicOri, subjectMQTTtoONOFF))) { + if ((cmpToMainTopic(topicOri, subjectMQTTtoONOFF))) { Log.trace(F("MQTTtoONOFF" CR)); char* endptr = NULL; long gpio = strtol(datacallback, &endptr, 10); diff --git a/main/ZactuatorPWM.ino b/main/ZactuatorPWM.ino index 18975fa..c5757a0 100644 --- a/main/ZactuatorPWM.ino +++ b/main/ZactuatorPWM.ino @@ -197,7 +197,7 @@ boolean PWMtoMQTT() { # if jsonReceiving void MQTTtoPWM(char* topicOri, JsonObject& jsonData) { - if (TheengsUtils::cmpToMainTopic(topicOri, subjectMQTTtoPWMset)) { + if (cmpToMainTopic(topicOri, subjectMQTTtoPWMset)) { Log.trace(F("MQTTtoPWM JSON analysis" CR)); // Parse the target value for each channel int modifiedChannelBits = 0; @@ -230,7 +230,7 @@ void MQTTtoPWM(char* topicOri, JsonObject& jsonData) { } } fadeIsComplete = false; // The values will start to change during PWMLoop - } else if (TheengsUtils::cmpToMainTopic(topicOri, subjectMQTTtoPWMcalibrate)) { + } else if (cmpToMainTopic(topicOri, subjectMQTTtoPWMcalibrate)) { // Read the optional calibration data for each channel for (int i = 0; i < kNumChannels; ++i) { char key[64]; diff --git a/main/ZactuatorSomfy.ino b/main/ZactuatorSomfy.ino index fa224cd..ecae060 100644 --- a/main/ZactuatorSomfy.ino +++ b/main/ZactuatorSomfy.ino @@ -50,7 +50,7 @@ void setupSomfy() { # if jsonReceiving void MQTTtoSomfy(char* topicOri, JsonObject& jsonData) { - if (TheengsUtils::cmpToMainTopic(topicOri, subjectMQTTtoSomfy)) { + if (cmpToMainTopic(topicOri, subjectMQTTtoSomfy)) { Log.trace(F("MQTTtoSomfy json data analysis" CR)); float txFrequency = jsonData["frequency"] | RFConfig.frequency; # ifdef ZradioCC1101 // set Receive off and Transmitt on diff --git a/main/ZboardM5.ino b/main/ZboardM5.ino index d42fa69..276f717 100644 --- a/main/ZboardM5.ino +++ b/main/ZboardM5.ino @@ -117,7 +117,7 @@ void loopM5() { } void MQTTtoM5(char* topicOri, JsonObject& M5data) { // json object decoding - if (TheengsUtils::cmpToMainTopic(topicOri, subjectMQTTtoM5set)) { + if (cmpToMainTopic(topicOri, subjectMQTTtoM5set)) { Log.trace(F("MQTTtoM5 json set" CR)); // Log display set between M5 lcd (true) and serial monitor (false) if (M5data.containsKey("log-lcd")) { diff --git a/main/ZcommonRF.ino b/main/ZcommonRF.ino index ca439bf..3bbdd2b 100644 --- a/main/ZcommonRF.ino +++ b/main/ZcommonRF.ino @@ -301,7 +301,7 @@ void RFConfig_load() { } void MQTTtoRFset(char* topicOri, JsonObject& RFdata) { - if (TheengsUtils::cmpToMainTopic(topicOri, subjectMQTTtoRFset)) { + if (cmpToMainTopic(topicOri, subjectMQTTtoRFset)) { Log.trace(F("MQTTtoRF json set" CR)); /* diff --git a/main/ZdisplaySSD1306.ino b/main/ZdisplaySSD1306.ino index a3f8cac..db0d3a4 100644 --- a/main/ZdisplaySSD1306.ino +++ b/main/ZdisplaySSD1306.ino @@ -154,7 +154,7 @@ Handler for mqtt commands sent to the module */ void MQTTtoSSD1306(char* topicOri, JsonObject& SSD1306data) { // json object decoding bool success = false; - if (TheengsUtils::cmpToMainTopic(topicOri, subjectMQTTtoSSD1306set)) { + if (cmpToMainTopic(topicOri, subjectMQTTtoSSD1306set)) { Log.trace(F("MQTTtoSSD1306 json set" CR)); // properties if (SSD1306data.containsKey("onstate")) { diff --git a/main/Zgateway2G.ino b/main/Zgateway2G.ino index 0f027a5..3c8b44b 100644 --- a/main/Zgateway2G.ino +++ b/main/Zgateway2G.ino @@ -100,7 +100,7 @@ void MQTTto2G(char* topicOri, char* datacallback) { String data = datacallback; String topic = topicOri; - if (TheengsUtils::cmpToMainTopic(topicOri, subjectMQTTto2G)) { + if (cmpToMainTopic(topicOri, subjectMQTTto2G)) { Log.trace(F("MQTTto2G data analysis" CR)); // 2G DATA ANALYSIS String phone_number = ""; @@ -128,7 +128,7 @@ void MQTTto2G(char* topicOri, char* datacallback) { # if jsonReceiving void MQTTto2G(char* topicOri, JsonObject& SMSdata) { - if (TheengsUtils::cmpToMainTopic(topicOri, subjectMQTTto2G)) { + if (cmpToMainTopic(topicOri, subjectMQTTto2G)) { const char* sms = SMSdata["message"]; const char* phone = SMSdata["phone"]; Log.trace(F("MQTTto2G json data analysis" CR)); diff --git a/main/ZgatewayBLEConnect.h b/main/ZgatewayBLEConnect.h index 406cac1..cedbd77 100644 --- a/main/ZgatewayBLEConnect.h +++ b/main/ZgatewayBLEConnect.h @@ -91,5 +91,14 @@ public: bool processActions(std::vector& actions) override; }; +class SBCU_connect : public zBLEConnect { + uint8_t m_notifyVal; + void notifyCB(NimBLERemoteCharacteristic* pChar, uint8_t* pData, size_t length, bool isNotify); + +public: + SBCU_connect(NimBLEAddress& addr) : zBLEConnect(addr) {} + bool processActions(std::vector& actions) override; +}; + #endif //ESP32 #endif //zBLEConnect_h diff --git a/main/ZgatewayBLEConnect.ino b/main/ZgatewayBLEConnect.ino index 70af3b6..c3b2e80 100644 --- a/main/ZgatewayBLEConnect.ino +++ b/main/ZgatewayBLEConnect.ino @@ -609,5 +609,94 @@ bool SBBT_connect::processActions(std::vector& actions) { return result; } +/*-----------------------SBCU HANDLING-----------------------*/ +void SBCU_connect::notifyCB(NimBLERemoteCharacteristic* pChar, uint8_t* pData, size_t length, bool isNotify) { + if (m_taskHandle == nullptr) { + return; // unexpected notification + } + if (!BTProcessLock) { + Log.trace(F("Callback from %s characteristic" CR), pChar->getUUID().toString().c_str()); + + if (length) { + m_notifyVal = *pData; + } else { + Log.notice(F("Invalid notification data" CR)); + return; + } + } else { + Log.trace(F("Callback process canceled by BTProcessLock" CR)); + } + + xTaskNotifyGive(m_taskHandle); +} + +bool SBCU_connect::processActions(std::vector& actions) { + NimBLEUUID serviceUUID("cba20d00-224d-11e6-9fb8-0002a5d5c51b"); + NimBLEUUID charUUID("cba20002-224d-11e6-9fb8-0002a5d5c51b"); + NimBLEUUID notifyCharUUID("cba20003-224d-11e6-9fb8-0002a5d5c51b"); + static byte CLOSE[] = {0x57, 0x0f, 0x45, 0x01, 0x01, 0x01, 0x64}; + static byte OPEN[] = {0x57, 0x0f, 0x45, 0x01, 0x01, 0x01, 0x00}; + static byte MOVE[] = {0x57, 0x0f, 0x45, 0x01, 0x01, 0x01, 0x00}; + static byte STOP[] = {0x57, 0x0f, 0x45, 0x01, 0x01, 0x00, 0x01}; + + bool result = false; + if (actions.size() > 0) { + for (auto& it : actions) { + if (NimBLEAddress(it.addr) == m_pClient->getPeerAddress()) { + NimBLERemoteCharacteristic* pChar = getCharacteristic(serviceUUID, charUUID); + NimBLERemoteCharacteristic* pNotifyChar = getCharacteristic(serviceUUID, notifyCharUUID); + int value = -1; + if (it.value_type == BLE_VAL_INT) { + value = std::stoi(it.value); + } + if (it.write && pChar && pNotifyChar) { + Log.trace(F("processing Switchbot %s" CR), it.value.c_str()); + if (pNotifyChar->subscribe(true, + std::bind(&SBCU_connect::notifyCB, + this, std::placeholders::_1, std::placeholders::_2, + std::placeholders::_3, std::placeholders::_4), + true)) { + if (it.value == "open" && it.value_type == BLE_VAL_STRING) { + result = pChar->writeValue(OPEN, 7, false); + value = 100; + } else if (it.value == "close" && it.value_type == BLE_VAL_STRING) { + result = pChar->writeValue(CLOSE, 7, false); + value = 0; + } else if (it.value == "stop" && it.value_type == BLE_VAL_STRING) { + result = pChar->writeValue(STOP, 7, false); + } else if (it.value_type == BLE_VAL_INT) { + if (value >= 0 && value <= 100) { + byte posByte = (byte)value; + MOVE[6] = posByte; + result = pChar->writeValue(MOVE, 7, false); + } + } + + if (result) { + m_taskHandle = xTaskGetCurrentTaskHandle(); + if (ulTaskNotifyTake(pdTRUE, pdMS_TO_TICKS(BLE_CNCT_TIMEOUT)) == pdFALSE) { + m_taskHandle = nullptr; + } + result = m_notifyVal == 0x01; + } + } + } + + it.complete = result; + if (result || it.ttl <= 1) { + StaticJsonDocument BLEdataBuffer; + JsonObject BLEdata = BLEdataBuffer.to(); + BLEdata["id"] = it.addr; + BLEdata["position"] = value; + buildTopicFromId(BLEdata, subjectBTtoMQTT); + enqueueJsonObject(BLEdata, QueueSemaphoreTimeOutTask); + } + } + } + } + + return result; +} + # endif //ZgatewayBT #endif //ESP32 diff --git a/main/ZgatewayBT.ino b/main/ZgatewayBT.ino index 085ea94..6604140 100644 --- a/main/ZgatewayBT.ino +++ b/main/ZgatewayBT.ino @@ -1474,7 +1474,7 @@ void MQTTtoBTAction(JsonObject& BTdata) { } void MQTTtoBT(char* topicOri, JsonObject& BTdata) { // json object decoding - if (TheengsUtils::cmpToMainTopic(topicOri, subjectMQTTtoBTset)) { + if (cmpToMainTopic(topicOri, subjectMQTTtoBTset)) { Log.trace(F("MQTTtoBT json set" CR)); // Black list & white list set @@ -1512,7 +1512,7 @@ void MQTTtoBT(char* topicOri, JsonObject& BTdata) { // json object decoding // Load config from json if available BTConfig_fromJson(BTdata); - } else if (TheengsUtils::cmpToMainTopic(topicOri, subjectMQTTtoBT)) { + } else if (cmpToMainTopic(topicOri, subjectMQTTtoBT)) { KnownBTActions(BTdata); MQTTtoBTAction(BTdata); } diff --git a/main/ZgatewayIR.ino b/main/ZgatewayIR.ino index e47d1f7..7ec4878 100644 --- a/main/ZgatewayIR.ino +++ b/main/ZgatewayIR.ino @@ -163,7 +163,7 @@ bool sendIdentifiedProtocol(const char* protocol_name, uint64_t data, const char # if jsonReceiving void MQTTtoIR(char* topicOri, JsonObject& IRdata) { - if (TheengsUtils::cmpToMainTopic(topicOri, subjectMQTTtoIR)) { + if (cmpToMainTopic(topicOri, subjectMQTTtoIR)) { Log.trace(F("MQTTtoIR json" CR)); uint64_t data = IRdata["value"]; const char* raw = IRdata["raw"]; diff --git a/main/ZgatewayLORA.ino b/main/ZgatewayLORA.ino index 116ee3f..33546c3 100644 --- a/main/ZgatewayLORA.ino +++ b/main/ZgatewayLORA.ino @@ -484,7 +484,7 @@ void LORAtoMQTT() { # if jsonReceiving void MQTTtoLORA(char* topicOri, JsonObject& LORAdata) { // json object decoding - if (TheengsUtils::cmpToMainTopic(topicOri, subjectMQTTtoLORA)) { + if (cmpToMainTopic(topicOri, subjectMQTTtoLORA)) { Log.trace(F("MQTTtoLORA json" CR)); const char* message = LORAdata["message"]; const char* hex = LORAdata["hex"]; @@ -512,7 +512,7 @@ void MQTTtoLORA(char* topicOri, JsonObject& LORAdata) { // json object decoding Log.error(F("MQTTtoLORA Fail json" CR)); } } - if (TheengsUtils::cmpToMainTopic(topicOri, subjectMQTTtoLORAset)) { + if (cmpToMainTopic(topicOri, subjectMQTTtoLORAset)) { Log.trace(F("MQTTtoLORA json set" CR)); /* * Configuration modifications priorities: @@ -536,7 +536,7 @@ void MQTTtoLORA(char* topicOri, JsonObject& LORAdata) { // json object decoding # endif # if simpleReceiving void MQTTtoLORA(char* topicOri, char* LORAarray) { // json object decoding - if (TheengsUtils::cmpToMainTopic(topicOri, subjectMQTTtoLORA)) { + if (cmpToMainTopic(topicOri, subjectMQTTtoLORA)) { LoRa.beginPacket(); LoRa.print(LORAarray); LoRa.endPacket(); diff --git a/main/ZgatewayPilight.ino b/main/ZgatewayPilight.ino index 1d0bb84..70d7e23 100644 --- a/main/ZgatewayPilight.ino +++ b/main/ZgatewayPilight.ino @@ -154,7 +154,7 @@ void PilighttoMQTT() { } void MQTTtoPilight(char* topicOri, JsonObject& Pilightdata) { - if (TheengsUtils::cmpToMainTopic(topicOri, subjectMQTTtoPilightProtocol)) { + if (cmpToMainTopic(topicOri, subjectMQTTtoPilightProtocol)) { bool success = false; if (Pilightdata.containsKey("reset")) { rf.limitProtocols(rf.availableProtocols()); @@ -194,7 +194,7 @@ void MQTTtoPilight(char* topicOri, JsonObject& Pilightdata) { pub(subjectGTWPilighttoMQTT, "{\"Status\": \"Error\"}"); // Fail feedback Log.error(F("MQTTtoPilightProtocol Fail json" CR)); } - } else if (TheengsUtils::cmpToMainTopic(topicOri, subjectMQTTtoPilight)) { + } else if (cmpToMainTopic(topicOri, subjectMQTTtoPilight)) { const char* message = Pilightdata["message"]; Log.notice(F("MQTTtoPilight message: %s" CR), message); const char* protocol = Pilightdata["protocol"]; diff --git a/main/ZgatewayRF.ino b/main/ZgatewayRF.ino index 30e6e51..baa4606 100644 --- a/main/ZgatewayRF.ino +++ b/main/ZgatewayRF.ino @@ -193,7 +193,7 @@ void MQTTtoRF(char* topicOri, char* datacallback) { valueBITS = (topic.substring(pos3, pos3 + 2)).toInt(); } - if ((TheengsUtils::cmpToMainTopic(topicOri, subjectMQTTtoRF)) && (valuePRT == 0) && (valuePLSL == 0) && (valueBITS == 0)) { + if ((cmpToMainTopic(topicOri, subjectMQTTtoRF)) && (valuePRT == 0) && (valuePLSL == 0) && (valueBITS == 0)) { Log.trace(F("MQTTtoRF dflt" CR)); mySwitch.setProtocol(1, 350); mySwitch.send(data, 24); @@ -225,7 +225,7 @@ void MQTTtoRF(char* topicOri, char* datacallback) { # if jsonReceiving void MQTTtoRF(char* topicOri, JsonObject& RFdata) { // json object decoding - if (TheengsUtils::cmpToMainTopic(topicOri, subjectMQTTtoRF)) { + if (cmpToMainTopic(topicOri, subjectMQTTtoRF)) { Log.trace(F("MQTTtoRF json" CR)); uint64_t data = RFdata["value"]; if (data != 0) { diff --git a/main/ZgatewayRF2.ino b/main/ZgatewayRF2.ino index 9097948..cea3217 100644 --- a/main/ZgatewayRF2.ino +++ b/main/ZgatewayRF2.ino @@ -243,7 +243,7 @@ void MQTTtoRF2(char* topicOri, char* datacallback) { # if jsonReceiving void MQTTtoRF2(char* topicOri, JsonObject& RF2data) { // json object decoding - if (TheengsUtils::cmpToMainTopic(topicOri, subjectMQTTtoRF2)) { + if (cmpToMainTopic(topicOri, subjectMQTTtoRF2)) { Log.trace(F("MQTTtoRF2 json" CR)); int boolSWITCHTYPE = RF2data["switchType"] | 99; bool success = false; diff --git a/main/ZgatewayRFM69.ino b/main/ZgatewayRFM69.ino index fb6dad9..b5bafa0 100644 --- a/main/ZgatewayRFM69.ino +++ b/main/ZgatewayRFM69.ino @@ -172,7 +172,7 @@ bool RFM69toMQTT(void) { # if simpleReceiving void MQTTtoRFM69(char* topicOri, char* datacallback) { - if (TheengsUtils::cmpToMainTopic(topicOri, subjectMQTTtoRFM69)) { + if (cmpToMainTopic(topicOri, subjectMQTTtoRFM69)) { Log.trace(F("MQTTtoRFM69 data analysis" CR)); char data[RF69_MAX_DATA_LEN + 1]; memcpy(data, (void*)datacallback, RF69_MAX_DATA_LEN); @@ -201,7 +201,7 @@ void MQTTtoRFM69(char* topicOri, char* datacallback) { # endif # if jsonReceiving void MQTTtoRFM69(char* topicOri, JsonObject& RFM69data) { - if (TheengsUtils::cmpToMainTopic(topicOri, subjectMQTTtoRFM69)) { + if (cmpToMainTopic(topicOri, subjectMQTTtoRFM69)) { const char* data = RFM69data["data"]; Log.trace(F("MQTTtoRFM69 json data analysis" CR)); if (data) { diff --git a/main/ZgatewaySERIAL.ino b/main/ZgatewaySERIAL.ino index f2c08f4..ed5320b 100644 --- a/main/ZgatewaySERIAL.ino +++ b/main/ZgatewaySERIAL.ino @@ -243,7 +243,7 @@ void sendMQTTfromNestedJson(JsonVariant obj, char* topic, int level, int maxLeve # endif void XtoSERIAL(const char* topicOri, JsonObject& SERIALdata) { - if (TheengsUtils::cmpToMainTopic(topicOri, subjectXtoSERIAL) || SYSConfig.serial) { + if (cmpToMainTopic(topicOri, subjectXtoSERIAL) || SYSConfig.serial) { Log.trace(F(" MQTTtoSERIAL" CR)); const char* prefix = SERIALdata["prefix"] | SERIALPre; const char* postfix = SERIALdata["postfix"] | SERIALPost; diff --git a/main/ZgatewaySRFB.ino b/main/ZgatewaySRFB.ino index df0640d..b3fceea 100644 --- a/main/ZgatewaySRFB.ino +++ b/main/ZgatewaySRFB.ino @@ -245,7 +245,7 @@ void MQTTtoSRFB(char* topicOri, JsonObject& SRFBdata) { // RF DATA ANALYSIS const char* raw = SRFBdata["raw"]; int valueRPT = SRFBdata["repeat"] | 1; - if (TheengsUtils::cmpToMainTopic(topicOri, subjectMQTTtoSRFB)) { + if (cmpToMainTopic(topicOri, subjectMQTTtoSRFB)) { Log.trace(F("MQTTtoSRFB json" CR)); if (raw) { // send raw in priority when defined in the json Log.trace(F("MQTTtoSRFB raw ok" CR)); diff --git a/main/ZwebUI.ino b/main/ZwebUI.ino index 5ddb635..98ed55a 100644 --- a/main/ZwebUI.ino +++ b/main/ZwebUI.ino @@ -1686,7 +1686,7 @@ void WebUILoop() { void MQTTtoWebUI(char* topicOri, JsonObject& WebUIdata) { // json object decoding bool success = false; - if (TheengsUtils::cmpToMainTopic(topicOri, subjectMQTTtoWebUIset)) { + if (cmpToMainTopic(topicOri, subjectMQTTtoWebUIset)) { WEBUI_TRACE_LOG(F("MQTTtoWebUI json set" CR)); // properties if (WebUIdata.containsKey("displayMetric")) { diff --git a/main/main.ino b/main/main.ino index 246b397..2e38c27 100644 --- a/main/main.ino +++ b/main/main.ino @@ -820,6 +820,22 @@ void SYSConfig_save() { void SYSConfig_save() {} #endif +bool cmpToMainTopic(const char* topicOri, const char* toAdd) { + // Is string "" equal to ""? + // Compare first part with first chunk + if (strncmp(topicOri, mqtt_topic, strlen(mqtt_topic)) != 0) + return false; + // Move pointer of sizeof chunk + topicOri += strlen(mqtt_topic); + // And so on... + if (strncmp(topicOri, gateway_name, strlen(gateway_name)) != 0) + return false; + topicOri += strlen(gateway_name); + if (strncmp(topicOri, toAdd, strlen(toAdd)) != 0) + return false; + return true; +} + #if defined(ESP32) void SYSConfig_load() { StaticJsonDocument jsonBuffer; @@ -3148,7 +3164,7 @@ void readCntParameters(int index) { #endif void MQTTtoSYS(char* topicOri, JsonObject& SYSdata) { // json object decoding - if (TheengsUtils::cmpToMainTopic(topicOri, subjectMQTTtoSYSset)) { + if (cmpToMainTopic(topicOri, subjectMQTTtoSYSset)) { bool restartESP = false; Log.trace(F("MQTTtoSYS json" CR)); if (SYSdata.containsKey("cmd")) {