Regman
Regman

Reputation: 21

How to start with zigpy command line and Sonoff Zigbee 3.0 USB Dongle Plus (ZBDongle-E)?

Introduction and problem statement

I recently bought a "Sonoff Zigbee 3.0 USB Dongle Plus" (model "ZBDongle-E") and a Lixee ZLinky_TIC.

I want to pair them and acquire data that is measured by the ZLinky_TIC using simple command lines. Furthermore I want to avoid to install frameworks for home automation like Home assistant, MQTT stuff, etc because I think it is an overkill...

On Ubuntu (22.04) I have installed zigpy (https://github.com/zigpy/zigpy) and bellows (https://github.com/zigpy/bellows) using pip.

First, I wanted to scan the available components (similarly to what we can do with Wifi or Bluetooth).

The bellows command provide a scan command but it requires to specify the "device".

Does anyone know how to use this command and can tell me how to specify the device argument?

Main issue

The documentation does not explain clearly how to specify the device. Please read the help provided in the following appendix section. One can see that the --device option expects a TEXT but what should be stated ?


Appendix : help provided by the bellows command line :

~$ bellows --help
Usage: bellows [OPTIONS] COMMAND [ARGS]...

Options:
  -v, --verbosity LVL             Either CRITICAL, ERROR, WARNING, INFO or
                                  DEBUG
  -d, --device TEXT               [required]
  -b, --baudrate INTEGER
  --flow-control [software|hardware]
                                  use hardware flow control
  --help                          Show this message and exit.

Commands:
  backup           Backup NCP config to stdio.
  bootloader       Start bootloader
  config           Get/set configuration on the NCP
  devices          Show device database
  dump             Capture frames on CHANNEL and write to FILE in tcpdump...
  form             Form a new ZigBee network
  info             Get NCP information
  join             Join an existing ZigBee network as an end device
  leave            Leave the ZigBee network
  permit           Allow devices to join this ZigBee network
  permit-with-key  Allow devices to join this ZigBee network using an...
  restore          Backup NCP config to stdio.
  scan             Scan for networks or radio interference
  stream           Transmit random stream of characters on CHANNEL with...
  tone             Transmit continuous unmodulated tone on CHANNEL with...
  zcl              Perform ZCL operations against a device
  zdo              Perform ZDO operations against a device

Upvotes: 0

Views: 5084

Answers (2)

Regman
Regman

Reputation: 21

Thank you for your feedback. I finally managed to get it work. The following discussion contains many useful information: First steps - documentation update · Issue #40 · zigpy/bellows

I will try to summarize it and add my own tips:

  1. The --device argument waits for the path of the radio device (I also call it radio dongle). It can be obtained using dmesg when plugging in the radio dongle to the computer. (In my case, I faced an issue because the radio dongle was taken by the modem manager and I had to create a rule in /etc/udev/rule.d/ to disable modem manager for the dongle) ; the device path is something like : /dev/tty...
  2. Additionally, in my case, the default --baudrate (which is 57600) does not work ; in order to know the baudrate, I had to dig a little bit in the radio dongle documentation and quickly found that it required a value of 115200
  3. Then, we should perform the form command in order to start the network but, when executed for the first time, it fails with the error:
Error: Invalid value for '-D' / '--database': File '/home/username/.config/bellows/app.db' does not exist.

As discussed in 1, the initial file of the database has just to be created manually:

touch $HOME/.config/bellows/app.db
  1. Now, the network can be initialized:
bellows -b 115200 -d /dev/ttyACM0 form
  1. Now, the coordinator should allow pairing:
bellows -b 115200 -d /dev/ttyACM0 permit

By default the permit duration is 30s but it can be modified with -t option. (When executed, the command looks like hung and do not provide any feedback about successful pairing. ) At that moment, one has to start the pairing process of the end device (in my case, it was an electrical power meter) ; once done, I am unsure but I guess that the pairing credentials are stored in app.db. Anyway, you can now reboot the host computer or disconnect+connect again the radio dongle, the end device remains reachable with the bellows commands.

  1. Now we can perform a devices listing with:
bellows -b 115200 -d /dev/ttyACM0 devices

This outputs something like this:

Device:
  NWK: 0xd84e
  IEEE: 00:17:88:01:10:50:ca:d2
  Endpoints:
    242: profile=0xa1e0, device_type=97
      Input Clusters:
        GreenPowerProxy (33)
      Output Clusters:
        GreenPowerProxy (33)
    11: profile=0xc05e, device_type=DeviceType.DIMMABLE_LIGHT
      Input Clusters:
        Basic (0)
        Identify (3)
        Groups (4)
        Scenes (5)
        On/Off (6)
        Level control (8)
        LightLink (4096)
      Output Clusters:
        Ota (25)

(this not from my setup, this example is taken from Issue connecting Xiaomi devices · Issue #43 · zigpy/bellows just for illustrating purposes).

  1. Now we can get some attributes (information) from the end device. To do so, we use a command like:
bellows -b 115200 -d /dev/ttyACM0 zcl '00:17:88:01:10:50:ca:d2' 11 3 read-attribute 0

The documentation of this command is as follows:

Usage: bellows zcl NODE ENDPOINT CLUSTER read-attribute [OPTIONS] ATTRIBUTE

The values of NODE, ENDPOINT and CLUSTER are straightforwardly obtained from the devices command. The ATTRIBUTE number should be obtained from the end device documentation (above I put a value of 0 which I picked at random, again just for illustrating purpose).

Side-note: In my case, the last command fails most of the time (with an error Failed to deliver message: <EmberStatus.DELIVERY_FAILED: 102> which requires further investigations) but some times, it works.

This ends my quick and dirty tutorial to start with the bellows command line.

Upvotes: 0

Alexander K
Alexander K

Reputation: 1

First of all you can't sniff for other devices without network (at least with conventional tools).

Zigbee is more to wifi rather than bluetooth. In order to sniff traffic (again, using conventional tools) you have to create network, join devices there, add EZSP in sniffer mode, use https://github.com/zsmartsystems/com.zsmartsystems.zigbee.sniffer and wireshark to sniff.

Answer to your question is pretty simple :

bellows -d /dev/ttyACM0 --flow-control hardware -b 115200 info
[MAC GOES HERE]
[0xAAAA]
[<EmberNetworkStatus.JOINED_NETWORK: 2>]
[<EmberStatus.SUCCESS: 0>, <EmberNodeType.ROUTER: 2>,
......

-d specifies device

Upvotes: 0

Related Questions