libretiny-eu / libretiny

PlatformIO development platform for IoT modules
http://docs.libretiny.eu/
MIT License
382 stars 55 forks source link

libretuya-esphome: MQTT: realtek-ambz #80

Open dkaukov opened 1 year ago

dkaukov commented 1 year ago

Enabling MQTT in the ESPHome for "realtek-ambz" produces the error:

Processing sw09 (board: wr3; framework: arduino; platform: https://github.com/kuba2k2/libretuya.git)
--------------------------------------------------------------------------------
HARDWARE: RTL8710BN 125MHz, 256KB RAM, 788KB Flash
 - framework-arduino-api @ 3.0.0-a4cbfc+sha.3a4cbfc 
 - framework-realtek-amb1 @ 0.0.0+v2022.06.21.sha.c4e44ef 
 - library-flashdb@03500fa @ 3500.0.0-fa+sha.03500fa 
 - library-lwip@2.1.3-amb1 @ 2.1.3-amb1+sha.5d6edaa 
 - library-printf@6.0.0 @ 6.0.0+sha.8b831c1 
 - tool-ltchiptool @ 2.0.2+sha.7559033 
LDF: Library Dependency Finder -> https://bit.ly/configure-pio-ldf
Dependency Graph
|-- AsyncMqttClient-esphome @ 0.8.6+sha.a659596
|-- ArduinoJson @ 6.18.5
Compiling .pioenvs/sw09/src/esphome/components/api/api_connection.cpp.o
....
In file included from .piolibdeps/sw09/AsyncMqttClient-esphome/src/AsyncMqttClient.h:4:0,
                 from src/esphome/components/mqtt/mqtt_backend_arduino.h:6,
                 from src/esphome/components/mqtt/mqtt_client.h:15,
                 from src/esphome/components/mqtt/custom_mqtt_device.h:7,
                 from src/esphome/components/mqtt/custom_mqtt_device.cpp:1:
.piolibdeps/sw09/AsyncMqttClient-esphome/src/AsyncMqttClient.hpp:14:22: fatal error: AsyncTCP.h: No such file or directory

******************************************************************
* Looking for AsyncTCP.h dependency? Check our library registry!
*
* CLI  > platformio lib search "header:AsyncTCP.h"
* Web  > https://registry.platformio.org/search?q=header:AsyncTCP.h
*
******************************************************************

compilation terminated.
*** [.pioenvs/sw09/src/esphome/components/mqtt/custom_mqtt_device.cpp.o] Error 1
========================= [FAILED] Took 10.31 seconds =========================
kuba2k2 commented 1 year ago

Add web_server component and it should work. Keep this issue open so that I remember to fix it.

dkaukov commented 1 year ago

:+1:

dkaukov commented 1 year ago

It compiles, but crashing on MQTT connection.

djanknecht commented 1 year ago

Hi, i realized to late that MQTT for beken-72xx is not implemented yet (https://docs.libretuya.ml/docs/status/arduino/). An ESPHome configuration with MQTT enabled compiles - but is also crashing on MQTT connections or shortly after the connection. Topics are sent once. @kuba2k2 is implementing/fixing MQTT for beken-72xx planned in the near future? I need MQTT for ioBroker support...

kuba2k2 commented 1 year ago

It's not my priority currently. Also, I don't have ways to test it - I don't have any MQTT broker, except for mosquitto installed on my PC locally, which I tested and it didn't crash.

djanknecht commented 1 year ago

ok! Maybe i can help by providing some more information? Can i grab some logs somehow? The device is accessible only via network, i used cloudcutter to flash.

kuba2k2 commented 1 year ago

A device without UART access won't do. When I was fixing issues on various components, I even had a JTAG debugger attached sometimes.

Gradecak commented 1 year ago

I seem to be running into the same issue. The firmware compiles and flashes, but shortly after the reboot the device crashes. It also appears that on boot the a message single message makes it into the broker (mosquitto) before crashing.

camsaway commented 11 months ago

I also have the same issue I believe. CBU module (BK7231N) in a tongou rail switch. Works fine on Esphome API, but crashes after 1 message on MQTT. (Mosquito broker in HASS that i use for all my other devices)

Let me know if there are any logs I can get to assist

alessiocappa commented 10 months ago

I also have the same issue I believe. CBU module (BK7231N) in a tongou rail switch. Works fine on Esphome API, but crashes after 1 message on MQTT. (Mosquito broker in HASS that i use for all my other devices)

Let me know if there are any logs I can get to assist

I think I’m running into the same issue. I have the same board (CBU) and I can compile the firmware if I add the mqtt component. However, as soon as the device starts I can only see a message in the console saying “MQTT Connected!” and this is the only message that gets constantly spammed into the console. No other updates for sensors or button are sent to the MQTT broker.

I can’t even access the device via its IP, but the web server is enabled in the configuration. I don’t know if it constantly restarts or what, I can perform OTA update though, so I guess it stays online.

Any help on this would be highly appreciated, let me know if I can provide you additional information or logs.

BinaryBrain86 commented 8 months ago

Same issue on my side. I've got a WRE2 Board in a power plug with an RTL8710BN chip. As long as I keep the mqtt component disabled / commanded it works. But ones I compile and download OTA with the mqtt component, the board is'nt anymore reachable and opens after a while the fallback hot spot. It seem's some how the WiFi connection will be cut of, because of the mqtt component and hangs somewhere on a loop. The topics will be created, so for very short moment the establishment of connection must be succeed. I'm using ioBroker as well, so no chance for the api component and HASS for me. @kuba2k2 Let me know how I can help, because without mqtt this power plug is just another lab rat for me.

That's my yaml in case it's useful.


  name: plug01
  friendly_name: plug01

rtl87xx:
  board: wr2e
  framework:
    version: dev

# Enable logging
logger:

# Enable Home Assistant API
#api:
#  encryption:
#    key: "NNmEHnn7ZGraG+GLnM1l9vkvern/aLGSRdV1SQtQtHs="

ota:
  password: "3855fb12edfaac040202d0493ace64de"

wifi:
  ssid: "mySSID"
  password: "myPassword"

  # Enable fallback hotspot in case wifi connection fails
  ap:
    ssid: "Plug01 Fallback Hotspot"

captive_portal:

# Example configuration entry
web_server:
  port: 80

binary_sensor:
  - platform: gpio
    pin:
      number: 05
      inverted: true
      mode:
        input: true
        pullup: true
    name: "TouchSwitch"
    on_press:
      - switch.toggle: relay
  - platform: status
    name: "TouchSwitch Status"

sensor:
  - platform: wifi_signal
    name: "Plug01 WiFi Signal"
    update_interval: 60s

switch:
  - platform: gpio
    name: "Relay"
    on_turn_on:
      then:
      - switch.turn_on: led
    on_turn_off:
      then:
      - switch.turn_off: led
    pin:
      number: 14
      inverted: true
    id: relay

  - platform: gpio
    name: "Status LED"
    pin:
      number: 19
      inverted: true
    id: led

status_led:
  pin:
    number: 12
    inverted: true
alessiocappa commented 8 months ago

Same issue on my side. I've got a WRE2 Board in a power plug with an RTL8710BN chip. As long as I keep the mqtt component disabled / commanded it works. But ones I compile and download OTA with the mqtt component, the board is'nt anymore reachable and opens after a while the fallback hot spot. It seem's some how the WiFi connection will be cut of, because of the mqtt component and hangs somewhere on a loop. The topics will be created, so for very short moment the establishment of connection must be succeed. I'm using ioBroker as well, so no chance for the api component and HASS for me. @kuba2k2 Let me know how I can help, because without mqtt this power plug is just another lab rat for me.

That's my yaml in case it's useful.

  name: plug01
  friendly_name: plug01

rtl87xx:
  board: wr2e
  framework:
    version: dev

# Enable logging
logger:

# Enable Home Assistant API
#api:
#  encryption:
#    key: "NNmEHnn7ZGraG+GLnM1l9vkvern/aLGSRdV1SQtQtHs="

ota:
  password: "3855fb12edfaac040202d0493ace64de"

wifi:
  ssid: "mySSID"
  password: "myPassword"

  # Enable fallback hotspot in case wifi connection fails
  ap:
    ssid: "Plug01 Fallback Hotspot"

captive_portal:

# Example configuration entry
web_server:
  port: 80

binary_sensor:
  - platform: gpio
    pin:
      number: 05
      inverted: true
      mode:
        input: true
        pullup: true
    name: "TouchSwitch"
    on_press:
      - switch.toggle: relay
  - platform: status
    name: "TouchSwitch Status"

sensor:
  - platform: wifi_signal
    name: "Plug01 WiFi Signal"
    update_interval: 60s

switch:
  - platform: gpio
    name: "Relay"
    on_turn_on:
      then:
      - switch.turn_on: led
    on_turn_off:
      then:
      - switch.turn_off: led
    pin:
      number: 14
      inverted: true
    id: relay

  - platform: gpio
    name: "Status LED"
    pin:
      number: 19
      inverted: true
    id: led

status_led:
  pin:
    number: 12
    inverted: true

What version of the firmware are you using? Now that libretiny has been merged into esphome, I would suggest you try the official version to see if it works. I did some quick tests, and I found out that mqtt is working fine using the latest esphome release. However, I noticed that deep sleep is not supported anymore in the official release, which is what I'm currently struggling with, but in your case this should not be a problem if you need to control a plug.

BinaryBrain86 commented 8 months ago

@alessiocappa I am using the docker version from here (2023.9.0-dev) on my Pi 4 to manage the device and I installed it according to this Tut. I flashed the Board with the Itchiptool v4.6.0. In the first place I used this yaml to got the device connected to my WiFi.

name: plug01
  friendly_name: plug01

rtl87xx:
  board: wr2e
  framework:
    version: dev

# Enable logging
logger:

# Enable Home Assistant API
api:
  encryption:
    key: "NNmEHnn7ZGraG+GLnM1l9vkvern/aLGSRdV1SQtQtHs="

ota:
  password: "3855fb12edfaac040202d0493ace64de"

wifi:
  ssid: "mySSID"
  password: "myPassword"

  # Enable fallback hotspot in case wifi connection fails
  ap:
    ssid: "Plug01 Fallback Hotspot"

captive_portal:

# Example configuration entry
web_server:
  port: 80

Have you link for me and the reader to this post to the official version as a docker container? Thanks for the effort.

BinaryBrain86 commented 8 months ago

@alessiocappa Ok, I guess I found it (here). I was first confused, because the device wizzard wasn't showing the WR2E board. So I choose something, and exchange the yaml configuration. Without the mqtt component same status. So my file and device still work.

Unfortunately the yaml wouldn't accept and compile with the mqtt component (see picture). It seems not to be available for the WR2E board with the RTL8710BN chip. Or I am doing something wrong? image

Which device platform are you using? Beken chip?

kuba2k2 commented 8 months ago

Newer versions of ESPHome (specifically the upstream version, not the fork) make MQTT compilation on Realtek impossible, due to the crashing issues. Older versions will compile (they didn't have such a check) but will obviously not work properly.

MQTT is incompatible with Realtek. I have not been able to get it to work yet - I don't know what makes it crash (and I've been searching for the cause).

alessiocappa commented 8 months ago

@alessiocappa Ok, I guess I found it (here). I was first confused, because the device wizzard wasn't showing the WR2E board. So I choose something, and exchange the yaml configuration. Without the mqtt component same status. So my file and device still work.

Unfortunately the yaml wouldn't accept and compile with the mqtt component (see picture). It seems not to be available for the WR2E board with the RTL8710BN chip. Or I am doing something wrong? image

Which device platform are you using? Beken chip?

@BinaryBrain86 sorry, I think I misread the chip you're using. Indeed, I'm using a CBU board (BK7231N) and MQTT seems to be working fine with the latest ESPHome version.

BinaryBrain86 commented 8 months ago

Newer versions of ESPHome (specifically the upstream version, not the fork) make MQTT compilation on Realtek impossible, due to the crashing issues. Older versions will compile (they didn't have such a check) but will obviously not work properly.

MQTT is incompatible with Realtek. I have not been able to get it to work yet - I don't know what makes it crash (and I've been searching for the cause).

@kuba2k2 Thanks for the information, and even more I appreciate your effort. I was searching in the Repo for mqtt and found this:

image

I'm right the library here will be used for mqtt? In that case you probably considered this (I know it's written ESP8266, but who knows it might take effects on other IoT chips).

image

I tried to go through some Python build scripts, but after a while I lost the thread.

kuba2k2 commented 8 months ago

This library is not used in ESPHome. The one used is called AsyncMqttClient-esphome.

BinaryBrain86 commented 8 months ago

Not sure I'm on the right spot, but in the PlatformIO.ini is still version 1.0.0 referenced. image 2.0.0 Is already released. Not sure if it matter. image

kuba2k2 commented 8 months ago

This file is not used for compilation, though it should have been updated too. This file doesn't affect errors.

As I have mentioned before, MQTT with this library is incompatible with Realtek. This is not about compilation errors or different versions - it crashes on runtime. There's nothing you can do by changing versions.