Open Goz3rr opened 2 years ago
Hey there @esphome/core, mind taking a look at this issue as it has been labeled with an integration (mdns
) you are listed as a code owner for? Thanks!
(message by CodeOwnersMention)
Hi! Similiar problem here.
Running: ESPHOME Stable: 2021.12.1 Device: Sonoff Dual R3 v1.6
As soon as I enable esp32_ble_tracker I get a some strange side effects: 1.) Disconnect from API randomly, device gets unavailable in HA 2.) When trying to upload a new fimware, it gets aborted between 10 and 80 Percent, with connection broken - timeout 3.) WebServer upload is luckily working
Now I am heavily using the current sensor for my current based covers. Not sure if the board is just overloaded with BLE tracking enabled.
As soon as I disable the BLE stuff, the ESP32 is fine again.
My config:
#ESP32 current based cover (DUAL R3 v1.6 Sonoff)
#'coverofficesmall' - Open position reached. Took 11.9s.
#'coverofficesmall' - Close position reached. Took 11.5s.
substitutions:
device_name: coverofficesmall
open_duration: 11.9sec
close_duration: 11.5sec
max_duration: 12.5sec
esphome:
name: ${device_name}
esp32:
board: esp32dev
framework:
type: arduino
wifi:
reboot_timeout: 0s
domain: ".iot.heisig.one"
networks:
- ssid: !secret wifi_ssid
- password: !secret wifi_pass
- ssid: 'rescue'
- password: '12345678'
# Enable logging
logger:
# Enable Web server
web_server:
port: 80
# Enable Home Assistant API/OTA
api:
password: !secret api_pass2
reboot_timeout: 0s
ota:
safe_mode: true
password: !secret ota_pass
# Enable Bluetooth scanning for this ESP32
#esp32_ble_tracker:
# Sync time with Home Assistant
time:
- platform: homeassistant
id: homeassistant_time
# cse7761 uart port
uart:
tx_pin: GPIO25
rx_pin: GPIO26
baud_rate: 38400
parity: EVEN
text_sensor:
- platform: version
name: "${device_name} Version"
icon: mdi:information-outline
- platform: wifi_info
ip_address:
name: "${device_name} IP"
icon: mdi:ip-network-outline
ssid:
name: "${device_name} SSID"
icon: mdi:signal-distance-variant
bssid:
name: "${device_name} BSSID"
icon: mdi:signal-distance-variant
sensor:
# Uptime sensor
- platform: uptime
name: "${device_name} Uptime"
unit_of_measurement: days
update_interval: 4h
filters:
- multiply: 0.000011574
# WiFi Signal sensor
- platform: wifi_signal
name: "${device_name} WiFi"
update_interval: 300s
icon: mdi:signal-variant
#Xiaomi Mijia Temp and Humidity Sensor Office
# - platform: xiaomi_lywsdcgq
# mac_address: 58:2D:34:3A:EB:4E
# temperature:
# name: "Raumtemperatur"
# humidity:
# name: "Luftfeuchtigkeit"
# battery_level:
# name: "Batteriestand"
#Power Monitor Dual R3
- platform: cse7761
voltage:
name: "${device_name} Volt"
internal: true
filters:
- throttle: 300s
current_1:
name: "${device_name} Ampere Öffnen"
id: open_current
internal: true
filters:
- filter_out: 0.0
current_2:
name: "${device_name} Ampere_Schließen"
id: close_current
internal: true
filters:
- filter_out: 0.0
active_power_1:
name: "${device_name} Watt Öffnen"
internal: true
filters:
- filter_out: 0.0
active_power_2:
name: "${device_name} Watt Schließen"
internal: true
filters:
- filter_out: 0.0
update_interval: 0.6s
binary_sensor:
#BuildIn-Button - Mainly for Testing
- platform: gpio
pin:
number: GPIO0
mode: INPUT_PULLUP
inverted: True
name: "${device_name} Knöpfchen#1"
id: button
internal: True
on_click:
then:
- switch.toggle: open_relay
on_double_click:
then:
- switch.toggle: close_relay
# use this config for momentary switches
- platform: gpio
pin:
number: GPIO32
mode: INPUT_PULLUP
inverted: true
name: "${device_name} Taster#1"
id: switch1
internal: True
on_press:
then:
- lambda: |
if (id(rollers).current_operation == COVER_OPERATION_IDLE) {
// Cover is idle, check current state and open cover.
auto call = id(rollers).make_call();
call.set_command_open();
call.perform();
}
else {
// Cover is opening/closing. Stop it.
auto call = id(rollers).make_call();
call.set_command_stop();
call.perform();
}
- platform: gpio
pin:
number: GPIO33
mode: INPUT_PULLUP
inverted: true
name: "${device_name} Taster#2"
id: switch2
internal: True
on_press:
then:
- lambda: |
if (id(rollers).current_operation == COVER_OPERATION_IDLE) {
// Cover is idle, check current state and close cover.
auto call = id(rollers).make_call();
call.set_command_close();
call.perform();
}
else {
// Cover is opening/closing. Stop it.
auto call = id(rollers).make_call();
call.set_command_stop();
call.perform();
}
#Reset Device
on_multi_click:
- timing:
#six times short
- ON for at most 1.5s
- OFF for at most 1.5s
- ON for at most 1.5s
- OFF for at most 1.5s
- ON for at most 1.5s
- OFF for at most 1.5s
- ON for at most 1.5s
- OFF for at most 1.5s
- ON for at most 1.5s
- OFF for at least 0s
then:
- switch.toggle: reset
status_led:
pin:
number: GPIO13
inverted: true
switch:
# Switch to restart the shutter
- platform: restart
id: reset
name: "${device_name} Restart"
- platform: gpio
id: open_relay
pin:
number: GPIO27
name: ${device_name} Relais Öffnen"
internal: True
restore_mode: RESTORE_DEFAULT_OFF
interlock: &interlock_group [open_relay, close_relay]
interlock_wait_time: 250ms
- platform: gpio
id: close_relay
pin:
number: GPIO14
name: ${device_name} Relais Schließen"
internal: True
restore_mode: RESTORE_DEFAULT_OFF
interlock: *interlock_group
interlock_wait_time: 250ms
cover:
- platform: current_based
name: ${device_name}
id: rollers
max_duration: ${max_duration}
open_sensor: open_current
open_moving_current_threshold: 0.45
open_duration: ${open_duration}
open_action:
- switch.turn_on: open_relay
close_sensor: close_current
close_moving_current_threshold: 0.45
close_duration: ${close_duration}
close_action:
- switch.turn_on: close_relay
stop_action:
- switch.turn_off: close_relay
- switch.turn_off: open_relay
obstacle_rollback: 30%
start_sensing_delay: 1s
malfunction_detection: true
malfunction_action:
then:
- logger.log: "Malfunction detected. Relay welded."
ESP32 shares for BLE and WiFi the same antenna, meaning that WiFi and BLE cannot use the antenna at the same time. This of course has impact on WiFi and/or BLE usage since the access to the antenna has to be coordinated. The BLE and WiFi controllers in the ESP32 firmware try their best to make this work seamless but in reality there are some issues with this approach.
Not that this helps with your issue, but maybe the devs take a look into that direction as a cause of problems with WiFi and BLE.
I'm seeing the same problems: with BLE enabled esp32 does crash pretty often if used with Web.
For me it was pretty easy and constant problem when:
esp32_ble_tracker
enabled/metrics
prometheus metrics by discovering all devices over mDNSThe stack trace shows problem with parsing lines in AsyncWebServer
. I would assume that this server is not thread-safe which causes issues when using multiple cores.
Hi! Similiar problem here.
Running: ESPHOME Stable: 2021.12.1 Device: Sonoff Dual R3 v1.6
As soon as I enable esp32_ble_tracker I get a some strange side effects: 1.) Disconnect from API randomly, device gets unavailable in HA 2.) When trying to upload a new fimware, it gets aborted between 10 and 80 Percent, with connection broken - timeout 3.) WebServer upload is luckily working
Now I am heavily using the current sensor for my current based covers. Not sure if the board is just overloaded with BLE tracking enabled.
As soon as I disable the BLE stuff, the ESP32 is fine again.
My config:
#ESP32 current based cover (DUAL R3 v1.6 Sonoff) #'coverofficesmall' - Open position reached. Took 11.9s. #'coverofficesmall' - Close position reached. Took 11.5s. substitutions: device_name: coverofficesmall open_duration: 11.9sec close_duration: 11.5sec max_duration: 12.5sec esphome: name: ${device_name} esp32: board: esp32dev framework: type: arduino wifi: reboot_timeout: 0s domain: ".iot.heisig.one" networks: - ssid: !secret wifi_ssid - password: !secret wifi_pass - ssid: 'rescue' - password: '12345678' # Enable logging logger: # Enable Web server web_server: port: 80 # Enable Home Assistant API/OTA api: password: !secret api_pass2 reboot_timeout: 0s ota: safe_mode: true password: !secret ota_pass # Enable Bluetooth scanning for this ESP32 #esp32_ble_tracker: # Sync time with Home Assistant time: - platform: homeassistant id: homeassistant_time # cse7761 uart port uart: tx_pin: GPIO25 rx_pin: GPIO26 baud_rate: 38400 parity: EVEN text_sensor: - platform: version name: "${device_name} Version" icon: mdi:information-outline - platform: wifi_info ip_address: name: "${device_name} IP" icon: mdi:ip-network-outline ssid: name: "${device_name} SSID" icon: mdi:signal-distance-variant bssid: name: "${device_name} BSSID" icon: mdi:signal-distance-variant sensor: # Uptime sensor - platform: uptime name: "${device_name} Uptime" unit_of_measurement: days update_interval: 4h filters: - multiply: 0.000011574 # WiFi Signal sensor - platform: wifi_signal name: "${device_name} WiFi" update_interval: 300s icon: mdi:signal-variant #Xiaomi Mijia Temp and Humidity Sensor Office # - platform: xiaomi_lywsdcgq # mac_address: 58:2D:34:3A:EB:4E # temperature: # name: "Raumtemperatur" # humidity: # name: "Luftfeuchtigkeit" # battery_level: # name: "Batteriestand" #Power Monitor Dual R3 - platform: cse7761 voltage: name: "${device_name} Volt" internal: true filters: - throttle: 300s current_1: name: "${device_name} Ampere Öffnen" id: open_current internal: true filters: - filter_out: 0.0 current_2: name: "${device_name} Ampere_Schließen" id: close_current internal: true filters: - filter_out: 0.0 active_power_1: name: "${device_name} Watt Öffnen" internal: true filters: - filter_out: 0.0 active_power_2: name: "${device_name} Watt Schließen" internal: true filters: - filter_out: 0.0 update_interval: 0.6s binary_sensor: #BuildIn-Button - Mainly for Testing - platform: gpio pin: number: GPIO0 mode: INPUT_PULLUP inverted: True name: "${device_name} Knöpfchen#1" id: button internal: True on_click: then: - switch.toggle: open_relay on_double_click: then: - switch.toggle: close_relay # use this config for momentary switches - platform: gpio pin: number: GPIO32 mode: INPUT_PULLUP inverted: true name: "${device_name} Taster#1" id: switch1 internal: True on_press: then: - lambda: | if (id(rollers).current_operation == COVER_OPERATION_IDLE) { // Cover is idle, check current state and open cover. auto call = id(rollers).make_call(); call.set_command_open(); call.perform(); } else { // Cover is opening/closing. Stop it. auto call = id(rollers).make_call(); call.set_command_stop(); call.perform(); } - platform: gpio pin: number: GPIO33 mode: INPUT_PULLUP inverted: true name: "${device_name} Taster#2" id: switch2 internal: True on_press: then: - lambda: | if (id(rollers).current_operation == COVER_OPERATION_IDLE) { // Cover is idle, check current state and close cover. auto call = id(rollers).make_call(); call.set_command_close(); call.perform(); } else { // Cover is opening/closing. Stop it. auto call = id(rollers).make_call(); call.set_command_stop(); call.perform(); } #Reset Device on_multi_click: - timing: #six times short - ON for at most 1.5s - OFF for at most 1.5s - ON for at most 1.5s - OFF for at most 1.5s - ON for at most 1.5s - OFF for at most 1.5s - ON for at most 1.5s - OFF for at most 1.5s - ON for at most 1.5s - OFF for at least 0s then: - switch.toggle: reset status_led: pin: number: GPIO13 inverted: true switch: # Switch to restart the shutter - platform: restart id: reset name: "${device_name} Restart" - platform: gpio id: open_relay pin: number: GPIO27 name: ${device_name} Relais Öffnen" internal: True restore_mode: RESTORE_DEFAULT_OFF interlock: &interlock_group [open_relay, close_relay] interlock_wait_time: 250ms - platform: gpio id: close_relay pin: number: GPIO14 name: ${device_name} Relais Schließen" internal: True restore_mode: RESTORE_DEFAULT_OFF interlock: *interlock_group interlock_wait_time: 250ms cover: - platform: current_based name: ${device_name} id: rollers max_duration: ${max_duration} open_sensor: open_current open_moving_current_threshold: 0.45 open_duration: ${open_duration} open_action: - switch.turn_on: open_relay close_sensor: close_current close_moving_current_threshold: 0.45 close_duration: ${close_duration} close_action: - switch.turn_on: close_relay stop_action: - switch.turn_off: close_relay - switch.turn_off: open_relay obstacle_rollback: 30% start_sensing_delay: 1s malfunction_detection: true malfunction_action: then: - logger.log: "Malfunction detected. Relay welded."
Similar issue here happening after update to version 2022.1.0 (happened the same with 2021.12.x). Unfortunately I don't remember anymore what was the working version I had before, otherwise I would just downgrade...
For me it is working fine, since I disabled the web server. No random restart since 7 days now.
Still with Version ESPHOME Stable: 2021.12.1
I start to think that the problem here is extensive memory (and flash, less likely) usage of BT and BLE stack. There's a very little memory left that results in a lot of fragmentation and random failures in memory allocation.
I think that if we would maybe use https://github.com/h2zero/NimBLE-Arduino for BLE tracking as an alternative, this very likely would solve this issue.
The problem
After enabling
esp32_ble_tracker
in the config, the device will no longer be reachable via the mDNS hostname (breaking the log and OTA). If I manually set a DNS entry for the correct hostname and IP, both will start working again, however the log will lose connection exactly every 3 minutes and then reconnect after a few seconds. In addition to this, the device itself logs losing connection to Home Assistant at seemingly random times:[W][api.connection:080]: Home Assistant 2021.11.1 (192.168.0.10): Connection reset
Rarely I also see:[W][wifi_esp32:495]: Event: Disconnected ssid='[my ssid]' bssid=xx:xx:xx:8A:6B:7A reason='Not Authenticated'
This is quite annoying because after it reconnects, Home Assistant will record a new value even the actual value hasn't changed for hours/days.Which version of ESPHome has the issue?
2021.10.3, 2021.9.3 and 1.19.4 from my tests, so I assume everything in between as well.
What type of installation are you using?
Docker
Which version of Home Assistant has the issue?
2021.11.1
What platform are you using?
ESP32
Board
nodemcu
Component causing the issue
esp32_ble_tracker
Example YAML snippet
Anything in the logs that might be useful for us?
Log from ESP32 when not working, but I don't see anything weird:
Additional information
When![image](https://user-images.githubusercontent.com/761433/140795074-36bc3c93-2bc1-4735-aa78-b54bc536c163.png)
esp32_ble_tracker
is enabled, these are all the mDNS messages I see after resetting the device:When it is disabled, the device seems to send the same packets on reset but also sends periodic packets now (repeating forever every ~16 seconds):![image](https://user-images.githubusercontent.com/761433/140795187-edb1ebd7-77d5-4e0f-bf3f-7a983566583e.png)
Combined with the wifi issues, could it be something timer related that is not being executed?