alengwenus / esphome_components

External components for ESPHome
GNU General Public License v3.0
29 stars 9 forks source link

Wireless upgrade is broken when UART receives data #2

Closed Skeletitor closed 2 years ago

Skeletitor commented 2 years ago

Device: d1_mini

INFO Uploading /data/esp-gridmeter/.pioenvs/esp-gridmeter/firmware.bin (419712 bytes)
INFO Compressed to 291714 bytes
Uploading: [=========================                                   ] 41% 
ERROR Error sending data: [Errno 104] Connection reset by peer

Update works if you disconnect/lift up the IR reading pobe. I guess the UART communication breaks the OTA update.

Maybee there is a possibility to use an automation to disable the UART communication when entering the 'on_begin' method of OTA Update component. I'm very new to esphome, but this is my first thought for a workarround

alengwenus commented 2 years ago

Unfortunately I cannot reproduce this behavior with my setup. 🤔 OTA works as expected even if data is read from UART. Usually all components are deactivated on OTA. So an additional automation shouldn't be necessary.

Could you post your configuration, please?

Skeletitor commented 2 years ago

Hi, I apologize for the delay. My daughter brought some kind of epidemic from kindergarten and I am lying down. Electricity meter: eHZ

ESP Config:

esphome:
  name: esp-gridmeter
  platform: ESP8266
  board: d1_mini

ota:
  password: "XXX"

# Enable Home Assistant API
api:

wifi:
  ssid: "XX XX"
  password: "XXX"

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "Esp-Gridmeter Fallback Hotspot"
    password: "XXX"

captive_portal:

external_components:
  - source:
      type: git
      url: https://github.com/alengwenus/esphome_components
    components: [ sml ]

# Enable logging
logger:
  hardware_uart: UART1
  level: DEBUG

uart:
  id: uart_bus
  tx_pin: D4
  rx_pin: D5
  baud_rate: 9600
  data_bits: 8
  parity: NONE
  stop_bits: 1

sml:
  id: mysml
  uart_id: uart_bus

sensor:
  - platform: wifi_signal
    name: "SML WiFi Signal Sensor"
    update_interval: 10s

  - platform: sml
    name: "Total energy 1"
    sml_id: mysml
    obis_code: "1-0:1.8.1"
    unit_of_measurement: kWh
    accuracy_decimals: 1
    device_class: energy
    state_class: total_increasing
    filters:
      - multiply: 0.0001

  - platform: sml
    name: "Active power"
    sml_id: mysml
    obis_code: "1-0:1.7.1"
    unit_of_measurement: W
    device_class: power
    filters:
      - multiply: 0.1
    accuracy_decimals: 1

text_sensor:
  - platform: sml
    name: "Manufacturer"
    sml_id: mysml
    obis_code: "129-129:199.130.3"
    format: text
alengwenus commented 2 years ago

Thanks @Skeletitor ! You are using a software UART on pins 4 and 5. So it might be that you face an already reported isssue (https://github.com/esphome/issues/issues/2629). If that‘s the case this is not a problem with the SML component itself. A solution would be to use the hardware UART on the TX/RX pins (GPIO1/GPIO3) until the issue gets solved. Maybe you could test this?

Skeletitor commented 2 years ago

Hi Thx, hope I understood that.

---- Config changed to:

uart:
  id: uart_bus
  #tx_pin: GPIO2
  #tx_pin: D4
  rx_pin: GPIO14
  #rx_pin: D5
  baud_rate: 9600
  data_bits: 8
  parity: NONE
  stop_bits: 1

Upgraded without a connected reading probe. The second OTA ave the same result:

Flash: [====      ]  39.8% (used 415528 bytes from 1044464 bytes)
========================= [SUCCESS] Took 9.57 seconds =========================
INFO Successfully compiled program.
INFO Resolving IP address of esp-gridmeter.local
INFO  -> 192.168.10.228
INFO Uploading /data/esp-gridmeter/.pioenvs/esp-gridmeter/firmware.bin (419680 bytes)
INFO Compressed to 291660 bytes
Uploading: [=================                                           ] 28% 
ERROR Error sending data: [Errno 104] Connection reset by peer

I only use a reading diode connected to PIN5 (GPIO14). Would it make sense to change the PIN?

Skeletitor commented 2 years ago

ok.. Sorry... You already told me to use GPIO1 (TX) and/or GPIO3 (RX) PIN... I'll check that

Skeletitor commented 2 years ago

Hi, I guess it's the same issue (https://github.com/esphome/issues/issues/2629) Using hardware UART (RX/TX pins) fixes the ota ability