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

Zigbee electrical measurement cluster - sending data

Hello,
I'm trying to send some payload via ELECTRICAL_MEASUREMENT cluster.
The sending is realized in the similar way to the zigbee_light_switch example.

I'm sending data to the broadcast addr:

    zb_uint16_t addr = 0xFFFF;
    uint16_t measured_val = 0xABCD;

    NRF_LOG_INFO("Send el measurement command");

    ZB_CUSTOM_EL_MEASUREMENT_SEND_REQ(bufid,
                           addr,
                           ZB_APS_ADDR_MODE_16_ENDP_PRESENT,
                           HA_SMART_PLUG_ENDPOINT, //todo
                           HA_SMART_PLUG_ENDPOINT,
                           ZB_AF_HA_PROFILE_ID,
                           ZB_ZCL_DISABLE_DEFAULT_RESPONSE,
                           NULL,
                           measured_val);


Where the macro is:
#define ZB_CUSTOM_EL_MEASUREMENT_SEND_REQ(                                                                                                    \
    buffer, addr, dst_addr_mode, dst_ep, ep, prof_id, def_resp, cb, measured_val)                                                             \
{                                                                                                                                             \
  zb_uint8_t* ptr = ZB_ZCL_START_PACKET_REQ(buffer)                                                                                           \
  ZB_ZCL_CONSTRUCT_SPECIFIC_COMMAND_REQ_FRAME_CONTROL(ptr, def_resp)                                                                          \
  ZB_ZCL_CONSTRUCT_COMMAND_HEADER_REQ(ptr, ZB_ZCL_GET_SEQ_NUM(), ZB_ZCL_CMD_ELECTRICAL_MEASUREMENT_GET_MEASUREMENT_PROFILE_RESPONSE_COMMAND); \
  ZB_ZCL_PACKET_PUT_DATA16_VAL(ptr, (measured_val));                                                                                          \
  ZB_ZCL_FINISH_PACKET(buffer, ptr)                                                                                                           \
  ZB_ZCL_SEND_COMMAND_SHORT(                                                                                                                  \
      buffer, addr, dst_addr_mode, dst_ep, ep, prof_id, ZB_ZCL_CLUSTER_ID_ELECTRICAL_MEASUREMENT, cb);                                        \
}


After that I'm trying to find those data in the sniffer.



Cluster ID is correct, Cmd ID is also correct and the measured_val (0xABCD) is visible.

Unfortunatelly the packet seems to be malformed. Any idea what am I doing wrong and how to fix it ?

BR,
Jakub

Parents Reply
  • Thanks a lot. I am doing something wrong for sure Slight smile. In the ZB_ZCL_ELECTRICAL_MEASUREMENT_SEND_GET_MEASUREMENT_PROFILE_INFO_RESP  there is no place for the measured value. So in my understanding I should do the following:

    1. Update the measured value "internally" by calling the ZB_ZCL_SET_ATTRIBUTE.
    2. Gateway should send me request with proper ID to get those measured data.
    3. The ZB stack will send the response automatically in the background with updated (in I-st step) parameters.

    Please correct me if I am wrong.

    BR,
    Jakub

Children
  • That's correct!
    In Zigbee the sensor data is stored as an attribute value. The other device may:
    - Query for the current value via the Read Attribute Request.
    - Subscribe to the attribute value changes via binding & configuring the reporting.

    There is a CLI example inside the SDK that is capable of doing both things.The sequence of commands, required to test the reporting can be found here:
    https://infocenter.nordicsemi.com/topic/sdk_tz_v4.1.0/zigbee_multi_sensor_example.html?cp=7_3_3_8_5_3_1#zigbee_multi_sensor_example_test

    The command that you were asking should be sent in response to the Get Measurement Profile Info command.

    BR,
    Tomchy

  • Hello again,

    I've tried the cli example but I occured some problems.
    Let me describe the whole procedure:

    1. Update <proj_dir>/nrf-thread-sdk/examples/zigbee/light_control/light_bulb/main.c with function to read device address just after 'zb_set_long_address(ieee_addr);' call:

    zb_get_long_address(buf);
    
    for(int i = 0 ; i < 8; i++)
    {
        NRF_LOG_INFO("MY ADDR: %X", buf[i]);
    }

    2. Connect first nRF52-DK (A) make and flash it with <proj_dir>/nrf-thread-sdk/examples/zigbee/light_control/light_bulb/ hex file

    3. Connect second nRF52-DK (B) and flash it with cli example

    4. Open <proj_dir>/testing/zigbee_cli/config.yaml and update COM port (B) and eui64 with addr from 1.

    5. Run mqtt broker (mosquitto.exe)

    6. Run python3 cli.py

    7.  'Client started' occurs in the cli.py output and LED3 on (B) lights up.

    8. Type 'mosquitto_pub -t home/light2/on_off/state -m 0'.

    9.  Notice that logs in the cli.py terminal occured:
        cli.py: INFO: Message - Topic: home/light2/on_off/state ,Payload: b'0'
        cli.py: INFO: CLI cmd send : EUI64=F4CE36CC34102197 EP=10 CLUSTER=0006 CMD=0000 RESP=True PAYLOAD=None

    PROBLEMS:

    - The LED on (A) - light bulb does not change its state
    - The sniffer doesn't see any Zigbee traffic on channel 16

    I suppose that there is still something i do wrong.

    BR,
    Jakub

  • Hi,

    estatiokvit said:
    Open <proj_dir>/testing/zigbee_cli/config.yaml and update COM port (B) and eui64 with addr from 1.

    I am a bit confused by your post. There is no Zigbee CLI example currently released for NCS so I am not sure where did you find this CLI example? Tomchy linked to the CLI example from the nRF5 SDK for Thread&Zigbee v4.1.0. I recommend you use this one since the example is still not available on NCS. It is possible to run the CLI example from the nRF5 SDK and run the light bulb on NCS and have both on the same network.

Related