zigpy-espzb icon indicating copy to clipboard operation
zigpy-espzb copied to clipboard

Cannot receive response from ESP32

Open kahlenberg opened this issue 6 months ago • 7 comments

Hi again,

I am receiving timeout error when trying to run zigpy on Rasperry Pi running Home Assistant. I am using ESP32-C6-Pico board and configured ESP32 to use UART1 for Zigbee. Here is my config for building the image:

Image

Image

Image

So, I am using UART1 with pins 20 and 21, using UART0 for debugging.

There are many confusions with the zigpy, zigpy-espzb and zigpy-cli codes. I wrote a script to set the environment:

#!/bin/sh

echo "==> Updating package list and installing dependencies..."
apk update
apk add git python3 py3-pip py3-virtualenv build-base tio bash curl unzip

echo "==> Creating working directory..."
mkdir -p /root/zigpy_dev && cd /root/zigpy_dev

echo "==> Creating Python virtual environment..."
python3 -m venv venv
 . venv/bin/activate

echo "==> Virtual environment activated."

echo "==> Cloning zigpy (master)..."
git clone --branch master https://github.com/zigpy/zigpy.git

echo "==> Cloning zigpy-espzb (feature/fixes-serialization)..."
git clone --branch feature/fixes-serialization https://github.com/lhespress/zigpy-espzb.git

echo "==> Cloning zigpy-cli (feature/zigpy_espzb)..."
git clone --branch feature/zigpy_espzb https://github.com/lhespress/zigpy-cli.git

echo "==> Installing zigpy packages in editable mode..."
pip install -e ./zigpy
pip install -e ./zigpy-espzb
pip install -e ./zigpy-cli

echo "==> Installing esptool inside the same virtual environment..."
pip install esptool

echo "==> Setup complete!"
echo "To activate this environment later, run:"
echo ". /root/zigpy_dev/venv/bin/activate"

As you can see, I am using master branch of zigpy, feature/fixes-serialization branch of zigpy-espzb, feature/zigpy_espzb branch of zigpy-cli. But when I run the zigpy comamnd I get an error about ota provider (AttributeError: 'Ledvance' object has no attribute 'get'). I fixed it by adding following code to radio.py.

config = {
   ....
    "ota": {
        "providers": []
    },
}

Now when I run the command zigpy -vvv radio --baudrate 115200 znsp /dev/ttyAMA0 info, I get a log message from ESP32 in debug console:

I (407) main_task: Returned from app_main()
I (29437) ESP_NCP_FRAME: 00 00 02 04 00 00 00 9b 9b

I think, that means, ESP32 receives command correctly.

Here is the zigpy log:

(venv) ➜  usb zigpy -vvv radio --baudrate 115200 znsp /dev/ttyAMA0 info
2025-05-09 23:43:29.764 a0d7b954-ssh asyncio DEBUG Using selector: EpollSelector
2025-05-09 23:43:29.887 a0d7b954-ssh zigpy_espzb.uart DEBUG Connecting to /dev/ttyAMA0
2025-05-09 23:43:29.888 a0d7b954-ssh zigpy.serial DEBUG Opening a serial connection to '/dev/ttyAMA0' (baudrate=115200, xonxoff=False, rtscts=False)
2025-05-09 23:43:29.891 a0d7b954-ssh zigpy_espzb.uart DEBUG Connection made
2025-05-09 23:43:29.892 a0d7b954-ssh zigpy_espzb.uart DEBUG Connected to /dev/ttyAMA0
2025-05-09 23:43:29.893 a0d7b954-ssh zigpy_espzb.api DEBUG Sending SystemFirmwareReq() (seq=0)
2025-05-09 23:43:29.895 a0d7b954-ssh zigpy_espzb.uart DEBUG Send: 00000204000000
2025-05-09 23:43:31.699 a0d7b954-ssh zigpy_espzb.api DEBUG No response to 'SystemFirmwareReq()' command with seq 0
2025-05-09 23:43:31.701 a0d7b954-ssh zigpy_espzb.api DEBUG Serial '/dev/ttyAMA0' connection lost unexpectedly: None
Traceback (most recent call last):
  File "/root/zigpy_dev/zigpy-espzb/zigpy_espzb/api.py", line 147, in send_command
    return await fut
           ^^^^^^^^^
asyncio.exceptions.CancelledError

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/root/venv/bin/zigpy", line 8, in <module>
    sys.exit(cli())
             ^^^^^
  File "/root/venv/lib/python3.12/site-packages/click/core.py", line 1161, in __call__
    return self.main(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/root/venv/lib/python3.12/site-packages/click/core.py", line 1082, in main
    rv = self.invoke(ctx)
         ^^^^^^^^^^^^^^^^
  File "/root/venv/lib/python3.12/site-packages/click/core.py", line 1697, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/root/venv/lib/python3.12/site-packages/click/core.py", line 1697, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/root/venv/lib/python3.12/site-packages/click/core.py", line 1443, in invoke
    return ctx.invoke(self.callback, **ctx.params)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/root/venv/lib/python3.12/site-packages/click/core.py", line 788, in invoke
    return __callback(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/root/venv/lib/python3.12/site-packages/click/decorators.py", line 45, in new_func
    return f(get_current_context().obj, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/root/zigpy_dev/zigpy-cli/zigpy_cli/cli.py", line 20, in inner
    return loop.run_until_complete(cmd(*args, **kwargs))
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/asyncio/base_events.py", line 691, in run_until_complete
    return future.result()
           ^^^^^^^^^^^^^^^
  File "/root/zigpy_dev/zigpy-cli/zigpy_cli/radio.py", line 85, in info
    await app.connect()
  File "/root/zigpy_dev/zigpy-espzb/zigpy_espzb/zigbee/application.py", line 69, in connect
    await api.connect()
  File "/root/zigpy_dev/zigpy-espzb/zigpy_espzb/api.py", line 87, in connect
    self._firmware_version = await self.system_firmware()
                             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/root/zigpy_dev/zigpy-espzb/zigpy_espzb/api.py", line 537, in system_firmware
    rsp = await self.send_command(commands.SystemFirmwareReq())
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/root/zigpy_dev/zigpy-espzb/zigpy_espzb/api.py", line 146, in send_command
    async with asyncio_timeout(COMMAND_TIMEOUT):
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/asyncio/timeouts.py", line 115, in __aexit__
    raise TimeoutError from exc_val
TimeoutError

What is the problem? What am I doing wrong?

kahlenberg avatar May 09 '25 22:05 kahlenberg

Same issue here https://github.com/lhespress/zigpy-espzb/issues/20

semaf avatar May 11 '25 16:05 semaf

@kahlenberg Since there are still some issues under confirmation, you can refer to the discussion under https://github.com/lhespress/zigpy-espzb/pull/13 . The NCP firmware corresponding to this branch has not been released. Could you provide me with your configuration information? I will update the firmware for you. or you can also use the firmware under this link https://github.com/lhespress/zigpy-espzb/pull/13#issuecomment-2428831410

lhespress avatar May 12 '25 02:05 lhespress

Thank you for the H2 build.

semaf avatar May 12 '25 06:05 semaf

@lhespress Which configuration do you mean? I am using ESP32-C6-Pico board. I want to use USB as ESP32 debug logs and flashing and UART1(GPIO20 - RX and GPIO21 - TX) as main Zigbee communication port.

kahlenberg avatar May 12 '25 06:05 kahlenberg

@lhespress Which configuration do you mean? I am using ESP32-C6-Pico board. I want to use USB as ESP32 debug logs and flashing and UART1(GPIO20 - RX and GPIO21 - TX) as main Zigbee communication port.

You miss maybe to flash the bootloader?

Take this ESP32-C6 build for the moment and flash it with bootloader.

esptool.py --chip esp32c6 -p /dev/ttyACM2 -b 460800 --before=default_reset --after=hard_reset write_flash --flash_mode dio --flash_freq 80m --flash_size 4MB 0x0 bootloader/bootloader.bin 0x20000 esp_zigbee_ncp.bin 0x8000 partition_table/partition-table.bin 0xf000 ota_data_initial.bin

semaf avatar May 12 '25 07:05 semaf

@lhespress Which configuration do you mean? I am using ESP32-C6-Pico board. I want to use USB as ESP32 debug logs and flashing and UART1(GPIO20 - RX and GPIO21 - TX) as main Zigbee communication port.

@kahlenberg Configuration information means which port as main Zigbee communication in your board.

Take this build_esp32c6_20250513.zip which match your Zigbee communication port UART1(GPIO20 - RX and GPIO21 - TX).

lhespress avatar May 13 '25 06:05 lhespress

Image

That build configuration is unclear. Do you select "Configure the Zigbee device type (Zigbee Coordinator or Router device)" option?

Note that the second option to "Configure the Zigbee radio type (Connect to 15.4 radio via Radio Spinel UART)" is not meant for use with this zigpy-espzb library but is instead used for Thread Border Router or other projects that uses the Spinel product , such as example ziggurat (as well as the "ZigBee on Host" project):

  • https://github.com/zigpy/ziggurat

  • https://github.com/zigpy/zigpy/discussions/1571

PS: Off-topic; but FYI, the Spinel protocol is the interface for OpenThread RCP (Radio Co-Processor), so it is not the same as the custom Espressif ZNSP (Zigbee NCP Serial Protocol) that this zigpy-espzb project uses. Again, that is off-tpic but you can find more info here:

  • https://openthread.io/platforms/co-processor
  • https://github.com/openthread/spinel-spec

Hedda avatar May 13 '25 11:05 Hedda