Skip to content

Commit

Permalink
v6.10 Support for Meter Plus and minor fixes (#57)
Browse files Browse the repository at this point in the history
* Fixi wifi print message and compiler error on mac (#56)

adding this to the meter plus support release

* v6.10 Support for Meter Plus and minor fixes

Co-authored-by: Vin W <[email protected]>
  • Loading branch information
devWaves and vin-w authored Feb 28, 2022
1 parent 7da9c75 commit e9bd280
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 18 deletions.
19 changes: 12 additions & 7 deletions Arduino IDE Files/SwitchBot-BLE2MQTT-ESP32.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -505,7 +506,7 @@ static std::map<std::string, int> 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
Expand Down Expand Up @@ -1379,6 +1380,8 @@ bool writeSettings(NimBLEAdvertisedDevice* advDeviceToUse) {
}
return true;
}

return false;
}

/** Define a class to handle the callbacks when advertisments are received */
Expand All @@ -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<std::string, NimBLEAdvertisedDevice*>::iterator itY;
if ((shouldMQTTUpdateForDevice(advStr) || isContactDevice(deviceName) || isMotionDevice(deviceName)) && initialScanComplete) {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -505,7 +506,7 @@ static std::map<std::string, int> 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
Expand Down Expand Up @@ -1379,6 +1380,8 @@ bool writeSettings(NimBLEAdvertisedDevice* advDeviceToUse) {
}
return true;
}

return false;
}

/** Define a class to handle the callbacks when advertisments are received */
Expand All @@ -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<std::string, NimBLEAdvertisedDevice*>::iterator itY;
if ((shouldMQTTUpdateForDevice(advStr) || isContactDevice(deviceName) || isMotionDevice(deviceName)) && initialScanComplete) {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
11 changes: 7 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

<a href="https://www.buymeacoffee.com/devwaves" target="_blank"><img src="https://www.buymeacoffee.com/assets/img/custom_images/orange_img.png" alt="Buy Me A Coffee" style="height: 41px !important;width: 174px !important;box-shadow: 0px 3px 2px 0px rgba(190, 190, 190, 0.5) !important;-webkit-box-shadow: 0px 3px 2px 0px rgba(190, 190, 190, 0.5) !important;" ></a>


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
Expand Down

0 comments on commit e9bd280

Please sign in to comment.