devWaves / SwitchBot-MQTT-BLE-ESP32

Allows for multiple SwitchBot bots and curtains to be controlled via MQTT sent to ESP32. ESP32 will send BLE commands to switchbots and return MQTT responses to the broker. Also supports Temperature, Motion, Contact sensors
MIT License
549 stars 68 forks source link

Slow reaction time every now and then #5

Closed Pierre-33 closed 3 years ago

Pierre-33 commented 3 years ago

First, many thanks for this great project, I'm doing my first Arduino step with it :)

I only use the push command on a SwitchBot and it works like a charm most of the time, but every now and then it takes a very long time (something like a minute) between the MQTT command and the actual reaction of the SwitchBot.

The SwitchBot is literally next to the esp32, so it shouldn't be related to Bluetooth range.

It's my first time using MQTT as well so I can't be sure if this delay is caused by the broker (I'm using the one provided with Home Assistant) or by the esp32, but if I would guess, I would say a very long process is triggered every now and then on the esp32 which makes it unresponsive for a few minutes.

Is that a know behavior?

devWaves commented 3 years ago

sorry I don't have this issue. With the latest version it works all the time for me with the following conditions.....

if you have autoRescan=true it will rescan every X seconds. once a scan starts it needs to finish in order to make a BLE command call. If the bot is right next to it though, the scan should finish fast. You need at least one full scan (the initial scan) in order to control bots

if you are only using the bots (like me) make sure the meter and curtain map lists are empty or the inside is commented out (otherwise the scan will be looking forever for a non existing MAC). Make sure the bot list only has valid mac addresses

in version 1.5 you will now see the onboard LED on the esp32 turn on while it is busy (with the default settings). If the LED is on, that means the esp32 is busy. If the LED is not on, a control command should be somewhat instant. (not the same as the power LED, that is always on)

In a future version I am looking at prioritizing control commands over scanning. I had issues last time I tried. A rescan deletes all previous linked BLE devices, if a scan doesnt finish and you try to control it, a reference is missing

make sure your initialScan value is large enough that it will always find all devices, otherwise it is similar to an incomplete scan. initialScan can be a large number, it will only scan for as long a needed. The default 120 should be plenty if the esp32 is close

the autoRescan is good for the temp sensors. The bots dont need it as much and it can be set to false which should give faster control

devWaves commented 3 years ago

if you also have the actual switchbot hub, I can't say if that causes any issues or not. It is possible a switchbot hub could lock the bot temporarily while connected for some reason, not allowing other connections. But I have no idea

Pierre-33 commented 3 years ago

Thanks for your quick answer! :)

if you are only using the bots (like me) make sure the meter and curtain map lists are empty or the inside is commented out (otherwise the scan will be looking forever for a non existing MAC). Make sure the bot list only has valid Mac addresses

That should be it! I replace switchbotone with my switch bot and left switchbottwo with it's fake Mac address, I'll try that asap, but I have good hope it should fix my issue :)

in version 1.5 you will now see the onboard LED on the esp32 turn on while it is busy (with the default settings). If the LED is on, that means the esp32 is busy. If the LED is not on, a control command should be somewhat instant. (not the same as the power LED, that is always on)

That should be really helpful. On a side note, it would be really helpful as well to have the configuration in a separate file (like a .h") if you plan to release regular update :)