diff --git a/Arduino IDE Files/SwitchBot-BLE2MQTT-ESP32.ino b/Arduino IDE Files/SwitchBot-BLE2MQTT-ESP32.ino index 6b20354..06159c5 100644 --- a/Arduino IDE Files/SwitchBot-BLE2MQTT-ESP32.ino +++ b/Arduino IDE Files/SwitchBot-BLE2MQTT-ESP32.ino @@ -11,13 +11,14 @@ ** I do not know where performance will be affected by number of devices ** ** This is an unofficial SwitchBot integration. User takes full responsibility with the use of this code ** - v6.9 + v6.10 - Created: on Feb 14 2022 + Created: on Feb 27 2022 Author: devWaves Contributions from: HardcoreWR + vin-w based off of the work from https://github.com/combatistor/ESP32_BLE_Gateway @@ -505,7 +506,7 @@ static std::map botWaitBetweenControlTimes = { /* ANYTHING CHANGED BELOW THIS COMMENT MAY RESULT IN ISSUES - ALL SETTINGS TO CONFIGURE ARE ABOVE THIS LINE */ -static const String versionNum = "v6.9"; +static const String versionNum = "v6.10"; /* Server Index Page @@ -1379,6 +1380,8 @@ bool writeSettings(NimBLEAdvertisedDevice* advDeviceToUse) { } return true; } + + return false; } /** Define a class to handle the callbacks when advertisments are received */ @@ -1401,7 +1404,7 @@ class AdvertisedDeviceCallbacks: public NimBLEAdvertisedDeviceCallbacks { if (itS != allSwitchbotsOpp.end()) { std::string deviceName = itS->second.c_str(); - if ((advertisedDevice->isAdvertisingService(NimBLEUUID("cba20d00-224d-11e6-9fb8-0002a5d5c51b"))) || isContactDevice(deviceName) || isMotionDevice(deviceName)) + if ((advertisedDevice->isAdvertisingService(NimBLEUUID("cba20d00-224d-11e6-9fb8-0002a5d5c51b"))) || isContactDevice(deviceName) || isMotionDevice(deviceName) || isMeterDevice(deviceName)) { std::map::iterator itY; if ((shouldMQTTUpdateForDevice(advStr) || isContactDevice(deviceName) || isMotionDevice(deviceName)) && initialScanComplete) { @@ -2112,6 +2115,9 @@ void setup () { } forceRescan = false; pinMode (LED_PIN, OUTPUT); + + Serial.begin(115200); + // Connect to WiFi network WiFi.begin(ssid, password); if (printSerialOutputForDebugging) { @@ -2336,7 +2342,6 @@ void setup () { } botsSimulatedONHoldTimes = botsSimulatedONHoldTimesTemp; - Serial.begin(115200); Serial.println("Switchbot ESP32 starting..."); if (!printSerialOutputForDebugging) { Serial.println("Set printSerialOutputForDebugging = true to see more Serial output"); @@ -3149,7 +3154,7 @@ bool processQueue() { bool shouldContinue = true; int count = 0; bool sendInitial = true; - while (sendInitial || (lastCommandWasBusy && retryBotOnBusy) || retryBotSetNoResponse && noResponse && (count <= noResponseRetryAmount)) { + while (sendInitial || (lastCommandWasBusy && retryBotOnBusy) || (retryBotSetNoResponse && noResponse && (count <= noResponseRetryAmount))) { sendInitial = false; count++; shouldContinue = true; @@ -3499,7 +3504,7 @@ void rescanMQTT(std::string payload) { else { int value = docIn["sec"]; String secString = String(value); - if (secString.c_str() != "") { + if (strlen(secString.c_str()) != 0) { bool isNum = is_number(secString.c_str()); if (isNum) { int aVal; diff --git a/PlatformIO Files/SwitchBot-BLE2MQTT-ESP32/src/SwitchBot-BLE2MQTT-ESP32.cpp b/PlatformIO Files/SwitchBot-BLE2MQTT-ESP32/src/SwitchBot-BLE2MQTT-ESP32.cpp index fb77d7d..305bca0 100644 --- a/PlatformIO Files/SwitchBot-BLE2MQTT-ESP32/src/SwitchBot-BLE2MQTT-ESP32.cpp +++ b/PlatformIO Files/SwitchBot-BLE2MQTT-ESP32/src/SwitchBot-BLE2MQTT-ESP32.cpp @@ -11,13 +11,14 @@ ** I do not know where performance will be affected by number of devices ** ** This is an unofficial SwitchBot integration. User takes full responsibility with the use of this code ** - v6.9 + v6.10 - Created: on Feb 14 2022 + Created: on Feb 27 2022 Author: devWaves Contributions from: HardcoreWR + vin-w based off of the work from https://github.com/combatistor/ESP32_BLE_Gateway @@ -505,7 +506,7 @@ static std::map botWaitBetweenControlTimes = { /* ANYTHING CHANGED BELOW THIS COMMENT MAY RESULT IN ISSUES - ALL SETTINGS TO CONFIGURE ARE ABOVE THIS LINE */ -static const String versionNum = "v6.9"; +static const String versionNum = "v6.10"; /* Server Index Page @@ -1379,6 +1380,8 @@ bool writeSettings(NimBLEAdvertisedDevice* advDeviceToUse) { } return true; } + + return false; } /** Define a class to handle the callbacks when advertisments are received */ @@ -1401,7 +1404,7 @@ class AdvertisedDeviceCallbacks: public NimBLEAdvertisedDeviceCallbacks { if (itS != allSwitchbotsOpp.end()) { std::string deviceName = itS->second.c_str(); - if ((advertisedDevice->isAdvertisingService(NimBLEUUID("cba20d00-224d-11e6-9fb8-0002a5d5c51b"))) || isContactDevice(deviceName) || isMotionDevice(deviceName)) + if ((advertisedDevice->isAdvertisingService(NimBLEUUID("cba20d00-224d-11e6-9fb8-0002a5d5c51b"))) || isContactDevice(deviceName) || isMotionDevice(deviceName) || isMeterDevice(deviceName)) { std::map::iterator itY; if ((shouldMQTTUpdateForDevice(advStr) || isContactDevice(deviceName) || isMotionDevice(deviceName)) && initialScanComplete) { @@ -2112,6 +2115,9 @@ void setup () { } forceRescan = false; pinMode (LED_PIN, OUTPUT); + + Serial.begin(115200); + // Connect to WiFi network WiFi.begin(ssid, password); if (printSerialOutputForDebugging) { @@ -2336,7 +2342,6 @@ void setup () { } botsSimulatedONHoldTimes = botsSimulatedONHoldTimesTemp; - Serial.begin(115200); Serial.println("Switchbot ESP32 starting..."); if (!printSerialOutputForDebugging) { Serial.println("Set printSerialOutputForDebugging = true to see more Serial output"); @@ -3149,7 +3154,7 @@ bool processQueue() { bool shouldContinue = true; int count = 0; bool sendInitial = true; - while (sendInitial || (lastCommandWasBusy && retryBotOnBusy) || retryBotSetNoResponse && noResponse && (count <= noResponseRetryAmount)) { + while (sendInitial || (lastCommandWasBusy && retryBotOnBusy) || (retryBotSetNoResponse && noResponse && (count <= noResponseRetryAmount))) { sendInitial = false; count++; shouldContinue = true; @@ -3499,7 +3504,7 @@ void rescanMQTT(std::string payload) { else { int value = docIn["sec"]; String secString = String(value); - if (secString.c_str() != "") { + if (strlen(secString.c_str()) != 0) { bool isNum = is_number(secString.c_str()); if (isNum) { int aVal; diff --git a/README.md b/README.md index 5de9e12..f0107a4 100644 --- a/README.md +++ b/README.md @@ -4,16 +4,19 @@ Switchbot local control using ESP32. no switchbot hub used/required. works with https://github.com/devWaves/SwitchBot-MQTT-BLE-ESP32 -v6.9 +v6.10 -Created: on Feb 14 2022 - Author: devWaves +Created: on Feb 27 2022 + + Author: + devWaves Buy Me A Coffee Contributions from: - HardcoreWR + - HardcoreWR + - vin-w Code can be installed using Arduino IDE OR using Visual Studio Code PlatformIO - For Arduino IDE - Use only the SwitchBot-BLE2MQTT-ESP32.ino file