Take a look at the MQTT Binary Sensor docs. You can do this for any MQTT devices that supports the connectivity and json attributes.
unfortunately seems that my Huami Amazfit Verge does not advertise any kind of BLE message… what do you use as a beacon? and How?
Check out the docs:
There’s also a page about troubleshooting which explains how things work:
You may also want to try using the NRF Connect app on your phone to scan for your Amazefit. Some devices are visible even though they don’t broadcast as a beacon (I have an old MiBand2 that can be tracked), but other devices like my LG G Watch does not broadcast and is only visible to the paired phone.
Anyone got this type of errors?
And did you managed to build it after all.
Verbose mode can be enabled via `-v, --verbose` option
CONFIGURATION: https://docs.platformio.org/page/boards/espressif32/esp32dev.html
PLATFORM: Espressif 32 1.11.0 > Espressif ESP32 Dev Module
HARDWARE: ESP32 240MHz, 320KB RAM, 4MB Flash
DEBUG: Current (esp-prog) External (esp-prog, iot-bus-jtag, jlink, minimodule, olimex-arm-usb-ocd, olimex-arm-usb-ocd-h, olimex-arm-usb-tiny-h, olimex-jtag-tiny, tumpa)
PACKAGES: toolchain-xtensa32 2.50200.80 (5.2.0), framework-arduinoespressif32 2.10004.191002 (1.0.4), tool-esptoolpy 1.20600.0 (2.6.0)
Converting ESP32-mqtt-room.ino
LDF: Library Dependency Finder -> http://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Looking for ArduinoJSON library in registry
Found: https://platformio.org/lib/show/64/ArduinoJson
LibraryManager: Installing id=64 @ ^6
ArduinoJson @ 6.12.0 is already installed
Found 29 compatible libraries
Scanning dependencies...
Dependency Graph
|-- <ESP32 BLE Arduino> 1.0.1
|-- <AsyncMqttClient> 0.8.2
| |-- <AsyncTCP> 1.1.1
|-- <AsyncTCP> 1.1.1
|-- <ArduinoJson> 6.12.0
|-- <ArduinoOTA> 1.0
| |-- <Update> 1.0
| |-- <WiFi> 1.0
| |-- <ESPmDNS> 1.0
| | |-- <WiFi> 1.0
|-- <WiFi> 1.0
Compiling .pio\build\esp32\src\ESP32-mqtt-room.ino.cpp.o
Generating partitions .pio\build\esp32\partitions.bin
Compiling .pio\build\esp32\lib7cf\BLE\BLE2902.cpp.o
Compiling .pio\build\esp32\lib7cf\BLE\BLE2904.cpp.o
Compiling .pio\build\esp32\lib7cf\BLE\BLEAddress.cpp.o
Compiling .pio\build\esp32\lib7cf\BLE\BLEAdvertisedDevice.cpp.o
Compiling .pio\build\esp32\lib7cf\BLE\BLEAdvertising.cpp.o
Compiling .pio\build\esp32\lib7cf\BLE\BLEBeacon.cpp.o
Compiling .pio\build\esp32\lib7cf\BLE\BLECharacteristic.cpp.o
Compiling .pio\build\esp32\lib7cf\BLE\BLECharacteristicMap.cpp.o
Compiling .pio\build\esp32\lib7cf\BLE\BLEClient.cpp.o
Compiling .pio\build\esp32\lib7cf\BLE\BLEDescriptor.cpp.o
Compiling .pio\build\esp32\lib7cf\BLE\BLEDescriptorMap.cpp.o
Compiling .pio\build\esp32\lib7cf\BLE\BLEDevice.cpp.o
Compiling .pio\build\esp32\lib7cf\BLE\BLEEddystoneTLM.cpp.o
Compiling .pio\build\esp32\lib7cf\BLE\BLEEddystoneURL.cpp.o
Compiling .pio\build\esp32\lib7cf\BLE\BLEExceptions.cpp.o
Compiling .pio\build\esp32\lib7cf\BLE\BLEHIDDevice.cpp.o
Compiling .pio\build\esp32\lib7cf\BLE\BLERemoteCharacteristic.cpp.o
Compiling .pio\build\esp32\lib7cf\BLE\BLERemoteDescriptor.cpp.o
Compiling .pio\build\esp32\lib7cf\BLE\BLERemoteService.cpp.o
Compiling .pio\build\esp32\lib7cf\BLE\BLEScan.cpp.o
Compiling .pio\build\esp32\lib7cf\BLE\BLESecurity.cpp.o
Compiling .pio\build\esp32\lib7cf\BLE\BLEServer.cpp.o
Compiling .pio\build\esp32\lib7cf\BLE\BLEService.cpp.o
Compiling .pio\build\esp32\lib7cf\BLE\BLEServiceMap.cpp.o
Compiling .pio\build\esp32\lib7cf\BLE\BLEUUID.cpp.o
Compiling .pio\build\esp32\lib7cf\BLE\BLEUtils.cpp.o
Compiling .pio\build\esp32\lib7cf\BLE\BLEValue.cpp.o
Compiling .pio\build\esp32\lib7cf\BLE\FreeRTOS.cpp.o
Compiling .pio\build\esp32\lib7cf\BLE\GeneralUtils.cpp.o
Compiling .pio\build\esp32\lib395\AsyncTCP_ID1826\AsyncTCP.cpp.o
Compiling .pio\build\esp32\lib7b6\AsyncMqttClient_ID346\AsyncMqttClient.cpp.o
C:/Users/Maxi/Documents/PlatformIO/ESP32-mqtt-room-master/ESP32-mqtt-room.ino: In function 'bool sendTelemetry(int, int)':
C:/Users/Maxi/Documents/PlatformIO/ESP32-mqtt-room-master/ESP32-mqtt-room.ino:107:21: error: 'maxDistance' was not declared in this scope
tele["max_dist"] = maxDistance;
^
C:/Users/Maxi/Documents/PlatformIO/ESP32-mqtt-room-master/ESP32-mqtt-room.ino:122:25: error: 'telemetryTopic' was not declared in this scope
if (mqttClient.publish(telemetryTopic, 0, 1, teleMessageBuffer) == true) {
^
C:/Users/Maxi/Documents/PlatformIO/ESP32-mqtt-room-master/ESP32-mqtt-room.ino: In function 'void WiFiEvent(system_event_id_t)':
C:/Users/Maxi/Documents/PlatformIO/ESP32-mqtt-room-master/ESP32-mqtt-room.ino:209:19: error: 'LED_BUILTIN' was not declared in this scope
digitalWrite(LED_BUILTIN, !LED_ON);
^
C:/Users/Maxi/Documents/PlatformIO/ESP32-mqtt-room-master/ESP32-mqtt-room.ino:209:33: error: 'LED_ON' was not declared in this scope
digitalWrite(LED_BUILTIN, !LED_ON);
^
C:/Users/Maxi/Documents/PlatformIO/ESP32-mqtt-room-master/ESP32-mqtt-room.ino:207:9: warning: enumeration value 'SYSTEM_EVENT_SCAN_DONE' not handled in switch [-Wswitch]
switch(event) {
^
C:/Users/Maxi/Documents/PlatformIO/ESP32-mqtt-room-master/ESP32-mqtt-room.ino:207:9: warning: enumeration value 'SYSTEM_EVENT_STA_CONNECTED' not handled in switch [-Wswitch]
C:/Users/Maxi/Documents/PlatformIO/ESP32-mqtt-room-master/ESP32-mqtt-room.ino:207:9: warning: enumeration value 'SYSTEM_EVENT_STA_AUTHMODE_CHANGE' not handled in switch [-Wswitch]
C:/Users/Maxi/Documents/PlatformIO/ESP32-mqtt-room-master/ESP32-mqtt-room.ino:207:9: warning: enumeration value 'SYSTEM_EVENT_STA_LOST_IP' not handled in switch [-Wswitch]
C:/Users/Maxi/Documents/PlatformIO/ESP32-mqtt-room-master/ESP32-mqtt-room.ino:207:9: warning: enumeration value 'SYSTEM_EVENT_STA_WPS_ER_SUCCESS' not handled in switch [-Wswitch]
C:/Users/Maxi/Documents/PlatformIO/ESP32-mqtt-room-master/ESP32-mqtt-room.ino:207:9: warning: enumeration value 'SYSTEM_EVENT_STA_WPS_ER_FAILED' not handled in switch [-Wswitch]
C:/Users/Maxi/Documents/PlatformIO/ESP32-mqtt-room-master/ESP32-mqtt-room.ino:207:9: warning: enumeration value 'SYSTEM_EVENT_STA_WPS_ER_TIMEOUT' not handled in switch [-Wswitch]
C:/Users/Maxi/Documents/PlatformIO/ESP32-mqtt-room-master/ESP32-mqtt-room.ino:207:9: warning: enumeration value 'SYSTEM_EVENT_STA_WPS_ER_PIN' not handled in switch [-Wswitch]
C:/Users/Maxi/Documents/PlatformIO/ESP32-mqtt-room-master/ESP32-mqtt-room.ino:207:9: warning: enumeration value 'SYSTEM_EVENT_STA_WPS_ER_PBC_OVERLAP' not handled in switch [-Wswitch]
C:/Users/Maxi/Documents/PlatformIO/ESP32-mqtt-room-master/ESP32-mqtt-room.ino:207:9: warning: enumeration value 'SYSTEM_EVENT_AP_START' not handled in switch [-Wswitch]
C:/Users/Maxi/Documents/PlatformIO/ESP32-mqtt-room-master/ESP32-mqtt-room.ino:207:9: warning: enumeration value 'SYSTEM_EVENT_AP_STOP' not handled in switch [-Wswitch]
C:/Users/Maxi/Documents/PlatformIO/ESP32-mqtt-room-master/ESP32-mqtt-room.ino:207:9: warning: enumeration value 'SYSTEM_EVENT_AP_STACONNECTED' not handled in switch [-Wswitch]
C:/Users/Maxi/Documents/PlatformIO/ESP32-mqtt-room-master/ESP32-mqtt-room.ino:207:9: warning: enumeration value 'SYSTEM_EVENT_AP_STADISCONNECTED' not handled in switch [-Wswitch]
C:/Users/Maxi/Documents/PlatformIO/ESP32-mqtt-room-master/ESP32-mqtt-room.ino:207:9: warning: enumeration value 'SYSTEM_EVENT_AP_STAIPASSIGNED' not handled in switch [-Wswitch]
C:/Users/Maxi/Documents/PlatformIO/ESP32-mqtt-room-master/ESP32-mqtt-room.ino:207:9: warning: enumeration value 'SYSTEM_EVENT_AP_PROBEREQRECVED' not handled in switch [-Wswitch]
C:/Users/Maxi/Documents/PlatformIO/ESP32-mqtt-room-master/ESP32-mqtt-room.ino:207:9: warning: enumeration value 'SYSTEM_EVENT_GOT_IP6' not handled in switch [-Wswitch]
C:/Users/Maxi/Documents/PlatformIO/ESP32-mqtt-room-master/ESP32-mqtt-room.ino:207:9: warning: enumeration value 'SYSTEM_EVENT_ETH_START' not handled in switch [-Wswitch]
C:/Users/Maxi/Documents/PlatformIO/ESP32-mqtt-room-master/ESP32-mqtt-room.ino:207:9: warning: enumeration value 'SYSTEM_EVENT_ETH_STOP' not handled in switch [-Wswitch]
C:/Users/Maxi/Documents/PlatformIO/ESP32-mqtt-room-master/ESP32-mqtt-room.ino:207:9: warning: enumeration value 'SYSTEM_EVENT_ETH_CONNECTED' not handled in switch [-Wswitch]
Compiling .pio\build\esp32\lib7b6\AsyncMqttClient_ID346\AsyncMqttClient\Packets\ConnAckPacket.cpp.o
C:/Users/Maxi/Documents/PlatformIO/ESP32-mqtt-room-master/ESP32-mqtt-room.ino:207:9: warning: enumeration value 'SYSTEM_EVENT_ETH_DISCONNECTED' not handled in switch [-Wswitch]
C:/Users/Maxi/Documents/PlatformIO/ESP32-mqtt-room-master/ESP32-mqtt-room.ino:207:9: warning: enumeration value 'SYSTEM_EVENT_ETH_GOT_IP' not handled in switch [-Wswitch]
C:/Users/Maxi/Documents/PlatformIO/ESP32-mqtt-room-master/ESP32-mqtt-room.ino:207:9: warning: enumeration value 'SYSTEM_EVENT_MAX' not handled in switch [-Wswitch]
C:/Users/Maxi/Documents/PlatformIO/ESP32-mqtt-room-master/ESP32-mqtt-room.ino: In function 'void onMqttConnect(bool)':
C:/Users/Maxi/Documents/PlatformIO/ESP32-mqtt-room-master/ESP32-mqtt-room.ino:255:25: error: 'availabilityTopic' was not declared in this scope
if (mqttClient.publish(availabilityTopic, 0, 1, "CONNECTED") == true) {
^
C:/Users/Maxi/Documents/PlatformIO/ESP32-mqtt-room-master/ESP32-mqtt-room.ino: In function 'bool reportDevice(BLEAdvertisedDevice)':
C:/Users/Maxi/Documents/PlatformIO/ESP32-mqtt-room-master/ESP32-mqtt-room.ino:395:8: error: 'maxDistance' was not declared in this scope
if (maxDistance == 0 || doc["distance"] < maxDistance) {
^
Compiling .pio\build\esp32\lib7b6\AsyncMqttClient_ID346\AsyncMqttClient\Packets\PingRespPacket.cpp.o
C:/Users/Maxi/Documents/PlatformIO/ESP32-mqtt-room-master/ESP32-mqtt-room.ino: In member function 'virtual void MyAdvertisedDeviceCallbacks::onResult(BLEAdvertisedDevice)':
C:/Users/Maxi/Documents/PlatformIO/ESP32-mqtt-room-master/ESP32-mqtt-room.ino:431:16: error: 'LED_BUILTIN' was not declared in this scope
digitalWrite(LED_BUILTIN, LED_ON);
^
C:/Users/Maxi/Documents/PlatformIO/ESP32-mqtt-room-master/ESP32-mqtt-room.ino:431:29: error: 'LED_ON' was not declared in this scope
digitalWrite(LED_BUILTIN, LED_ON);
^
C:/Users/Maxi/Documents/PlatformIO/ESP32-mqtt-room-master/ESP32-mqtt-room.ino: In lambda function:
C:/Users/Maxi/Documents/PlatformIO/ESP32-mqtt-room-master/ESP32-mqtt-room.ino:488:17: error: 'LED_BUILTIN' was not declared in this scope
digitalWrite(LED_BUILTIN, !LED_ON);
^
C:/Users/Maxi/Documents/PlatformIO/ESP32-mqtt-room-master/ESP32-mqtt-room.ino:488:31: error: 'LED_ON' was not declared in this scope
digitalWrite(LED_BUILTIN, !LED_ON);
^
C:/Users/Maxi/Documents/PlatformIO/ESP32-mqtt-room-master/ESP32-mqtt-room.ino: In lambda function:
C:/Users/Maxi/Documents/PlatformIO/ESP32-mqtt-room-master/ESP32-mqtt-room.ino:493:50: warning: unknown conversion type character 0xa in format [-Wformat=]
Serial.printf("Progress: %u% \n\r", percent);
^
C:/Users/Maxi/Documents/PlatformIO/ESP32-mqtt-room-master/ESP32-mqtt-room.ino:494:17: error: 'LED_BUILTIN' was not declared in this scope
digitalWrite(LED_BUILTIN, percent % 2);
^
C:/Users/Maxi/Documents/PlatformIO/ESP32-mqtt-room-master/ESP32-mqtt-room.ino: In function 'void setup()':
C:/Users/Maxi/Documents/PlatformIO/ESP32-mqtt-room-master/ESP32-mqtt-room.ino:514:10: error: 'LED_BUILTIN' was not declared in this scope
pinMode(LED_BUILTIN, OUTPUT);
^
C:/Users/Maxi/Documents/PlatformIO/ESP32-mqtt-room-master/ESP32-mqtt-room.ino:515:28: error: 'LED_ON' was not declared in this scope
digitalWrite(LED_BUILTIN, LED_ON);
^
C:/Users/Maxi/Documents/PlatformIO/ESP32-mqtt-room-master/ESP32-mqtt-room.ino:526:21: error: 'availabilityTopic' was not declared in this scope
mqttClient.setWill(availabilityTopic, 0, 1, "DISCONNECTED");
^
C:/Users/Maxi/Documents/PlatformIO/ESP32-mqtt-room-master/ESP32-mqtt-room.ino: In function 'bool sendTelemetry(int, int)':
C:/Users/Maxi/Documents/PlatformIO/ESP32-mqtt-room-master/ESP32-mqtt-room.ino:130:1: warning: control reaches end of non-void function [-Wreturn-type]
}
^
C:/Users/Maxi/Documents/PlatformIO/ESP32-mqtt-room-master/ESP32-mqtt-room.ino: In function 'bool handleMqttDisconnect()':
C:/Users/Maxi/Documents/PlatformIO/ESP32-mqtt-room-master/ESP32-mqtt-room.ino:173:1: warning: control reaches end of non-void function [-Wreturn-type]
}
^
*** [.pio\build\esp32\src\ESP32-mqtt-room.ino.cpp.o] Error 1
C:\Users\Maxi\.platformio\packages\framework-arduinoespressif32\libraries\BLE\src\BLERemoteService.cpp: In member function 'void BLERemoteService::getCharacteristics(std::map<short unsigned int, BLERemoteCharacteristic*>*)':
C:\Users\Maxi\.platformio\packages\framework-arduinoespressif32\libraries\BLE\src\BLERemoteService.cpp:246:89: warning: parameter 'pCharacteristicMap' set but not used [-Wunused-but-set-parameter]
void BLERemoteService::getCharacteristics(std::map<uint16_t, BLERemoteCharacteristic*>* pCharacteristicMap) {
^
.pio\libdeps\esp32\AsyncMqttClient_ID346\src\AsyncMqttClient.cpp: In constructor 'AsyncMqttClient::AsyncMqttClient()':
.pio\libdeps\esp32\AsyncMqttClient_ID346\src\AsyncMqttClient.cpp:40:61: warning: format '%x' expects argument of type 'unsigned int', but argument 3 has type 'uint64_t {aka long long unsigned int}' [-Wformat=]
sprintf(_generatedClientId, "esp32%06x", ESP.getEfuseMac());
^
.pio\libdeps\esp32\AsyncMqttClient_ID346\src\AsyncMqttClient.cpp:40:61: warning: format '%x' expects argument of type 'unsigned int', but argument 3 has type 'uint64_t {aka long long unsigned int}' [-Wformat=]
============================================================================================================================================= [FAILED] Took 5.63 seconds =============================================================================================================================================
The terminal process terminated with exit code: 1
Terminal will be reused by tasks, press any key to close it.
Looks like some missing values from your configuration file. Did you update to a newer release using an older config file? If you look at the example config file, you should see all the fields you’ll need. I try not to add breaking changes, but when new features are added that are user-configurable, it’s a challenge to keep from breaking things.
I’ve added this to the troubleshooting section of the repo’s site. Will be published at the next release.
Yeah! It was my old config file that was creating issues.
Although now the Wifi refuses to connect. It loops between Event 4 and 5.
Tried with 5 different boards to make sure it wasn’t a faulty antenna.
If you have any idea!
Try erasing the flash on the device entirely before uploading, may have saved an old WiFi in the SPIFFS. Other than that, I’m not sure what could be going wrong aside from incorrect credentials.
I was so excited when I came across this project so I went ahead and got me an ESP32. All good now, other than the fact that my Galaxy S8 running BeaconScope goes out of reach (no MQTT, not_home HA frontend) as soon as it’s more than 50-70 cm away from the ESP32 At a distance of up to 10-15 cm - presence detected rock solid, between 30-50 cm it’s intermittent and anything over 70 - it’s game over. There’s surely a way to get a better range, right???
sensor:
- platform: mqtt_room
device_id: "2f234454cf6d4a0fadf2f4911ba9ffa6-1-1"
name: 'Phone bt_room'
state_topic: 'room_presence'
timeout: 10
away_timeout: 15
I suspect that beacon scope is misreporting the transmitter power versus distance. You may want to modify those values so that they more accurately reflect the distance calculated. If you have a second mobile device with BLE, you can use NRF Connect (another useful bluetooth low energy app) to scan and view the reported distance.
The values I’m currently using are: transmitter power: Low
and measured power: -79
Cheers
Yup! This improved things greatly. I can set the ESP32 and my phone at 3-4 meters apart before connection drops. Any other pointers how to increase this to 5-6m please?
Also, do you reckon a cheapo xiaomi mi band will be usable this way? I don’t imagine I will be able to adjust TX power on it but is it broadcasting ibeacon formatted messages at all?
The config you posted has a max distance setting of 4m. This is the cut off distance, so the ESP will not report any devices it thinks are further away. If you want it to report everything, set that value to zero and it will report every advertising packet it sees in the scan.
The idea of the max distance setting is to ensure that your ESP isn’t picking up advertising packets that are outside the room in which the device is located. For small rooms, I’ve found that a setting of 3m is good, while larger rooms will need a higher setting. Play around with the max distance, as well as the transmit power and measured power on your phone and see what results you can get.
I’ve tested with a Mi Band 2, and it does respond to a scan with a useable message, so it should work. It’s not strictly an iBeacon format, but since it doesn’t change its bluetooth hardware MAC address in the scan responses (the way phones do), it should work fine. Note that the configuration will be slightly different, the device ID in your sensors.yaml
will be just the hardware MAC address, without a major or minor version number.
Okay, so i’ve tried to get this working for a couple of days.
I’ve read the documentation several times, upside down even.
I see the ESP’s in my ARP in the router, I see it in the unifi controller aswell.
They get IP and sends packets…
I got this in my hassio MQTT Broker addon:
1573655959: New client connected from 192.168.1.xx as esp32_2 (p2, c1, k60, u'username').
1573655962: New connection from 192.168.1.xx on port 1883.
1573655962: Client esp32_2 already connected, closing old connection.
1573655962: New client connected from 192.168.1.xx as esp32_2 (p2, c1, k60, u'username').
1573655985: New connection from 192.168.1.xx on port 1883.
1573655985: New client connected from 192.168.1.xx as nvr2112 (p1, c1, k60, u'username').
1573655985: Client nvr2112 disconnected.
1573655996: New connection from 192.168.1.xx on port 1883.
1573655996: New client connected from 192.168.1.xx as nvr2125 (p1, c1, k60, u'username').
1573655996: Client nvr2125 disconnected.
1573656098: New connection from 192.168.1.xx on port 1883.
1573656098: Client esp32_1 already connected, closing old connection.
1573656098: New client connected from 192.168.1.xx as esp32_1 (p2, c1, k60, u'username').
1573656130: New connection from 192.168.1.xx on port 1883.
[INFO] found username on local database
1573656130: Client esp32_1 already connected, closing old connection.
1573656130: New client connected from 192.168.1.xx as esp32_1 (p2, c1, k60, u'username').
1573656137: New connection from 192.168.1.xx on port 1883.
1573656137: Client esp32_2 already connected, closing old connection.
1573656137: New client connected from 192.168.1.xx as esp32_2 (p2, c1, k60, u'username').
1573656173: New connection from 192.168.1.xx on port 1883.
1573656173: Client esp32_1 already connected, closing old connection.
1573656173: New client connected from 192.168.1.xx as esp32_1 (p2, c1, k60, u'username').
1573656180: New connection from 192.168.1.xx on port 1883.
1573656180: Client esp32_1 already connected, closing old connection.
1573656180: New client connected from 192.168.1.xx as esp32_1 (p2, c1, k60, u'username').
1573656212: New connection from 192.168.1.xx on port 1883.
1573656212: Client esp32_3 already connected, closing old connection.
1573656212: New client connected from 192.168.1.xx as esp32_3 (p2, c1, k60, u'username').
The binary sensor is disconnected. Why? In Atom it says:
devices_discovered: 14
devices_reported: 2
Telemetry sent
Scanning...
More from Atom serial monitor:
Connecting to WiFi...
[WiFi-event] event: 0
Wifi Ready
restarted
[WiFi-event] event: 2
STA Start
WiFi Time remaining: 1999
[WiFi-event] event: 4
[WiFi-event] event: 7
IP address: 192.168.1.xx
Hostname: esp32_3
Connecting to MQTT
Stopping wifi reconnect timer
Scanning... Connected to MQTT.
Success sending message to topic: presence_nodes/Sovrummet
Telemetry sent
Scan done! Devices found: 11
binary_sensor.yaml
platform: mqtt
name: ESP32 3
state_topic: "presence_nodes/esp32_3"
json_attributes_topic: "presence_nodes/esp32_3/tele"
payload_on: "CONNECTED"
payload_off: "DISCONNECTED"
device_class: connectivity
sensor.yaml
platform: mqtt_room
device_id: "2F234454-CF6D-4A0F-ADF2-F4911BA9FFA6-1-0"
name: 'Oskars_bt_mqtt'
state_topic: 'room_presence'
timeout: 10
away_timeout: 15
You’ll see this regularly in the MQTT logs, as due to the need to use antenna sharing, the WiFi has to be temporarily put into a lower priority than the bluetooth for the duration of the scan. The MQTT connection can suffer. The time is not long enough to trigger a disconnect, but when the connection gets re-established, I see this show in my log. You’ll notice other devices crop up in there with less regularity.
…or that’s what I’ve convinced myself is the case.
What’s concerning to me is the frequency at which this happens. What is your config for scan duration and wait time? Can you paste your config (minus any secret info) for the module or modules. Currently I don’t do any linting to check that they’re not misconfigured in such a way as to cause a repeated scan loop.
Hi,
this is my Settings_local.h:
https://pastebin.com/xxUX7xbV
I hope it was the settings file you wanted to see.
That was, and it all looks fine to me.
I just noticed in your sensor.yaml configuration, you’ve included dashes in the device id. You should strip those out and leave in only the ones separating the ID from the major and minor version numbers, like this:
platform: mqtt_room
device_id: 2F234454CF6D4A0FADF2F4911BA9FFA6-1-0
name: 'Oskars_bt_mqtt'
state_topic: 'room_presence'
timeout: 10
away_timeout: 15
Is the binary sensor showing DISCONNECTED the only issue you’re encountering, or are there other problems as well?
The problem I have is that the binary sensor says DISCONNECTED and that the sensor shows not_home.
Even when I changed the dashes.
Edit: nevermind, the only problem now is the DISCONNECTED part. Now it shows distance and what esp Im connected to.
Edit2: I have 4 meters in the settings file, but it will not connect if Im more then 1 meter away. Is there any tips for that?
Okay, glad we’ve got partial success.
Next, can you subscribe to the mqtt topic presence_nodes/#
and paste the results? It woultd show us the payloads for all the esp32s and their telemetry as well.
I’m currently working on a fix for distance calculations for generic BLE devices, as the default used in the code isn’t very accurate.
Thank you for your patience.
Here is some of the output:
presence_nodes/esp32_2/tele {"room":"Koket","ip":"192.168.1.x","hostname":"esp32_2","scan_dur":5,"wait_dur":5,"max_dist":4,"disc_ct":26,"rept_ct":3}
presence_nodes/Köket CONNECTED
presence_nodes/Koket CONNECTED
presence_nodes/Kallaren CONNECTED
presence_nodes/esp32_1/tele {"room":"Kallaren","ip":"192.168.1.x","hostname":"esp32_1","scan_dur":5,"wait_dur":5,"max_dist":4,"disc_ct":10,"rept_ct":2}
presence_nodes/Sovrummet CONNECTED
EDIT: I think I can see the problem myself. I’m changing the state_topic
to "presence_nodes/Sovrummet"
instead of "presence_nodes/esp32_1"
EDIT2: Yepp, that was it. Thank you for your help @ptrsnja!
Glad it’s working now! How are the distance calculations looking? I’ve found that it gets less accurate the further I get, and seems to grow exponentially. I’m currently working on a fix for that, but no idea how long until I’m ready to release a new version.
I experience the same as you. I had to increase “measured power” in the BeaconScope app to -72 instead of -59 to get some connection.
I will try different settings and update the thread if I get some better results.