I have a Zigbee router app that is mostly based on the light_bulb sample. I have noticed that unlike other Zigbee devices on the network (e.g. Philips Hue bulbs), there is often a noticeable lag between the time a command is sent and when the nRF52840 processes it.
Upon further investigation it seems like the Zigbee stack on this device is pretty laggy in general. For instance, at the bottom of main() I added:
while (1) {
LOG_INF("tick %lld", k_uptime_get());
zb_ret_t error_code = zb_buf_get_out_delayed_func(tock_cb);
//zb_ret_t error_code = ZB_SCHEDULE_APP_CALLBACK(tock_cb, 0);
if (error_code != RET_OK)
LOG_ERR("error %d", error_code);
k_sleep(K_SECONDS(2));
}
And the function it calls is just:
static void tock_cb(zb_uint8_t bufid)
{
LOG_INF("tock %lld", k_uptime_get());
if (bufid)
zb_buf_free(bufid);
}
zb_buf_get_out_delayed_func() often takes hundreds of milliseconds before running the callback. This happens even if there is almost no Zigbee network traffic going on, and even if I use zb_mem_config_max.h. There are no other threads in my app, just the Zigbee thread and the main thread. Also no Bluetooth support.
I: Device is running
I: tick 44
I: Production configuration is not present or invalid (status: -1)
I: tock 53
I: Zigbee stack initialized
I: Unimplemented signal (signal: 54, status: 0)
I: Joined network successfully on reboot signal (Extended PAN ID: xxx, PAN ID: yyy)
I: tick 2046
I: tock 2112
I: tick 4047
I: tock 4132
I: tick 6048
I: tock 6159
I: tick 8050
I: tock 8187
I: tick 10051
I: tock 10185
I: tick 12052
I: tock 12218
I: tick 14054
I: tock 14247
[...]
I: tick 26062
I: tock 26262
I: tick 28064
I: tock 28444
I: tick 30065
I: tock 30157
When the device is not connected to a network the time delta is on the order of a few milliseconds (presumably some sort of scheduling interval). Also, if I use ZB_SCHEDULE_APP_CALLBACK instead of zb_buf_get_out_delayed_func, a very short interval is seen as well. But when it's connected,
This app isn't using sleepy mode or any other sort of explicit power save feature.
Where is this latency coming from, and what can I do about it?