This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

CC2340R5: How to obtain the RSSI between the device and the coordinator

Part Number: CC2340R5

After connecting to the coordinator, I used the function zb_zdo_get_diag_data(0, &lqi, &rssi); 1s obtains one RSSI value, but every time I obtain a RSSI value, it doesn't change. It remains the same as the first RSSI value obtained.

SDK:9_10
cc2340R5

  • Hi,

    Are you using a ZED or ZR, and how often is it communication (outside of data polling) with the ZC?  Can you provide a code snippet of how it is being used in your application?

    static void handle_diag_data_resp(zb_bufid_t buf)
    {
      zb_zdo_get_diag_data_resp_params_t *resp_params;
    
      resp_params = ZB_BUF_GET_PARAM(buf, zb_zdo_get_diag_data_resp_params_t);
    
      ZVUNUSED(resp_params);
    
      Log_printf(LogModule_Zigbee_App, Log_INFO, "handle_diag_data_resp, status: %d, addr: 0x%x, lqi: %d, rssi: %d",
                 resp_params->status, resp_params->short_address,
                 resp_params->lqi, resp_params->rssi);
    
      zb_buf_free(buf);
    }
    
    static void send_diag_data_req(zb_uint16_t short_address)
    {
      zb_zdo_get_diag_data_req_params_t *req;
      zb_bufid_t buf;
    
      buf = zb_buf_get_out();
      if (buf != ZB_BUF_INVALID)
      {
        req = ZB_BUF_GET_PARAM(buf, zb_zdo_get_diag_data_req_params_t);
        ZB_BZERO(req, sizeof(*req));
    
        req->short_address = short_address;
        zb_zdo_get_diag_data_async(buf, handle_diag_data_resp);
      }
      else
      {
        Log_printf(LogModule_Zigbee_App, Log_ERROR, "Failed to get a buffer");
      }
    }
    
    zb_uint8_t zcl_specific_cluster_cmd_handler(zb_uint8_t param)
    {
    //...
      send_diag_data_req(g_dst_addr);
    //...
    }

    Regards,
    Ryan

  • void GetRSSI_TimeoutCb(zb_uint8_t param)
    {
      uint8_t rsp[6] = {0};
      int8_t RSSI = 0;
      zb_time_t time;
      RSSI = zstackGetRssi();
      rsp[0] = RSSI;
      data_send_process(CMD_USER_GET_RSSI_START, rsp, sizeof(rsp));
      if (ZB_SCHEDULE_GET_ALARM_TIME(GetRSSI_TimeoutCb, 0, &time) != RET_OK)
      {
        ZB_SCHEDULE_APP_ALARM(GetRSSI_TimeoutCb, 0, 1 * ZB_TIME_ONE_SECOND);
      }
     
    }

    int8_t zstackGetRssi(void)
    {
      zb_uint8_t lqi;
      zb_int8_t rssi;
      zb_zdo_get_diag_data(0, &lqi, &rssi);
      //zb_mac_diag_data_get(0, &appLastLqi, &appLastRssi);
      return rssi;
    }

    I'm using ZED, and the communication frequency with ZC is 3 seconds. I also tried 3 seconds once, but the RSSI value remained unchanged.
  • The code you provided I have tried before, but it didn't work.

  • I ran into similar trouble for both sleepy ZED and non-sleepy ZR nodes, here is the workaround I was able to use the following workaround:

      #include "zb_nwk_neighbor.h"
      
      //...
      
      volatile zb_uint8_t lqi = ZB_MAC_LQI_UNDEFINED;
      volatile zb_int8_t rssi = ZB_MAC_RSSI_UNDEFINED;
    
      zb_ret_t ret;
      zb_neighbor_tbl_ent_t *nbt;
    
      ret = zb_nwk_neighbor_get_by_idx(0, &nbt);
      if (ret == RET_OK)
      {
        lqi = nbt->lqi;
        rssi = nbt->rssi;
      }

    Note: the "volatile" assignment is only to keep lqi/rssi from being optimized out by the compiler.  Replacing zb_nwk_neighbor_get_by_idx with zb_nwk_neighbor_get_by_short is also completely acceptable.

    Regards,
    Ryan

  • Hi,Ryan.I used the code you provided and found that the RSSI value still changed very slowly. Because I noticed in my project, the RSSI value only changes when there is a ZCL command sent (such as report attribute, Time:write attribute, etc.), and if there are only data request packets, the RSSI value will not change.

  • Your observation is correct and what I was referring to earlier:

    how often is it communication (outside of data polling) with the ZC

    The RSSI/LQI will only be observed for Zigbee application packets, not data polling.

    Regards,
    Ryan

  • OK, I see. Thank you.