Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switchbot detection #1288

Closed
xanderificnl opened this issue Oct 16, 2022 · 61 comments
Closed

Switchbot detection #1288

xanderificnl opened this issue Oct 16, 2022 · 61 comments

Comments

@xanderificnl
Copy link

N: Scan begin
N: Send on /BTtoMQTT/C6C752663CBF msg {"id":"C6:C7:52:66:3C:BF","mac_type":1,"manufacturerdata":"6909c6c752663cbf850f049243","rssi":-63}
N: Found 0 devices, scan number 61 end
N: Scan begin
N: Found 1 devices, scan number N62 en: d
Device detected: C6:C7:52:66:3C:BF

Describe the bug
OpenMQTTGateway isn't recognizing my Switchbot Meter Plus properly.

To Reproduce

  • Flash several different ESP32

Expected behavior
For it to recognize my Switchbot Meter Plus.

Environment (please complete the following information):

  • esp32dev-ble from binary (site)
  • esp32dev-ble-cont from binary (site)
  • esp32dev-ble self-built

latest versions

Additional context

Pinging @DigiH / issue #20

The switchbot is C6:C7:52:66:3C:BF

In essense the monitor just says this:

Device detected: C6:C7:52:66:3C:BF
N: Scan begin
N: Send on /BTtoMQTT/C6C752663CBF msg {"id":"C6:C7:52:66:3C:BF","mac_type":1,"manufacturerdata":"6909c6c752663cbf850f049243","rssi":-58}
N: Found 0 devices, scan number 373 end

and when I press the bluetooth button on the meter:

N: Device detected: C6:C7:52:66:3C:BF
N: Send on /BTtoMQTT/C6C752663CBF msg {"id":"C6:C7:52:66:3C:BF","mac_type":1,"manufacturerdata":"6909c6c752663cbf880b06924c","rssi":-32,"servicedata":"4980e406924c","servicedatauuid":"0xfd3d"}
N: Found 1 devices, scan number 441 end

N: Device detected: 5E:3C:86:96:DD:A7
N: Send on /BTtoMQTT/C6C752663CBF msg {"id":"C6:C7:52:66:3C:BF","mac_type":1,"manufacturerdata":"6909c6c752663cbf8d0f099242","rssi":-37}
N: Send on /BTtoMQTT/5E3C8696DDA7 msg {"id":"5E:3C:86:96:DD:A7","mac_type":1,"manufacturerdata":"4c0010055f1c12f757","rssi":-60,"txpower":12}
N: Found 0 devices, scan number 527 end

-snip-

N: Device detected: C6:C7:52:66:3C:BF
N: Send on /BTtoMQTT/C6C752663CBF msg {"id":"C6:C7:52:66:3C:BF","mac_type":1,"manufacturerdata":"6909c6c752663cbf8e0f099245","rssi":-26,"servicedata":"49c0e4099245","servicedatauuid":"0xfd3d"}
N: Found 1 devices, scan number 590 end

N: Scan begin
N: Send on /BTtoMQTT/C6C752663CBF msg {"id":"C6:C7:52:66:3C:BF","mac_type":1,"manufacturerdata":"6909c6c752663cbf8f0f099242","rssi":-25}
N: Found 0 devices, scan number 612 end
N: Send on /SYStoMQTT msg {"uptime":700,"version":"v0.9.16","freemem":134236,"mqttport":"1883","mqttsecure":false,"freestack":4780,"rssi":-37,"SSID":"XiFi","BSSID":"08:55:31:D6:79:49","ip":"192.168.88.231","mac":"34:86:5D:FD:4F:08","lowpowermode":0,"btqblck":0,"btqsum":382,"btqsnd":330,"btqavg":1.157576,"interval":0,"scanbcnct":10,"scnct":592,"modules":["BT"]}

On MQTT:

# home/OpenMQTTGateway_ESP32_BLE_C/BTtoMQTT/C6C752663CBF
{
  "id": "C6:C7:52:66:3C:BF",
  "mac_type": 1,
  "manufacturerdata": "6909c6c752663cbf8d0f099242",
  "rssi": -36,
  "servicedata": "49c0e4099242",
  "servicedatauuid": "0xfd3d"
}
@xanderificnl
Copy link
Author

xanderificnl commented Oct 16, 2022

Here we go, the first actual scan (I saw) with data:

N: Device detected: 71:3A:F0:36:95:D0
N: Send on /BTtoMQTT/C6C752663CBF msg {"id":"C6:C7:52:66:3C:BF","mac_type":1,"rssi":-25,"brand":"SwitchBot","model":"Meter (Plus)","model_id":"THX1/W230150X","tempc":19,"tempf":66.2,"hum":66,"batt":100}
N: Send on /BTtoMQTT/713AF03695D0 msg {"id":"71:3A:F0:36:95:D0","mac_type":1,"manufacturerdata":"4c0010056e1cc98704","rssi":-91,"txpower":8}
N: Found 0 devices, scan number 802 end

: Device detected: C6:C7:52:66:3C:BF
N: Scan begin
N: Send on /BTtoMQTT/C6C752663CBF msg {"id":"C6:C7:52:66:3C:BF","mac_type":1,"manufacturerdata":"6909c6c752663cbf910f009342","rssi":-24}
N: Found 0 devices, scan number 822 end

@xanderificnl
Copy link
Author

xanderificnl commented Oct 16, 2022

Might the issue be that I assumed the meter readings should stay whereas they are only advertised when announced by the switchbot?

I feel absurdly stupid. Yes - the readings are all there. It was just my assumption that was wrong!

@DigiH
Copy link
Collaborator

DigiH commented Oct 16, 2022

I feel absurdly stupid. Yes - the readings are all there. It was just my assumption that was wrong!

No, that is not the case!

There are too little proper readings from your SwitchBot Meter, and while you might have mistaken things a bit with the readings staying - they will once you incorporate the MQTT messages into a controller backend like Home Assistand, OpenHAB etc. - and looking at your data the decoder doesn't decode all the messages.

Do you have the SwitchBot Meter in Add Mode by any chance? If so can you switch it into Normal Mode?

It is the "servicedata" whioch holds the information about the temperature, humidity and battery level, so you should never see any undecoded messages from your SwitchBot Meter which includes "servicedata".

If you still do, even after having the device in Normal Mode, please continue to post these messages here, as they then do not adhere to the SwitchBot documented encoding, but might be some not yet documented decoding of newly released Meters.

Then we can add those decoding guidelines to then Theengs Decoder for more frequent correctly decoded messages.

@DigiH DigiH reopened this Oct 16, 2022
@xanderificnl
Copy link
Author

It was a pebkac (problem exists between keyboard and computer). Clearly, my assumptions made me blind for what was right in front of me, i.e. this project merely mirroring signals from bluetooth to MQTT.

I do apologize for wasting your time @DigiH. And I do want to express my gratitude to all maintainers and developers for making an awesome project. Hopefully not all users are so blind as me haha.

Can we close this?

@DigiH
Copy link
Collaborator

DigiH commented Oct 16, 2022

Please see my message above, while you might have mistaken a few things a bit, you are very correct in stating that not all the messages are decoded which could/should be decoded, due to the fast that your SwitchBot Meter might be a very recent purchase with a slightly newer format which isn't fully recognised by the Decoder yet.

So thanks for pointing this out!

There should never be any message from your SwitchBot Meter which has any "servicedata" in it and it is not decoded, like the one below.

If there is only "manufacturerdata" that is another case and can safely be ignored.

# home/OpenMQTTGateway_ESP32_BLE_C/BTtoMQTT/C6C752663CBF
{
  "id": "C6:C7:52:66:3C:BF",
  "mac_type": 1,
  "manufacturerdata": "6909c6c752663cbf8d0f099242",
  "rssi": -36,
  "servicedata": "49c0e4099242",
  "servicedatauuid": "0xfd3d"
}

@xanderificnl
Copy link
Author

Thanks. I feel a tad less stupid now!

So the servicedata was a pretty common occurence, and while I looked through your code last night - I did pick up on it containing the readings. That's why I figured there was something wrong, I also tried compiling with your decoder library but that made no difference.

I'm guessing the "add" mode is when I'm pressing the button? For what it's worth, the other project* has been running since yesterday and has been updating my broker very regularly.

What can I do to help with the new format?

* https://github.com/devWaves/SwitchBot-MQTT-BLE-ESP32

@DigiH
Copy link
Collaborator

DigiH commented Oct 16, 2022

What can I do to help with the new format?

If you are compiling your builds with Platformio, you can just change the Decoder URL in the platformio.ini file from

decoder = https://github.com/theengs/decoder.git#v0.6.2

to

decoder = https://github.com/DigiH/decoder#SBMT-test

to test the decoder changes I just uploaded. Then rebuild and upload OMG again to your ESP32.

You should not see any undecoded messages now which include "servicedata", and as you said, they were quite a few of those before, they should now all be properly decoded messages, and therefore more frequent.

@xanderificnl
Copy link
Author

xanderificnl commented Oct 16, 2022

Adding the device ID (i.e. the SBMT-test branch) has worked. Here's what's happening now:

  • Turn on the ESP32
  • The switchbot gets picked up automatically
  • It'll get picked up everyonce in awhile - a quick glance at MQTT explorer suggests it picks up sensor readings at least once every 30 seconds - sometimes (such as shown below) quicker.

image

This is sweet! I think this resolves the issue and now I have every excuse I need to get working on OMG <-> Homie integration ;-)

Thank you @DigiH, much appreciated and such speed!

@DigiH
Copy link
Collaborator

DigiH commented Oct 16, 2022

This is sweet! I think this resolves the issue and now I have every excuse I need to get working on OMG <-> Homie integration ;-)

Great, I'll will be looking forward to your Homie integration!

Thank you @DigiH, much appreciated and such speed!

Thank you for pointing this out, and helping along to pinpoint and verify this different ID! As this is not documented on the official SwitchBot API pages (yet).

I have merged this into the official Theengs Decoder development branch, and will delete my test branch soon. So if you have to rebuild for any reason please use

decoder = https://github.com/theengs/decoder

for any future builds.

Thanks again!

Please also close this OMG issue, if you're happy with the changes. Thanks

@xanderificnl
Copy link
Author

This is sweet! I think this resolves the issue and now I have every excuse I need to get working on OMG <-> Homie integration ;-)

Great, I'll will be looking forward to your Homie integration!

I'm almost looking forward to fighting with the compiler! I do love the language but man, compilers and I never C eye to eye ;)

Thank you @DigiH, much appreciated and such speed!

Thank you for pointing this out, and helping along to pinpoint and verify this different ID! As this is not documented on the official SwitchBot API pages (yet).

You're most welcome!

I have merged this into the official Theengs Decoder development branch, and will delete my test branch soon. So if you have to rebuild for any reason please use

decoder = https://github.com/theengs/decoder

for any future builds.

Just rebuilded to switch back from *-cont to esp32-dev-ble and used that repository.

Thanks again!

Please also close this OMG issue, if you're happy with the changes. Thanks

I am happy with the solution. I'm going to put on some monitoring and have it run over night, see how many times it published sensor data - and hopefully this can be the start of a beautiful array of BLE devices broadcasting sensors for OMG to pick up.

Cheers!

@xanderificnl
Copy link
Author

After @DigiH fixed the issue, I recompiled to esp32-dev-ble (verified it used the fix) and had two ESP32's running side by side.

One with OMG and another with SwitchBot-MQTT-BLE-ESP32. Both with the defaults + WiFi configuration.

I monitored them via a tmux-background window and mosquitto-sub, i.e.:

mosquitto_sub -h 172.16.32.2 -t home/OpenMQTTGateway_ESP32_BLE/BTtoMQTT/C6C752663CBF | ax -o json | tee log/openmqttgateway.log
mosquitto_sub -h 172.16.32.2 -t switchbot/switchbot-relay/meter/one/attributes | ax -o json | tee log/switcbot-mqtt-ble-esp32.log 

The log files are here: switcbot-mqtt-ble-esp32.log and openmqttgateway.log

Here are some interesting bits:

$ wc -l ./openmqttgateway.log 
5812 ./openmqttgateway.log
$ grep 'tempc' ./openmqttgateway.log | wc -l
170
$ wc -l ./switcbot-mqtt-ble-esp32.log
897 ./switcbot-mqtt-ble-esp32.log

In short:

  • OMG picked up the Switchbot a staggering amount of times but unfortunately only reported sensor data about 170 times;
  • Switchbot-mqtt reported 897 times sensor data. It should be noted it's status on MQTT is 'passive scanning' and it does have inherit knowledge of the Switchbot's mac address.

I'm going to restart the *-cont version to see how often it'll report sensor data. I do recall it showing 10+ sensor readings in a small window

@DigiH can you advise? I'm guessing 170 sensor readings over 5 days is very low. Am I missing something?

@DigiH
Copy link
Collaborator

DigiH commented Oct 22, 2022

Hi @xanderificnl

I'm guessing 170 sensor readings over 5 days is very low. Am I missing something?

Yes, absolutely, and great that you made these logs. The openmqttgateway.log clearly shows that most of the messages received from the SwitchBot Meter have manufacturerdata only in them, missing the servicedata required for Theengs Decpder decoding.

I'm going to restart the *-cont version to see how often it'll report sensor data.

Did you see any changes with the *-cont version, more specifically, was more data with servicedata being picked up and was therefor decoded?

Do you have a sample log with the *-cont version?

I just looked at the official SwitchBot BLE API again and realised that there are two formats for the Meters:

(Old) Broadcast Message - Manufacturer data
(New) Broadcast Message - Service data

https://github.com/OpenWonderLabs/SwitchBotAPI-BLE/blob/latest/devicetypes/meter.md#meter-broadcast-message-format

If and why your Meter seems to send out both formats, and if the manufacturerdata contains all the information - I'll have to have a closer look, only saw that the last byte looks like being the humidity.

Which firmware version does your Meter have? Might there be a firmware update for it in the SwitchBot app?

Any chance of resetting your Meter, to see how it behaves after a default resetting/new start?

Generally I'd expect the Meter to be picked up roughly every minutes, as it already is now with the default OMG BLE binary, but with it transmitting data which can/is being decoded, so correct data from the Meter every minute.

@DigiH
Copy link
Collaborator

DigiH commented Oct 22, 2022

As I don't have a SwitchBot Meter myself I just checked with a colleague, and his logging shows the opposite of yours. In general the messages received by his SwitchBot Meter do contain both the manufacturerdata and servicedata, with the servicedata correctly being decoded and the wanted information included in the messages.

Only now and then his Meter messages also only contain the manufacturerdata and are not being decoded, which unfortunately is the majority with your device.

  • Could you see if there is a new firmware version for your Meter
  • Could you do a reset on it
  • After the reset, could you not pair it with your phone and not monitor it with SwitchBot-MQTT-BLE-ESP32, just in case either also creates direct connections to the Meter, somehow inhibiting the complete braodcasts.
  • Could you then try logging with the esp32dev-ble-datatest environment/binary, so that we also get the raw data included in the decoded messages?

Thanks

@xanderificnl
Copy link
Author

Hi.

Hopefully I haven't missed answering a question.

  1. Cheers & Thanks so much. Appreciate you working with me to figure this out!
  2. The *-cont version was ran via rcom -d /dev/ttyUSB0 | grep SwitchBot w/o storing any logs. It had about 3 results in 30 minutes.
  3. App states firmware v0.6. There was no firmware update I could find in the app.
  4. Unpaired the device from my phone and I've turned off the Switchbot-MQTT ESP.
  5. Followed these instructions to reset the switchbot.
  6. Flashed via Platform.io to esp32dev-ble from development branch. Configuration below.
  7. Currently logging with TZ=UTC rcom -d /dev/ttyUSB0 | tee serial.log. See below.
  8. I'll publish a longer log after a couple of hours - can you confirm this is the kind of data you're looking for?

Config

[platformio]
; default_envs = esp32dev-ble
default_envs = esp32dev-ble-datatest

[libraries]
decoder = https://github.com/theengs/decoder
; #development
; decoder = https://github.com/DigiH/decoder#SBMT-test
;decoder = https://github.com/theengs/decoder

[env:esp32dev-ble-datatest]
platform = ${com.esp32_platform}
board = esp32dev
board_build.partitions = min_spiffs.csv
lib_deps =
  ${com-esp.lib_deps}
  ${libraries.wifimanager32}
  ${libraries.ble}
  ${libraries.decoder}
build_flags =
  ${com-esp.build_flags}
  '-DZgatewayBT="BT"'
  '-DLED_SEND_RECEIVE=2'
  '-DLED_SEND_RECEIVE_ON=0'
  '-DpubBLEManufacturerData=true'
  '-DpubKnownBLEServiceData=true'
  '-DpubBLEServiceUUID=true'
  '-DGateway_Name="OpenMQTTGateway_ESP32_BLE"'
  '-DMQTT_SERVER="172.16.32.2"'
  '-DMQTT_USER="username"'
  '-DMQTT_PASS="pwd"'
  '-Dwifi_ssid="XiFi"'
  '-Dwifi_password="l3ttersandnumbers"'

Log

At 16:03 (UTC) I pressed the bluetooth button to see what would happen, the bluetooth indicator lighted and it got picked up. So there may be a bit of a nuance in the data around that timestamp.

$ TZ=UTC rcom -d /dev/ttyUSB0 | tee serial.log

[15:57:03.0016] rst:0x1 (POWERON_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
[15:57:03.0066] configsip: 0, SPIWP:0xee
[15:57:03.0086] clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
[15:57:03.0145] mode:DIO, clock div:2
[15:57:03.0166] load:0x3fff0018,len:4
[15:57:03.0187] load:0x3fff001c,len:1044
[15:57:03.0218] load:0x40078000,len:10124
[15:57:03.0236] load:0x40080400,len:5828
[15:57:03.0256] entry 0x400806a8
[15:57:03.6081] N: 
[15:57:03.6086] ************* WELCOME TO OpenMQTTGateway **************
[15:57:03.6136] N: OpenMQTTGateway Version: version_tag
[15:57:03.7625] *WM: [1] Free heap:        151860
[15:57:03.7656] *WM: [1] ESP-IDF version:  v3.3.5-1-g85c43024c
[15:57:03.7696] *WM: [3] allocating params bytes: 20
[15:57:03.7735] *WM: [2] Added Parameter: server
[15:57:03.7765] *WM: [2] Added Parameter: port
[15:57:03.7819] *WM: [2] Added Parameter: user
[15:57:03.7819] *WM: [2] Added Parameter: pass
[15:57:03.7846] *WM: [2] Added Parameter: secure
[15:57:03.7875] *WM: [3] Updated _max_params: 10
[15:57:03.7907] *WM: [3] re-allocating params bytes: 40
[15:57:03.7945] *WM: [2] Added Parameter: cert
[15:57:03.7965] *WM: [2] Added Parameter: name
[15:57:03.7996] *WM: [2] Added Parameter: topic
[15:57:03.8026] N: Attempting Wifi connection with saved AP: 0
[15:57:04.2972] N: Attempting Wifi connection with saved AP: 1
[15:57:04.3016] E (919) wifi:sta is connecting, return error
[15:57:04.3057] [E][WiFiSTA.cpp:221] begin(): connect failed!
[15:57:04.7992] N: Attempting Wifi connection with saved AP: 2
[15:57:04.8038] E (1421) wifi:sta is connecting, return error
[15:57:04.8075] [E][WiFiSTA.cpp:221] begin(): connect failed!
[15:57:05.3011] N: Attempting Wifi connection with saved AP: 3
[15:57:05.3056] E (1923) wifi:sta is connecting, return error
[15:57:05.3096] [E][WiFiSTA.cpp:221] begin(): connect failed!
[15:57:05.8031] N: Attempting Wifi connection with saved AP: 4
[15:57:05.8076] E (2425) wifi:sta is connecting, return error
[15:57:05.8115] [E][WiFiSTA.cpp:221] begin(): connect failed!
[15:57:06.3051] N: Connect your phone to WIFI AP: OpenMQTTGateway_ESP32_BLE with PWD: your_password
[15:57:06.3125] *WM: [1] AutoConnect 
[15:57:06.3146] *WM: [2] ESP32 event handler enabled 
[15:57:06.3186] *WM: [1] AutoConnect: ESP Already Connected 
[15:57:06.3227] *WM: [1] STA static IP:
[15:57:06.3247] *WM: [2] setSTAConfig static ip not set 
[15:57:06.3276] *WM: [1] AutoConnect: SUCCESS 
[15:57:06.3306] *WM: [1] STA IP Address: 192.168.88.231
[15:57:07.8327] [E][Preferences.cpp:472] getString(): nvs_get_str len fail: BTConfig NOT_FOUND
[15:57:07.8396] N: BT config loaded
[15:57:07.8416] N: BT config: {
[15:57:07.8436]   "bleconnect": true,
[15:57:07.8455]   "interval": 55555,
[15:57:07.8475]   "scanbcnct": 10,
[15:57:07.8485]   "onlysensors": false,
[15:57:07.8553]   "hasspresence": false,
[15:57:07.8553]   "presenceTopic": "presence/",
[15:57:07.8678]   "presenceUseBeaconUuid": false,
[15:57:07.8678]   "minrssi": -100,
[15:57:07.8678]   "extDecoderEnable": false,
[15:57:07.8678]   "extDecoderTopic": "undecoded",
[15:57:07.8678]   "filterConnectable": false,
[15:57:07.8702]   "pubKnownServiceData": true,
[15:57:07.8717]   "pubUnknownServiceData": true,
[15:57:07.8746]   "pubKnownManufData": true,
[15:57:07.8776]   "pubUnknownManufData": true,
[15:57:07.8818]   "pubServiceDataUUID": true,
[15:57:07.8836]   "pubBeaconUuidForTopic": false,
[15:57:07.8865]   "ignoreWBlist": false
[15:57:07.8886] }
[15:57:07.8886] N: BT config loaded
[15:57:07.8906] N: BLE scans interval: 55555
[15:57:07.8926] N: BLE scans number before connect: 10
[15:57:07.8966] N: Publishing only BLE sensors: false
[15:57:07.8996] N: minrssi: -100
[15:57:07.9005] N: Low Power Mode: 0
[15:57:08.0855] N: OpenMQTTGateway modules: ["BT"]
[15:57:08.0887] N: ************** Setup OpenMQTTGateway end **************
[15:57:08.0936] W: MQTT connection...
[15:57:08.1462] N: Connected to broker
[15:57:08.2223] N: Send on /SYStoMQTT msg {"uptime":4,"version":"version_tag","freemem":132232,"mqttport":"1883","mqttsecure":false,"freestack":4756,"rssi":-45,"SSID":"XiFi","BSSID":"08:55:31:D6:79:49","ip":"192.168.88.231","mac":"34:86:5D:FD:4F:08","lowpowermode":0,"btqblck":0,"btqsum":0,"btqsnd":0,"btqavg":0,"interval":55555,"scanbcnct":10,"scnct":0,"modules":["BT"]}
[15:57:09.0853] N: Scan begin
[15:57:15.5942] N: Device detected: C6:C7:52:66:3C:BF
[15:57:15.6457] N: Send on /BTtoMQTT/C6C752663CBF msg {"id":"C6:C7:52:66:3C:BF","mac_type":1,"manufacturerdata":"6909c6c752663cbf010b02924f","rssi":-37,"servicedata":"6980e402924c","servicedatauuid":"0xfd3d","brand":"SwitchBot","model":"Meter (Plus)","model_id":"THX1/W230150X","tempc":18.2,"tempf":64.76,"hum":76,"batt":100}
[15:57:17.9453] N: Device detected: C5:A0:54:C5:5A:E2
[15:57:17.9895] N: Send on /BTtoMQTT/C5A054C55AE2 msg {"id":"C5:A0:54:C5:5A:E2","mac_type":1,"manufacturerdata":"4c0012020003","rssi":-28}
[15:57:19.0966] N: Found 2 devices, scan number 1 end
[15:57:19.1006] N: BLE Connect begin
[15:57:19.1027] N: BLE Connect end
[15:58:14.6571] N: Scan begin
[15:58:22.0124] N: Device detected: C5:A0:54:C5:5A:E2
[15:58:22.0568] N: Send on /BTtoMQTT/C5A054C55AE2 msg {"id":"C5:A0:54:C5:5A:E2","mac_type":1,"manufacturerdata":"4c0012020003","rssi":-31}
[15:58:24.6665] N: Found 2 devices, scan number 2 end
[15:58:24.6704] N: Device detected: C6:C7:52:66:3C:BF
[15:58:24.7114] N: Send on /BTtoMQTT/C6C752663CBF msg {"id":"C6:C7:52:66:3C:BF","mac_type":1,"manufacturerdata":"6909c6c752663cbf030b04924c","rssi":-37}
[15:59:08.2137] N: Send on /SYStoMQTT msg {"uptime":124,"version":"version_tag","freemem":139068,"mqttport":"1883","mqttsecure":false,"freestack":3444,"rssi":-47,"SSID":"XiFi","BSSID":"08:55:31:D6:79:49","ip":"192.168.88.231","mac":"34:86:5D:FD:4F:08","lowpowermode":0,"btqblck":0,"btqsum":4,"btqsnd":4,"btqavg":1,"interval":55555,"scanbcnct":10,"scnct":2,"modules":["BT"]}
[15:59:20.2280] N: Scan begin
[15:59:24.0554] N: Device detected: C5:A0:54:C5:5A:E2
[15:59:24.0996] N: Send on /BTtoMQTT/C5A054C55AE2 msg {"id":"C5:A0:54:C5:5A:E2","mac_type":1,"manufacturerdata":"4c0012020003","rssi":-32}
[15:59:30.2376] N: Found 2 devices, scan nuN: mDevice detectebd: C6:C7:52:66:3C:BF
[15:59:30.2442] er 3 end
[15:59:30.2830] N: Send on /BTtoMQTT/C6C752663CBF msg {"id":"C6:C7:52:66:3C:BF","mac_type":1,"manufacturerdata":"6909c6c752663cbf030b04924c","rssi":-38}
[16:00:25.8028] N: Scan begin
[16:00:26.4665] N: Device detected: E4:8F:4C:26:CE:EE
[16:00:26.5107] N: Send on /BTtoMQTT/E48F4C26CEEE msg {"id":"E4:8F:4C:26:CE:EE","mac_type":1,"manufacturerdata":"4c0012020000","rssi":-31}
[16:00:35.8144] N: Found 2 devices, scan number 4 end
[16:00:35.8194] N: Device detected: C6:C7:52:66:3C:BF
[16:00:35.8587] N: Send on /BTtoMQTT/C6C752663CBF msg {"id":"C6:C7:52:66:3C:BF","mac_type":1,"manufacturerdata":"6909c6c752663cbf040b04924a","rssi":-37}
[16:01:08.2136] N: Send on /SYStoMQTT msg {"uptime":244,"version":"version_tag","freemem":139064,"mqttport":"1883","mqttsecure":false,"freestack":3444,"rssi":-46,"SSID":"XiFi","BSSID":"08:55:31:D6:79:49","ip":"192.168.88.231","mac":"34:86:5D:FD:4F:08","lowpowermode":0,"btqblck":0,"btqsum":8,"btqsnd":8,"btqavg":1,"interval":55555,"scanbcnct":10,"scnct":4,"modules":["BT"]}
[16:01:31.3771] N: Scan begin
[16:01:32.5069] N: Device detected: E4:8F:4C:26:CE:EE
[16:01:32.5513] N: Send on /BTtoMQTT/E48F4C26CEEE msg {"id":"E4:8F:4C:26:CE:EE","mac_type":1,"manufacturerdata":"4c0012020000","rssi":-31}
[16:01:41.3867] N: Found 2 devices, scan number N5:  eDevice detected: C6:C7:52:66:3C:BF
[16:01:41.3933] nd
[16:01:41.4319] N: Send on /BTtoMQTT/C6C752663CBF msg {"id":"C6:C7:52:66:3C:BF","mac_type":1,"manufacturerdata":"6909c6c752663cbf050b03924a","rssi":-38}
[16:02:36.9539] N: Scan begin
[16:02:40.5621] N: Device detected: E4:8F:4C:26:CE:EE
[16:02:40.6061] N: Send on /BTtoMQTT/E48F4C26CEEE msg {"id":"E4:8F:4C:26:CE:EE","mac_type":1,"manufacturerdata":"4c0012020000","rssi":-26}
[16:02:46.9651] N: Device detected: C6:C7:52:66:3C:BF
[16:02:46.9693] N: Found 2 devices, scan number 6 end
[16:02:47.0095] N: Send on /BTtoMQTT/C6C752663CBF msg {"id":"C6:C7:52:66:3C:BF","mac_type":1,"manufacturerdata":"6909c6c752663cbf050b03924a","rssi":-37}
[16:03:08.1974] N: Send on /SYStoMQTT msg {"uptime":364,"version":"version_tag","freemem":138884,"mqttport":"1883","mqttsecure":false,"freestack":3444,"rssi":-49,"SSID":"XiFi","BSSID":"08:55:31:D6:79:49","ip":"192.168.88.231","mac":"34:86:5D:FD:4F:08","lowpowermode":0,"btqblck":0,"btqsum":12,"btqsnd":12,"btqavg":1,"interval":55555,"scanbcnct":10,"scnct":6,"modules":["BT"]}
[16:03:42.5320] N: Scan begin
[16:03:43.5356] N: Device detected: C6:C7:52:66:3C:BF
[16:03:43.5699] N: Send on /BTtoMQTT/C6C752663CBF msg {"id":"C6:C7:52:66:3C:BF","mac_type":1,"manufacturerdata":"6909c6c752663cbf050b03924a","rssi":-31,"servicedata":"4980e403924a","servicedatauuid":"0xfd3d","brand":"SwitchBot","model":"Meter (Plus)","model_id":"THX1/W230150X","tempc":18.3,"tempf":64.94,"hum":74,"batt":100}
[16:03:52.5419] N: Found 1 devices, scan number 7 end
[16:04:48.1079] N: Scan begin
[16:04:49.4824] N: Device detected: C6:C7:52:66:3C:BF
[16:04:49.5162] N: Send on /BTtoMQTT/C6C752663CBF msg {"id":"C6:C7:52:66:3C:BF","mac_type":1,"manufacturerdata":"6909c6c752663cbf050b03924a","rssi":-33,"servicedata":"4980e403924a","servicedatauuid":"0xfd3d","brand":"SwitchBot","model":"Meter (Plus)","model_id":"THX1/W230150X","tempc":18.3,"tempf":64.94,"hum":74,"batt":100}
[16:04:52.6639] N: Device detected: E4:8F:4C:26:CE:EE
[16:04:52.7075] N: Send on /BTtoMQTT/E48F4C26CEEE msg {"id":"E4:8F:4C:26:CE:EE","mac_type":1,"manufacturerdata":"4c0012020000","rssi":-33}
[16:04:58.1198] N: Found 3 devices, scan nuN: mDevice detectebd: 3C:91:80:C9:28:58
[16:04:58.1264] er 8 end
[16:04:58.1264] N: Send on /BTtoMQTT/3C9180C92858 msg {"id":"3C:91:80:C9:28:58","mac_type":0,"rssi":-81}
[16:05:08.1890] N: Send on /SYStoMQTT msg {"uptime":484,"version":"version_tag","freemem":138744,"mqttport":"1883","mqttsecure":false,"freestack":3444,"rssi":-48,"SSID":"XiFi","BSSID":"08:55:31:D6:79:49","ip":"192.168.88.231","mac":"34:86:5D:FD:4F:08","lowpowermode":0,"btqblck":0,"btqsum":16,"btqsnd":16,"btqavg":1,"interval":55555,"scanbcnct":10,"scnct":8,"modules":["BT"]}
[16:05:53.6860] N: Scan begin
[16:05:56.7341] N: Device detected: E4:8F:4C:26:CE:EE
[16:05:56.7783] N: Send on /BTtoMQTT/E48F4C26CEEE msg {"id":"E4:8F:4C:26:CE:EE","mac_type":1,"manufacturerdata":"4c0012020000","rssi":-33}
[16:05:58.3342] N: Device detected: C6:C7:52:66:3C:BF
[16:05:58.3680] N: Send on /BTtoMQTT/C6C752663CBF msg {"id":"C6:C7:52:66:3C:BF","mac_type":1,"manufacturerdata":"6909c6c752663cbf060b02924a","rssi":-30,"servicedata":"6980e402924a","servicedatauuid":"0xfd3d","brand":"SwitchBot","model":"Meter (Plus)","model_id":"THX1/W230150X","tempc":18.2,"tempf":64.76,"hum":74,"batt":100}
[16:06:03.6935] N: Found 3 devices, scan number 9 end
[16:06:03.6973] N: Device detected: 3C:91:80:C9:28:58
[16:06:03.7003] N: Send on /BTtoMQTT/3C9180C92858 msg {"id":"3C:91:80:C9:28:58","mac_type":0,"rssi":-81}
[16:06:59.2570] N: Scan begin
[16:07:08.1807] N: Send on /SYStoMQTT msg {"uptime":604,"version":"version_tag","freemem":138900,"mqttport":"1883","mqttsecure":false,"freestack":3444,"rssi":-48,"SSID":"XiFi","BSSID":"08:55:31:D6:79:49","ip":"192.168.88.231","mac":"34:86:5D:FD:4F:08","lowpowermode":0,"btqblck":0,"btqsum":19,"btqsnd":19,"btqavg":1,"interval":55555,"scanbcnct":10,"scnct":9,"modules":["BT"]}
[16:07:09.2667] N: Found N: Device detected: C6:C7:52:66:3C:BF
[16:07:09.2713] 2 devices, scan number 10 end
[16:07:09.2743] N: BLE Connect begin
[16:07:09.2753] N: BLE Connect end
[16:07:09.3107] N: Device detected: 50:CB:2D:D9:62:25
[16:07:09.3542] N: Send on /BTtoMQTT/C6C752663CBF msg {"id":"C6:C7:52:66:3C:BF","mac_type":1,"manufacturerdata":"6909c6c752663cbf060b02924a","rssi":-29}
[16:07:09.3663] N: Send on /BTtoMQTT/50CB2DD96225 msg {"id":"50:CB:2D:D9:62:25","mac_type":1,"manufacturerdata":"4c0010054e1c3b4881","rssi":-90,"txpower":12}
[16:08:04.8319] N: Scan begin
[16:08:14.8325] N: Device detected: E4:8F:4C:26:CE:EE
[16:08:14.8412] N: Found 3 devices, scan number 11 end
[16:08:14.8766] N: Device detected: 3C:91:80:C9:28:58
[16:08:14.8803] N: Device detected: C6:C7:52:66:3C:BF
[16:08:14.9207] N: Send on /BTtoMQTT/E48F4C26CEEE msg {"id":"E4:8F:4C:26:CE:EE","mac_type":1,"manufacturerdata":"4c0012020000","rssi":-28}
[16:08:14.9313] N: Send on /BTtoMQTT/3C9180C92858 msg {"id":"3C:91:80:C9:28:58","mac_type":0,"rssi":-80}
[16:08:14.9394] N: Send on /BTtoMQTT/C6C752663CBF msg {"id":"C6:C7:52:66:3C:BF","mac_type":1,"manufacturerdata":"6909c6c752663cbf060b02924a","rssi":-33}

@DigiH
Copy link
Collaborator

DigiH commented Oct 22, 2022

Hi,

The 'fix' I implemented previously, which allows for the 49… servicedata to be decoded, should actually be taken out again, as 49… servicedata indicates being in ADD MODE, which only last for 120 seconds, as can be seen in your

At 16:03 (UTC) I pressed the bluetooth button to see what would happen, the bluetooth indicator lighted and it got picked up. So there may be a bit of a nuance in the data around that timestamp.

but will/should never appear in normal broadcast mode.

8. I'll publish a longer log after a couple of hours - can you confirm this is the kind of data you're looking for?

Yes, the configuration looks fine, the steps you follow sound fine, but why so many manufacturerdata only messages is still a mystery to me.

If the longer log will be not serial, but as the above ones with mosquitto-sub, that will be great.

Just out of curiosity - you haven't set ActiveBLEScan in config_BT.h to false by any chance, possibly for some other environment/test?

Have all the different OMG tests been done on the same ESP32?

Looking forward to your longer logs.

@xanderificnl
Copy link
Author

xanderificnl commented Oct 22, 2022

Hi,

Before filing this issue, I repulled 0.9.16 and had a clean tree. Today I moved to the development branch. Git reports my tree is clean (gitignore ignores env files). So ActiveBLEScan is default, in config_BT.h:

$ grep 'define ActiveBLEScan' main/config_BT.h 
#  define ActiveBLEScan true // Set active scanning, this will get more data from the advertiser.

I've started a subscriber for mosquitto-sub

Things do appear to be going much better so far. I've had more sensor readings by OMG than I've had in the past 10 days.

Here's a preview of the formatted logs so far:

{"@timestamp":"2022-10-22T19:26:56+02:00","id":"C6:C7:52:66:3C:BF","mac_type":1,"manufacturerdata":"6909c6c752663cbf110b09914b","rssi":-29}
{"@timestamp":"2022-10-22T19:29:07+02:00","id":"C6:C7:52:66:3C:BF","mac_type":1,"manufacturerdata":"6909c6c752663cbf110b09914b","rssi":-29}
{"@timestamp":"2022-10-22T19:31:18+02:00","id":"C6:C7:52:66:3C:BF","mac_type":1,"manufacturerdata":"6909c6c752663cbf110b09914b","rssi":-33}
{"@timestamp":"2022-10-22T19:32:24+02:00","id":"C6:C7:52:66:3C:BF","mac_type":1,"manufacturerdata":"6909c6c752663cbf110b09914b","rssi":-33}
{"@timestamp":"2022-10-22T19:33:28+02:00","batt":100,"brand":"SwitchBot","hum":75,"id":"C6:C7:52:66:3C:BF","mac_type":1,"manufacturerdata":"6909c6c752663cbf120b09914b","model":"Meter (Plus)","model_id":"THX1/W230150X","rssi":-30,"servicedata":"6980e409914b","servicedatauuid":"0xfd3d","tempc":17.9,"tempf":64.22}
{"@timestamp":"2022-10-22T19:34:35+02:00","id":"C6:C7:52:66:3C:BF","mac_type":1,"manufacturerdata":"6909c6c752663cbf120b09914b","rssi":-32}
{"@timestamp":"2022-10-22T19:35:41+02:00","id":"C6:C7:52:66:3C:BF","mac_type":1,"manufacturerdata":"6909c6c752663cbf120b09914b","rssi":-29}
{"@timestamp":"2022-10-22T19:36:36+02:00","batt":100,"brand":"SwitchBot","hum":75,"id":"C6:C7:52:66:3C:BF","mac_type":1,"manufacturerdata":"6909c6c752663cbf120b09914b","model":"Meter (Plus)","model_id":"THX1/W230150X","rssi":-30,"servicedata":"6980e409914b","servicedatauuid":"0xfd3d","tempc":17.9,"tempf":64.22}
{"@timestamp":"2022-10-22T19:37:43+02:00","batt":100,"brand":"SwitchBot","hum":75,"id":"C6:C7:52:66:3C:BF","mac_type":1,"manufacturerdata":"6909c6c752663cbf120b09914b","model":"Meter (Plus)","model_id":"THX1/W230150X","rssi":-31,"servicedata":"6980e409914b","servicedatauuid":"0xfd3d","tempc":17.9,"tempf":64.22}

- edit -

I've ran OMG on 2 different ESPs. One of those is was eventually flashed with SwitchBot-MQTT-ESP - which is currently off.

@DigiH
Copy link
Collaborator

DigiH commented Oct 22, 2022

The [env:esp32dev-ble-datatest] environment looks fine. Could you just add the build_flags?

'-DTimeBtwRead=0'
'-DScan_duration=1000'
'-DAttemptBLECOnnect=false'

to make it a env:esp32dev-ble-datatest-cont. Logging for ten minutes or so should be more than enough then to see what the different broadcast ratios are.

Thanks

@xanderificnl
Copy link
Author

xanderificnl commented Oct 22, 2022

For completeness: it reported sensor readings 43 times in approximately 2 hours. A lot more than previously - but still less than what your friend sees.


switched to the new build flags, and here's the log:

{"@timestamp":"2022-10-22T19:59:08+02:00","id":"C6:C7:52:66:3C:BF","mac_type":1,"manufacturerdata":"6909c6c752663cbf150b09914a","rssi":-30}
{"@timestamp":"2022-10-22T19:59:13+02:00","batt":100,"brand":"SwitchBot","hum":74,"id":"C6:C7:52:66:3C:BF","mac_type":1,"manufacturerdata":"6909c6c752663cbf150b09914a","model":"Meter (Plus)","model_id":"THX1/W230150X","rssi":-31,"servicedata":"6980e409914a","servicedatauuid":"0xfd3d","tempc":17.9,"tempf":64.22}
{"@timestamp":"2022-10-22T19:59:25+02:00","batt":100,"brand":"SwitchBot","hum":74,"id":"C6:C7:52:66:3C:BF","mac_type":1,"manufacturerdata":"6909c6c752663cbf150b09914a","model":"Meter (Plus)","model_id":"THX1/W230150X","rssi":-31,"servicedata":"6980e409914a","servicedatauuid":"0xfd3d","tempc":17.9,"tempf":64.22}
{"@timestamp":"2022-10-22T19:59:31+02:00","id":"C6:C7:52:66:3C:BF","mac_type":1,"manufacturerdata":"6909c6c752663cbf150b09914a","rssi":-33}
{"@timestamp":"2022-10-22T19:59:33+02:00","id":"C6:C7:52:66:3C:BF","mac_type":1,"manufacturerdata":"6909c6c752663cbf150b09914a","rssi":-33}
{"@timestamp":"2022-10-22T19:59:37+02:00","id":"C6:C7:52:66:3C:BF","mac_type":1,"manufacturerdata":"6909c6c752663cbf150b09914a","rssi":-32}
{"@timestamp":"2022-10-22T19:59:39+02:00","batt":100,"brand":"SwitchBot","hum":74,"id":"C6:C7:52:66:3C:BF","mac_type":1,"manufacturerdata":"6909c6c752663cbf150b09914a","model":"Meter (Plus)","model_id":"THX1/W230150X","rssi":-33,"servicedata":"6980e409914a","servicedatauuid":"0xfd3d","tempc":17.9,"tempf":64.22}
{"@timestamp":"2022-10-22T19:59:45+02:00","id":"C6:C7:52:66:3C:BF","mac_type":1,"manufacturerdata":"6909c6c752663cbf150b09914a","rssi":-81}
{"@timestamp":"2022-10-22T19:59:47+02:00","batt":100,"brand":"SwitchBot","hum":74,"id":"C6:C7:52:66:3C:BF","mac_type":1,"manufacturerdata":"6909c6c752663cbf150b09914a","model":"Meter (Plus)","model_id":"THX1/W230150X","rssi":-33,"servicedata":"6980e409914a","servicedatauuid":"0xfd3d","tempc":17.9,"tempf":64.22}
{"@timestamp":"2022-10-22T19:59:49+02:00","id":"C6:C7:52:66:3C:BF","mac_type":1,"manufacturerdata":"6909c6c752663cbf150b09914a","rssi":-30}
{"@timestamp":"2022-10-22T19:59:53+02:00","id":"C6:C7:52:66:3C:BF","mac_type":1,"manufacturerdata":"6909c6c752663cbf150b09914a","rssi":-30}
{"@timestamp":"2022-10-22T19:59:55+02:00","id":"C6:C7:52:66:3C:BF","mac_type":1,"manufacturerdata":"6909c6c752663cbf150b09914a","rssi":-62}
{"@timestamp":"2022-10-22T20:00:03+02:00","id":"C6:C7:52:66:3C:BF","mac_type":1,"manufacturerdata":"6909c6c752663cbf150b09914a","rssi":-30}
{"@timestamp":"2022-10-22T20:00:05+02:00","id":"C6:C7:52:66:3C:BF","mac_type":1,"manufacturerdata":"6909c6c752663cbf150b09914a","rssi":-33}
{"@timestamp":"2022-10-22T20:00:13+02:00","id":"C6:C7:52:66:3C:BF","mac_type":1,"manufacturerdata":"6909c6c752663cbf150b09914a","rssi":-30}
{"@timestamp":"2022-10-22T20:00:19+02:00","id":"C6:C7:52:66:3C:BF","mac_type":1,"manufacturerdata":"6909c6c752663cbf150b09914a","rssi":-30}
{"@timestamp":"2022-10-22T20:00:23+02:00","id":"C6:C7:52:66:3C:BF","mac_type":1,"manufacturerdata":"6909c6c752663cbf150b09914a","rssi":-32}
{"@timestamp":"2022-10-22T20:00:27+02:00","id":"C6:C7:52:66:3C:BF","mac_type":1,"manufacturerdata":"6909c6c752663cbf150b09914a","rssi":-30}
{"@timestamp":"2022-10-22T20:00:29+02:00","id":"C6:C7:52:66:3C:BF","mac_type":1,"manufacturerdata":"6909c6c752663cbf150b09914a","rssi":-30}
{"@timestamp":"2022-10-22T20:00:33+02:00","id":"C6:C7:52:66:3C:BF","mac_type":1,"manufacturerdata":"6909c6c752663cbf150b09914a","rssi":-30}
{"@timestamp":"2022-10-22T20:00:35+02:00","id":"C6:C7:52:66:3C:BF","mac_type":1,"manufacturerdata":"6909c6c752663cbf150b09914a","rssi":-30}
{"@timestamp":"2022-10-22T20:00:41+02:00","id":"C6:C7:52:66:3C:BF","mac_type":1,"manufacturerdata":"6909c6c752663cbf150b09914a","rssi":-30}
{"@timestamp":"2022-10-22T20:00:43+02:00","id":"C6:C7:52:66:3C:BF","mac_type":1,"manufacturerdata":"6909c6c752663cbf150b09914a","rssi":-33}
{"@timestamp":"2022-10-22T20:00:57+02:00","batt":100,"brand":"SwitchBot","hum":74,"id":"C6:C7:52:66:3C:BF","mac_type":1,"manufacturerdata":"6909c6c752663cbf150b09914a","model":"Meter (Plus)","model_id":"THX1/W230150X","rssi":-31,"servicedata":"6980e409914a","servicedatauuid":"0xfd3d","tempc":17.9,"tempf":64.22}
{"@timestamp":"2022-10-22T20:01:02+02:00","id":"C6:C7:52:66:3C:BF","mac_type":1,"manufacturerdata":"6909c6c752663cbf150b09914a","rssi":-33}
{"@timestamp":"2022-10-22T20:01:04+02:00","id":"C6:C7:52:66:3C:BF","mac_type":1,"manufacturerdata":"6909c6c752663cbf150b09914a","rssi":-30}
{"@timestamp":"2022-10-22T20:01:10+02:00","id":"C6:C7:52:66:3C:BF","mac_type":1,"manufacturerdata":"6909c6c752663cbf150b09914a","rssi":-30}
{"@timestamp":"2022-10-22T20:01:11+02:00","batt":100,"brand":"SwitchBot","hum":74,"id":"C6:C7:52:66:3C:BF","mac_type":1,"manufacturerdata":"6909c6c752663cbf150b09914a","model":"Meter (Plus)","model_id":"THX1/W230150X","rssi":-33,"servicedata":"6980e409914a","servicedatauuid":"0xfd3d","tempc":17.9,"tempf":64.22}
{"@timestamp":"2022-10-22T20:01:18+02:00","id":"C6:C7:52:66:3C:BF","mac_type":1,"manufacturerdata":"6909c6c752663cbf150b09914a","rssi":-30}
{"@timestamp":"2022-10-22T20:01:26+02:00","id":"C6:C7:52:66:3C:BF","mac_type":1,"manufacturerdata":"6909c6c752663cbf150b09914a","rssi":-30}
{"@timestamp":"2022-10-22T20:01:27+02:00","batt":100,"brand":"SwitchBot","hum":74,"id":"C6:C7:52:66:3C:BF","mac_type":1,"manufacturerdata":"6909c6c752663cbf150b09914a","model":"Meter (Plus)","model_id":"THX1/W230150X","rssi":-33,"servicedata":"6980e409914a","servicedatauuid":"0xfd3d","tempc":17.9,"tempf":64.22}
{"@timestamp":"2022-10-22T20:01:35+02:00","batt":100,"brand":"SwitchBot","hum":74,"id":"C6:C7:52:66:3C:BF","mac_type":1,"manufacturerdata":"6909c6c752663cbf150b09914a","model":"Meter (Plus)","model_id":"THX1/W230150X","rssi":-31,"servicedata":"6980e409914a","servicedatauuid":"0xfd3d","tempc":17.9,"tempf":64.22}
{"@timestamp":"2022-10-22T20:01:41+02:00","batt":100,"brand":"SwitchBot","hum":74,"id":"C6:C7:52:66:3C:BF","mac_type":1,"manufacturerdata":"6909c6c752663cbf150b09914a","model":"Meter (Plus)","model_id":"THX1/W230150X","rssi":-30,"servicedata":"6980e409914a","servicedatauuid":"0xfd3d","tempc":17.9,"tempf":64.22}
{"@timestamp":"2022-10-22T20:01:53+02:00","id":"C6:C7:52:66:3C:BF","mac_type":1,"manufacturerdata":"6909c6c752663cbf150b09914a","rssi":-30}
{"@timestamp":"2022-10-22T20:01:55+02:00","id":"C6:C7:52:66:3C:BF","mac_type":1,"manufacturerdata":"6909c6c752663cbf150b09914a","rssi":-32}
{"@timestamp":"2022-10-22T20:01:59+02:00","id":"C6:C7:52:66:3C:BF","mac_type":1,"manufacturerdata":"6909c6c752663cbf150b09914a","rssi":-30}
{"@timestamp":"2022-10-22T20:02:01+02:00","id":"C6:C7:52:66:3C:BF","mac_type":1,"manufacturerdata":"6909c6c752663cbf150b09914a","rssi":-30}
{"@timestamp":"2022-10-22T20:02:07+02:00","batt":100,"brand":"SwitchBot","hum":74,"id":"C6:C7:52:66:3C:BF","mac_type":1,"manufacturerdata":"6909c6c752663cbf150b09914a","model":"Meter (Plus)","model_id":"THX1/W230150X","rssi":-31,"servicedata":"6980e409914a","servicedatauuid":"0xfd3d","tempc":17.9,"tempf":64.22}
{"@timestamp":"2022-10-22T20:02:09+02:00","batt":100,"brand":"SwitchBot","hum":74,"id":"C6:C7:52:66:3C:BF","mac_type":1,"manufacturerdata":"6909c6c752663cbf150b09914a","model":"Meter (Plus)","model_id":"THX1/W230150X","rssi":-33,"servicedata":"6980e409914a","servicedatauuid":"0xfd3d","tempc":17.9,"tempf":64.22}
{"@timestamp":"2022-10-22T20:02:13+02:00","batt":100,"brand":"SwitchBot","hum":74,"id":"C6:C7:52:66:3C:BF","mac_type":1,"manufacturerdata":"6909c6c752663cbf150b09914a","model":"Meter (Plus)","model_id":"THX1/W230150X","rssi":-33,"servicedata":"6980e409914a","servicedatauuid":"0xfd3d","tempc":17.9,"tempf":64.22}
{"@timestamp":"2022-10-22T20:02:17+02:00","id":"C6:C7:52:66:3C:BF","mac_type":1,"manufacturerdata":"6909c6c752663cbf150b09914a","rssi":-32}
{"@timestamp":"2022-10-22T20:02:19+02:00","id":"C6:C7:52:66:3C:BF","mac_type":1,"manufacturerdata":"6909c6c752663cbf150b09914a","rssi":-34}
{"@timestamp":"2022-10-22T20:02:25+02:00","id":"C6:C7:52:66:3C:BF","mac_type":1,"manufacturerdata":"6909c6c752663cbf150b09914a","rssi":-30}
{"@timestamp":"2022-10-22T20:02:27+02:00","batt":100,"brand":"SwitchBot","hum":74,"id":"C6:C7:52:66:3C:BF","mac_type":1,"manufacturerdata":"6909c6c752663cbf150b09914a","model":"Meter (Plus)","model_id":"THX1/W230150X","rssi":-33,"servicedata":"6980e409914a","servicedatauuid":"0xfd3d","tempc":17.9,"tempf":64.22}
{"@timestamp":"2022-10-22T20:02:32+02:00","id":"C6:C7:52:66:3C:BF","mac_type":1,"manufacturerdata":"6909c6c752663cbf150b09914a","rssi":-32}
{"@timestamp":"2022-10-22T20:02:36+02:00","id":"C6:C7:52:66:3C:BF","mac_type":1,"manufacturerdata":"6909c6c752663cbf150b09914a","rssi":-30}
{"@timestamp":"2022-10-22T20:02:40+02:00","id":"C6:C7:52:66:3C:BF","mac_type":1,"manufacturerdata":"6909c6c752663cbf150b09914a","rssi":-30}
{"@timestamp":"2022-10-22T20:02:42+02:00","id":"C6:C7:52:66:3C:BF","mac_type":1,"manufacturerdata":"6909c6c752663cbf150b09914a","rssi":-30}
{"@timestamp":"2022-10-22T20:02:50+02:00","id":"C6:C7:52:66:3C:BF","mac_type":1,"manufacturerdata":"6909c6c752663cbf150b09914a","rssi":-30}
{"@timestamp":"2022-10-22T20:02:54+02:00","id":"C6:C7:52:66:3C:BF","mac_type":1,"manufacturerdata":"6909c6c752663cbf150b09914a","rssi":-33}
{"@timestamp":"2022-10-22T20:02:56+02:00","id":"C6:C7:52:66:3C:BF","mac_type":1,"manufacturerdata":"6909c6c752663cbf150b09914a","rssi":-30}
{"@timestamp":"2022-10-22T20:02:58+02:00","id":"C6:C7:52:66:3C:BF","mac_type":1,"manufacturerdata":"6909c6c752663cbf150b09914a","rssi":-30}
{"@timestamp":"2022-10-22T20:03:02+02:00","id":"C6:C7:52:66:3C:BF","mac_type":1,"manufacturerdata":"6909c6c752663cbf150b09914a","rssi":-30}
{"@timestamp":"2022-10-22T20:03:04+02:00","id":"C6:C7:52:66:3C:BF","mac_type":1,"manufacturerdata":"6909c6c752663cbf150b09914a","rssi":-30}
{"@timestamp":"2022-10-22T20:03:08+02:00","id":"C6:C7:52:66:3C:BF","mac_type":1,"manufacturerdata":"6909c6c752663cbf150b09914a","rssi":-32}
{"@timestamp":"2022-10-22T20:03:10+02:00","id":"C6:C7:52:66:3C:BF","mac_type":1,"manufacturerdata":"6909c6c752663cbf150b09914a","rssi":-32}
{"@timestamp":"2022-10-22T20:03:18+02:00","id":"C6:C7:52:66:3C:BF","mac_type":1,"manufacturerdata":"6909c6c752663cbf150b09914a","rssi":-30}
{"@timestamp":"2022-10-22T20:03:20+02:00","id":"C6:C7:52:66:3C:BF","mac_type":1,"manufacturerdata":"6909c6c752663cbf150b09914a","rssi":-30}
{"@timestamp":"2022-10-22T20:03:24+02:00","id":"C6:C7:52:66:3C:BF","mac_type":1,"manufacturerdata":"6909c6c752663cbf150b09914a","rssi":-30}
{"@timestamp":"2022-10-22T20:03:26+02:00","id":"C6:C7:52:66:3C:BF","mac_type":1,"manufacturerdata":"6909c6c752663cbf150b09914a","rssi":-30}
{"@timestamp":"2022-10-22T20:03:32+02:00","id":"C6:C7:52:66:3C:BF","mac_type":1,"manufacturerdata":"6909c6c752663cbf150b09914a","rssi":-30}
{"@timestamp":"2022-10-22T20:03:38+02:00","id":"C6:C7:52:66:3C:BF","mac_type":1,"manufacturerdata":"6909c6c752663cbf150b09914a","rssi":-30}
{"@timestamp":"2022-10-22T20:03:39+02:00","batt":100,"brand":"SwitchBot","hum":74,"id":"C6:C7:52:66:3C:BF","mac_type":1,"manufacturerdata":"6909c6c752663cbf150b09914a","model":"Meter (Plus)","model_id":"THX1/W230150X","rssi":-31,"servicedata":"6980e409914a","servicedatauuid":"0xfd3d","tempc":17.9,"tempf":64.22}
{"@timestamp":"2022-10-22T20:03:46+02:00","id":"C6:C7:52:66:3C:BF","mac_type":1,"manufacturerdata":"6909c6c752663cbf150b09914a","rssi":-30}
{"@timestamp":"2022-10-22T20:03:48+02:00","batt":100,"brand":"SwitchBot","hum":74,"id":"C6:C7:52:66:3C:BF","mac_type":1,"manufacturerdata":"6909c6c752663cbf160b09914a","model":"Meter (Plus)","model_id":"THX1/W230150X","rssi":-31,"servicedata":"6980e409914a","servicedatauuid":"0xfd3d","tempc":17.9,"tempf":64.22}
{"@timestamp":"2022-10-22T20:03:56+02:00","id":"C6:C7:52:66:3C:BF","mac_type":1,"manufacturerdata":"6909c6c752663cbf160b09914a","rssi":-33}
{"@timestamp":"2022-10-22T20:04:02+02:00","id":"C6:C7:52:66:3C:BF","mac_type":1,"manufacturerdata":"6909c6c752663cbf160b09914a","rssi":-30}
{"@timestamp":"2022-10-22T20:04:08+02:00","batt":100,"brand":"SwitchBot","hum":74,"id":"C6:C7:52:66:3C:BF","mac_type":1,"manufacturerdata":"6909c6c752663cbf160b09914a","model":"Meter (Plus)","model_id":"THX1/W230150X","rssi":-31,"servicedata":"6980e409914a","servicedatauuid":"0xfd3d","tempc":17.9,"tempf":64.22}
{"@timestamp":"2022-10-22T20:04:10+02:00","id":"C6:C7:52:66:3C:BF","mac_type":1,"manufacturerdata":"6909c6c752663cbf160b09914a","rssi":-33}
{"@timestamp":"2022-10-22T20:04:14+02:00","id":"C6:C7:52:66:3C:BF","mac_type":1,"manufacturerdata":"6909c6c752663cbf160b09914a","rssi":-30}
{"@timestamp":"2022-10-22T20:04:23+02:00","id":"C6:C7:52:66:3C:BF","mac_type":1,"manufacturerdata":"6909c6c752663cbf160b09914a","rssi":-30}
{"@timestamp":"2022-10-22T20:04:25+02:00","id":"C6:C7:52:66:3C:BF","mac_type":1,"manufacturerdata":"6909c6c752663cbf160b09914a","rssi":-30}
{"@timestamp":"2022-10-22T20:04:26+02:00","batt":100,"brand":"SwitchBot","hum":74,"id":"C6:C7:52:66:3C:BF","mac_type":1,"manufacturerdata":"6909c6c752663cbf160b09914a","model":"Meter (Plus)","model_id":"THX1/W230150X","rssi":-32,"servicedata":"6980e409914a","servicedatauuid":"0xfd3d","tempc":17.9,"tempf":64.22}
{"@timestamp":"2022-10-22T20:04:30+02:00","batt":100,"brand":"SwitchBot","hum":74,"id":"C6:C7:52:66:3C:BF","mac_type":1,"manufacturerdata":"6909c6c752663cbf160b09914a","model":"Meter (Plus)","model_id":"THX1/W230150X","rssi":-33,"servicedata":"6980e409914a","servicedatauuid":"0xfd3d","tempc":17.9,"tempf":64.22}
{"@timestamp":"2022-10-22T20:04:39+02:00","id":"C6:C7:52:66:3C:BF","mac_type":1,"manufacturerdata":"6909c6c752663cbf160b09914a","rssi":-30}
{"@timestamp":"2022-10-22T20:04:41+02:00","id":"C6:C7:52:66:3C:BF","mac_type":1,"manufacturerdata":"6909c6c752663cbf160b09914a","rssi":-30}
{"@timestamp":"2022-10-22T20:04:47+02:00","id":"C6:C7:52:66:3C:BF","mac_type":1,"manufacturerdata":"6909c6c752663cbf160b09914a","rssi":-32}
{"@timestamp":"2022-10-22T20:04:49+02:00","id":"C6:C7:52:66:3C:BF","mac_type":1,"manufacturerdata":"6909c6c752663cbf160b09914a","rssi":-30}
{"@timestamp":"2022-10-22T20:04:55+02:00","id":"C6:C7:52:66:3C:BF","mac_type":1,"manufacturerdata":"6909c6c752663cbf160b09914a","rssi":-33}
{"@timestamp":"2022-10-22T20:05:03+02:00","id":"C6:C7:52:66:3C:BF","mac_type":1,"manufacturerdata":"6909c6c752663cbf160b09914a","rssi":-33}
{"@timestamp":"2022-10-22T20:05:12+02:00","batt":100,"brand":"SwitchBot","hum":74,"id":"C6:C7:52:66:3C:BF","mac_type":1,"manufacturerdata":"6909c6c752663cbf160b09914a","model":"Meter (Plus)","model_id":"THX1/W230150X","rssi":-31,"servicedata":"6980e409914a","servicedatauuid":"0xfd3d","tempc":17.9,"tempf":64.22}
{"@timestamp":"2022-10-22T20:05:15+02:00","id":"C6:C7:52:66:3C:BF","mac_type":1,"manufacturerdata":"6909c6c752663cbf160b09914a","rssi":-30}
{"@timestamp":"2022-10-22T20:05:22+02:00","batt":100,"brand":"SwitchBot","hum":74,"id":"C6:C7:52:66:3C:BF","mac_type":1,"manufacturerdata":"6909c6c752663cbf160b09914a","model":"Meter (Plus)","model_id":"THX1/W230150X","rssi":-31,"servicedata":"6980e409914a","servicedatauuid":"0xfd3d","tempc":17.9,"tempf":64.22}
{"@timestamp":"2022-10-22T20:05:26+02:00","id":"C6:C7:52:66:3C:BF","mac_type":1,"manufacturerdata":"6909c6c752663cbf160b09914a","rssi":-30}
{"@timestamp":"2022-10-22T20:05:32+02:00","id":"C6:C7:52:66:3C:BF","mac_type":1,"manufacturerdata":"6909c6c752663cbf160b09914a","rssi":-30}
{"@timestamp":"2022-10-22T20:05:34+02:00","batt":100,"brand":"SwitchBot","hum":74,"id":"C6:C7:52:66:3C:BF","mac_type":1,"manufacturerdata":"6909c6c752663cbf160b09914a","model":"Meter (Plus)","model_id":"THX1/W230150X","rssi":-31,"servicedata":"6980e409914a","servicedatauuid":"0xfd3d","tempc":17.9,"tempf":64.22}
{"@timestamp":"2022-10-22T20:05:40+02:00","id":"C6:C7:52:66:3C:BF","mac_type":1,"manufacturerdata":"6909c6c752663cbf160b09914a","rssi":-30}
{"@timestamp":"2022-10-22T20:05:42+02:00","id":"C6:C7:52:66:3C:BF","mac_type":1,"manufacturerdata":"6909c6c752663cbf160b09914a","rssi":-30}
{"@timestamp":"2022-10-22T20:05:50+02:00","id":"C6:C7:52:66:3C:BF","mac_type":1,"manufacturerdata":"6909c6c752663cbf160b09914a","rssi":-31}
{"@timestamp":"2022-10-22T20:05:54+02:00","id":"C6:C7:52:66:3C:BF","mac_type":1,"manufacturerdata":"6909c6c752663cbf160b09914a","rssi":-30}
{"@timestamp":"2022-10-22T20:05:56+02:00","id":"C6:C7:52:66:3C:BF","mac_type":1,"manufacturerdata":"6909c6c752663cbf160b09914a","rssi":-32}
{"@timestamp":"2022-10-22T20:05:58+02:00","id":"C6:C7:52:66:3C:BF","mac_type":1,"manufacturerdata":"6909c6c752663cbf160b09914a","rssi":-30}
{"@timestamp":"2022-10-22T20:06:05+02:00","id":"C6:C7:52:66:3C:BF","mac_type":1,"manufacturerdata":"6909c6c752663cbf160b09914a","rssi":-30}
{"@timestamp":"2022-10-22T20:06:11+02:00","id":"C6:C7:52:66:3C:BF","mac_type":1,"manufacturerdata":"6909c6c752663cbf160b09914a","rssi":-30}
{"@timestamp":"2022-10-22T20:06:12+02:00","batt":100,"brand":"SwitchBot","hum":74,"id":"C6:C7:52:66:3C:BF","mac_type":1,"manufacturerdata":"6909c6c752663cbf160b09914a","model":"Meter (Plus)","model_id":"THX1/W230150X","rssi":-33,"servicedata":"6980e409914a","servicedatauuid":"0xfd3d","tempc":17.9,"tempf":64.22}
{"@timestamp":"2022-10-22T20:06:19+02:00","id":"C6:C7:52:66:3C:BF","mac_type":1,"manufacturerdata":"6909c6c752663cbf160b09914a","rssi":-33}
{"@timestamp":"2022-10-22T20:06:21+02:00","id":"C6:C7:52:66:3C:BF","mac_type":1,"manufacturerdata":"6909c6c752663cbf160b09914a","rssi":-30}
{"@timestamp":"2022-10-22T20:06:27+02:00","id":"C6:C7:52:66:3C:BF","mac_type":1,"manufacturerdata":"6909c6c752663cbf160b09914a","rssi":-81}
{"@timestamp":"2022-10-22T20:06:29+02:00","id":"C6:C7:52:66:3C:BF","mac_type":1,"manufacturerdata":"6909c6c752663cbf160b09914a","rssi":-33}
{"@timestamp":"2022-10-22T20:06:35+02:00","id":"C6:C7:52:66:3C:BF","mac_type":1,"manufacturerdata":"6909c6c752663cbf160b09914a","rssi":-33}
{"@timestamp":"2022-10-22T20:06:37+02:00","id":"C6:C7:52:66:3C:BF","mac_type":1,"manufacturerdata":"6909c6c752663cbf160b09914a","rssi":-30}
{"@timestamp":"2022-10-22T20:06:43+02:00","id":"C6:C7:52:66:3C:BF","mac_type":1,"manufacturerdata":"6909c6c752663cbf160b09914a","rssi":-31}
{"@timestamp":"2022-10-22T20:06:45+02:00","id":"C6:C7:52:66:3C:BF","mac_type":1,"manufacturerdata":"6909c6c752663cbf160b09914a","rssi":-31}
{"@timestamp":"2022-10-22T20:06:51+02:00","id":"C6:C7:52:66:3C:BF","mac_type":1,"manufacturerdata":"6909c6c752663cbf160b09914a","rssi":-33}
{"@timestamp":"2022-10-22T20:06:53+02:00","id":"C6:C7:52:66:3C:BF","mac_type":1,"manufacturerdata":"6909c6c752663cbf160b09914a","rssi":-33}
{"@timestamp":"2022-10-22T20:07:01+02:00","id":"C6:C7:52:66:3C:BF","mac_type":1,"manufacturerdata":"6909c6c752663cbf160b09914a","rssi":-30}
{"@timestamp":"2022-10-22T20:07:07+02:00","id":"C6:C7:52:66:3C:BF","mac_type":1,"manufacturerdata":"6909c6c752663cbf160b09914a","rssi":-33}
{"@timestamp":"2022-10-22T20:07:13+02:00","id":"C6:C7:52:66:3C:BF","mac_type":1,"manufacturerdata":"6909c6c752663cbf160b09914a","rssi":-33}
{"@timestamp":"2022-10-22T20:07:15+02:00","id":"C6:C7:52:66:3C:BF","mac_type":1,"manufacturerdata":"6909c6c752663cbf160b09914a","rssi":-33}
{"@timestamp":"2022-10-22T20:07:19+02:00","id":"C6:C7:52:66:3C:BF","mac_type":1,"manufacturerdata":"6909c6c752663cbf160b09914a","rssi":-30}
{"@timestamp":"2022-10-22T20:07:20+02:00","batt":100,"brand":"SwitchBot","hum":74,"id":"C6:C7:52:66:3C:BF","mac_type":1,"manufacturerdata":"6909c6c752663cbf160b09914a","model":"Meter (Plus)","model_id":"THX1/W230150X","rssi":-33,"servicedata":"6980e409914a","servicedatauuid":"0xfd3d","tempc":17.9,"tempf":64.22}
{"@timestamp":"2022-10-22T20:07:27+02:00","id":"C6:C7:52:66:3C:BF","mac_type":1,"manufacturerdata":"6909c6c752663cbf160b09914a","rssi":-30}
{"@timestamp":"2022-10-22T20:07:29+02:00","id":"C6:C7:52:66:3C:BF","mac_type":1,"manufacturerdata":"6909c6c752663cbf160b09914a","rssi":-30}
{"@timestamp":"2022-10-22T20:07:38+02:00","id":"C6:C7:52:66:3C:BF","mac_type":1,"manufacturerdata":"6909c6c752663cbf160b09914a","rssi":-30}
{"@timestamp":"2022-10-22T20:07:42+02:00","id":"C6:C7:52:66:3C:BF","mac_type":1,"manufacturerdata":"6909c6c752663cbf160b09914a","rssi":-30}
{"@timestamp":"2022-10-22T20:07:48+02:00","batt":100,"brand":"SwitchBot","hum":74,"id":"C6:C7:52:66:3C:BF","mac_type":1,"manufacturerdata":"6909c6c752663cbf160b09914a","model":"Meter (Plus)","model_id":"THX1/W230150X","rssi":-31,"servicedata":"6980e409914a","servicedatauuid":"0xfd3d","tempc":17.9,"tempf":64.22}
{"@timestamp":"2022-10-22T20:07:55+02:00","id":"C6:C7:52:66:3C:BF","mac_type":1,"manufacturerdata":"6909c6c752663cbf160b09914a","rssi":-78}
{"@timestamp":"2022-10-22T20:07:59+02:00","id":"C6:C7:52:66:3C:BF","mac_type":1,"manufacturerdata":"6909c6c752663cbf160b09914a","rssi":-33}
{"@timestamp":"2022-10-22T20:08:06+02:00","batt":100,"brand":"SwitchBot","hum":74,"id":"C6:C7:52:66:3C:BF","mac_type":1,"manufacturerdata":"6909c6c752663cbf160b09914a","model":"Meter (Plus)","model_id":"THX1/W230150X","rssi":-33,"servicedata":"6980e409914a","servicedatauuid":"0xfd3d","tempc":17.9,"tempf":64.22}
{"@timestamp":"2022-10-22T20:08:15+02:00","id":"C6:C7:52:66:3C:BF","mac_type":1,"manufacturerdata":"6909c6c752663cbf160b09914a","rssi":-30}
{"@timestamp":"2022-10-22T20:08:17+02:00","id":"C6:C7:52:66:3C:BF","mac_type":1,"manufacturerdata":"6909c6c752663cbf160b09914a","rssi":-30}
{"@timestamp":"2022-10-22T20:08:22+02:00","batt":100,"brand":"SwitchBot","hum":74,"id":"C6:C7:52:66:3C:BF","mac_type":1,"manufacturerdata":"6909c6c752663cbf160b09914a","model":"Meter (Plus)","model_id":"THX1/W230150X","rssi":-31,"servicedata":"6980e409914a","servicedatauuid":"0xfd3d","tempc":17.9,"tempf":64.22}
{"@timestamp":"2022-10-22T20:08:25+02:00","batt":100,"brand":"SwitchBot","hum":74,"id":"C6:C7:52:66:3C:BF","mac_type":1,"manufacturerdata":"6909c6c752663cbf160b09914a","model":"Meter (Plus)","model_id":"THX1/W230150X","rssi":-33,"servicedata":"6980e409914a","servicedatauuid":"0xfd3d","tempc":17.9,"tempf":64.22}
{"@timestamp":"2022-10-22T20:08:27+02:00","id":"C6:C7:52:66:3C:BF","mac_type":1,"manufacturerdata":"6909c6c752663cbf160b09914a","rssi":-33}
{"@timestamp":"2022-10-22T20:08:30+02:00","batt":100,"brand":"SwitchBot","hum":74,"id":"C6:C7:52:66:3C:BF","mac_type":1,"manufacturerdata":"6909c6c752663cbf160b09914a","model":"Meter (Plus)","model_id":"THX1/W230150X","rssi":-31,"servicedata":"6980e409914a","servicedatauuid":"0xfd3d","tempc":17.9,"tempf":64.22}
{"@timestamp":"2022-10-22T20:08:33+02:00","id":"C6:C7:52:66:3C:BF","mac_type":1,"manufacturerdata":"6909c6c752663cbf160b09914a","rssi":-30}
{"@timestamp":"2022-10-22T20:08:37+02:00","id":"C6:C7:52:66:3C:BF","mac_type":1,"manufacturerdata":"6909c6c752663cbf160b09914a","rssi":-30}
{"@timestamp":"2022-10-22T20:08:41+02:00","batt":100,"brand":"SwitchBot","hum":74,"id":"C6:C7:52:66:3C:BF","mac_type":1,"manufacturerdata":"6909c6c752663cbf160b09914a","model":"Meter (Plus)","model_id":"THX1/W230150X","rssi":-33,"servicedata":"6980e409914a","servicedatauuid":"0xfd3d","tempc":17.9,"tempf":64.22}
{"@timestamp":"2022-10-22T20:08:43+02:00","id":"C6:C7:52:66:3C:BF","mac_type":1,"manufacturerdata":"6909c6c752663cbf160b09914a","rssi":-33}
{"@timestamp":"2022-10-22T20:08:51+02:00","id":"C6:C7:52:66:3C:BF","mac_type":1,"manufacturerdata":"6909c6c752663cbf160b09914a","rssi":-33}
{"@timestamp":"2022-10-22T20:08:53+02:00","id":"C6:C7:52:66:3C:BF","mac_type":1,"manufacturerdata":"6909c6c752663cbf160b09914a","rssi":-30}
{"@timestamp":"2022-10-22T20:08:59+02:00","id":"C6:C7:52:66:3C:BF","mac_type":1,"manufacturerdata":"6909c6c752663cbf160b09914a","rssi":-30}
{"@timestamp":"2022-10-22T20:09:01+02:00","id":"C6:C7:52:66:3C:BF","mac_type":1,"manufacturerdata":"6909c6c752663cbf160b09914a","rssi":-30}
{"@timestamp":"2022-10-22T20:09:09+02:00","id":"C6:C7:52:66:3C:BF","mac_type":1,"manufacturerdata":"6909c6c752663cbf160b09914a","rssi":-33}
{"@timestamp":"2022-10-22T20:09:11+02:00","batt":100,"brand":"SwitchBot","hum":74,"id":"C6:C7:52:66:3C:BF","mac_type":1,"manufacturerdata":"6909c6c752663cbf160b09914a","model":"Meter (Plus)","model_id":"THX1/W230150X","rssi":-31,"servicedata":"6980e409914a","servicedatauuid":"0xfd3d","tempc":17.9,"tempf":64.22}
{"@timestamp":"2022-10-22T20:09:15+02:00","id":"C6:C7:52:66:3C:BF","mac_type":1,"manufacturerdata":"6909c6c752663cbf160b09914a","rssi":-33}

time (in seconds) between sensor readings:

5 12 14 8 70 14 16 8 6 26 2 4 14 72 9 20 18 4 42 10 12 38 68 28 18 16 2 6 10 31 14 104 22 24 8 6 6 10 38 20 8 8 7 1 13 20 16 51 26 10 22 19 32 6 8 8 54 8 

- edit -

Just unpacked a new ESP for testing; and it -won't- connect to WiFi with the exact same configuration, i.e. all I did was press "upload". Starting to wonder if there may be remnants of a previous configuration dangling around on the other 2 ESPs.

Added '-DESPWifiManualSetup=true' and now it connects fine. Curious to see what results I'm getting on a brand new ESP.

@xanderificnl
Copy link
Author

xanderificnl commented Oct 22, 2022

Wow. On a brand new ESP, with these opts:

[env:esp32dev-ble-datatest]
platform = ${com.esp32_platform}
board = esp32dev
board_build.partitions = min_spiffs.csv
lib_deps =
  ${com-esp.lib_deps}
  ${libraries.wifimanager32}
  ${libraries.ble}
  ${libraries.decoder}
build_flags =
  ${com-esp.build_flags}
  '-DZgatewayBT="BT"'
  '-DLED_SEND_RECEIVE=2'
  '-DLED_SEND_RECEIVE_ON=0'
  '-DpubBLEManufacturerData=true'
  '-DpubKnownBLEServiceData=true'
  '-DpubBLEServiceUUID=true'
  '-DGateway_Name="OpenMQTTGateway_ESP32_BLE"'
  '-DMQTT_SERVER="172.16.32.2"'
  '-DMQTT_USER="username"'
  '-DMQTT_PASS="pwd"'
  '-Dwifi_ssid="XiFi"'
  '-Dwifi_password="snip"'
  '-DTimeBtwRead=0'
  '-DScan_duration=1000'
  '-DAttemptBLECOnnect=false'
  '-DESPWifiManualSetup=true'

This is happening:

{"@timestamp":"2022-10-22T20:41:13+02:00","id":"C6:C7:52:66:3C:BF","mac_type":1,"manufacturerdata":"6909c6c752663cbf1d0b009249","rssi":-27}
{"@timestamp":"2022-10-22T20:41:22+02:00","batt":100,"brand":"SwitchBot","hum":73,"id":"C6:C7:52:66:3C:BF","mac_type":1,"manufacturerdata":"6909c6c752663cbf1d0b009249","model":"Meter (Plus)","model_id":"THX1/W230150X","rssi":-33,"servicedata":"698064009249","servicedatauuid":"0xfd3d","tempc":18,"tempf":64.4}
{"@timestamp":"2022-10-22T20:41:26+02:00","batt":100,"brand":"SwitchBot","hum":73,"id":"C6:C7:52:66:3C:BF","mac_type":1,"manufacturerdata":"6909c6c752663cbf1d0b009249","model":"Meter (Plus)","model_id":"THX1/W230150X","rssi":-30,"servicedata":"698064009249","servicedatauuid":"0xfd3d","tempc":18,"tempf":64.4}
{"@timestamp":"2022-10-22T20:41:34+02:00","batt":100,"brand":"SwitchBot","hum":73,"id":"C6:C7:52:66:3C:BF","mac_type":1,"manufacturerdata":"6909c6c752663cbf1d0b009249","model":"Meter (Plus)","model_id":"THX1/W230150X","rssi":-30,"servicedata":"698064009249","servicedatauuid":"0xfd3d","tempc":18,"tempf":64.4}
{"@timestamp":"2022-10-22T20:41:36+02:00","batt":100,"brand":"SwitchBot","hum":73,"id":"C6:C7:52:66:3C:BF","mac_type":1,"manufacturerdata":"6909c6c752663cbf1d0b009249","model":"Meter (Plus)","model_id":"THX1/W230150X","rssi":-30,"servicedata":"698064009249","servicedatauuid":"0xfd3d","tempc":18,"tempf":64.4}
{"@timestamp":"2022-10-22T20:41:42+02:00","batt":100,"brand":"SwitchBot","hum":73,"id":"C6:C7:52:66:3C:BF","mac_type":1,"manufacturerdata":"6909c6c752663cbf1d0b009249","model":"Meter (Plus)","model_id":"THX1/W230150X","rssi":-33,"servicedata":"698064009249","servicedatauuid":"0xfd3d","tempc":18,"tempf":64.4}
{"@timestamp":"2022-10-22T20:41:46+02:00","id":"C6:C7:52:66:3C:BF","mac_type":1,"manufacturerdata":"6909c6c752663cbf1d0b009249","rssi":-28}
{"@timestamp":"2022-10-22T20:41:56+02:00","batt":100,"brand":"SwitchBot","hum":73,"id":"C6:C7:52:66:3C:BF","mac_type":1,"manufacturerdata":"6909c6c752663cbf1d0b009249","model":"Meter (Plus)","model_id":"THX1/W230150X","rssi":-33,"servicedata":"698064009249","servicedatauuid":"0xfd3d","tempc":18,"tempf":64.4}
{"@timestamp":"2022-10-22T20:41:58+02:00","batt":100,"brand":"SwitchBot","hum":73,"id":"C6:C7:52:66:3C:BF","mac_type":1,"manufacturerdata":"6909c6c752663cbf1d0b009249","model":"Meter (Plus)","model_id":"THX1/W230150X","rssi":-32,"servicedata":"698064009249","servicedatauuid":"0xfd3d","tempc":18,"tempf":64.4}
{"@timestamp":"2022-10-22T20:42:00+02:00","batt":100,"brand":"SwitchBot","hum":73,"id":"C6:C7:52:66:3C:BF","mac_type":1,"manufacturerdata":"6909c6c752663cbf1d0b009249","model":"Meter (Plus)","model_id":"THX1/W230150X","rssi":-32,"servicedata":"698064009249","servicedatauuid":"0xfd3d","tempc":18,"tempf":64.4}
{"@timestamp":"2022-10-22T20:42:06+02:00","batt":100,"brand":"SwitchBot","hum":73,"id":"C6:C7:52:66:3C:BF","mac_type":1,"manufacturerdata":"6909c6c752663cbf1d0b009249","model":"Meter (Plus)","model_id":"THX1/W230150X","rssi":-32,"servicedata":"698064009249","servicedatauuid":"0xfd3d","tempc":18,"tempf":64.4}
{"@timestamp":"2022-10-22T20:42:08+02:00","batt":100,"brand":"SwitchBot","hum":73,"id":"C6:C7:52:66:3C:BF","mac_type":1,"manufacturerdata":"6909c6c752663cbf1d0b009249","model":"Meter (Plus)","model_id":"THX1/W230150X","rssi":-29,"servicedata":"698064009249","servicedatauuid":"0xfd3d","tempc":18,"tempf":64.4}
{"@timestamp":"2022-10-22T20:42:16+02:00","batt":100,"brand":"SwitchBot","hum":73,"id":"C6:C7:52:66:3C:BF","mac_type":1,"manufacturerdata":"6909c6c752663cbf1d0b009249","model":"Meter (Plus)","model_id":"THX1/W230150X","rssi":-33,"servicedata":"698064009249","servicedatauuid":"0xfd3d","tempc":18,"tempf":64.4}
{"@timestamp":"2022-10-22T20:42:22+02:00","id":"C6:C7:52:66:3C:BF","mac_type":1,"manufacturerdata":"6909c6c752663cbf1d0b009249","rssi":-29}
{"@timestamp":"2022-10-22T20:42:32+02:00","batt":100,"brand":"SwitchBot","hum":73,"id":"C6:C7:52:66:3C:BF","mac_type":1,"manufacturerdata":"6909c6c752663cbf1d0b009249","model":"Meter (Plus)","model_id":"THX1/W230150X","rssi":-32,"servicedata":"698064009249","servicedatauuid":"0xfd3d","tempc":18,"tempf":64.4}
{"@timestamp":"2022-10-22T20:42:38+02:00","id":"C6:C7:52:66:3C:BF","mac_type":1,"manufacturerdata":"6909c6c752663cbf1d0b009249","rssi":-31}
{"@timestamp":"2022-10-22T20:42:40+02:00","id":"C6:C7:52:66:3C:BF","mac_type":1,"manufacturerdata":"6909c6c752663cbf1d0b009249","rssi":-27}
{"@timestamp":"2022-10-22T20:42:54+02:00","batt":100,"brand":"SwitchBot","hum":73,"id":"C6:C7:52:66:3C:BF","mac_type":1,"manufacturerdata":"6909c6c752663cbf1d0b009249","model":"Meter (Plus)","model_id":"THX1/W230150X","rssi":-28,"servicedata":"698064009249","servicedatauuid":"0xfd3d","tempc":18,"tempf":64.4}
{"@timestamp":"2022-10-22T20:43:04+02:00","batt":100,"brand":"SwitchBot","hum":73,"id":"C6:C7:52:66:3C:BF","mac_type":1,"manufacturerdata":"6909c6c752663cbf1d0b009249","model":"Meter (Plus)","model_id":"THX1/W230150X","rssi":-33,"servicedata":"698064009249","servicedatauuid":"0xfd3d","tempc":18,"tempf":64.4}
{"@timestamp":"2022-10-22T20:43:10+02:00","batt":100,"brand":"SwitchBot","hum":73,"id":"C6:C7:52:66:3C:BF","mac_type":1,"manufacturerdata":"6909c6c752663cbf1d0b009249","model":"Meter (Plus)","model_id":"THX1/W230150X","rssi":-30,"servicedata":"698064009249","servicedatauuid":"0xfd3d","tempc":18,"tempf":64.4}
{"@timestamp":"2022-10-22T20:43:12+02:00","batt":100,"brand":"SwitchBot","hum":73,"id":"C6:C7:52:66:3C:BF","mac_type":1,"manufacturerdata":"6909c6c752663cbf1d0b009249","model":"Meter (Plus)","model_id":"THX1/W230150X","rssi":-33,"servicedata":"698064009249","servicedatauuid":"0xfd3d","tempc":18,"tempf":64.4}
{"@timestamp":"2022-10-22T20:43:18+02:00","batt":100,"brand":"SwitchBot","hum":73,"id":"C6:C7:52:66:3C:BF","mac_type":1,"manufacturerdata":"6909c6c752663cbf1d0b009249","model":"Meter (Plus)","model_id":"THX1/W230150X","rssi":-30,"servicedata":"698064009249","servicedatauuid":"0xfd3d","tempc":18,"tempf":64.4}
{"@timestamp":"2022-10-22T20:43:27+02:00","id":"C6:C7:52:66:3C:BF","mac_type":1,"manufacturerdata":"6909c6c752663cbf1d0b009249","rssi":-28}
{"@timestamp":"2022-10-22T20:43:29+02:00","id":"C6:C7:52:66:3C:BF","mac_type":1,"manufacturerdata":"6909c6c752663cbf1d0b009249","rssi":-28}
{"@timestamp":"2022-10-22T20:43:32+02:00","batt":100,"brand":"SwitchBot","hum":73,"id":"C6:C7:52:66:3C:BF","mac_type":1,"manufacturerdata":"6909c6c752663cbf1d0b009249","model":"Meter (Plus)","model_id":"THX1/W230150X","rssi":-32,"servicedata":"698064009249","servicedatauuid":"0xfd3d","tempc":18,"tempf":64.4}
{"@timestamp":"2022-10-22T20:43:41+02:00","id":"C6:C7:52:66:3C:BF","mac_type":1,"manufacturerdata":"6909c6c752663cbf1d0b009249","rssi":-31}

So perhaps the other 2 ESP32s need a full reflash?

(I did believe the "upload" on platformio did that.)

So something weird happened. I grabbed an ESP32 that was lying around, I pressed 'upload' and it wasn't able to connect to WiFi. FIgured it was a fluke, and unpacked a new one. Same problem.

Added the '-DESPWifiManualSetup=true' flag, and it did work. A flag I had used before on the other 2 ESPs.

So apparently the other 2 ESPs still have dangling settings running afoul?

New ESP: 5 minutes & 36 sensor readings....

@DigiH
Copy link
Collaborator

DigiH commented Oct 22, 2022

Just unpacked a new ESP for testing; and it -won't- connect to WiFi with the exact same configuration, i.e. all I did was press "upload". Starting to wonder if there may be remnants of a previous configuration dangling around on the other 2 ESPs.

Best to erase the Flash before uploading a new configuration to a new or well used ESP32. Worth a try with these two.

(I did believe the "upload" on platformio did that.)

esptool.py --port /dev/ttyUSB0 erase_flash

in the platformio terminal will do the trick.

time (in seconds) between sensor readings:

5 12 14 8 70 14 16 8 6 26 2 4 14 72 9 20 18 4 42 10 12 38 68 28 18 16 2 6 10 31 14 104 22 24 8 6 6 10 38 20 8 8 7 1 13 20 16 51 26 10 22 19 32 6 8 8 54 8 

Well, more regular decoded readings than the previous switcbot-mqtt-ble-esp32.log now, undecoded 'breaks' not more than roughly a minute apart.

Still very curious as to why there are so many more manufacturerdata only messages than decoded ones including the servicedata, when it should be the other way round.

But this clearly shows that with the default

'-DTimeBtwRead=55000'
'-DScan_duration=10000'

the 10 second scan window every 55 seconds could/would easily fall into several manufacturerdata only broadcasts, continuously only showing these for a long time, even if correctly decoded servicedata messages had been broadcast during the TimeBtwRead - when no OMG scan occurs. What you saw before with the default environment/binary.

Is/was the SwitchBot Meter linked to a SwitchBot Hub at all?

Any improvements after clearing the flash before a new upload?

@DigiH
Copy link
Collaborator

DigiH commented Oct 22, 2022

Added the '-DESPWifiManualSetup=true' flag, and it did work. A flag I had used before on the other 2 ESPs.

if you use manual WiFi and MQTT broker credentials, as in your environment above

  '-DMQTT_SERVER="172.16.32.2"'
  '-DMQTT_USER="username"'
  '-DMQTT_PASS="pwd"'
  '-Dwifi_ssid="XiFi"'
  '-Dwifi_password="snip"'

you will always also have to set
'-DESPWifiManualSetup=true'

as otherwise the above should be recognised. As it is indicated in the above environment.

@xanderificnl
Copy link
Author

Yeah, so I did start off with the binary release - and that didn't give me sensor data. So I moved on to building myself and fiddling with settings. So presumably increasing the window might solve the issue?

I don't have or own a hub.

So on the brand new ESP is off and I've wiped one of the previous ESPs, cleaned the environment, built and uploaded it. These are the logs:

{"@timestamp":"2022-10-22T21:08:54+02:00","id":"C6:C7:52:66:3C:BF","mac_type":1,"manufacturerdata":"6909c6c752663cbf200b009249","rssi":-25}
{"@timestamp":"2022-10-22T21:09:01+02:00","id":"C6:C7:52:66:3C:BF","mac_type":1,"manufacturerdata":"6909c6c752663cbf210b009249","rssi":-25}
{"@timestamp":"2022-10-22T21:09:02+02:00","id":"C6:C7:52:66:3C:BF","mac_type":1,"manufacturerdata":"6909c6c752663cbf210b009249","rssi":-24}
{"@timestamp":"2022-10-22T21:09:06+02:00","id":"C6:C7:52:66:3C:BF","mac_type":1,"manufacturerdata":"6909c6c752663cbf210b009249","rssi":-23}
{"@timestamp":"2022-10-22T21:09:08+02:00","id":"C6:C7:52:66:3C:BF","mac_type":1,"manufacturerdata":"6909c6c752663cbf210b009249","rssi":-24}
{"@timestamp":"2022-10-22T21:09:10+02:00","id":"C6:C7:52:66:3C:BF","mac_type":1,"manufacturerdata":"6909c6c752663cbf210b009249","rssi":-25}
{"@timestamp":"2022-10-22T21:09:12+02:00","id":"C6:C7:52:66:3C:BF","mac_type":1,"manufacturerdata":"6909c6c752663cbf210b009249","rssi":-23}
{"@timestamp":"2022-10-22T21:09:16+02:00","id":"C6:C7:52:66:3C:BF","mac_type":1,"manufacturerdata":"6909c6c752663cbf210b009249","rssi":-24}
{"@timestamp":"2022-10-22T21:09:18+02:00","batt":100,"brand":"SwitchBot","hum":73,"id":"C6:C7:52:66:3C:BF","mac_type":1,"manufacturerdata":"6909c6c752663cbf210b009249","model":"Meter (Plus)","model_id":"THX1/W230150X","rssi":-27,"servicedata":"698064009249","servicedatauuid":"0xfd3d","tempc":18,"tempf":64.4}
{"@timestamp":"2022-10-22T21:09:20+02:00","id":"C6:C7:52:66:3C:BF","mac_type":1,"manufacturerdata":"6909c6c752663cbf210b009249","rssi":-26}
{"@timestamp":"2022-10-22T21:09:26+02:00","id":"C6:C7:52:66:3C:BF","mac_type":1,"manufacturerdata":"6909c6c752663cbf210b009249","rssi":-23}
{"@timestamp":"2022-10-22T21:09:28+02:00","id":"C6:C7:52:66:3C:BF","mac_type":1,"manufacturerdata":"6909c6c752663cbf210b009249","rssi":-26}
{"@timestamp":"2022-10-22T21:09:30+02:00","id":"C6:C7:52:66:3C:BF","mac_type":1,"manufacturerdata":"6909c6c752663cbf210b009249","rssi":-26}
{"@timestamp":"2022-10-22T21:09:32+02:00","id":"C6:C7:52:66:3C:BF","mac_type":1,"manufacturerdata":"6909c6c752663cbf210b009249","rssi":-24}
{"@timestamp":"2022-10-22T21:09:36+02:00","id":"C6:C7:52:66:3C:BF","mac_type":1,"manufacturerdata":"6909c6c752663cbf210b009249","rssi":-24}
{"@timestamp":"2022-10-22T21:09:42+02:00","id":"C6:C7:52:66:3C:BF","mac_type":1,"manufacturerdata":"6909c6c752663cbf210b009249","rssi":-26}
{"@timestamp":"2022-10-22T21:09:44+02:00","id":"C6:C7:52:66:3C:BF","mac_type":1,"manufacturerdata":"6909c6c752663cbf210b009249","rssi":-24}
{"@timestamp":"2022-10-22T21:09:50+02:00","batt":100,"brand":"SwitchBot","hum":73,"id":"C6:C7:52:66:3C:BF","mac_type":1,"manufacturerdata":"6909c6c752663cbf210b009249","model":"Meter (Plus)","model_id":"THX1/W230150X","rssi":-26,"servicedata":"698064009249","servicedatauuid":"0xfd3d","tempc":18,"tempf":64.4}
{"@timestamp":"2022-10-22T21:09:52+02:00","id":"C6:C7:52:66:3C:BF","mac_type":1,"manufacturerdata":"6909c6c752663cbf210b009249","rssi":-23}

So the brand new ESP actually flooded the logs with sensor data but that also returned to manufacturerdata. So it was mostlikely a fluke.

Presumably changing/increase the window would solve it?

@xanderificnl
Copy link
Author

with regards to the window: I wasn't reading correctly. You meant with the regular release, not the adjusted settings we've been using, correct?

you will always also have to set '-DESPWifiManualSetup=true'

Yes, but with the ESP I had been testing on, I hadn't set that flag for the datatest environment. It still connected to WiFi whereas 2 other ESPs failed to do so. So there must have been dangling resources/configuration going on.

I'm inclinded to let the new ESP run for a night and see how it fares. So far it's been doing so much better even though it does seem to get flooded with manufacturer-only messages everyonce in a while.

@DigiH
Copy link
Collaborator

DigiH commented Oct 22, 2022

Presumably changing/increase the window would solve it?

Yes, I would think having a go with the TimeBtwRead and Scan_duration should give you a usable result, as the continuous scanning showed that you can catch a decoded message at least every minute.

Just to show that something is still amiss is the comparison between your -cont log and the colleague's -cont log

Screenshot 2022-10-22 at 21 14 50

That right side would also be the ideal for your SwichBot Meter as well!

Why there seems to be a majority of manufacturerdata only messages is beyond me at this stage, but I think we found, that with nicely adjusted TimeBtwRead and Scan_duration settings you can get a workable OMG setup, with at least one correct decoded reading every minute.

with regards to the window: I wasn't reading correctly. You meant with the regular release, not the adjusted settings we've been using, correct?

Correct, that was meant for the regular default ble release, using these default settings as a comparison.

@xanderificnl
Copy link
Author

xanderificnl commented Oct 22, 2022

That's a huge difference. With the new ESP, I've been seeing only manufacturer data for more than 5 minutes now and that's with esp32dev-ble-datatest.

I'm going to google around some more and see if I can find a project that allows me to use an ESP32 as a BLE-receiver and inspect that data in Wireshark. Presumably, we'd get a little bit more raw information about what's going on.

Something tells me that my Switchbot is looking for a hub, or it maybe found a hub (that isn't mine) somewhere near me. Or that it's looking for registration or something along those lines. i.e. that it's saying "I'm here" w/ the manufacturer only data.

Thanks for the help. It's really nice, I'll update when I get the chance!

@1technophile
Copy link
Owner

Hello,

Do you mind sharing a picture of the back of your sensor.
Here is mind that report constantly data:
IMG_20221023_081904

The goal is to check for any model difference.

@xanderificnl
Copy link
Author

with the PR

Mostly manufacturer only readings

esphome

The nimble example gave me a bit of grieve so I figured: let's try ESPHome's esp32_ble_tracker module.

Default tracker config

[00:07:23.6600] [C][esp32_ble_tracker:787]: BLE Tracker:
[00:07:23.6644] [C][esp32_ble_tracker:788]:   Scan Duration: 300 s
[00:07:23.6706] [C][esp32_ble_tracker:789]:   Scan Interval: 320.0 ms
[00:07:23.6765] [C][esp32_ble_tracker:790]:   Scan Window: 30.0 ms
[00:07:23.6814] [C][esp32_ble_tracker:791]:   Scan Type: ACTIVE
[00:07:23.6866] [C][esp32_ble_tracker:792]:   Continuous Scanning: True

Excerpt from the serial console:

[00:20:36.0707] [VV][esp32_ble_tracker:575]: Parse Result:
[00:20:36.0753] [VV][esp32_ble_tracker:592]:   Address: C6:C7:52:66:3C:BF (RANDOM)
[00:20:36.0823] [VV][esp32_ble_tracker:594]:   RSSI: -27
[00:20:36.0877] [VV][esp32_ble_tracker:595]:   Name: ''
[00:20:36.0913] [VV][esp32_ble_tracker:603]:   Ad Flag: 6
[00:20:36.0963] [VV][esp32_ble_tracker:609]:   Manufacturer data: C6.C7.52.66.3C.BF.61.0B.07.91.4A (11)
[00:20:36.1056] [VV][esp32_ble_tracker:620]:   Service data:
[00:20:36.1104] [VV][esp32_ble_tracker:621]:     UUID: 0xFD3D
[00:20:36.1162] [VV][esp32_ble_tracker:622]:     Data: 69.80.E4.07.91.4A (6)
[00:20:36.1213] [VV][esp32_ble_tracker:625]: Adv data: 02.01.06.0E.FF.69.09.C6.C7.52.66.3C.BF.61.0B.07.91.4A.09.16.3D.FD.69.80.E4.07.91.4A (28)
[00:20:36.1334] [D][ble_adv:012]: SwitchBot
[00:20:36.1373] [V][component:199]: Component esp32_ble_tracker took a long time for an operation (0.06 s).
[00:20:36.1463] [V][component:200]: Components should block for at most 20-30ms.

[00:25:31.8750] [VV][esp32_ble_tracker:575]: Parse Result:
[00:25:31.8805] [VV][esp32_ble_tracker:592]:   Address: C6:C7:52:66:3C:BF (RANDOM)
[00:25:31.8866] [VV][esp32_ble_tracker:594]:   RSSI: -28
[00:25:31.8916] [VV][esp32_ble_tracker:595]:   Name: ''
[00:25:31.8967] [VV][esp32_ble_tracker:603]:   Ad Flag: 6
[00:25:31.9029] [VV][esp32_ble_tracker:609]:   Manufacturer data: C6.C7.52.66.3C.BF.66.0B.03.92.57 (11)
[00:25:31.9096] [VV][esp32_ble_tracker:620]:   Service data:
[00:25:31.9145] [VV][esp32_ble_tracker:621]:     UUID: 0xFD3D
[00:25:31.9196] [VV][esp32_ble_tracker:622]:     Data: 69.80.E4.03.92.57 (6)
[00:25:31.9256] [VV][esp32_ble_tracker:625]: Adv data: 02.01.06.0E.FF.69.09.C6.C7.52.66.3C.BF.66.0B.03.92.57.09.16.3D.FD.69.80.E4.03.92.57 (28)
[00:25:31.9376] [V][component:199]: Component esp32_ble_tracker took a long time for an operation (0.05 s).
[00:25:31.9469] [V][component:200]: Components should block for at most 20-30ms.

[00:25:41.1333] [VV][esp32_ble_tracker:575]: Parse Result:
[00:25:41.1386] [VV][esp32_ble_tracker:592]:   Address: C6:C7:52:66:3C:BF (RANDOM)
[00:25:41.1455] [VV][esp32_ble_tracker:594]:   RSSI: -23
[00:25:41.1495] [VV][esp32_ble_tracker:595]:   Name: ''
[00:25:41.1549] [VV][esp32_ble_tracker:603]:   Ad Flag: 6
[00:25:41.1595] [VV][esp32_ble_tracker:609]:   Manufacturer data: C6.C7.52.66.3C.BF.68.0B.03.92.50 (11)
[00:25:41.1676] [VV][esp32_ble_tracker:620]:   Service data:
[00:25:41.1729] [VV][esp32_ble_tracker:621]:     UUID: 0xFD3D
[00:25:41.1777] [VV][esp32_ble_tracker:622]:     Data: 69.80.E4.03.92.50 (6)
[00:25:41.1846] [VV][esp32_ble_tracker:625]: Adv data: 02.01.06.0E.FF.69.09.C6.C7.52.66.3C.BF.68.0B.03.92.50.09.16.3D.FD.69.80.E4.03.92.50 (28)

It reads about once a minute w/ service data. The component warning happens after some devices, but not all. Interestingly to note is that the manufacturer data changes whereas with OMG it stays the same, i.e. from one of my omg.log's

$ jq '.manufacturerdata' ~/omg.log | wc -l
46
$ jq '.manufacturerdata' ~/omg.log | sort -u
"6909c6c752663cbf290b079149"
"6909c6c752663cbf2a0b069149"

So far ESPHome's output is comparable with Theengs, compared the data into ESPHome's dotted format for readability i.e.

~ manufacturer data
ESPHOME C6.C7.52.66.3C.BF.68.0B.03.92.50
Theengs C6.C7.52.66.3C.BF.39.0B.05.91.4B
OMG 69.09.C6.C7.52.66.3C.BF.2A.0B.06.91.49

Why do you think OMG's is prefixed by 69.09 instead of the mac address such as the others?

@h2zero
Copy link
Collaborator

h2zero commented Oct 25, 2022

The nimble example gave me a bit of grieve

Could you elaborate on this?

Why do you think OMG's is prefixed by 69.09 instead of the mac address such as the others?

I'll look into this.
EDIT: looked into it, simple explanation is different representation.
manufacturer_data={2409: 'c6c752663cbf390b05914b'} ~= "manufacturerdata":"6909c6c752663cbf210b009249"
6909 in little endian = 0x0969 = 2409 decimal, which represents the manufacturer ID in the BLE manufacturer data type.
OMG simply provides the entire data packet when publishing and does not separate out the ID as the other applications do.

@xanderificnl
Copy link
Author

The nimble example gave me a bit of grieve

Could you elaborate on this?

I was in a bit of a rush (had a few moments in between work), so I figured I'd quickly install Arduino's IDE; but found Arduino's web IDE instead. So I imported the library and added the example, but it wouldn't compile. It ran into an issue looking for a config.h file. I figured, I'd look into it a little bit later. So I did, and then it ran into missing FreeRTOS (iirc) and so I added that, but that didn't pan out. So again, I figured I'd look into it a bit later and in the meantime I just flashed ESPHome w/ some config to get some data.

So nimble example gave me a bit of grieve really means I'm still very inexperienced in the ESP* ecosystem and haven't found my way around yet :)

Truth be told, I probably overlooked something obvious; or read over something while it was staring me in the face.

6909 in little endian = 0x0969 = 2409 decimal, which represents the manufacturer ID in the BLE manufacturer data type.

Ah, that makes sense. I'll be giving the nimble example another try - hopefully later today - to see if I can confirm the observations made with ESPHome.

--

I do want to express my gratitude to all of you, and especially @DigiH for all his time and effort, for helping me out and looking into this!

@DigiH
Copy link
Collaborator

DigiH commented Oct 25, 2022

Interestingly to note is that the manufacturer data changes whereas with OMG it stays the same

Not quite the case ;) as with OMG/Decoder the manufacturerdata also changes, as the last 3 bytes do actually contain the temperature and humidity information (no battery). Easily visible when both manufacturerdata and servicedata are present

{"@timestamp":"2022-10-22T20:07:20+02:00","batt":100,"brand":"SwitchBot","hum":74,"id":"C6:C7:52:66:3C:BF","mac_type":1,"manufacturerdata":"6909c6c752663cbf160b09914a","model":"Meter (Plus)","model_id":"THX1/W230150X","rssi":-33,"servicedata":"6980e409914a","servicedatauuid":"0xfd3d","tempc":17.9,"tempf":64.22}

Unfortunately when it is a manufacturerdata only transmission there is no additional clear identification as with the servicedata's device type and the servicedatauuid to uniquely identify this device to be able to use manufacturerdata only for a clear decoding.

{"@timestamp":"2022-10-22T20:08:51+02:00","id":"C6:C7:52:66:3C:BF","mac_type":1,"manufacturerdata":"6909c6c752663cbf160b09914a","rssi":-33}

@xanderificnl
Copy link
Author

xanderificnl commented Oct 26, 2022

Here are the logs of the NimBLE example:

[c6:c7:52:66:3c:bf = the switchbot]

[15:09:07.0065] Scanning...
[15:09:07.2946] Advertised Device: Name: HwZ_fb113f1ab1002b1915, Address: 00:a0:50:63:16:55 
[15:09:07.3965] Advertised Device: Name: , Address: 64:6f:d4:4f:e1:57, manufacturer data: 4c001005441c8bb550, txPower: 12 
[15:09:12.1448] Advertised Device: Name: , Address: f5:e4:04:f9:c7:e8, manufacturer data: 4c0012020003 
[15:09:24.4545] Advertised Device: Name: , Address: d4:5d:76:96:ee:4c, manufacturer data: 4c0012020000 
[15:09:26.2919] Advertised Device: Name: , Address: c6:c7:52:66:3c:bf, manufacturer data: 6909c6c752663cbfc10b01924d
[15:09:26.3007] Service Data:
[15:09:26.3027] UUID: 0xfd3d, Data: i���M 
[15:10:07.2678] Advertised Device: Name: HwZ_fb113f1ab1002b1915, Address: 00:a0:50:63:16:55 
[15:10:08.1237] Advertised Device: Name: , Address: 64:6f:d4:4f:e1:57, manufacturer data: 4c001005441c8bb550, txPower: 12 
[15:10:16.1883] Advertised Device: Name: , Address: f5:e4:04:f9:c7:e8, manufacturer data: 4c0012020003 
[15:10:26.4362] Advertised Device: Name: , Address: c6:c7:52:66:3c:bf, manufacturer data: 6909c6c752663cbfc10b01924d
[15:10:26.4456] Service Data:
[15:10:26.4465] UUID: 0xfd3d, Data: i���M 
[15:11:07.2196] Advertised Device: Name: HwZ_fb113f1ab1002b1915, Address: 00:a0:50:63:16:55 
[15:11:12.5512] Advertised Device: Name: , Address: c6:c7:52:66:3c:bf, manufacturer data: 6909c6c752663cbfc10b01924d
[15:11:12.5604] Service Data:
[15:11:12.5614] UUID: 0xfd3d, Data: i���M 
[15:11:14.6790] Advertised Device: Name: , Address: 64:6f:d4:4f:e1:57, manufacturer data: 4c001005441c8bb550, txPower: 12 
[15:11:16.2264] Advertised Device: Name: , Address: f5:e4:04:f9:c7:e8, manufacturer data: 4c0012020003 
[15:12:07.1737] Advertised Device: Name: , Address: 64:6f:d4:4f:e1:57, manufacturer data: 4c001005441c8bb550, txPower: 12 
[15:12:10.2758] Advertised Device: Name: , Address: f5:e4:04:f9:c7:e8, manufacturer data: 4c0012020003 
[15:12:25.1998] Advertised Device: Name: , Address: 58:8e:c6:2a:9a:7f, manufacturer data: 4c0002151ca92e23f0874df7b9a2fd4b716a4bf60084000003 
[15:12:30.7349] Advertised Device: Name: , Address: c6:c7:52:66:3c:bf, manufacturer data: 6909c6c752663cbfc10b01924d
[15:12:30.7441] Service Data:
[15:12:30.7451] UUID: 0xfd3d, Data: i���M 
[15:13:07.1300] Advertised Device: Name: HwZ_fb113f1ab1002b1915, Address: 00:a0:50:63:16:55 
[15:13:08.0068] Advertised Device: Name: , Address: 64:6f:d4:4f:e1:57, manufacturer data: 4c001005441c8bb550, txPower: 12 
[15:13:08.3238] Advertised Device: Name: , Address: f5:e4:04:f9:c7:e8, manufacturer data: 4c0012020003 
[15:13:08.7941] Advertised Device: Name: , Address: c6:c7:52:66:3c:bf, manufacturer data: 6909c6c752663cbfc10b01924d
[15:13:08.8030] Service Data:
[15:13:08.8050] UUID: 0xfd3d, Data: i���M 
[15:14:07.0962] Advertised Device: Name: HwZ_fb113f1ab1002b1915, Address: 00:a0:50:63:16:55 
[15:14:09.6395] Advertised Device: Name: , Address: 64:6f:d4:4f:e1:57, manufacturer data: 4c001005441c8bb550, txPower: 12 
[15:14:14.3629] Advertised Device: Name: , Address: f5:e4:04:f9:c7:e8, manufacturer data: 4c0012020003 
[15:14:16.9680] Advertised Device: Name: , Address: c6:c7:52:66:3c:bf, manufacturer data: 6909c6c752663cbfc10b01924d
[15:14:16.9769] Service Data:
[15:14:16.9789] UUID: 0xfd3d, Data: i���M 

The nimble example gave me a bit of grieve

Could you elaborate on this?

@h2zero The problem was either with me and/or the web ide. After installing Arduino's IDE locally, I got the example running in less than 5 minutes flat w/o any fuzz.

Plan:

So far - BLE-scanner (the nimble example) has only picked up the switchbot with service data. The service data isn't very readable, so I'll try to adjust that to something more readable for us. At the very least, it does appear (as suggested by Theengs GW and ESPHome) there are no readings without service data.

I'm also going to flash an ESP with OMG-BLE-CONT and log the output of that. Presumably, at some point it'll randomly pick up a sensor reading; and we'll be able to compare its reading w/ the output from BLE-scanner.


[edit]

Modified the nimble example to filter on the MAC of the switchbot + decode the service data. I'm not a hero in these languages but I'm hopeful I did it correctly: https://gist.github.com/xanderificnl/c264238e4318f6462c6db1f83559f563

Here's an example of output (decode values are prefixed with '>>'):

[18:40:38.1801] [switchbot] Advertised Device: Name: , Address: c6:c7:52:66:3c:bf, manufacturer data: 6909c6c752663cbfe00b01924d
[18:40:38.1904] Service Data:
[18:40:38.1914] UUID: 0xfd3d, Data: i���M 
[18:40:38.1943] >> 6980e401924d 
[18:41:48.3144] [switchbot] Advertised Device: Name: , Address: c6:c7:52:66:3c:bf, manufacturer data: 6909c6c752663cbfe00b01924d
[18:41:48.3251] Service Data:
[18:41:48.3262] UUID: 0xfd3d, Data: i���M 
[18:41:48.3281] >> 6980e401924d 
[18:41:50.9557] Advertised Device: Name: , Address: ef:b8:c4:77:64:e8, manufacturer data: 4c0012020003 
[18:42:25.7317] Advertised Device: Name: , Address: 72:5e:d0:eb:ee:76, manufacturer data: 4c0002151ca92e23f0874df7b9a2fd4b716a4bf6008d000003 
[18:42:44.1366] Advertised Device: Name: , Address: d4:e7:a5:87:5b:ba, manufacturer data: 4c0012020003 
[18:42:59.7265] [switchbot] Advertised Device: Name: , Address: c6:c7:52:66:3c:bf, manufacturer data: 6909c6c752663cbfe00b01924d
[18:42:59.7370] Service Data:
[18:42:59.7380] UUID: 0xfd3d, Data: i�� 
[18:42:59.7400] >> 6980e400924d 

@1technophile
Copy link
Owner

Let me try to run it on my side with my switchbot, and share what I see

@1technophile
Copy link
Owner

1technophile commented Oct 31, 2022

I tried in my side with different versions of NimBLEArduino and the sketch below but got constant reporting of servicedata.

Could you try this sketch please with NimBLEArduino v1.3.8 and share your logs:

/** Example of continuous scanning for BLE advertisements.
 * This example will scan forever while consuming as few resources as possible
 * and report all advertisments on the serial monitor.
 *
 * Created: on January 31 2021
 *      Author: H2zero
 *
 */

#include "NimBLEDevice.h"

NimBLEScan* pBLEScan;

std::string convertServiceData(std::string deviceServiceData) {
  int serviceDataLength = (int)deviceServiceData.length();
  char spr[2 * serviceDataLength + 1];
  for (int i = 0; i < serviceDataLength; i++) sprintf(spr + 2 * i, "%.2x", (unsigned char)deviceServiceData[i]);
  spr[2 * serviceDataLength] = 0;
  return spr;
}

class MyAdvertisedDeviceCallbacks: public NimBLEAdvertisedDeviceCallbacks {
    void onResult(NimBLEAdvertisedDevice* advertisedDevice) {
      Serial.println("-----------------------------------------------------------------------------------");
      Serial.printf("Advertised Device mac: %s \n", advertisedDevice->getAddress().toString().c_str());
      Serial.printf("Advertised Device name: %s \n", (char*)advertisedDevice->getName().c_str());
      if (advertisedDevice->haveManufacturerData()) {
         char* manufacturerdata = BLEUtils::buildHexData(NULL, (uint8_t*)advertisedDevice->getManufacturerData().data(), advertisedDevice->getManufacturerData().length());
         Serial.printf("Advertised Device manufacturer data: %s \n", manufacturerdata);
         free(manufacturerdata);
      }
      if (advertisedDevice->haveServiceData()) {
          int serviceDataCount = advertisedDevice->getServiceDataCount();
           Serial.printf("Get services data number: %d \n", serviceDataCount);
          for (int j = 0; j < serviceDataCount; j++) {
            std::string service_data = convertServiceData(advertisedDevice->getServiceData(j));
            Serial.printf("Service data: %s \n", service_data.c_str());
            std::string serviceDatauuid = advertisedDevice->getServiceDataUUID(j).toString();
            Serial.printf("Service data UUID: %s \n", (char*)serviceDatauuid.c_str());
          }
      }
    }
};

void setup() {
  Serial.begin(115200);
  Serial.println("Scanning...");

/** *Optional* Sets the filtering mode used by the scanner in the BLE controller.
 *
 *  Can be one of:
 *  CONFIG_BTDM_SCAN_DUPL_TYPE_DEVICE (0) (default)
 *  Filter by device address only, advertisements from the same address will be reported only once.
 *
 *  CONFIG_BTDM_SCAN_DUPL_TYPE_DATA (1)
 *  Filter by data only, advertisements with the same data will only be reported once,
 *  even from different addresses.
 *
 *  CONFIG_BTDM_SCAN_DUPL_TYPE_DATA_DEVICE (2)
 *  Filter by address and data, advertisements from the same address will be reported only once,
 *  except if the data in the advertisement has changed, then it will be reported again.
 *
 *  Can only be used BEFORE calling NimBLEDevice::init.
*/
  NimBLEDevice::setScanFilterMode(CONFIG_BTDM_SCAN_DUPL_TYPE_DEVICE);

/** *Optional* Sets the scan filter cache size in the BLE controller.
 *  When the number of duplicate advertisements seen by the controller
 *  reaches this value it will clear the cache and start reporting previously
 *  seen devices. The larger this number, the longer time between repeated
 *  device reports. Range 10 - 1000. (default 20)
 *
 *  Can only be used BEFORE calling NimBLEDevice::init.
 */
  NimBLEDevice::setScanDuplicateCacheSize(200);

  NimBLEDevice::init("");

  pBLEScan = NimBLEDevice::getScan(); //create new scan
  // Set the callback for when devices are discovered, no duplicates.
  pBLEScan->setAdvertisedDeviceCallbacks(new MyAdvertisedDeviceCallbacks(), false);
  pBLEScan->setActiveScan(true); // Set active scanning, this will get more data from the advertiser.
  pBLEScan->setInterval(97); // How often the scan occurs / switches channels; in milliseconds,
  pBLEScan->setWindow(37);  // How long to scan during the interval; in milliseconds.
  pBLEScan->setMaxResults(0); // do not store the scan results, use callback only.
}

void loop() {
  // If an error occurs that stops the scan, it will be restarted here.
  if(pBLEScan->isScanning() == false) {
      // Start scan with: duration = 0 seconds(forever), no scan end callback, not a continuation of a previous scan.
      pBLEScan->start(0, nullptr, false);
  }

  delay(2000);
}

@xanderificnl
Copy link
Author

xanderificnl commented Nov 1, 2022

Attached is the log.

Notably, the switchbot got picked up with the service data a total of 113 times. Somehow, only OMG is picking up manufacturer-only data on various ESP32s. So why is OMG seeing manufacturer only data and nothing else is?

I've run 3 different nimble continuous scanners (the default, yours and mine), ESPHome and Theengs Gateway (on my laptop).

serial.log

Can we get OMG to dump what it sees to serial before it starts processing it?

@1technophile
Copy link
Owner

1technophile commented Nov 1, 2022

Thanks for sharing this, we can see that the servicedata is retrieved constantly when focusing on the library functions only.

Can we get OMG to dump what it sees to serial before it starts processing it?

Yes you would need to set the debug log level to LOG_LEVEL_TRACE here

Or add this into your pio env build_flags:
'-DLOG_LEVEL=LOG_LEVEL_TRACE'

@xanderificnl
Copy link
Author

Cheers, thanks!


You can skip forward to [interesting bit] below.


The final tally of the library functions: 289 broadcasts - all including service data.

Steps:

  1. PIO: clean all
  2. PIO: clean all all (I'm not sure why that's an option, but sure - why not.)
  3. GIT: reset
  4. GIT: pull origin/development (clean tree)
  5. ESP: erase flash.
  6. OMG: Added log level to config. See below for full config.
  7. PIO: build (all dependencies are fetched etc.)
  8. PIO: upload / flash
  9. RCOM: open serial log & tee serial.log.
  10. ESP: restart (so we can see OMG boot).

Full config:

[platformio]
default_envs =
  esp32dev-ble-cont

;esp32 cnt
[env:esp32dev-ble-cont]
platform = ${com.esp32_platform}
board = esp32dev
board_build.partitions = min_spiffs.csv
lib_deps =
  ${com-esp.lib_deps}
  ${libraries.wifimanager32}
  ${libraries.ble}
  ${libraries.decoder}
build_flags =
  ${com-esp.build_flags}
  '-DZgatewayBT="BT"'
  '-DLED_SEND_RECEIVE=2'
  '-DLED_SEND_RECEIVE_ON=0'
  '-DGateway_Name="kfwnlnfkwl"'
  '-DAttemptBLEConnect=false'
  '-DMQTT_SERVER="172.16.32.2"'
  '-Dwifi_ssid="XiFi"'
  '-Dwifi_password="-snip-"'
  '-DESPWifiManualSetup=true'
  '-DLOG_LEVEL=LOG_LEVEL_TRACE'
upload_port = /dev/ttyUSB0

interesting bit

serial.log <-- LOG before my edit

After not seeing anything standing out, I modified ZgatewayBT.ino to include:

Log.trace(F("%s" CR), advertisedDevice->toString().c_str());

Which yielded the familiar: T: Name: , Address: c6:c7:52:66:3c:bf, manufacturer data: 6909c6c752663cbfa00f029243

  1. I re-ran the BLE example against NimBLE 1.3.8 (the one used by OMG). The example still returned continuous service data.
  2. I bumped OMG's NimBLE to 1.4.1., but that again made no difference.
  3. Made OMG's settings look like those from NimBLE:
// config_BT.h
 #ifndef Scan_duration
-#  define Scan_duration 10000 //define the time for a scan
+#  define Scan_duration 0 //define the time for a scan
 #endif
 #ifndef BLEScanInterval
-#  define BLEScanInterval 52 // How often the scan occurs / switches channels; in milliseconds,
+#  define BLEScanInterval 97 // How often the scan occurs / switches channels; in milliseconds,
 #endif
 #ifndef BLEScanWindow
-#  define BLEScanWindow 30 // How long to scan during the interval; in milliseconds.
+#  define BLEScanWindow 37 // How long to scan during the interval; in milliseconds.

and this starts to happen:

[02:07:38.0405] N: Send on /BTtoMQTT/C6C752663CBF msg {"id":"C6:C7:52:66:3C:BF","mac_type":1,"rssi":-48,"brand":"SwitchBot","model":"Meter (Plus)","model_id":"THX1/W230150X","tempc":18.5,"tempf":65.3,"hum":66,"batt":100}
[02:08:14.4896] N: Send on /BTtoMQTT/C6C752663CBF msg {"id":"C6:C7:52:66:3C:BF","mac_type":1,"rssi":-49,"brand":"SwitchBot","model":"Meter (Plus)","model_id":"THX1/W230150X","tempc":18.5,"tempf":65.3,"hum":65,"batt":100}
[02:09:48.7264] N: Send on /BTtoMQTT/C6C752663CBF msg {"id":"C6:C7:52:66:3C:BF","mac_type":1,"rssi":-48,"brand":"SwitchBot","model":"Meter (Plus)","model_id":"THX1/W230150X","tempc":18.5,"tempf":65.3,"hum":65,"batt":100}
- 02:10 nothing.
[02:11:42.9423] N: Send on /BTtoMQTT/C6C752663CBF msg {"id":"C6:C7:52:66:3C:BF","mac_type":1,"rssi":-48,"brand":"SwitchBot","model":"Meter (Plus)","model_id":"THX1/W230150X","tempc":18.5,"tempf":65.3,"hum":65,"batt":100}
[02:12:31.0727] N: Send on /BTtoMQTT/C6C752663CBF msg {"id":"C6:C7:52:66:3C:BF","mac_type":1,"rssi":-55,"brand":"SwitchBot","model":"Meter (Plus)","model_id":"THX1/W230150X","tempc":18.5,"tempf":65.3,"hum":65,"batt":100}
[02:13:35.2240] N: Send on /BTtoMQTT/C6C752663CBF msg {"id":"C6:C7:52:66:3C:BF","mac_type":1,"rssi":-55,"brand":"SwitchBot","model":"Meter (Plus)","model_id":"THX1/W230150X","tempc":18.5,"tempf":65.3,"hum":65,"batt":100}
- 02:14 nothing
- 02:15 nothing
[02:16:23.5750] N: Send on /BTtoMQTT/C6C752663CBF msg {"id":"C6:C7:52:66:3C:BF","mac_type":1,"rssi":-50,"brand":"SwitchBot","model":"Meter (Plus)","model_id":"THX1/W230150X","tempc":18.5,"tempf":65.3,"hum":65,"batt":100}
- 02:17 nothing
[02:18:34.5287] N: Send on /BTtoMQTT/C6C752663CBF msg {"id":"C6:C7:52:66:3C:BF","mac_type":1,"rssi":-47,"brand":"SwitchBot","model":"Meter (Plus)","model_id":"THX1/W230150X","tempc":18.5,"tempf":65.3,"hum":65,"batt":100}
- 02:19
[02:20:44.8493] N: Send on /BTtoMQTT/C6C752663CBF msg {"id":"C6:C7:52:66:3C:BF","mac_type":1,"rssi":-54,"brand":"SwitchBot","model":"Meter (Plus)","model_id":"THX1/W230150X","tempc":18.5,"tempf":65.3,"hum":65,"batt":100}
- 02:21
[02:22:49.1084] N: Send on /BTtoMQTT/C6C752663CBF msg {"id":"C6:C7:52:66:3C:BF","mac_type":1,"rssi":-49,"brand":"SwitchBot","model":"Meter (Plus)","model_id":"THX1/W230150X","tempc":18.5,"tempf":65.3,"hum":65,"batt":100}
[02:23:29.1938] N: Send on /BTtoMQTT/C6C752663CBF msg {"id":"C6:C7:52:66:3C:BF","mac_type":1,"rssi":-48,"brand":"SwitchBot","model":"Meter (Plus)","model_id":"THX1/W230150X","tempc":18.5,"tempf":65.3,"hum":65,"batt":100}

and I'm starting to see this (previously unseen):

[02:24:25.4183] T: Device mac C6:C7:52:66:3C:BF
[02:24:25.4212] T: Device already discovered or that doesn't require discovery C6:C7:52:66:3C:BF
-truncated-
[02:29:10.5493] N: Device detected: C6:C7:52:66:3C:BF
[02:29:10.5533] T: getDeviceByMac C6:C7:52:66:3C:BF
[02:29:10.5923] T: getDeviceByMac C6:C7:52:66:3C:BF
[02:29:10.5953] T: update C6:C7:52:66:3C:BF

At this point, restarting the ESP may result in the Switchbot being seen or not at all (missing the window permanently, it seems). What's strange is that Theengs' Gateway was about to get 16 readings per minute from the Switchbot [via my laptop].

So I'll:

  1. re-run Theengs' Gateway from my laptop - to confirm it's still getting lots of readings per minute;
  2. re-run the Example using the default values from OMG;
  3. fiddle some more with the window & intervals.

Any advice and suggestions are appreciated.

@1technophile
Copy link
Owner

I think it is progressing well, thanks to your thorough testing.

If you could try OMG only with this modification:
+# define Scan_duration 0 //define the time for a scan

It would enable pinpointing the continuous scan versus the windows/interval modification as a potential cause.

@xanderificnl
Copy link
Author

xanderificnl commented Nov 2, 2022

So I git reset'd and cleaned flash, etc... all the usual steps.

$ tail -f ~/serial.log | grep 'Send on /BTtoMQTT/C6C752663CBF msg' --text
[19:06:36.8231] N: Send on /BTtoMQTT/C6C752663CBF msg {"id":"C6:C7:52:66:3C:BF","mac_type":1,"rssi":-23,"brand":"SwitchBot","model":"Meter (Plus)","model_id":"THX1/W230150X","tempc":17.6,"tempf":63.68,"hum":63,"batt":100}
[19:07:20.7559] N: Send on /BTtoMQTT/C6C752663CBF msg {"id":"C6:C7:52:66:3C:BF","mac_type":1,"rssi":-25,"brand":"SwitchBot","model":"Meter (Plus)","model_id":"THX1/W230150X","tempc":17.6,"tempf":63.68,"hum":63,"batt":100}
[19:08:04.8407] N: Send on /BTtoMQTT/C6C752663CBF msg {"id":"C6:C7:52:66:3C:BF","mac_type":1,"rssi":-23,"brand":"SwitchBot","model":"Meter (Plus)","model_id":"THX1/W230150X","tempc":17.6,"tempf":63.68,"hum":63,"batt":100}
[19:08:58.9555] N: Send on /BTtoMQTT/C6C752663CBF msg {"id":"C6:C7:52:66:3C:BF","mac_type":1,"rssi":-23,"brand":"SwitchBot","model":"Meter (Plus)","model_id":"THX1/W230150X","tempc":17.6,"tempf":63.68,"hum":63,"batt":100}
[19:09:55.0747] N: Send on /BTtoMQTT/C6C752663CBF msg {"id":"C6:C7:52:66:3C:BF","mac_type":1,"rssi":-25,"brand":"SwitchBot","model":"Meter (Plus)","model_id":"THX1/W230150X","tempc":17.6,"tempf":63.68,"hum":63,"batt":100}
[19:10:59.2287] N: Send on /BTtoMQTT/C6C752663CBF msg {"id":"C6:C7:52:66:3C:BF","mac_type":1,"rssi":-25,"brand":"SwitchBot","model":"Meter (Plus)","model_id":"THX1/W230150X","tempc":17.6,"tempf":63.68,"hum":63,"batt":100}
[19:11:17.2785] N: Send on /BTtoMQTT/C6C752663CBF msg {"id":"C6:C7:52:66:3C:BF","mac_type":1,"rssi":-23,"brand":"SwitchBot","model":"Meter (Plus)","model_id":"THX1/W230150X","tempc":17.6,"tempf":63.68,"hum":63,"batt":100}
[19:12:15.4207] N: Send on /BTtoMQTT/C6C752663CBF msg {"id":"C6:C7:52:66:3C:BF","mac_type":1,"rssi":-25,"brand":"SwitchBot","model":"Meter (Plus)","model_id":"THX1/W230150X","tempc":17.6,"tempf":63.68,"hum":63,"batt":100}
[19:12:55.5311] N: Send on /BTtoMQTT/C6C752663CBF msg {"id":"C6:C7:52:66:3C:BF","mac_type":1,"rssi":-25,"brand":"SwitchBot","model":"Meter (Plus)","model_id":"THX1/W230150X","tempc":17.6,"tempf":63.68,"hum":63,"batt":100}
[19:13:35.6211] N: Send on /BTtoMQTT/C6C752663CBF msg {"id":"C6:C7:52:66:3C:BF","mac_type":1,"rssi":-23,"brand":"SwitchBot","model":"Meter (Plus)","model_id":"THX1/W230150X","tempc":17.6,"tempf":63.68,"hum":63,"batt":100}
[19:14:21.7341] N: Send on /BTtoMQTT/C6C752663CBF msg {"id":"C6:C7:52:66:3C:BF","mac_type":1,"rssi":-25,"brand":"SwitchBot","model":"Meter (Plus)","model_id":"THX1/W230150X","tempc":17.6,"tempf":63.68,"hum":63,"batt":100}
[19:15:13.8228] N: Send on /BTtoMQTT/C6C752663CBF msg {"id":"C6:C7:52:66:3C:BF","mac_type":1,"rssi":-25,"brand":"SwitchBot","model":"Meter (Plus)","model_id":"THX1/W230150X","tempc":17.6,"tempf":63.68,"hum":63,"batt":100}
[19:15:56.6092] N: Send on /BTtoMQTT/C6C752663CBF msg {"id":"C6:C7:52:66:3C:BF","mac_type":1,"rssi":-23,"brand":"SwitchBot","model":"Meter (Plus)","model_id":"THX1/W230150X","tempc":17.6,"tempf":63.68,"hum":63,"batt":100}
[19:17:20.7737] N: Send on /BTtoMQTT/C6C752663CBF msg {"id":"C6:C7:52:66:3C:BF","mac_type":1,"rssi":-23,"brand":"SwitchBot","model":"Meter (Plus)","model_id":"THX1/W230150X","tempc":17.6,"tempf":63.68,"hum":63,"batt":100}
[19:17:50.8383] N: Send on /BTtoMQTT/C6C752663CBF msg {"id":"C6:C7:52:66:3C:BF","mac_type":1,"rssi":-23,"brand":"SwitchBot","model":"Meter (Plus)","model_id":"THX1/W230150X","tempc":17.6,"tempf":63.68,"hum":63,"batt":100}
[19:18:22.9103] N: Send on /BTtoMQTT/C6C752663CBF msg {"id":"C6:C7:52:66:3C:BF","mac_type":1,"rssi":-23,"brand":"SwitchBot","model":"Meter (Plus)","model_id":"THX1/W230150X","tempc":17.6,"tempf":63.68,"hum":63,"batt":100}
[19:19:07.0096] N: Send on /BTtoMQTT/C6C752663CBF msg {"id":"C6:C7:52:66:3C:BF","mac_type":1,"rssi":-23,"brand":"SwitchBot","model":"Meter (Plus)","model_id":"THX1/W230150X","tempc":17.6,"tempf":63.68,"hum":63,"batt":100}
[19:19:59.1179] N: Send on /BTtoMQTT/C6C752663CBF msg {"id":"C6:C7:52:66:3C:BF","mac_type":1,"rssi":-23,"brand":"SwitchBot","model":"Meter (Plus)","model_id":"THX1/W230150X","tempc":17.6,"tempf":63.68,"hum":63,"batt":100}
[19:20:59.2501] N: Send on /BTtoMQTT/C6C752663CBF msg {"id":"C6:C7:52:66:3C:BF","mac_type":1,"rssi":-25,"brand":"SwitchBot","model":"Meter (Plus)","model_id":"THX1/W230150X","tempc":17.6,"tempf":63.68,"hum":63,"batt":100}
[19:21:27.3194] N: Send on /BTtoMQTT/C6C752663CBF msg {"id":"C6:C7:52:66:3C:BF","mac_type":1,"rssi":-23,"brand":"SwitchBot","model":"Meter (Plus)","model_id":"THX1/W230150X","tempc":17.6,"tempf":63.68,"hum":63,"batt":100}
[19:22:19.4526] N: Send on /BTtoMQTT/C6C752663CBF msg {"id":"C6:C7:52:66:3C:BF","mac_type":1,"rssi":-25,"brand":"SwitchBot","model":"Meter (Plus)","model_id":"THX1/W230150X","tempc":17.6,"tempf":63.68,"hum":63,"batt":100}
[19:23:11.5887] N: Send on /BTtoMQTT/C6C752663CBF msg {"id":"C6:C7:52:66:3C:BF","mac_type":1,"rssi":-25,"brand":"SwitchBot","model":"Meter (Plus)","model_id":"THX1/W230150X","tempc":17.6,"tempf":63.68,"hum":63,"batt":100}
[19:23:57.6940] N: Send on /BTtoMQTT/C6C752663CBF msg {"id":"C6:C7:52:66:3C:BF","mac_type":1,"rssi":-25,"brand":"SwitchBot","model":"Meter (Plus)","model_id":"THX1/W230150X","tempc":17.6,"tempf":63.68,"hum":63,"batt":100}
[19:24:35.7754] N: Send on /BTtoMQTT/C6C752663CBF msg {"id":"C6:C7:52:66:3C:BF","mac_type":1,"rssi":-25,"brand":"SwitchBot","model":"Meter (Plus)","model_id":"THX1/W230150X","tempc":17.6,"tempf":63.68,"hum":63,"batt":100}
[19:25:25.5042] N: Send on /BTtoMQTT/C6C752663CBF msg {"id":"C6:C7:52:66:3C:BF","mac_type":1,"rssi":-25,"brand":"SwitchBot","model":"Meter (Plus)","model_id":"THX1/W230150X","tempc":17.6,"tempf":63.68,"hum":63,"batt":100}
[19:26:10.6404] N: Send on /BTtoMQTT/C6C752663CBF msg {"id":"C6:C7:52:66:3C:BF","mac_type":1,"rssi":-23,"brand":"SwitchBot","model":"Meter (Plus)","model_id":"THX1/W230150X","tempc":17.6,"tempf":63.68,"hum":63,"batt":100}
[19:26:56.7396] N: Send on /BTtoMQTT/C6C752663CBF msg {"id":"C6:C7:52:66:3C:BF","mac_type":1,"rssi":-23,"brand":"SwitchBot","model":"Meter (Plus)","model_id":"THX1/W230150X","tempc":17.6,"tempf":63.68,"hum":63,"batt":100}
[19:27:44.8513] N: Send on /BTtoMQTT/C6C752663CBF msg {"id":"C6:C7:52:66:3C:BF","mac_type":1,"rssi":-23,"brand":"SwitchBot","model":"Meter (Plus)","model_id":"THX1/W230150X","tempc":17.6,"tempf":63.68,"hum":63,"batt":100}
[19:28:32.9657] N: Send on /BTtoMQTT/C6C752663CBF msg {"id":"C6:C7:52:66:3C:BF","mac_type":1,"rssi":-23,"brand":"SwitchBot","model":"Meter (Plus)","model_id":"THX1/W230150X","tempc":17.6,"tempf":63.68,"hum":63,"batt":100}
[19:29:17.0707] N: Send on /BTtoMQTT/C6C752663CBF msg {"id":"C6:C7:52:66:3C:BF","mac_type":1,"rssi":-23,"brand":"SwitchBot","model":"Meter (Plus)","model_id":"THX1/W230150X","tempc":17.6,"tempf":63.68,"hum":63,"batt":100}
[19:30:15.2065] N: Send on /BTtoMQTT/C6C752663CBF msg {"id":"C6:C7:52:66:3C:BF","mac_type":1,"rssi":-22,"brand":"SwitchBot","model":"Meter (Plus)","model_id":"THX1/W230150X","tempc":17.6,"tempf":63.68,"hum":63,"batt":100}
[19:31:23.3740] N: Send on /BTtoMQTT/C6C752663CBF msg {"id":"C6:C7:52:66:3C:BF","mac_type":1,"rssi":-23,"brand":"SwitchBot","model":"Meter (Plus)","model_id":"THX1/W230150X","tempc":17.6,"tempf":63.68,"hum":63,"batt":100}
[19:31:43.4112] N: Send on /BTtoMQTT/C6C752663CBF msg {"id":"C6:C7:52:66:3C:BF","mac_type":1,"rssi":-25,"brand":"SwitchBot","model":"Meter (Plus)","model_id":"THX1/W230150X","tempc":17.6,"tempf":63.68,"hum":63,"batt":100}
[19:32:29.5253] N: Send on /BTtoMQTT/C6C752663CBF msg {"id":"C6:C7:52:66:3C:BF","mac_type":1,"rssi":-25,"brand":"SwitchBot","model":"Meter (Plus)","model_id":"THX1/W230150X","tempc":17.6,"tempf":63.68,"hum":63,"batt":100}
[19:33:15.6246] N: Send on /BTtoMQTT/C6C752663CBF msg {"id":"C6:C7:52:66:3C:BF","mac_type":1,"rssi":-23,"brand":"SwitchBot","model":"Meter (Plus)","model_id":"THX1/W230150X","tempc":17.6,"tempf":63.68,"hum":63,"batt":100}
[19:34:15.7493] N: Send on /BTtoMQTT/C6C752663CBF msg {"id":"C6:C7:52:66:3C:BF","mac_type":1,"rssi":-25,"brand":"SwitchBot","model":"Meter (Plus)","model_id":"THX1/W230150X","tempc":17.6,"tempf":63.68,"hum":63,"batt":100}
[19:34:55.8437] N: Send on /BTtoMQTT/C6C752663CBF msg {"id":"C6:C7:52:66:3C:BF","mac_type":1,"rssi":-25,"brand":"SwitchBot","model":"Meter (Plus)","model_id":"THX1/W230150X","tempc":17.6,"tempf":63.68,"hum":63,"batt":100}
[19:35:56.5946] N: Send on /BTtoMQTT/C6C752663CBF msg {"id":"C6:C7:52:66:3C:BF","mac_type":1,"rssi":-23,"brand":"SwitchBot","model":"Meter (Plus)","model_id":"THX1/W230150X","tempc":17.6,"tempf":63.68,"hum":63,"batt":100}
[19:36:24.6657] N: Send on /BTtoMQTT/C6C752663CBF msg {"id":"C6:C7:52:66:3C:BF","mac_type":1,"rssi":-23,"brand":"SwitchBot","model":"Meter (Plus)","model_id":"THX1/W230150X","tempc":17.6,"tempf":63.68,"hum":63,"batt":100}
[19:38:12.9177] N: Send on /BTtoMQTT/C6C752663CBF msg {"id":"C6:C7:52:66:3C:BF","mac_type":1,"rssi":-25,"brand":"SwitchBot","model":"Meter (Plus)","model_id":"THX1/W230150X","tempc":17.6,"tempf":63.68,"hum":63,"batt":100}
[19:39:09.0419] N: Send on /BTtoMQTT/C6C752663CBF msg {"id":"C6:C7:52:66:3C:BF","mac_type":1,"rssi":-23,"brand":"SwitchBot","model":"Meter (Plus)","model_id":"THX1/W230150X","tempc":17.6,"tempf":63.68,"hum":63,"batt":100}
[19:39:39.1083] N: Send on /BTtoMQTT/C6C752663CBF msg {"id":"C6:C7:52:66:3C:BF","mac_type":1,"rssi":-25,"brand":"SwitchBot","model":"Meter (Plus)","model_id":"THX1/W230150X","tempc":17.6,"tempf":63.68,"hum":63,"batt":100}
[19:40:29.2269] N: Send on /BTtoMQTT/C6C752663CBF msg {"id":"C6:C7:52:66:3C:BF","mac_type":1,"rssi":-25,"brand":"SwitchBot","model":"Meter (Plus)","model_id":"THX1/W230150X","tempc":17.6,"tempf":63.68,"hum":63,"batt":100}
[19:41:11.3115] N: Send on /BTtoMQTT/C6C752663CBF msg {"id":"C6:C7:52:66:3C:BF","mac_type":1,"rssi":-23,"brand":"SwitchBot","model":"Meter (Plus)","model_id":"THX1/W230150X","tempc":17.6,"tempf":63.68,"hum":63,"batt":100}
[19:42:23.4485] N: Send on /BTtoMQTT/C6C752663CBF msg {"id":"C6:C7:52:66:3C:BF","mac_type":1,"rssi":-25,"brand":"SwitchBot","model":"Meter (Plus)","model_id":"THX1/W230150X","tempc":17.6,"tempf":63.68,"hum":63,"batt":100}
[19:43:03.5479] N: Send on /BTtoMQTT/C6C752663CBF msg {"id":"C6:C7:52:66:3C:BF","mac_type":1,"rssi":-25,"brand":"SwitchBot","model":"Meter (Plus)","model_id":"THX1/W230150X","tempc":17.6,"tempf":63.68,"hum":63,"batt":100}
[19:43:29.6018] N: Send on /BTtoMQTT/C6C752663CBF msg {"id":"C6:C7:52:66:3C:BF","mac_type":1,"rssi":-23,"brand":"SwitchBot","model":"Meter (Plus)","model_id":"THX1/W230150X","tempc":17.6,"tempf":63.68,"hum":63,"batt":100}
[19:44:17.7321] N: Send on /BTtoMQTT/C6C752663CBF msg {"id":"C6:C7:52:66:3C:BF","mac_type":1,"rssi":-25,"brand":"SwitchBot","model":"Meter (Plus)","model_id":"THX1/W230150X","tempc":17.6,"tempf":63.68,"hum":63,"batt":100}
[19:45:01.8140] N: Send on /BTtoMQTT/C6C752663CBF msg {"id":"C6:C7:52:66:3C:BF","mac_type":1,"rssi":-25,"brand":"SwitchBot","model":"Meter (Plus)","model_id":"THX1/W230150X","tempc":17.6,"tempf":63.68,"hum":63,"batt":100}
[19:45:48.5702] N: Send on /BTtoMQTT/C6C752663CBF msg {"id":"C6:C7:52:66:3C:BF","mac_type":1,"rssi":-25,"brand":"SwitchBot","model":"Meter (Plus)","model_id":"THX1/W230150X","tempc":17.6,"tempf":63.68,"hum":63,"batt":100}
[19:46:38.6787] N: Send on /BTtoMQTT/C6C752663CBF msg {"id":"C6:C7:52:66:3C:BF","mac_type":1,"rssi":-25,"brand":"SwitchBot","model":"Meter (Plus)","model_id":"THX1/W230150X","tempc":17.6,"tempf":63.68,"hum":63,"batt":100}
[19:47:58.8710] N: Send on /BTtoMQTT/C6C752663CBF msg {"id":"C6:C7:52:66:3C:BF","mac_type":1,"rssi":-25,"brand":"SwitchBot","model":"Meter (Plus)","model_id":"THX1/W230150X","tempc":17.6,"tempf":63.68,"hum":63,"batt":100}
[19:48:10.9084] N: Send on /BTtoMQTT/C6C752663CBF msg {"id":"C6:C7:52:66:3C:BF","mac_type":1,"rssi":-23,"brand":"SwitchBot","model":"Meter (Plus)","model_id":"THX1/W230150X","tempc":17.6,"tempf":63.68,"hum":63,"batt":100}
[19:49:07.0251] N: Send on /BTtoMQTT/C6C752663CBF msg {"id":"C6:C7:52:66:3C:BF","mac_type":1,"rssi":-20,"brand":"SwitchBot","model":"Meter (Plus)","model_id":"THX1/W230150X","tempc":17.6,"tempf":63.68,"hum":63,"batt":100}
[19:49:47.1149] N: Send on /BTtoMQTT/C6C752663CBF msg {"id":"C6:C7:52:66:3C:BF","mac_type":1,"rssi":-25,"brand":"SwitchBot","model":"Meter (Plus)","model_id":"THX1/W230150X","tempc":17.6,"tempf":63.68,"hum":63,"batt":100}
[19:50:49.2682] N: Send on /BTtoMQTT/C6C752663CBF msg {"id":"C6:C7:52:66:3C:BF","mac_type":1,"rssi":-25,"brand":"SwitchBot","model":"Meter (Plus)","model_id":"THX1/W230150X","tempc":17.6,"tempf":63.68,"hum":63,"batt":100}
[19:51:21.3250] N: Send on /BTtoMQTT/C6C752663CBF msg {"id":"C6:C7:52:66:3C:BF","mac_type":1,"rssi":-23,"brand":"SwitchBot","model":"Meter (Plus)","model_id":"THX1/W230150X","tempc":17.6,"tempf":63.68,"hum":63,"batt":100}
[19:52:15.4302] N: Send on /BTtoMQTT/C6C752663CBF msg {"id":"C6:C7:52:66:3C:BF","mac_type":1,"rssi":-25,"brand":"SwitchBot","model":"Meter (Plus)","model_id":"THX1/W230150X","tempc":17.6,"tempf":63.68,"hum":63,"batt":100}
[19:52:55.5138] N: Send on /BTtoMQTT/C6C752663CBF msg {"id":"C6:C7:52:66:3C:BF","mac_type":1,"rssi":-25,"brand":"SwitchBot","model":"Meter (Plus)","model_id":"THX1/W230150X","tempc":17.6,"tempf":63.68,"hum":63,"batt":100}
*19:53 missing*
[19:54:07.6674] N: Send on /BTtoMQTT/C6C752663CBF msg {"id":"C6:C7:52:66:3C:BF","mac_type":1,"rssi":-23,"brand":"SwitchBot","model":"Meter (Plus)","model_id":"THX1/W230150X","tempc":17.6,"tempf":63.68,"hum":63,"batt":100}
[19:54:35.7314] N: Send on /BTtoMQTT/C6C752663CBF msg {"id":"C6:C7:52:66:3C:BF","mac_type":1,"rssi":-23,"brand":"SwitchBot","model":"Meter (Plus)","model_id":"THX1/W230150X","tempc":17.6,"tempf":63.68,"hum":63,"batt":100}
[19:55:24.6560] N: Send on /BTtoMQTT/C6C752663CBF msg {"id":"C6:C7:52:66:3C:BF","mac_type":1,"rssi":-23,"brand":"SwitchBot","model":"Meter (Plus)","model_id":"THX1/W230150X","tempc":17.6,"tempf":63.68,"hum":63,"batt":100}
[19:56:08.6321] N: Send on /BTtoMQTT/C6C752663CBF msg {"id":"C6:C7:52:66:3C:BF","mac_type":1,"rssi":-25,"brand":"SwitchBot","model":"Meter (Plus)","model_id":"THX1/W230150X","tempc":17.6,"tempf":63.68,"hum":63,"batt":100}
[19:57:08.7700] N: Send on /BTtoMQTT/C6C752663CBF msg {"id":"C6:C7:52:66:3C:BF","mac_type":1,"rssi":-25,"brand":"SwitchBot","model":"Meter (Plus)","model_id":"THX1/W230150X","tempc":17.6,"tempf":63.68,"hum":63,"batt":100}
[19:57:54.8812] N: Send on /BTtoMQTT/C6C752663CBF msg {"id":"C6:C7:52:66:3C:BF","mac_type":1,"rssi":-23,"brand":"SwitchBot","model":"Meter (Plus)","model_id":"THX1/W230150X","tempc":17.6,"tempf":63.68,"hum":63,"batt":100}
[19:58:24.9606] N: Send on /BTtoMQTT/C6C752663CBF msg {"id":"C6:C7:52:66:3C:BF","mac_type":1,"rssi":-23,"brand":"SwitchBot","model":"Meter (Plus)","model_id":"THX1/W230150X","tempc":17.6,"tempf":63.68,"hum":63,"batt":100}
[19:59:13.0880] N: Send on /BTtoMQTT/C6C752663CBF msg {"id":"C6:C7:52:66:3C:BF","mac_type":1,"rssi":-23,"brand":"SwitchBot","model":"Meter (Plus)","model_id":"THX1/W230150X","tempc":17.6,"tempf":63.68,"hum":63,"batt":100}
[20:00:03.2117] N: Send on /BTtoMQTT/C6C752663CBF msg {"id":"C6:C7:52:66:3C:BF","mac_type":1,"rssi":-25,"brand":"SwitchBot","model":"Meter (Plus)","model_id":"THX1/W230150X","tempc":17.6,"tempf":63.68,"hum":63,"batt":100}
[20:00:59.3281] N: Send on /BTtoMQTT/C6C752663CBF msg {"id":"C6:C7:52:66:3C:BF","mac_type":1,"rssi":-25,"brand":"SwitchBot","model":"Meter (Plus)","model_id":"THX1/W230150X","tempc":17.6,"tempf":63.68,"hum":63,"batt":100}
[20:01:41.4549] N: Send on /BTtoMQTT/C6C752663CBF msg {"id":"C6:C7:52:66:3C:BF","mac_type":1,"rssi":-25,"brand":"SwitchBot","model":"Meter (Plus)","model_id":"THX1/W230150X","tempc":17.6,"tempf":63.68,"hum":63,"batt":100}
[20:02:27.5781] N: Send on /BTtoMQTT/C6C752663CBF msg {"id":"C6:C7:52:66:3C:BF","mac_type":1,"rssi":-25,"brand":"SwitchBot","model":"Meter (Plus)","model_id":"THX1/W230150X","tempc":17.6,"tempf":63.68,"hum":63,"batt":100}
[20:03:07.6755] N: Send on /BTtoMQTT/C6C752663CBF msg {"id":"C6:C7:52:66:3C:BF","mac_type":1,"rssi":-25,"brand":"SwitchBot","model":"Meter (Plus)","model_id":"THX1/W230150X","tempc":17.6,"tempf":63.68,"hum":63,"batt":100}
[20:04:07.8224] N: Send on /BTtoMQTT/C6C752663CBF msg {"id":"C6:C7:52:66:3C:BF","mac_type":1,"rssi":-25,"brand":"SwitchBot","model":"Meter (Plus)","model_id":"THX1/W230150X","tempc":17.6,"tempf":63.68,"hum":63,"batt":100}
[20:04:47.9298] N: Send on /BTtoMQTT/C6C752663CBF msg {"id":"C6:C7:52:66:3C:BF","mac_type":1,"rssi":-25,"brand":"SwitchBot","model":"Meter (Plus)","model_id":"THX1/W230150X","tempc":17.6,"tempf":63.68,"hum":63,"batt":100}
[20:05:36.5333] N: Send on /BTtoMQTT/C6C752663CBF msg {"id":"C6:C7:52:66:3C:BF","mac_type":1,"rssi":-23,"brand":"SwitchBot","model":"Meter (Plus)","model_id":"THX1/W230150X","tempc":17.6,"tempf":63.68,"hum":63,"batt":100}
[20:06:18.6470] N: Send on /BTtoMQTT/C6C752663CBF msg {"id":"C6:C7:52:66:3C:BF","mac_type":1,"rssi":-25,"brand":"SwitchBot","model":"Meter (Plus)","model_id":"THX1/W230150X","tempc":17.6,"tempf":63.68,"hum":63,"batt":100}

so as far as I can see, it missed one beat at 19:53 which isn't very interesting on its own.

@1technophile
Copy link
Owner

Cool, seems Scan_duration 0 solve your issue. This could make us reconsider the existing parameters of esp32dev-ble-cont.

But doesn't explain why we have missing service data with esp32dev-ble

@xanderificnl
Copy link
Author

xanderificnl commented Nov 3, 2022

Running with the default esp32dev-ble at the moment with trace on.

One thing that stands out is that good readings are processed before the scan ends, and readings without service data are processed after the scan ends. Is it possible that OMG is freeing the data before it's retrieved?

Here's a clean reading for reference:

[05:13:25.3536] N: Scan begin
[05:13:27.3417] T: Creating BLE buffer
[05:13:27.3443] N: Device detected: 52:37:AE:7D:14:92
[05:13:27.3473] T: getDeviceByMac 52:37:AE:7D:14:92
[05:13:27.3853] T: No device found 
[05:13:27.3873] N: Send on /BTtoMQTT/5237AE7D1492 msg {"id":"52:37:AE:7D:14:92","mac_type":1,"manufacturerdata":"4c0010050a1c557eb6","rssi":-86,"txpower":12}
[05:13:27.4003] T: jsonPubl - ON
[05:13:27.4013] T: [ OMG->MQTT ] topic: home/esp32-dev-ble-fkenwlnflwe/BTtoMQTT/5237AE7D1492 msg: {"id":"52:37:AE:7D:14:92","mac_type":1,"manufacturerdata":"4c0010050a1c557eb6","rssi":-86,"txpower":12} 
[05:13:31.1258] T: Creating BLE buffer
[05:13:31.1277] N: Device detected: C6:C7:52:66:3C:BF
[05:13:31.1317] T: getDeviceByMac C6:C7:52:66:3C:BF
[05:13:31.1348] T: Get services data number: 1
[05:13:31.1377] T: Converted service data (6) to 69c0e406903f
[05:13:31.1417] T: Service data: 69c0e406903f
[05:13:31.1437] T: Service data UUID: 0xfd3d
[05:13:31.1668] T: Decoder found device: THX1/W230150X
[05:13:31.1708] T: getDeviceByMac C6:C7:52:66:3C:BF
[05:13:31.1737] T: update C6:C7:52:66:3C:BF
[05:13:31.1757] T: Removing servicedatauuid
[05:13:31.1787] T: Removing servicedata
[05:13:31.1807] T: Removing manufacturerdata
[05:13:31.1828] N: Send on /BTtoMQTT/C6C752663CBF msg {"id":"C6:C7:52:66:3C:BF","mac_type":1,"rssi":-25,"brand":"SwitchBot","model":"Meter (Plus)","model_id":"THX1/W230150X","tempc":16.6,"tempf":61.88,"hum":63,"batt":100}
[05:13:31.2007] T: jsonPubl - ON
[05:13:31.2029] T: [ OMG->MQTT ] topic: home/esp32-dev-ble-fkenwlnflwe/BTtoMQTT/C6C752663CBF msg: {"id":"C6:C7:52:66:3C:BF","mac_type":1,"rssi":-25,"brand":"SwitchBot","model":"Meter (Plus)","model_id":"THX1/W230150X","tempc":16.6,"tempf":61.88,"hum":63,"batt":100} 
[05:13:32.0078] T: Creating BLE buffer
[05:13:32.0098] N: Device detected: 52:37:AE:7D:14:92
[05:13:32.0138] T: getDeviceByMac 52:37:AE:7D:14:92
[05:13:32.0519] T: No device found 
[05:13:32.0538] N: Send on /BTtoMQTT/5237AE7D1492 msg {"id":"52:37:AE:7D:14:92","mac_type":1,"manufacturerdata":"4c0010050a1c557eb6","rssi":-86,"txpower":12}
[05:13:32.0658] T: jsonPubl - ON
[05:13:32.0678] T: [ OMG->MQTT ] topic: home/esp32-dev-ble-fkenwlnflwe/BTtoMQTT/5237AE7D1492 msg: {"id":"52:37:AE:7D:14:92","mac_type":1,"manufacturerdata":"4c0010050a1c557eb6","rssi":-86,"txpower":12} 
[05:13:35.3618] N: Found 2 devices, scan number 24 end
[05:13:35.3652] T: Process BLE stack free: 3068
[05:13:35.3682] T: macAdr C6:C7:52:66:3C:BF
[05:13:35.3702] T: macType 1
[05:13:35.3712] T: isDisc 1
[05:13:35.3722] T: isWhtL 0
[05:13:35.3732] T: isBlkL 0
[05:13:35.3752] T: connect 0
[05:13:35.3762] T: sensorModel_id 39
[05:13:35.3772] T: macAdr 6D:50:C9:F8:3B:43
[05:13:35.3802] T: macType 1
[05:13:35.3812] T: isDisc 0
[05:13:35.3822] T: isWhtL 0
[05:13:35.3832] T: isBlkL 0
[05:13:35.3842] T: connect 0
[05:13:35.3852] T: sensorModel_id 55
[05:14:16.6461] T: retrieving value of system characteristics Uptime (s):1569

Here's a bad reading. Ever since starting to look into this problem, I've seen garbled serial output, and I assumed it was simply the serial connection. Yet, as far as I can tell, proper readings are outputted nice and tidy and bad readings are generally accompanied by garbled output.

Scan begins [05:16:42.1104] N: Scan begin
[05:16:43.1864] T: Creating BLE buffer
[05:16:43.1884] N: Device detected: DF:AE:6F:EF:AA:86
[05:16:43.1924] T: getDeviceByMac DF:AE:6F:EF:AA:86
[05:16:43.2304] T: No device found 
[05:16:43.2324] N: Send on /BTtoMQTT/DFAE6FEFAA86 msg {"id":"DF:AE:6F:EF:AA:86","mac_type":1,"manufacturerdata":"4c0012020003","rssi":-56}
[05:16:43.2434] T: jsonPubl - ON
[05:16:43.2444] T: [ OMG->MQTT ] topic: home/esp32-dev-ble-fkenwlnflwe/BTtoMQTT/DFAE6FEFAA86 msg: {"id":"DF:AE:6F:EF:AA:86","mac_type":1,"manufacturerdata":"4c0012020003","rssi":-56} 
[05:16:48.4070] T: Creating BLE buffer
[05:16:48.4090] N: Device detected: 7F:14:32:27:45:54
[05:16:48.4130] T: getDeviceByMac 7F:14:32:27:45:54
[05:16:48.4510] T: No device found 
[05:16:48.4530] N: Send on /BTtoMQTT/7F1432274554 msg {"id":"7F:14:32:27:45:54","mac_type":1,"manufacturerdata":"4c001005021c03f543","rssi":-86,"txpower":12}
[05:16:48.4659] T: jsonPubl - ON
[05:16:48.4670] T: [ OMG->MQTT ] topic: home/esp32-dev-ble-fkenwlnflwe/BTtoMQTT/7F1432274554 msg: {"id":"7F:14:32:27:45:54","mac_type":1,"manufacturerdata":"4c001005021c03f543","rssi":-86,"txpower":12} 
[05:16:52.1188] T: Creating BLE buffer
Scan ends: [05:16:52.1214] N: Found 4 devices, scan number 27 end
First Switchbot mention [05:16:52.1244] N: Device detected: C6:C7:52:66:3C:BF
Garbled (T:) [05:16:52.1274] T: getDeT: viceByMac C6:C7:52:66:3C:BF 
Garbled (T:) [05:16:52.1314] Process BLE stack free: 3068
[05:16:52.1336] T: macAdr C6:C7:52:66:3C:BF
[05:16:52.1364] T: macType 1
[05:16:52.1376] T: isDisc 1
[05:16:52.1384] T: isWhtL 0
[05:16:52.1394] T: isBlkL 0
[05:16:52.1404] T: connect 0
[05:16:52.1414] T: sensorModel_id 39
[05:16:52.1434] T: macAdr 6D:50:C9:F8:3B:43
[05:16:52.1454] T: macType 1
[05:16:52.1464] T: isDisc 0
[05:16:52.1483] T: isWhtL 0
[05:16:52.1494] T: isBlkL 0
[05:16:52.1504] T: connect 0
[05:16:52.1514] T: sensorModel_id 55
[05:16:52.1634] T: No device found 
[05:16:52.1654] T: Creating BLE buffer
[05:16:52.1675] N: Device detected: 3C:91:80:C9:28:58
[05:16:52.1714] T: getDeviceByMac 3C:91:80:C9:28:58
[05:16:52.1745] T: No device found 
Sensorless reading [05:16:52.1754] N: Send on /BTtoMQTT/C6C752663CBF msg {"id":"C6:C7:52:66:3C:BF","mac_type":1,"manufacturerdata":"6909c6c752663cbf970f07903f","rssi":-24}
[05:17:47.6972] N: Scan begin

@h2zero
Copy link
Collaborator

h2zero commented Nov 3, 2022

Very interesting from the log:

�[90m[23:15:56.0996]�[0m N: Scan begin
�[90m[23:16:06.1060]�[0m T: Creating BLE buffer
�[90m[23:16:06.1086]�[0m N: Found 5 devices, scan number N: D7evice detected:  C6:C7:52:66:3C:BF
�[90m[23:16:06.1146]�[0m end
�[90m[23:16:06.1146]�[0m T: getDeviceByMac C6:C7:52:66:3C:BF
�[90m[23:16:06.1176]�[0m T: Process BLE stack free: 3068

Looks like the switchbot was only just detected as the scan ended and results in missing data. What I suspect is going on is that the switchbot advertisement was detected but no scan response had been received when the scan ended. When this occurs NimBLE will invoke the callback with whatever data it does have, complete or not, which in this case it was not.

Since the device advertises about every 10 seconds, I would adjust the scan duration to 15 seconds to allow more time to get the scan response data.

@xanderificnl
Copy link
Author

xanderificnl commented Nov 3, 2022

Currently running w/ '-DScan_duration=15000'

Results in:

[19:59:32.7484] T: Creating BLE buffer
[19:59:32.7504] N: Device detected: C6:C7:52:66:3C:BF
[19:59:32.7534] T: getDeviceByMac C6:C7:52:66:3C:BF
[19:59:32.7573] N: Found 6 devices, scan number 1 end
[19:59:32.7603] T: Process BLE stack free: 3068
[19:59:32.7633] N: BLE Connect begin
[19:59:32.7643] N: BLE Connect end
[19:59:32.7938] T: No device found 

I am fairly sure the Switchbot advertises a bit more than once per 10 seconds. Theengs' Gateway on my laptop picked up 16 sensor readings a minute, so that's about once per 3-4 seconds.

Theengs' readings for reference:

Ran with python3 -m TheengsGateway -H 172.16.32.2 --log_level=DEBUG 2>&1 | tee >(ts "%H:%M:%S" > theengs.log)

20:05:37 INFO:BLEGateway:Sent `{"id": "C6:C7:52:66:3C:BF", "rssi": -36, "brand": "SwitchBot", "model": "Meter (Plus)", "model_id": "THX1/W230150X", "tempc": 16.5, "tempf": 61.7, "hum": 67, "batt": 100}` to topic `home/TheengsGateway/BTtoMQTT/C6C752663CBF`
20:05:39 INFO:BLEGateway:Sent `{"id": "C6:C7:52:66:3C:BF", "rssi": -36, "brand": "SwitchBot", "model": "Meter (Plus)", "model_id": "THX1/W230150X", "tempc": 16.5, "tempf": 61.7, "hum": 67, "batt": 100}` to topic `home/TheengsGateway/BTtoMQTT/C6C752663CBF`
20:05:47 INFO:BLEGateway:Sent `{"id": "C6:C7:52:66:3C:BF", "rssi": -35, "brand": "SwitchBot", "model": "Meter (Plus)", "model_id": "THX1/W230150X", "tempc": 16.5, "tempf": 61.7, "hum": 67, "batt": 100}` to topic `home/TheengsGateway/BTtoMQTT/C6C752663CBF`
20:05:49 INFO:BLEGateway:Sent `{"id": "C6:C7:52:66:3C:BF", "rssi": -35, "brand": "SwitchBot", "model": "Meter (Plus)", "model_id": "THX1/W230150X", "tempc": 16.5, "tempf": 61.7, "hum": 67, "batt": 100}` to topic `home/TheengsGateway/BTtoMQTT/C6C752663CBF`
20:05:51 INFO:BLEGateway:Sent `{"id": "C6:C7:52:66:3C:BF", "rssi": -35, "brand": "SwitchBot", "model": "Meter (Plus)", "model_id": "THX1/W230150X", "tempc": 16.5, "tempf": 61.7, "hum": 67, "batt": 100}` to topic `home/TheengsGateway/BTtoMQTT/C6C752663CBF`
20:05:57 INFO:BLEGateway:Sent `{"id": "C6:C7:52:66:3C:BF", "rssi": -31, "brand": "SwitchBot", "model": "Meter (Plus)", "model_id": "THX1/W230150X", "tempc": 16.5, "tempf": 61.7, "hum": 67, "batt": 100}` to topic `home/TheengsGateway/BTtoMQTT/C6C752663CBF`
20:05:59 INFO:BLEGateway:Sent `{"id": "C6:C7:52:66:3C:BF", "rssi": -31, "brand": "SwitchBot", "model": "Meter (Plus)", "model_id": "THX1/W230150X", "tempc": 16.5, "tempf": 61.7, "hum": 67, "batt": 100}` to topic `home/TheengsGateway/BTtoMQTT/C6C752663CBF`
20:06:01 INFO:BLEGateway:Sent `{"id": "C6:C7:52:66:3C:BF", "rssi": -31, "brand": "SwitchBot", "model": "Meter (Plus)", "model_id": "THX1/W230150X", "tempc": 16.5, "tempf": 61.7, "hum": 67, "batt": 100}` to topic `home/TheengsGateway/BTtoMQTT/C6C752663CBF`
20:06:09 INFO:BLEGateway:Sent `{"id": "C6:C7:52:66:3C:BF", "rssi": -36, "brand": "SwitchBot", "model": "Meter (Plus)", "model_id": "THX1/W230150X", "tempc": 16.5, "tempf": 61.7, "hum": 67, "batt": 100}` to topic `home/TheengsGateway/BTtoMQTT/C6C752663CBF`
20:06:11 INFO:BLEGateway:Sent `{"id": "C6:C7:52:66:3C:BF", "rssi": -36, "brand": "SwitchBot", "model": "Meter (Plus)", "model_id": "THX1/W230150X", "tempc": 16.5, "tempf": 61.7, "hum": 67, "batt": 100}` to topic `home/TheengsGateway/BTtoMQTT/C6C752663CBF`
20:06:19 INFO:BLEGateway:Sent `{"id": "C6:C7:52:66:3C:BF", "rssi": -34, "brand": "SwitchBot", "model": "Meter (Plus)", "model_id": "THX1/W230150X", "tempc": 16.5, "tempf": 61.7, "hum": 67, "batt": 100}` to topic `home/TheengsGateway/BTtoMQTT/C6C752663CBF`
20:06:21 INFO:BLEGateway:Sent `{"id": "C6:C7:52:66:3C:BF", "rssi": -34, "brand": "SwitchBot", "model": "Meter (Plus)", "model_id": "THX1/W230150X", "tempc": 16.5, "tempf": 61.7, "hum": 67, "batt": 100}` to topic `home/TheengsGateway/BTtoMQTT/C6C752663CBF`
20:06:29 INFO:BLEGateway:Sent `{"id": "C6:C7:52:66:3C:BF", "rssi": -36, "brand": "SwitchBot", "model": "Meter (Plus)", "model_id": "THX1/W230150X", "tempc": 16.5, "tempf": 61.7, "hum": 67, "batt": 100}` to topic `home/TheengsGateway/BTtoMQTT/C6C752663CBF`
20:06:31 INFO:BLEGateway:Sent `{"id": "C6:C7:52:66:3C:BF", "rssi": -36, "brand": "SwitchBot", "model": "Meter (Plus)", "model_id": "THX1/W230150X", "tempc": 16.5, "tempf": 61.7, "hum": 67, "batt": 100}` to topic `home/TheengsGateway/BTtoMQTT/C6C752663CBF`
20:06:33 INFO:BLEGateway:Sent `{"id": "C6:C7:52:66:3C:BF", "rssi": -36, "brand": "SwitchBot", "model": "Meter (Plus)", "model_id": "THX1/W230150X", "tempc": 16.5, "tempf": 61.7, "hum": 67, "batt": 100}` to topic `home/TheengsGateway/BTtoMQTT/C6C752663CBF`
20:06:39 INFO:BLEGateway:Sent `{"id": "C6:C7:52:66:3C:BF", "rssi": -32, "brand": "SwitchBot", "model": "Meter (Plus)", "model_id": "THX1/W230150X", "tempc": 16.5, "tempf": 61.7, "hum": 67, "batt": 100}` to topic `home/TheengsGateway/BTtoMQTT/C6C752663CBF`
20:06:41 INFO:BLEGateway:Sent `{"id": "C6:C7:52:66:3C:BF", "rssi": -32, "brand": "SwitchBot", "model": "Meter (Plus)", "model_id": "THX1/W230150X", "tempc": 16.5, "tempf": 61.7, "hum": 67, "batt": 100}` to topic `home/TheengsGateway/BTtoMQTT/C6C752663CBF`

@h2zero
Copy link
Collaborator

h2zero commented Nov 3, 2022

Thanks for that, could you try one more thing? I'm curious what happens if you set the scan duration to 6 seconds instead. It's possible that this is caused by NimBLE when seeing the device multiple times during the scan.

@xanderificnl
Copy link
Author

Scan_duration to 6000

Results:

[20:14:57.9009] N: Found 3 devices, scan number 1 end
[20:14:57.9049] N: Device detected: 64:F6:5B:4E:54:2B
[20:14:57.9079] T: getDevT: Process BLE stack freie: ceByMac 64:F6:5B:4E:54:2B
[20:14:57.9129] 3068
[20:14:57.9139] N: BLE Connect begin
[20:14:57.9159] N: BLE Connect end
[20:14:57.9459] T: No device found 
[20:14:57.9478] T: Creating BLE buffer
[20:14:57.9499] N: Device detected: C6:C7:52:66:3C:BF
[20:14:57.9529] T: getDeviceByMac C6:C7:52:66:3C:BF
[20:14:57.9894] T: No device found 

With 2 seconds:

[20:16:45.2162] T: Creating BLE buffer
[20:16:45.2187] N: Found 3 devices, scan number 1 end
[20:16:45.2217] N: Device detected: 64:F6:5B:4E:54:2B
[20:16:45.2247] T: getDeviceByMac 64:F6:5B:4E:54:2B
[20:16:45.2287] T: Process BLE stack free: 3068
[20:16:45.2308] N: BLE Connect begin
[20:16:45.2327] N: BLE Connect end
[20:16:45.2607] T: No device found 
[20:16:45.2628] T: Creating BLE buffer
[20:16:45.2647] N: Device detected: C6:C7:52:66:3C:BF
[20:16:45.2688] T: getDeviceByMac C6:C7:52:66:3C:BF
[20:16:45.3052] T: No device found 

FWIW, a comparison of OMG & Theengs from MQTT:

image

@h2zero
Copy link
Collaborator

h2zero commented Nov 3, 2022

Hmm, not really what I expected but here is a NimBLE branch to try: https://github.com/h2zero/NimBLE-Arduino/tree/adv-data-fix

@xanderificnl
Copy link
Author

To confirm:

Removing unused dependencies...
Library Manager: Removing NimBLE-Arduino @ 1.3.8+sha.4a7529e
Library Manager: [email protected]+sha.4a7529e has been removed!
Library Manager: Installing git+https://github.com/h2zero/NimBLE-Arduino.git#adv-data-fix

# and

|-- NimBLE-Arduino @ 1.4.1+sha.4502d2b # sum of adv-data-fix commit

Running with 10s:

# 1
[21:21:07.0103] N: Scan begin
[21:21:14.5211] T: Creating BLE buffer
[21:21:14.5237] N: Device detected: DF:8B:8A:97:46:24
[21:21:14.5267] T: getDeviceByMac DF:8B:8A:97:46:24
[21:21:14.5657] T: No device found 
[21:21:14.5677] N: Send on /BTtoMQTT/DF8B8A974624 msg {"id":"DF:8B:8A:97:46:24","mac_type":1,"manufacturerdata":"4c0012020003","rssi":-54}
[21:21:14.5776] T: jsonPubl - ON
[21:21:14.5797] T: [ OMG->MQTT ] topic: home/reee/BTtoMQTT/DF8B8A974624 msg: {"id":"DF:8B:8A:97:46:24","mac_type":1,"manufacturerdata":"4c0012020003","rssi":-54} 
[21:21:17.0205] T: Creating BLE buffer
[21:21:17.0229] N: Found 5 devices, scan number 1 end
[21:21:17.0260] N: DeviceT: Process BLE stack fre e: detect3100
[21:21:17.0300] ed: C6:C7:52:66:3C:BF
[21:21:17.0319] TN: : BgetDeviceByMac C6:C7:52:66:3C:BF
[21:21:17.0359] LE Connect begin
[21:21:17.0369] N: BLE Connect end
[21:21:17.0670] T: No device found 
[21:21:17.0690] T: Creating BLE buffer
[21:21:17.0710] N: Device detected: 64:D5:24:BE:5B:6E
[21:21:17.0740] T: getDeviceByMac 64:D5:24:BE:5B:6E
[21:21:17.1110] T: No device found 
[21:21:17.1129] T: Creating BLE buffer
[21:21:17.1149] N: Device detected: 7B:24:FD:A4:6D:89
[21:21:17.1180] T: getDeviceByMac 7B:24:FD:A4:6D:89
[21:21:17.1544] T: No device found 
[21:21:17.1570] T: Creating BLE buffer
[21:21:17.1590] N: Device detected: 68:99:7A:56:0E:B5
[21:21:17.1620] T: getDeviceByMac 68:99:7A:56:0E:B5
[21:21:17.1990] T: Decoder found device: IBEACON
[21:21:17.2019] T: getDeviceByMac 68:99:7A:56:0E:B5
[21:21:17.2050] T: add 68:99:7A:56:0E:B5
[21:21:17.2079] T: Removing servicedatauuid
[21:21:17.2100] T: Removing servicedata
[21:21:17.2120] T: Removing manufacturerdata
[21:21:17.2150] T: Device mac 68:99:7A:56:0E:B5
[21:21:17.2169] T: Device already discovered or that doesn't require discovery 68:99:7A:56:0E:B5
[21:21:17.2240] N: Send on /BTtoMQTT/C6C752663CBF msg {"id":"C6:C7:52:66:3C:BF","mac_type":1,"manufacturerdata":"6909c6c752663cbf250f099043","rssi":-28}
[21:21:17.2359] T: jsonPubl - ON
[21:21:17.2380] T: [ OMG->MQTT ] topic: home/reee/BTtoMQTT/C6C752663CBF msg: {"id":"C6:C7:52:66:3C:BF","mac_type":1,"manufacturerdata":"6909c6c752663cbf250f099043","rssi":-28} 
[21:21:17.2519] N: Send on /BTtoMQTT/64D524BE5B6E msg {"id":"64:D5:24:BE:5B:6E","mac_type":1,"manufacturerdata":"4c001005071cbe93a6","rssi":-90,"txpower":12}
[21:21:17.2639] T: jsonPubl - ON
[21:21:17.2660] T: [ OMG->MQTT ] topic: home/reee/BTtoMQTT/64D524BE5B6E msg: {"id":"64:D5:24:BE:5B:6E","mac_type":1,"manufacturerdata":"4c001005071cbe93a6","rssi":-90,"txpower":12} 
[21:21:17.2800] N: Send on /BTtoMQTT/7B24FDA46D89 msg {"id":"7B:24:FD:A4:6D:89","mac_type":1,"manufacturerdata":"0106010690caae1b75","rssi":-79}
[21:21:17.2910] T: jsonPubl - ON
[21:21:17.2930] T: [ OMG->MQTT ] topic: home/reee/BTtoMQTT/7B24FDA46D89 msg: {"id":"7B:24:FD:A4:6D:89","mac_type":1,"manufacturerdata":"0106010690caae1b75","rssi":-79} 
[21:21:17.3060] N: Send on /BTtoMQTT/68997A560EB5 msg {"id":"68:99:7A:56:0E:B5","mac_type":1,"rssi":-86,"brand":"GENERIC","model":"iBeacon","model_id":"IBEACON","mfid":"4c00","uuid":"08dd9d6bc15e630f4ec5c1d452d21005","major":23068,"minor":22952,"txpower":-48}
[21:21:17.3270] T: jsonPubl - ON
[21:21:17.3290] T: [ OMG->MQTT ] topic: home/reee/BTtoMQTT/68997A560EB5 msg: {"id":"68:99:7A:56:0E:B5","mac_type":1,"rssi":-86,"brand":"GENERIC","model":"iBeacon","model_id":"IBEACON","mfid":"4c00","uuid":"08dd9d6bc15e630f4ec5c1d452d21005","major":23068,"minor":22952,"txpower":-48} 


# 2
[21:22:12.5977] N: Scan begin
[21:22:22.6073] T: Creating BLE buffer
[21:22:22.6103] N: Found 1 devices, scan number 2 end
[21:22:22.6133] N: Device detected: C6:C7:52:66:3C:BF
[21:22:22.6163] T: getDeviceByT: Process BLE stack freMac C6:C7:52:66:3C:BF
[21:22:22.6213] e: 3084
[21:22:22.6223] T: macAdr 68:99:7A:56:0E:B5
[21:22:22.6243] T: macType 1
[21:22:22.6263] T: isDisc 0
[21:22:22.6273] T: isWhtL 0
[21:22:22.6283] T: isBlkL 0
[21:22:22.6292] T: connect 0
[21:22:22.6303] T: sensorModel_id 55
[21:22:22.6532] T: No device found 
[21:22:22.6552] N: Send on /BTtoMQTT/C6C752663CBF msg {"id":"C6:C7:52:66:3C:BF","mac_type":1,"manufacturerdata":"6909c6c752663cbf250f099043","rssi":-38}
[21:22:22.6672] T: jsonPubl - ON
[21:22:22.6682] T: [ OMG->MQTT ] topic: home/reee/BTtoMQTT/C6C752663CBF msg: {"id":"C6:C7:52:66:3C:BF","mac_type":1,"manufacturerdata":"6909c6c752663cbf250f099043","rssi":-38} 

Running with 6s:

# 1
[21:27:19.1664] N: Scan begin
[21:27:22.2579] T: Creating BLE buffer
[21:27:22.2598] N: Device detected: 76:1E:17:B5:02:BE
[21:27:22.2638] T: getDeviceByMac 76:1E:17:B5:02:BE
[21:27:22.3023] T: No device found 
[21:27:22.3038] N: Send on /BTtoMQTT/761E17B502BE msg {"id":"76:1E:17:B5:02:BE","mac_type":1,"manufacturerdata":"4c001005071caa5cb1","rssi":-87,"txpower":12}
[21:27:22.3168] T: jsonPubl - ON
[21:27:22.3178] T: [ OMG->MQTT ] topic: home/reee/BTtoMQTT/761E17B502BE msg: {"id":"76:1E:17:B5:02:BE","mac_type":1,"manufacturerdata":"4c001005071caa5cb1","rssi":-87,"txpower":12} 
[21:27:25.1775] T: Creating BLE buffer
[21:27:25.1801] N: Found 4 devices, scan number 1 end
[21:27:25.1831] N: Device detected: 68:99:7A:56:0E:B5
[21:27:25.1861] T: getDeviceByMac 68:99:7A:56:0E:B5
[21:27:25.1891] T: Process BLE stack free: 3132
[21:27:25.1921] N: BLE Connect begin
[21:27:25.1941] N: BLE Connect end
[21:27:25.2226] T: Decoder found device: IBEACON
[21:27:25.2263] T: getDeviceByMac 68:99:7A:56:0E:B5
[21:27:25.2291] T: add 68:99:7A:56:0E:B5
[21:27:25.2311] T: Removing servicedatauuid
[21:27:25.2331] T: Removing servicedata
[21:27:25.2351] T: Removing manufacturerdata
[21:27:25.2383] T: Creating BLE buffer
[21:27:25.2402] N: Device detected: C6:C7:52:66:3C:BF
[21:27:25.2431] T: getDeviceByMac C6:C7:52:66:3C:BF
[21:27:25.2775] T: No device found 
[21:27:25.2801] T: Creating BLE buffer
[21:27:25.2821] N: Device detected: 7B:24:FD:A4:6D:89
[21:27:25.2851] T: getDeviceByMac 7B:24:FD:A4:6D:89
[21:27:25.3215] T: No device found 
[21:27:25.3232] T: Device mac 68:99:7A:56:0E:B5
[21:27:25.3262] T: Device already discovered or that doesn't require discovery 68:99:7A:56:0E:B5
[21:27:25.3331] N: Send on /BTtoMQTT/68997A560EB5 msg {"id":"68:99:7A:56:0E:B5","mac_type":1,"rssi":-84,"brand":"GENERIC","model":"iBeacon","model_id":"IBEACON","mfid":"4c00","uuid":"00e39d9dfff20e97b21dc21f59471005","major":23068,"minor":22952,"txpower":-48}
[21:27:25.3541] T: jsonPubl - ON
[21:27:25.3561] T: [ OMG->MQTT ] topic: home/reee/BTtoMQTT/68997A560EB5 msg: {"id":"68:99:7A:56:0E:B5","mac_type":1,"rssi":-84,"brand":"GENERIC","model":"iBeacon","model_id":"IBEACON","mfid":"4c00","uuid":"00e39d9dfff20e97b21dc21f59471005","major":23068,"minor":22952,"txpower":-48} 
[21:27:25.3791] N: Send on /BTtoMQTT/C6C752663CBF msg {"id":"C6:C7:52:66:3C:BF","mac_type":1,"manufacturerdata":"6909c6c752663cbf250f099043","rssi":-28}
[21:27:25.3913] T: jsonPubl - ON
[21:27:25.3921] T: [ OMG->MQTT ] topic: home/reee/BTtoMQTT/C6C752663CBF msg: {"id":"C6:C7:52:66:3C:BF","mac_type":1,"manufacturerdata":"6909c6c752663cbf250f099043","rssi":-28} 
[21:27:25.4062] N: Send on /BTtoMQTT/7B24FDA46D89 msg {"id":"7B:24:FD:A4:6D:89","mac_type":1,"manufacturerdata":"0106010690caae1b75","rssi":-78}
[21:27:25.4183] T: jsonPubl - ON
[21:27:25.4192] T: [ OMG->MQTT ] topic: home/reee/BTtoMQTT/7B24FDA46D89 msg: {"id":"7B:24:FD:A4:6D:89","mac_type":1,"manufacturerdata":"0106010690caae1b75","rssi":-78} 

 # 2
[21:28:20.7487] N: Scan begin
[21:28:21.6719] T: Creating BLE buffer
[21:28:21.6744] N: Device detected: C6:C7:52:66:3C:BF
[21:28:21.6774] T: getDeviceByMac C6:C7:52:66:3C:BF
[21:28:21.6804] T: Get services data number: 1
[21:28:21.6834] T: Converted service data (6) to 69c0e4099043
[21:28:21.6875] T: Service data: 69c0e4099043
[21:28:21.6904] T: Service data UUID: 0xfd3d
[21:28:21.7129] T: Decoder found device: THX1/W230150X
[21:28:21.7165] T: getDeviceByMac C6:C7:52:66:3C:BF
[21:28:21.7194] T: add C6:C7:52:66:3C:BF
[21:28:21.7214] T: Removing servicedatauuid
[21:28:21.7245] T: Removing servicedata
[21:28:21.7265] T: Removing manufacturerdata
[21:28:21.7285] T: Device mac 68:99:7A:56:0E:B5
[21:28:21.7315] T: Device already discovered or that doesn't require discovery 68:99:7A:56:0E:B5
[21:28:21.7384] T: Device mac C6:C7:52:66:3C:BF
[21:28:21.7414] T: Looking for Model_id: 39
[21:28:21.7434] T: properties: {"properties":{"tempc":{"unit":"°C","name":"temperature"},"hum":{"unit":"%","name":"humidity"},"batt":{"unit":"%","name":"battery"}}}
[21:28:21.7564] T: Key: tempcT: Unit: °CT: Name: temperatureT: Announce Device sensor on  homeassistant/sensor/C6C752663CBF-tempc/config
[21:28:21.7674] T: [ OMG->MQTT ] topic: homeassistant/sensor/C6C752663CBF-tempc/config msg: {"stat_t":"+/+/BTtoMQTT/C6C752663CBF","dev_cla":"temperature","unit_of_meas":"°C","name":"THX1/W230150X-tempc","uniq_id":"C6C752663CBF-tempc","val_tpl":"{{ value_json.tempc | is_defined }}","state_class":"measurement","device":{"identifiers":["C6C752663CBF"],"connections":[["mac","C6C752663CBF"]],"manufacturer":"SwitchBot","model":"THX1/W230150X","name":"Meter (Plus)-663CBF","via_device":"reee"}} 
[21:28:21.8094] T: Key: humT: Unit: %T: Name: humidityT: Announce Device sensor on  homeassistant/sensor/C6C752663CBF-hum/config
[21:28:21.8185] T: [ OMG->MQTT ] topic: homeassistant/sensor/C6C752663CBF-hum/config msg: {"stat_t":"+/+/BTtoMQTT/C6C752663CBF","dev_cla":"humidity","unit_of_meas":"%","name":"THX1/W230150X-hum","uniq_id":"C6C752663CBF-hum","val_tpl":"{{ value_json.hum | is_defined }}","state_class":"measurement","device":{"identifiers":["C6C752663CBF"],"connections":[["mac","C6C752663CBF"]],"manufacturer":"SwitchBot","model":"THX1/W230150X","name":"Meter (Plus)-663CBF","via_device":"reee"}} 
[21:28:21.8595] T: Key: battT: Unit: %T: Name: batteryT: Announce Device sensor on  homeassistant/sensor/C6C752663CBF-batt/config
[21:28:21.8694] T: [ OMG->MQTT ] topic: homeassistant/sensor/C6C752663CBF-batt/config msg: {"stat_t":"+/+/BTtoMQTT/C6C752663CBF","dev_cla":"battery","unit_of_meas":"%","name":"THX1/W230150X-batt","uniq_id":"C6C752663CBF-batt","val_tpl":"{{ value_json.batt | is_defined }}","state_class":"measurement","device":{"identifiers":["C6C752663CBF"],"connections":[["mac","C6C752663CBF"]],"manufacturer":"SwitchBot","model":"THX1/W230150X","name":"Meter (Plus)-663CBF","via_device":"reee"}} 
[21:28:21.9094] N: Send on /BTtoMQTT/C6C752663CBF msg {"id":"C6:C7:52:66:3C:BF","mac_type":1,"rssi":-33,"brand":"SwitchBot","model":"Meter (Plus)","model_id":"THX1/W230150X","tempc":16.9,"tempf":62.42,"hum":67,"batt":100}
[21:28:21.9275] T: jsonPubl - ON
[21:28:21.9294] T: [ OMG->MQTT ] topic: home/reee/BTtoMQTT/C6C752663CBF msg: {"id":"C6:C7:52:66:3C:BF","mac_type":1,"rssi":-33,"brand":"SwitchBot","model":"Meter (Plus)","model_id":"THX1/W230150X","tempc":16.9,"tempf":62.42,"hum":67,"batt":100} 
[21:28:26.0682] T: Creating BLE buffer
[21:28:26.0699] N: Device detected: 76:1E:17:B5:02:BE
[21:28:26.0740] T: getDeviceByMac 76:1E:17:B5:02:BE
[21:28:26.1120] T: No device found 
[21:28:26.1140] N: Send on /BTtoMQTT/761E17B502BE msg {"id":"76:1E:17:B5:02:BE","mac_type":1,"manufacturerdata":"4c001005071caa5cb1","rssi":-85,"txpower":12}
[21:28:26.1260] T: jsonPubl - ON
[21:28:26.1280] T: [ OMG->MQTT ] topic: home/reee/BTtoMQTT/761E17B502BE msg: {"id":"76:1E:17:B5:02:BE","mac_type":1,"manufacturerdata":"4c001005071caa5cb1","rssi":-85,"txpower":12} 
[21:28:26.7596] N: Found 2 devices, scan number 2 end
[21:28:26.7630] T: Process BLE stack free: 3084
[21:28:26.7660] T: macAdr 68:99:7A:56:0E:B5
[21:28:26.7680] T: macType 1
[21:28:26.7690] T: isDisc 0
[21:28:26.7700] T: isWhtL 0
[21:28:26.7710] T: isBlkL 0
[21:28:26.7730] T: connect 0
[21:28:26.7740] T: sensorModel_id 55
[21:28:26.7760] T: macAdr C6:C7:52:66:3C:BF
[21:28:26.7780] T: macType 1
[21:28:26.7790] T: isDisc 1
[21:28:26.7800] T: isWhtL 0
[21:28:26.7810] T: isBlkL 0
[21:28:26.7820] T: connect 0
[21:28:26.7830] T: sensorModel_id 39

# 3
[21:29:22.3352] N: Scan begin
[21:29:28.3459] T: Creating BLE buffer
[21:29:28.3479] N: Found 1 devices, scan number 3 end
[21:29:28.3509] N: Device detected: 76:1E:17:B5:02:BE
[21:29:28.3549] T: getDeviceByMac 76:1E:17:B5:02:BE
[21:29:28.3579] T: Process BLE stack free: 3084
[21:29:28.3609] T: macAdr 68:99:7A:56:0E:B5
[21:29:28.3629] T: macType 1
[21:29:28.3639] T: isDisc 0
[21:29:28.3649] T: isWhtL 0
[21:29:28.3659] T: isBlkL 0
[21:29:28.3669] T: connect 0
[21:29:28.3679] T: sensorModel_id 55
[21:29:28.3699] T: macAdr C6:C7:52:66:3C:BF
[21:29:28.3729] T: macType 1
[21:29:28.3739] T: isDisc 1
[21:29:28.3749] T: isWhtL 0
[21:29:28.3759] T: isBlkL 0
[21:29:28.3769] T: connect 0
[21:29:28.3779] T: sensorModel_id 39
[21:29:28.3899] T: No device found 
[21:29:28.3919] N: Send on /BTtoMQTT/761E17B502BE msg {"id":"76:1E:17:B5:02:BE","mac_type":1,"manufacturerdata":"4c001005071caa5cb1","rssi":-88,"txpower":12}
[21:29:28.4039] T: jsonPubl - ON
[21:29:28.4059] T: [ OMG->MQTT ] topic: home/reee/BTtoMQTT/761E17B502BE msg: {"id":"76:1E:17:B5:02:BE","mac_type":1,"manufacturerdata":"4c001005071caa5cb1","rssi":-88,"txpower":12} 

Does NimBLE have an underlying flag to enable trace logs? From outside tests (nimble examples, Theengs', ESPhome, etc.) we know the service data is always transmitted; but it'd be nice if we can literally tell the data was picked up by OMG at some point.

Can we dump a representation of NimBLEAdvertisedDevice as it is created? Life would be so much simpler if we could debug with gdb.

@h2zero
Copy link
Collaborator

h2zero commented Nov 3, 2022

Thanks for testing, you can enable NimBLE logs with -DCONFIG_NIMBLE_CPP_LOG_LEVEL=5.

When the device is created is when the callback is called and you get a reference to it, you can then call getPayload() to and getPayloadLength() on it to access the data directly and dump it.

@xanderificnl
Copy link
Author

xanderificnl commented Nov 3, 2022

Thanks for all the hard work you've given to the community and the help you're providing me. It's much appreciated :)

Initially I inserted this into OMG's callback:

    char* payload = BLEUtils::buildHexData(NULL, (uint8_t*)advertisedDevice->getPayload(), advertisedDevice->getPayloadLength());
    Log.trace(F("[payload] %s:  %s" CR), advertisedDevice->getAddress().toString().c_str(), payload);

That resulted in:

[22:16:14.4896] T: [payload] c6:c7:52:66:3c:bf:  0201060eff6909c6c752663cbf300f009142

At this point, I figured I could just copy an example by technophile, and insert that:
I did adjust the servicedata to use buildHexData but I left the serial.println & prinft's since I figured they don't really matter

    Serial.println("begin-----------------------------------------------------------------------------------");
    Serial.printf("Advertised Device mac: %s \n", advertisedDevice->getAddress().toString().c_str());
    Serial.printf("Advertised Device name: %s \n", (char*)advertisedDevice->getName().c_str());
    if (advertisedDevice->haveManufacturerData()) {
      char* manufacturerdata = BLEUtils::buildHexData(NULL, (uint8_t*)advertisedDevice->getManufacturerData().data(), advertisedDevice->getManufacturerData().length());
      Serial.printf("Advertised Device manufacturer data: %s \n", manufacturerdata);
      free(manufacturerdata);
    }
    if (advertisedDevice->haveServiceData()) {
      int serviceDataCount = advertisedDevice->getServiceDataCount();
      Serial.printf("Get services data number: %d \n", serviceDataCount);
      for (int j = 0; j < serviceDataCount; j++) {
        std::string service_data = NimBLEUtils::buildHexData(nullptr, (uint8_t*)advertisedDevice->getServiceData().data(), advertisedDevice->getServiceData().length());
        Serial.printf("Service data: %s \n", service_data.c_str());
        std::string serviceDatauuid = advertisedDevice->getServiceDataUUID(j).toString();
        Serial.printf("Service data UUID: %s \n", (char*)serviceDatauuid.c_str());
      }
    }
    Serial.println("end-----------------------------------------------------------------------------------");

also updated the queue sender to tell us when that happens, i.e.

    if (xQueueSend(BLEQueue, &advertisedDevice, 0) != pdTRUE) {
      Log.error(F("BLEQueue full" CR));
    } else {
      Log.trace(F("[xQueueSend] %s" CR), advertisedDevice->getAddress().toString().c_str());
    }

And here's a good reading:

[22:18:38.6682] I NimBLEScan: New advertiser: c6:c7:52:66:3c:bf
[22:18:38.6728] I NimBLEScan: Updated advertiser: c6:c7:52:66:3c:bf
[22:18:38.6777] begin-----------------------------------------------------------------------------------
[22:18:38.6848] Advertised Device mac: c6:c7:52:66:3c:bf 
[22:18:38.6888] Advertised Device name:  
[22:18:38.6907] Advertised Device manufacturer data: 6909c6c752663cbf310f009143 
[22:18:38.6968] Get services data number: 1 
[22:18:38.6998] Service data: 69c0e4009143 
[22:18:38.7018] Service data UUID: 0xfd3d 
[22:18:38.7038] end-----------------------------------------------------------------------------------
[22:18:38.7118] T: Creating BLE buffer
garbled [22:18:38.7138] T: [xQueueSend] Nc6:c7:52:66:3c:bf
[22:18:38.7168] : Device detected: C6:C7:52:66:3C:BF
[22:18:38.7198] T: getDeviceByMac C6:C7:52:66:3C:BF
[22:18:38.7228] T: Get services data number: 1
[22:18:38.7258] T: Converted service data (6) to 69c0e4009143
[22:18:38.7298] T: Service data: 69c0e4009143
[22:18:38.7328] T: Service data UUID: 0xfd3d
[22:18:38.7558] T: Decoder found device: THX1/W230150X
[22:18:38.7598] T: getDeviceByMac C6:C7:52:66:3C:BF
[22:18:38.7628] T: add C6:C7:52:66:3C:BF
[22:18:38.7648] T: Removing servicedatauuid
[22:18:38.7678] T: Removing servicedata
[22:18:38.7698] T: Removing manufacturerdata
[22:18:38.7718] T: Device mac C6:C7:52:66:3C:BF
[22:18:38.7747] T: Looking for Model_id: 39

and a bad reading:

[22:19:38.5385] D NimBLEScan: >> start: duration=6
[22:19:38.5449] D NimBLEScan: << start()
[22:19:40.8088] I NimBLEScan: New advertiser: c6:c7:52:66:3c:bf
[22:19:41.5864] I NimBLEScan: New advertiser: 46:dc:32:71:56:fa
[22:19:41.5909] I NimBLEScan: Updated advertiser: 46:dc:32:71:56:fa
[22:19:41.5958] begin-----------------------------------------------------------------------------------
[22:19:41.6028] Advertised Device mac: 46:dc:32:71:56:fa 
[22:19:41.6068] Advertised Device name:  
[22:19:41.6088] Advertised Device manufacturer data: 4c0010050a1cd1cf54 
[22:19:41.6138] end-----------------------------------------------------------------------------------
garbled [22:19:41.6218] T: CrT: eating BLE buffer
garbled [22:19:41.6238] [xQueueSend] N: Device detected: 46:dc:32:71:56:fa46:DC:32:71:56:FA
garbled [22:19:41.6299] 
[22:19:41.6299] T: getDeviceByMac 46:DC:32:71:56:FA
[22:19:41.6650] T: No device found 
[22:19:41.6669] N: Send on /BTtoMQTT/46DC327156FA msg {"id":"46:DC:32:71:56:FA","mac_type":1,"manufacturerdata":"4c0010050a1cd1cf54","rssi":-90,"txpower":12}
[22:19:41.6788] T: jsonPubl - ON
[22:19:41.6809] T: [ OMG->MQTT ] topic: home/reee/BTtoMQTT/46DC327156FA msg: {"id":"46:DC:32:71:56:FA","mac_type":1,"manufacturerdata":"4c0010050a1cd1cf54","rssi":-90,"txpower":12} 
[22:19:44.5466] D NimBLEScan: discovery complete; reason=0
[22:19:44.5512] begin-----------------------------------------------------------------------------------
[22:19:44.5592] Advertised Device mac: c6:c7:52:66:3c:bf 
[22:19:44.5622] Advertised Device name:  
[22:19:44.5642] Advertised Device manufacturer data: 6909c6c752663cbf310f009143 
[22:19:44.5702] end-----------------------------------------------------------------------------------
[22:19:44.5782] T: Creating BLE buffer
garbled [22:19:44.5801] TN: : Device det[ected: xQuC6:C7:52:66:3C:BF
garbled [22:19:44.5841] eT: getDeviceByMac C6:C7:52:66:3C:BF
garbled [22:19:44.5872] ueSend] c6:c7:52:66:3c:bf
[22:19:44.5892] N: Found 2 devices, scan number 2 end
[22:19:44.5921] T: Process BLE stack free: 3084
[22:19:44.5952] T: macAdr C6:C7:52:66:3C:BF
[22:19:44.5982] T: macType 1
[22:19:44.5992] T: isDisc 1
[22:19:44.6002] T: isWhtL 0
[22:19:44.6012] T: isBlkL 0
[22:19:44.6022] T: connect 0
[22:19:44.6032] T: sensorModel_id 39
[22:19:44.6187] T: No device found 
[22:19:44.6212] N: Send on /BTtoMQTT/C6C752663CBF msg {"id":"C6:C7:52:66:3C:BF","mac_type":1,"manufacturerdata":"6909c6c752663cbf310f009143","rssi":-37}
[22:19:44.6332] T: jsonPubl - ON
[22:19:44.6342] T: [ OMG->MQTT ] topic: home/reee/BTtoMQTT/C6C752663CBF msg: {"id":"C6:C7:52:66:3C:BF","mac_type":1,"manufacturerdata":"6909c6c752663cbf310f009143","rssi":-37} 

edit

also, here's a good reading w/ both payload & the extra data:

[22:25:30.3155] D NimBLEScan: >> start: duration=6
[22:25:30.3219] D NimBLEScan: << start()
[22:25:33.1902] I NimBLEScan: New advertiser: c6:c7:52:66:3c:bf
[22:25:33.1942] I NimBLEScan: Updated advertiser: c6:c7:52:66:3c:bf
[22:25:33.1992] begin-----------------------------------------------------------------------------------
[22:25:33.2072] Advertised Device mac: c6:c7:52:66:3c:bf 
[22:25:33.2112] Advertised Device name:  
[22:25:33.2132] Advertised Device manufacturer data: 6909c6c752663cbf320f099043 
[22:25:33.2182] Get services data number: 1 
[22:25:33.2212] Service data: 69c0e4099043 
[22:25:33.2231] Service data UUID: 0xfd3d 
[22:25:33.2262] end-----------------------------------------------------------------------------------
[22:25:33.2332] T: [payload] c6:c7:52:66:3c:bf:  0201060eff6909c6c752663cbf320f09904309163dfd69c0e4099043

and one w/o reading:

[22:26:31.9933] D NimBLEScan: >> start: duration=6
[22:26:31.9998] D NimBLEScan: << start()
[22:26:35.3523] I NimBLEScan: New advertiser: c6:c7:52:66:3c:bf
[22:26:37.9997] D NimBLEScan: discovery complete; reason=0
[22:26:38.0037] begin-----------------------------------------------------------------------------------
[22:26:38.0117] Advertised Device mac: c6:c7:52:66:3c:bf 
[22:26:38.0157] Advertised Device name:  
[22:26:38.0177] Advertised Device manufacturer data: 6909c6c752663cbf320f099043 
[22:26:38.0237] end-----------------------------------------------------------------------------------
[22:26:38.0307] T: [payload] c6:c7:52:66:3c:bf:  0201060eff6909c6c752663cbf320f099043
[22:26:38.0367] TT: [xQueueSend] c6:c7:52:66:3c:bf

To be honest, I'm getting a bit far out of my depth and I'm content to just letting it run with scan duration 0; but I'm more than happy to help trying to debug/narrow down this issue.

@h2zero
Copy link
Collaborator

h2zero commented Nov 3, 2022

You're welcome 😀 and thanks for your efforts as well, that's some great detailed troubleshooting!

Now for the issue at hand.

From the good reading:

[22:18:38.6682] I NimBLEScan: New advertiser: c6:c7:52:66:3c:bf  -- advertisement data stored here (manufacturer data is in this)
[22:18:38.6728] I NimBLEScan: Updated advertiser: c6:c7:52:66:3c:bf  -- scan response data is stored here (this is where the missing service data comes from) 

From the bad reading:

[22:19:40.8088] I NimBLEScan: New advertiser: c6:c7:52:66:3c:bf  -- advertisement data, all good here
************************************ missing scan response data here *********************************
[22:19:41.5864] I NimBLEScan: New advertiser: 46:dc:32:71:56:fa -- other device advertisement data
[22:19:41.5909] I NimBLEScan: Updated advertiser: 46:dc:32:71:56:fa -- other device scan response data

As to why this is happening, this would be incredibly hard to know for certain with logs alone. This could be due to a number of factors such as the device simply didn't receive the scan response request, or went to sleep. On our side there could have been an interruption in the receiver at the moment it was sent (think WiFi, due to shared antenna), radio interference, BLE stack bugs or bad timing.

The interesting thing about the applications that do work is that they are not simultaneously processing WiFi packets while scanning BLE, it would not surprise me if this was ultimately the root cause. Potential improvement might be provided by setting BLEScanInterval and BLEScanWindow to the same value (something like 37), this will cause the BLE stack to consume the maximum amount of antenna time, but may cause a WiFi disconnect.

@xanderificnl
Copy link
Author

For what it's worth, the ESP and the switchbot are within 20 cm of each other.

I'll try the window + interval shortly. We might also try disabling wifi fully (not sure how easy that'd be with OMG) since we can still see all the data over serial.

Thanks :)

@h2zero
Copy link
Collaborator

h2zero commented Nov 3, 2022

I'm not sure about fully disabling WiFi, could be quite difficult. Hopefully there is some improvement with those settings though, let me know if it helps.

@xanderificnl
Copy link
Author

I've just realized you may have missed that message. Technophile and I discovered that a scan_interval of 0 with the default OMG settings yielded at least one reading a minute, and sometimes two. During that run there were max 5 missing readings in a timeframe of a couple of hours. See this message.

Anyway, setting the scan interval & window to 37 does seem to work as well. I've seen a couple serviceless data so far, but mostly readings. So scan interval 0 still seems to pick up more and at slightly higher intervals (i.e. it takes about 60-70 seconds for each reading w/ these settings).

I've yet to see a wifi or mqtt disconnect. If there's anything else you'd like me to try/run, I'm more than happy to narrow down this issue further.

With the way OMG's output gets garbled, I've also wondered if maybe the multithreading may be causing things to run amok - but yesterday (or earlier) I already disabled the 2 lines switching/disabling/enabling cores and that made no difference.

@h2zero
Copy link
Collaborator

h2zero commented Nov 4, 2022

Glad those settings made an improvement! Yes, setting the scan duration to 0 for continuous scanning would work as well simply due to the scan having more opportunities to receive all the data.

I'm not sure how much better we can get than this, if I think of anything else I'll let you know.

@xanderificnl
Copy link
Author

Cheers, thanks everyone!

@DigiH
Copy link
Collaborator

DigiH commented Jan 2, 2024

Hi @xanderificnl

How have you been getting along with the above issue?

While most users seem to be getting the servicedata included, I am asking again here, as a very similar issue has been cropping up with the SwitchBot Outdoor Meter

#1845

From your above postings I can see that the manufacturerdata for the Meter Plus is one octet shorter than the Outdoor Meter, but I'm still a bit worried that other SwitchBot devices might fall under the same manufacturerdata only messages, as the uniquely identifying device ID is broadcast only with the servicedata.

We could still try and change the Meter (Plus( decoder in the same way for you to run so0me tests, if you are still seeing this issue.

For the Meter (Plus) there also seems to be some documentation about changing the advertisement broadcast mode

https://github.com/OpenWonderLabs/SwitchBotAPI-BLE/blob/latest/devicetypes/meter.md#broadcast-mode

which might also be an additional thing for you to try out.

@DigiH
Copy link
Collaborator

DigiH commented Jan 10, 2024

Unfortunately looking more into the other threads Outdoor Meter data, is is the same, the servicedata/uuid is really is required to uniquely identify the SwitchBot devices. So using the manufacturerdata only is unfortunately not an option.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants