ESPHome ESP32 + custom Bluetooth device disconnect interrupts WiFi

Tags: #<Tag:0x00007f326dc2e470>

I’m messing around with ESPHome on an ESP32 using the bluetooth functionality. I’m using some code written by another member of the community (@wettermann32) which I have uploaded to this location: https://github.com/spikeygg/esphome_radoneye_rd200/blob/fe7284d05b19f84446f0bcfb21a45b67d4846dff/radoneye_rd200_sensor.h.

I’ve noticed something strange with this implementation. When I cannot connect to the bluetooth device (or it gets disconnected), the ESP32 device also disconnects from WiFi. This makes it impossible to remotely flash (or even manage) the device if something happens to the Bluetooth device I’m trying to connect to.

I’ve flashed the device using USB and then pulled up both the WiFi log and the USB log so I can see them in parallel (see below). I want to make this solution more robust so that it stays connected to WiFi regardless of the Bluetooth connection state. Anyone know how to make that possible or is this just a bug or something with the ESP32?

Looking at the logs below, you can see that the USB one shows a 30 second gap from the Created client to the Connect Failed!!! messages, reviewing the WiFi log much of that is dropped until the update - time XXX because the device disconnects during that time for some reason and ESPHome tries to reconnect.

USB log:

[11:26:24][D][custom:057]: update - time 789
[11:26:25][D][custo[D][custom:046]:  - setup connect to mac ff:ff:ff:ff:ff:ff
[11:26:25][D][custom:048]:  - setup- Created client
[11:26:55][D][custom:052]:  - setup- Connect Failed!!!
[11:26:55][D][custom:121]: Not connected to sensor
[11:26:55][D][api:067]: Disconnecting 192.168.1.1
[11:26:55][D][api:067]: Disconnecting 192.168.1.1
[11:26:55][D][api:067]: Disconnecting 192.168.1.1
[11:26:55][D][api:067]: Disconnecting ESPHome v1.15.2 (192.168.1.1)
[11:26:55][D][api.connection:604]: Client 'ESPHome v1.15.2 (192.168.1.1)' connected successfully!
[11:27:24][D][custom:057]: update - time 849
[11:27:25][D][c\xf5[D][custom:046]:  - setup connect to mac ff:ff:ff:ff:ff:ff
[11:27:25][D][custom:048]:  - setup- Created client
[11:27:55][D][custom:052]:  - setup- Connect Failed!!!
[11:27:55][D][custom:121]: Not connected to sensor
[11:27:55][D][api:067]: Disconnecting 192.168.1.1
[11:27:55][D][api:067]: Disconnecting 192.168.1.1
[11:27:55][D][api:067]: Disconnecting 192.168.1.1
[11:27:55][D][api:067]: Disconnecting ESPHome v1.15.2 (192.168.1.1)
[11:27:55][D][api.connection:604]: Client 'ESPHome v1.15.2 (192.168.1.1)' connected successfully!
[11:28:24][D][custom:057]: update - time 909
[11:28:25][D][custom:046]:  - setup connect to mac ff:ff:ff:ff:ff:ff
[11:28:25][D][custom:048]:  - setup- Created client
[11:28:55][D][custom:052]:  - setup- Connect Failed!!!
[11:28:55][D][custom:121]: Not connected to sensor
[11:28:55][D][api:067]: Disconnecting 192.168.1.1
[11:28:55][D][api:067]: Disconnecting 192.168.1.1
[11:28:55][D][api:067]: Disconnecting 192.168.1.1
[11:28:55][D][api:067]: Disconnecting ESPHome v1.15.2 (192.168.1.1)
[11:28:55][D][api.connection:604]: Client 'ESPHome v1.15.2 (192.168.1.1)' connected successfully!

WiFi log:

[11:25:24][D][custom:057]: update - time 729
[11:25:24][D][custom:041]: setup start
[11:25:25][D][custom:046]:  - setup connect to mac ff:ff:ff:ff:ff:ff
[11:25:25][D][custom:048]:  - setup- Created client
WARNING Disconnected from API: Timeout while waiting for message response!
INFO Connecting to radon_device.local:6053 (192.168.1.105)
WARNING Couldn't connect to API (Timeout while waiting for message response!). Trying to reconnect in 1 seconds
INFO Connecting to radon_device.local:6053 (192.168.1.105)
WARNING Couldn't connect to API (Timeout while waiting for message response!). Trying to reconnect in 1 seconds
INFO Connecting to radon_device.local:6053 (192.168.1.105)
WARNING Couldn't connect to API (Timeout while waiting for message response!). Trying to reconnect in 2 seconds
INFO Connecting to radon_device.local:6053 (192.168.1.105)
INFO Successfully connected to radon_device.local
[11:26:24][D][custom:057]: update - time 789
[11:26:24][D][custom:041]: setup start
[11:26:25][D][custom:046]:  - setup connect to mac ff:ff:ff:ff:ff:ff
[11:26:25][D][custom:048]:  - setup- Created client
WARNING Disconnected from API: Timeout while waiting for message response!
INFO Connecting to radon_device.local:6053 (192.168.1.105)
WARNING Couldn't connect to API (Timeout while waiting for message response!). Trying to reconnect in 1 seconds
INFO Connecting to radon_device.local:6053 (192.168.1.105)
WARNING Couldn't connect to API (Timeout while waiting for message response!). Trying to reconnect in 1 seconds
INFO Connecting to radon_device.local:6053 (192.168.1.105)
WARNING Couldn't connect to API (Timeout while waiting for message response!). Trying to reconnect in 2 seconds
INFO Connecting to radon_device.local:6053 (192.168.1.105)
INFO Successfully connected to radon_device.local
[11:27:24][D][custom:057]: update - time 849
[11:27:24][D][custom:041]: setup start
[11:27:25][D][custom:046]:  - setup connect to mac ff:ff:ff:ff:ff:ff
[11:27:25][D][custom:048]:  - setup- Created client
WARNING Disconnected from API: Timeout while waiting for message response!
INFO Connecting to radon_device.local:6053 (192.168.1.105)
WARNING Couldn't connect to API (Timeout while waiting for message response!). Trying to reconnect in 1 seconds
INFO Connecting to radon_device.local:6053 (192.168.1.105)
WARNING Couldn't connect to API (Timeout while waiting for message response!). Trying to reconnect in 1 seconds
INFO Connecting to radon_device.local:6053 (192.168.1.105)
WARNING Couldn't connect to API (Timeout while waiting for message response!). Trying to reconnect in 2 seconds
INFO Connecting to radon_device.local:6053 (192.168.1.105)
INFO Successfully connected to radon_device.local
[11:28:24][D][custom:057]: update - time 909
[11:28:24][D][custom:041]: setup start
[11:28:25][D][custom:046]:  - setup connect to mac ff:ff:ff:ff:ff:ff
[11:28:25][D][custom:048]:  - setup- Created client
WARNING Disconnected from API: Timeout while waiting for message response!
INFO Connecting to radon_device.local:6053 (192.168.1.105)

I think this is the thread you seek: RadonEye BLE Interface

Haha, that’s the thread I posted to previously. :stuck_out_tongue:

just trying to debug a specific aspect of ESPHome and Bluetooth on ESP32 with this thread.

Sorry, my mistake, I see that now.