esphome / issues

Issue Tracker for ESPHome
https://esphome.io/
290 stars 34 forks source link

Accessing web interface (with this specific config?) (Json creation?) makes esp go offline #5316

Open henrykuijpers opened 6 months ago

henrykuijpers commented 6 months ago

The problem

I'm running a Modbus readout on an ESP32 (wroom32 dev board), in combination with a MAX485 board (the one that has DI, RE, DE, RO).

Often see messages in the logs about operations taking a lot of time.

Which version of ESPHome has the issue?

2023.12.5

What type of installation are you using?

Docker

Which version of Home Assistant has the issue?

n/a

What platform are you using?

ESP32

Board

ESP32

Component causing the issue

wroom32 (nodemcu-32s)

Example YAML snippet

substitutions:
  name: modbus-esp
  friendly_name: Modbus

esphome:
  name: ${name}
  comment: ${friendly_name}
  platform: esp32
  board: nodemcu-32s

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password
  domain: !secret wifi_domain

  ap:
    ssid: $friendly_name Wifi
    password: !secret wifi_password

captive_portal:

logger:
  level: VERY_VERBOSE

api:

ota:

switch:
  - platform: restart
    name: ${friendly_name} Restart

web_server:
  port: 80

#serial port
uart:
  id: mod_uart
  tx_pin: 17
  rx_pin: 16
  baud_rate: 9600
  stop_bits: 1

modbus:
  flow_control_pin: 4
  send_wait_time: 500ms
  uart_id: mod_uart
  id: mod_bus

modbus_controller:
  - id: SDM120M
    modbus_id: mod_bus
    address: 1
    setup_priority: -10

sensor:
  # General
  - platform: modbus_controller
    modbus_controller_id: SDM120M
    name: ${friendly_name} AvgFreq
    register_type: read
    address: 0x0046
    value_type: FP32
    unit_of_measurement: Hz
    state_class: "measurement"
    accuracy_decimals: 3

  - platform: modbus_controller
    modbus_controller_id: SDM120M
    name: ${friendly_name} Total System Power
    register_type: read
    address: 0x0034
    value_type: FP32
    unit_of_measurement: W
    state_class: "measurement"
    device_class: "power"
    accuracy_decimals: 3

  - platform: modbus_controller
    modbus_controller_id: SDM120M
    name: ${friendly_name} Total Active Energy
    register_type: read
    address: 0x0156
    value_type: FP32
    unit_of_measurement: kWh
    state_class: "total_increasing"
    device_class: "energy"
    accuracy_decimals: 3

  - platform: modbus_controller
    modbus_controller_id: SDM120M
    name: ${friendly_name} Average Line to Neutral Voltage
    register_type: read
    address: 0x002A
    value_type: FP32
    unit_of_measurement: V
    state_class: "measurement"
    device_class: "voltage"
    accuracy_decimals: 3

  - platform: modbus_controller
    modbus_controller_id: SDM120M
    name: ${friendly_name} Average Line Current
    register_type: read
    address: 0x002E
    value_type: FP32
    device_class: "current"
    state_class: "measurement"
    unit_of_measurement: A
    accuracy_decimals: 3

  - platform: modbus_controller
    modbus_controller_id: SDM120M
    name: ${friendly_name} Sum Line Current
    register_type: read
    address: 0x0030
    value_type: FP32
    device_class: "current"
    state_class: "measurement"
    unit_of_measurement: A
    accuracy_decimals: 3

  - platform: modbus_controller
    modbus_controller_id: SDM120M
    name: ${friendly_name} Total System Power
    register_type: read
    address: 0x0034
    value_type: FP32
    unit_of_measurement: W
    device_class: "power"
    state_class: "measurement"
    accuracy_decimals: 3

  - platform: modbus_controller
    modbus_controller_id: SDM120M
    name: ${friendly_name} Total System VA
    register_type: read
    address: 0x0038
    value_type: FP32
    device_class: ""
    state_class: "measurement"
    unit_of_measurement: VA
    accuracy_decimals: 3

  - platform: modbus_controller
    modbus_controller_id: SDM120M
    name: ${friendly_name} Total System VAr
    register_type: read
    address: 0x003C
    value_type: FP32
    device_class: ""
    state_class: "measurement"
    unit_of_measurement: VAr
    accuracy_decimals: 3

  - platform: modbus_controller
    modbus_controller_id: SDM120M
    name: ${friendly_name} Total System Power Factor
    register_type: read
    address: 0x003E
    value_type: FP32
    device_class: "power_factor"
    state_class: "measurement"
    unit_of_measurement: ""
    accuracy_decimals: 3

  - platform: modbus_controller
    modbus_controller_id: SDM120M
    name: ${friendly_name} Import Active Energy
    register_type: read
    address: 0x0048
    value_type: FP32
    unit_of_measurement: kWh
    state_class: "total_increasing"
    device_class: "energy"
    accuracy_decimals: 3

  - platform: modbus_controller
    modbus_controller_id: SDM120M
    name: ${friendly_name} Export Active Energy
    register_type: read
    address: 0x004A
    value_type: FP32
    unit_of_measurement: kWh
    state_class: "total_increasing"
    device_class: "energy"
    accuracy_decimals: 3

  - platform: modbus_controller
    modbus_controller_id: SDM120M
    name: ${friendly_name} Neutral Current
    register_type: read
    address: 0x00E0
    value_type: FP32
    device_class: "current"
    state_class: "measurement"
    unit_of_measurement: A
    accuracy_decimals: 3

  - platform: modbus_controller
    modbus_controller_id: SDM120M
    name: ${friendly_name} Total Reactive Energy
    register_type: read
    address: 0x0158
    value_type: FP32
    unit_of_measurement: kVArh
    state_class: "total_increasing"
    device_class: "energy"
    accuracy_decimals: 3

  # Power
  - platform: modbus_controller
    modbus_controller_id: SDM120M
    name: ${friendly_name} Phase 1 Power
    register_type: read
    address: 0x000C
    value_type: FP32
    unit_of_measurement: W
    device_class: "power"
    state_class: "measurement"
    accuracy_decimals: 3

  - platform: modbus_controller
    modbus_controller_id: SDM120M
    name: ${friendly_name} Phase 2 Power
    register_type: read
    address: 0x000E
    value_type: FP32
    unit_of_measurement: W
    device_class: "power"
    state_class: "measurement"
    accuracy_decimals: 3

  - platform: modbus_controller
    modbus_controller_id: SDM120M
    name: ${friendly_name} Phase 3 Power
    register_type: read
    address: 0x0010
    value_type: FP32
    unit_of_measurement: W
    device_class: "power"
    state_class: "measurement"
    accuracy_decimals: 3

  # Volts
  - platform: modbus_controller
    modbus_controller_id: SDM120M
    name: ${friendly_name} Phase 1 Voltage
    register_type: read
    address: 0x0000
    value_type: FP32
    unit_of_measurement: V
    device_class: "voltage"
    state_class: "measurement"
    accuracy_decimals: 3

  - platform: modbus_controller
    modbus_controller_id: SDM120M
    name: ${friendly_name} Phase 2 Voltage
    register_type: read
    address: 0x0002
    value_type: FP32
    device_class: "voltage"
    state_class: "measurement"
    unit_of_measurement: V
    accuracy_decimals: 3

  - platform: modbus_controller
    modbus_controller_id: SDM120M
    name: ${friendly_name} Phase 3 Voltage
    register_type: read
    address: 0x0004
    value_type: FP32
    device_class: "voltage"
    state_class: "measurement"
    unit_of_measurement: V
    accuracy_decimals: 3

  # Current
  - platform: modbus_controller
    modbus_controller_id: SDM120M
    name: ${friendly_name} Phase 1 Current
    register_type: read
    address: 0x0006
    value_type: FP32
    device_class: "current"
    state_class: "measurement"
    unit_of_measurement: A
    accuracy_decimals: 3

  - platform: modbus_controller
    modbus_controller_id: SDM120M
    name: ${friendly_name} Phase 2 Current
    register_type: read
    address: 0x0008
    value_type: FP32
    device_class: "current"
    state_class: "measurement"
    unit_of_measurement: A
    accuracy_decimals: 3

  - platform: modbus_controller
    modbus_controller_id: SDM120M
    name: ${friendly_name} Phase 3 Current
    register_type: read
    address: 0x00A0
    value_type: FP32
    device_class: "current"
    state_class: "measurement"
    unit_of_measurement: A
    accuracy_decimals: 3

  # Apparent Power
  - platform: modbus_controller
    modbus_controller_id: SDM120M
    name: ${friendly_name} Phase 1 Apparent Power
    register_type: read
    address: 0x0012
    value_type: FP32
    device_class: ""
    state_class: "measurement"
    unit_of_measurement: VA
    accuracy_decimals: 3

  - platform: modbus_controller
    modbus_controller_id: SDM120M
    name: ${friendly_name} Phase 2 Apparent Power
    register_type: read
    address: 0x0014
    value_type: FP32
    device_class: ""
    state_class: "measurement"
    unit_of_measurement: VA
    accuracy_decimals: 3

  - platform: modbus_controller
    modbus_controller_id: SDM120M
    name: ${friendly_name} Phase 3 Apparent Power
    register_type: read
    address: 0x0016
    value_type: FP32
    device_class: ""
    state_class: "measurement"
    unit_of_measurement: VA
    accuracy_decimals: 3

  # Reactive Power
  - platform: modbus_controller
    modbus_controller_id: SDM120M
    name: ${friendly_name} Phase 1 Reactive Power
    register_type: read
    address: 0x0018
    value_type: FP32
    device_class: ""
    state_class: "measurement"
    unit_of_measurement: VAr
    accuracy_decimals: 3

  - platform: modbus_controller
    modbus_controller_id: SDM120M
    name: ${friendly_name} Phase 2 Reactive Power
    register_type: read
    address: 0x001A
    value_type: FP32
    device_class: ""
    state_class: "measurement"
    unit_of_measurement: VAr
    accuracy_decimals: 3

  - platform: modbus_controller
    modbus_controller_id: SDM120M
    name: ${friendly_name} Phase 3 Reactive Power
    register_type: read
    address: 0x001C
    value_type: FP32
    device_class: ""
    state_class: "measurement"
    unit_of_measurement: VAr
    accuracy_decimals: 3

  # Power Factor
  - platform: modbus_controller
    modbus_controller_id: SDM120M
    name: ${friendly_name} Phase 1 Power Factor
    register_type: read
    address: 0x001E
    value_type: FP32
    device_class: "power_factor"
    state_class: "measurement"
    unit_of_measurement: ""
    accuracy_decimals: 3

  - platform: modbus_controller
    modbus_controller_id: SDM120M
    name: ${friendly_name} Phase 2 Power Factor
    register_type: read
    address: 0x0020
    value_type: FP32
    device_class: "power_factor"
    state_class: "measurement"
    unit_of_measurement: ""
    accuracy_decimals: 3

  - platform: modbus_controller
    modbus_controller_id: SDM120M
    name: ${friendly_name} Phase 3 Power Factor
    register_type: read
    address: 0x0022
    value_type: FP32
    device_class: "power_factor"
    state_class: "measurement"
    unit_of_measurement: ""
    accuracy_decimals: 3

Anything in the logs that might be useful for us?

16:02:11 | [W] | [component:214] | Component modbus took a long time for an operation (0.05 s).

(The message is apparently a feature, and it's fine that it takes a bit of time to process everything.)

After a while it starts increasing to 0.10 s, 0.20 s, ... And then suddenly it goes offline. ESP32 is still turned on (LEDs still burning), but the web interface is gone and there is no way to interact with it.

Additional information

No response

henrykuijpers commented 6 months ago

I closed the web interface and everything seems to be fine now. Tomorrow I can test again with the web interface open.

Somehow, that seems to be related to the problem. It could be that it is too heavy to create all the json packages? (I'm not very much into the technical details of esphome to know for sure it has anything to do with it or not.)

ssieb commented 6 months ago

Why did you disable the serial logs? You could watch those to see what's happening when it's not responding.

henrykuijpers commented 6 months ago

Why did you disable the serial logs? You could watch those to see what's happening when it's not responding.

Where do you see the serial logs disabled? I had them disabled at first, to not interfere too much with other things (it was written in an article somewhere), but I believe serial logs are not disabled anymore?

ssieb commented 6 months ago

You modified the pasted config after I saw it. So you can watch the serial logs to see what's happening.

henrykuijpers commented 6 months ago

Ah! I didn't realise that, then you were pretty quick!

Yes, I know, I can indeed monitor the serial logs. They should be the same as the OTA logs, right? Maybe the logs continue through the serial port, while the networking goes offline? That would be good test. I'll try to test this soon.

The only thing I observed was that it just stops. From that moment on, the esp is offline.

A few pieces of logging that I could capture (through web):


Time
level
Tag
Message
06:13:45
[D]
[sensor:094]
'Modbus Neutral Current': Sending state 0.00000 A with 3 decimals of accuracy
06:13:45
[V]
[json:038]
Attempting to allocate 512 bytes for JSON serialization
06:13:45
[V]
[json:058]
Size after shrink 88 bytes
06:13:45
[VV
][api.service:140]
send_sensor_state_response: SensorStateResponse {
  key: 2993591581
  state: 0
  missing_state: NO
}
06:13:45
[W]
[component:214]
Component modbus_controller took a long time for an operation (0.07 s).
06:13:45
[W]
[component:214]
Component modbus_controller took a long time for an operation (0.07 s).
06:13:45
[W]
[component:215]
Components should block for at most 20-30ms.
06:13:45
[V]
[modbus_controller:047]
Sending next modbus command to device 1 register 0x156 count 4
06:13:45
[VV
][uart.arduino_esp32:180]
   Flushing...
06:13:46
[V]
[modbus:199]
Modbus write: 01.04.01.56.00.04.10.25 (8)
06:13:46
[V]
[modbus_controller:509]
Command sent 4 0x156 4
06:13:46
[V]
[modbus:042]
Modbus received Byte  1 (0X1)
06:13:46
[V]
[modbus:042]
Modbus received Byte  4 (0X4)
06:13:46
[V]
[modbus:042]
Modbus received Byte  8 (0X8)
06:13:46
[V]
[modbus:042]
Modbus received Byte  67 (0X43)
06:13:46
[V]
[modbus:042]
Modbus received Byte  100 (0X64)
06:13:46
[V]
[modbus:042]
Modbus received Byte  215 (0Xd7)
06:13:46
[V]
[modbus:042]
Modbus received Byte  76 (0X4c)
06:13:46
[V]
[modbus:042]
Modbus received Byte  67 (0X43)
06:13:46
[V]
[modbus:042]
Modbus received Byte  28 (0X1c)
06:13:46
[V]
[modbus:042]
Modbus received Byte  24 (0X18)
06:13:46
[V]
[modbus:042]
Modbus received Byte  147 (0X93)
06:13:46
[V]
[modbus:042]
Modbus received Byte  216 (0Xd8)
06:13:46
[V]
[modbus:042]
Modbus received Byte  40 (0X28)
06:13:46
[V]
[modbus_controller:078]
Modbus response queued
06:13:46
[W]
[component:214]
Component modbus took a long time for an operation (0.07 s).
06:13:46
[W]
[component:215]
Components should block for at most 20-30ms.
06:13:46
[V]
[modbus_controller:086]
Process modbus response for address 0x156 size: 8
06:13:46
[V]
[modbus_controller:121]
data for register address : 0x156 :
06:13:46
[D]
[modbus_controller.sensor:025]
Sensor new state: 228.84
06:13:46
[V]
[sensor:043]
'Modbus Total Active Energy': Received new state 228.841003
06:13:46
[V]
[sensor:043]
'Modbus Total Active Energy': Received new state 228.841003
06:13:46
[D]
[sensor:094]
'Modbus Total Active Energy': Sending state 228.84100 kWh with 3 decimals of accuracy
06:13:46
[V]
[json:038]
Attempting to allocate 512 bytes for JSON serialization
06:13:46
[V]
[json:058]
Size after shrink 96 bytes
06:13:46
[VV
][api.service:140]
send_sensor_state_response: SensorStateResponse {
  key: 759117560
  state: 228.841
  missing_state: NO
}
06:13:46
[D]
[modbus_controller.sensor:025]
Sensor new state: 156.10
06:13:46
[D]
[modbus_controller.sensor:025]
Sensor new state: 156.10
06:13:46
[V]
[sensor:043]
'Modbus Total Reactive Energy': Received new state 156.095993
06:13:46
[V]
[sensor:043]
'Modbus Total Reactive Energy': Received new state 156.095993
06:13:46
[D]
[sensor:094]
'Modbus Total Reactive Energy': Sending state 156.09599 kVArh with 3 decimals of accuracy
06:13:46
[V]
[json:038]
Attempting to allocate 512 bytes for JSON serialization
06:13:46
[V]
[json:058]
Size after shrink 100 bytes
06:13:46
[V]
[json:058]
Size after shrink 100 bytes
06:13:46
[VV
][api.service:140]
send_sensor_state_response: SensorStateResponse {
  key: 3439512477
  state: 156.096
  missing_state: NO
}
06:13:46
[W]
[component:214]
Component modbus_controller took a long time for an operation (0.13 s).
06:13:46
[W]
[component:215]
Components should block for at most 20-30ms.
06:13:48
[VV
][scheduler:226]
Running interval '' with interval=10000 last_execution=29024 (now=39032)
06:13:58
[VV
][scheduler:226]
Running interval '' with interval=60000 last_execution=4294955911 (now=48616)
06:13:58
[VV
][scheduler:226]
Running interval '' with interval=10000 last_execution=39024 (now=49025)
ssieb commented 6 months ago

The serial logs work even if wifi is not connected. What I'm looking for is what is happening when it stops working.

github-actions[bot] commented 2 months ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

henrykuijpers commented 2 months ago

@ssieb Do you have a suggestion of what kind of configuration to use, to be able to analyze this further?

ssieb commented 2 months ago

What I already suggested. You need to watch the serial logs at the point (or after) it goes offline.