esphome / issues

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

Modbus CRC Check failed! C022!=00 PZEM004T-V3 #4746

Closed jonathanpalomino closed 11 months ago

jonathanpalomino commented 11 months ago

The problem

He conectado a los pines RX0 y TX0 sus correspondientes al PZEM-004T V3 (TX y RX) de 100A respectivamente. Sin embargo recibo los siguientes mensajes de error:

22:49:17 | [V] | [modbus:199] | Modbus write: 01.04.00.00.00.0A.70.0D (8) -- | -- | -- | -- 22:49:17 | [D] | [uart_debug:158] | >>> "p\r" 22:49:17 | [V] | [modbus:042] | Modbus received Byte 1 (0X1) 22:49:17 | [V] | [modbus:042] | Modbus received Byte 4 (0X4) 22:49:17 | [V] | [modbus:042] | Modbus received Byte 0 (0X0) 22:49:17 | [V] | [modbus:042] | Modbus received Byte 0 (0X0) 22:49:17 | [V] | [modbus:042] | Modbus received Byte 0 (0X0) 22:49:17 | [V] | [modbus:042] | Modbus received Byte 0 (0X0) 22:49:17 | [W] | [modbus:108] | Modbus CRC Check failed! C022!=00 22:49:17 | [W] | [modbus:108] | Modbus CRC Check failed! C022!=00 22:49:17 | [D] | [uart_debug:158] | <<< "\x01\x04\x00\x00\x00\n" 22:49:17 | [V] | [modbus:042] | Modbus received Byte 10 (0Xa) 22:49:17 | [V] | [modbus:042] | Modbus received Byte 112 (0X70) 22:49:17 | [V] | [modbus:042] | Modbus received Byte 13 (0Xd) 22:49:17 | [V] | [modbus:042] | Modbus received Byte 13 (0Xd)

Which version of ESPHome has the issue?

2023.7.0

What type of installation are you using?

Home Assistant Add-on

Which version of Home Assistant has the issue?

2023.7.0

What platform are you using?

ESP32

Board

ESP32-WROOM32

Component causing the issue

pzemac

Example YAML snippet

esphome:
  name: esphome-web-a70328
  friendly_name: ESPHome Web a70328

esp32:
  board: esp32dev
  framework:
    type: arduino

# Enable logging
logger:
  level: VERY_VERBOSE
  baud_rate: 0

# Enable Home Assistant API
api:
  encryption:
    key: "g4j73gUOGwzTmfZ7Dm1fa4KBx2VhvDfP6xwQiAnJLkk="

# Servidor Web para poder consultar información por web
# https://esphome.io/components/web_server.html
web_server:

ota:

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

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "Esphome-Web-A70328"
    password: "RtO60blWZypX"

captive_portal:

# Indicamos los pines donde hemos conectado TX y RX del dispositivo, teniendo en cuenta que siempre han de ser invertidos TX->RX, RX->TX
uart:
  id: energomonitor_uart
  rx_pin: GPIO1
  tx_pin: GPIO3
  baud_rate: 9600
  stop_bits: 2
  data_bits: 8
  parity: NONE
  debug:
    direction: BOTH
    dummy_receiver: false
    after:
      delimiter: "\n"
    sequence:
      - lambda: UARTDebug::log_string(direction, bytes);

sensor:
  # Usaremos pzemac o pzem004t dependiendo de si estamos usando un PZEM-004T V3 o V1
  - platform: pzemac
    address: 1
    current:
      name: "Current"
      accuracy_decimals: 2
    voltage:
      name: "Voltage"
      accuracy_decimals: 2
    energy:
      name: "Energy"
      unit_of_measurement: Wh
      accuracy_decimals: 1
      id: p_energy
    power:
      name: "Power"
      unit_of_measurement: W
      accuracy_decimals: 2
      id: p_power
    frequency:
      name: "Frequency"
      unit_of_measurement: Hz
      accuracy_decimals: 2
    power_factor:
      name: "Power Factor"
      accuracy_decimals: 2
      id: p_power_factor
    update_interval: 20s

Anything in the logs that might be useful for us?

He hecho la misma prueba con un ESP-WROOM-32 de 30 pines sin éxito

Additional information

He hecho la prueba con 3 PZEM-004T V3 de 100A sin éxito. Se hizo alimentación del modulo PZEM-004T V3 con transformador HI-LINK de 220V a 5v

ssieb commented 11 months ago

You appear to have something wired wrong because it looks like you're getting loopback. Also, remove all the parameters from under the uart debug:. The default settings are better for this.

jonathanpalomino commented 11 months ago

Parece que tienes algo mal conectado porque parece que estás recibiendo un bucle invertido. Además, elimine todos los parámetros de debajo del uart . La configuración predeterminada es mejor para esto.debug:

Hice lo mencionado pero ahora devuelve lo siguiente si pongo RX del PZEM con el RX0 del esp32 [23:58:23][VV][scheduler:226]: Running interval '' with interval=10000 last_execution=443162 (now=453163) [23:58:33][VV][scheduler:226]: Running interval '' with interval=10000 last_execution=453162 (now=463163) [23:58:34][VV][api.service:540]: on_ping_request: PingRequest {} [23:58:34][VV][api.service:043]: send_ping_response: PingResponse {} [23:58:41][VV][scheduler:226]: Running interval 'update' with interval=20000 last_execution=451085 (now=471086)

[23:58:41][V][modbus:199]: Modbus write: 01.04.00.00.00.0A.70.0D (8)

Si lo hago al revez, sigue saliendo el mensaje de CRC

janneman001 commented 11 months ago

Duplicate of #3912 ?

jonathanpalomino commented 11 months ago

Duplicate of #3912 ?

No, el sensor PZEM no genera información aparentemente ya que en esphome sale NA, estoy sospechando que tal vez tenga que ver con la dirección (podria tener una aleatoria entre 0x01 a 0xf0 segun el fabricante)

janneman001 commented 11 months ago

Ah right sorry for the spam

fireblade70 commented 11 months ago

I'm also having CRC errors with ESP32 devkit v1, TTL to RS485 (with built-in flow control) and PZEM-016. Previously, I used the PZEM-016 with the supplied USB-RS485 converter using modbus and this worked. I don't have logic analyser but i suspect it's a timing issue with the flow control as found similarly with other ESPhome\modbus related posts. With ESP32 iv tried all sorts with timing and ignoring CRC but still get errors. Hope this can be fixed soon. My alternative is to bypass the whole RS485 and interface directly with TTL like PZEM-004Tv3 update So I completely bypassed the RS485 physical layer (remove MAX485 at both ends so ESP32 Tx/Tx are interfacing directly with PZEM-016 Tx/Rx and it worked with same configuration file. This problem is obviously a timing issue to hardware flow control built around the MAX485 Rx enable. Although im getting data, I do get the following timing errors: [W][component:204]: Component modbus took a long time for an operation (0.07 s). [W][component:205]: Components should block for at most 20-30ms. I also changed from using modbus_controller to pzemac (both using modbus.h) components and both worked with same timing error. Any tips on solving errors? Have tried modbus: send_wait_time: 100ms. But still there.

jonathanpalomino commented 11 months ago

He logrado resolver el problema. Se trataba de 2 cosas que estaba haciendo mal según lo que encontré por internet: 1.- Había utilizado una fuente independiente de 5v, según el foro de implementación nativa en arduino para el pzem-004t v3 lo debo conectar al RX2 y TX2 así como GND y 3.3v. 2.- Me funciono ponerlo en un protoboard ya que al parecer los cables de puente utilizados estaban haciendo falso contacto.

Al codigo que use solo le cambie : rx_pin: GPIO16 tx_pin: GPIO17

Y el resultado es el siguiente:

220V Energy Reset | OFF | Off   On Current | 0.15 A |   Energy | 1.0 Wh |   Frequency | 60.00 Hz |   Power | 23.90 W |   Power Factor | 0.68 |   Voltage | 229.40 V