This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Zigbee CLI wrapper

Hello,

So I was exploring the nRF52840 DK as a Zigbee device when I found this page: Zigbee CLI wrapper.

This seems very promising, having a python CLI to interface with the nRF52840. However, I'm not finding too much information about it. I have installed successfully the zb-CLI-wrapper 0.3 using pip but now I don't have any start point. No documentation about the functions or either an example. 

I found this thread where someone refers to a demo script. Could someone point me to this script? Or to a documentation page about the functions allowed by the zb-CLI-wrapper?

Best regards,

Fernando Fontes

Parents
  • Hi Fernando,

    Did you download the files from https://pypi.org/project/zb-cli-wrapper/? In the download you will find a README file, which explains how to use the CLI wrapper, and the different functions you can use. The demo script (MQTT Zigbee gateway application) can be found in the "example" folder in the download. This example also has a README file with explanations.

    The example that you should program to your DK is the CLI Agent example.

    Best regards,

    Marte

  • Hi Marte,

    No, I just have installed it.

    I will download it now. 

    Thank you.

  • Hi Fernando,

    I am happy to help. Do not hesitate to ask if you have any more problems with the Zigbee CLI wrapper.

    Best regards,

    Marte

  • Hi Marte,

    Thank you for your support.

    So, after opening the README file and after investigating the MQTT_Zigbee_gateway.py file I was able to create my own script without any problem.

    However, I have a few questions about what is possible to do:

    1. To create a CLI device object I did the following:

    cli_dev = ZbCliDevice(**param)
    cli_dev.bdb.channel = config_dict['CLIDevice']['channels']
    cli_dev.bdb.role = config_dict['CLIDevice']['role']
    However, this gives me an error after the second run of the script since the bdb is already in running mode. How can I anticipate this? Is there a way to do a previous check if the dongle is already running the coordinator mode?

    2. To list the devices connected I need to run the match_desc command, my question is, how can I discover the devices connected without knowing in advance the implemented clusters? I want something like a broadcast command without knowing the implemented clusters. 

    3. In the README file is explained how can I read an attribute of a given cluster. However, it would be nice if it was possible to subscribe to the attribute changes. Is it possible? Running directly the CLI using the COM port I was able to do it using the zdo bind on and zcl subscribe on commands.... 

    Thank you in advance,
    Best regards,
    Fernando Fontes

Reply
  • Hi Marte,

    Thank you for your support.

    So, after opening the README file and after investigating the MQTT_Zigbee_gateway.py file I was able to create my own script without any problem.

    However, I have a few questions about what is possible to do:

    1. To create a CLI device object I did the following:

    cli_dev = ZbCliDevice(**param)
    cli_dev.bdb.channel = config_dict['CLIDevice']['channels']
    cli_dev.bdb.role = config_dict['CLIDevice']['role']
    However, this gives me an error after the second run of the script since the bdb is already in running mode. How can I anticipate this? Is there a way to do a previous check if the dongle is already running the coordinator mode?

    2. To list the devices connected I need to run the match_desc command, my question is, how can I discover the devices connected without knowing in advance the implemented clusters? I want something like a broadcast command without knowing the implemented clusters. 

    3. In the README file is explained how can I read an attribute of a given cluster. However, it would be nice if it was possible to subscribe to the attribute changes. Is it possible? Running directly the CLI using the COM port I was able to do it using the zdo bind on and zcl subscribe on commands.... 

    Thank you in advance,
    Best regards,
    Fernando Fontes

Children
  • Hi Fernando,

    Good to hear that you were able to create your own script!

    Q1

    A possible workaround for the connection error is to use the function wait_until_connected to check if you are connected before calling bdb.channel, bdb.role and bdb.start. This function returns None if CLI is not connected, so you can use it as follows:

    cli_dev = ZbCliDevice(**param)
    if cli_dev.wait_until_connected(timeout=1)==None:
        cli_dev.bdb.channel = config_dict['CLIDevice']['channels']
        cli_dev.bdb.role = config_dict['CLIDevice']['role']
        cli_dev.bdb.start()

    Here I added a timeout to the function, as by default it tries to connect 10 times before stopping, and I only want to check once to make sure I am not connected already.

    Q2

    You are limited by the commands that exist in the CLI library, all of which can be found here. Unfortunately, there is no command to broadcast just a general command to all devices as the commands always use something to identify the devices by, such as their addresses and endpoints for commands to a specific device, or their clusters for a more general command. However, almost all devices will have the Basic cluster. If they have an endpoint and have clusters implemented, they will also have the Basic cluster. The only example in our SDK that does not have this cluster is the light coordinator from the light control example, and this is because this example only has functionality for being a coordinator, so only the network steering commissioning mechanism, and nothing more. Therefore, you can send a match_desc command with the basic cluster (cluster ID 0). In terminal this will be:

    zdo match_desc 0xffff 0xffff 0x0104 1 0 0

    While in the wrapper it should be something like:

    response = cli_dev.zdo.match_desc([constants.BASIC_CLUSTER],[])

    Q3:

    Yes, that should be possible. The available commands can be found in the different files in zb_cli_wrapper/src/utils/cmd_wrappers/zigbee/. Bind on is a zdo command, so that is found in zdo.py, and subscribe is found in zcl.py since it is a zcl command.  If you look in these files you will see "Avalable commands" close to the top of the files, which lists all commands you can use from that module. For more information about how to use each command, you can look in the CommandWrapper class of the file, and look for the function corresponding to the command you want to use. There you will find some information as well as a line looking something like this:

    cmd = Commands.<command_name>.format(<parameters>)

    This line tells you what parameters the command takes, so this can be a good thing to use as a reference.

    For the specific case of sending zdo bind on and zcl subscribe, you can do something like the following:

    cli_dev.zdo.bind(src_eui64, src_ep, dst_eui64, dst_ep, cluster_id, dst_short)
    cli_dev.zcl.subscribe(eui64, ep, cluster_id, profile_id, attr_id, attr_type)

    This only subscribes to the attribute reports, but it does not print (or log) them. To do so, you must enable logging:

    cli_dev.log.enable(log_module, log_level)

    Best regards,

    Marte

Related