<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://devzone.nordicsemi.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>High latency on Zigbee router</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/86071/high-latency-on-zigbee-router</link><description>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</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Fri, 25 Mar 2022 08:23:13 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/86071/high-latency-on-zigbee-router" /><item><title>RE: High latency on Zigbee router</title><link>https://devzone.nordicsemi.com/thread/359925?ContentTypeID=1</link><pubDate>Fri, 25 Mar 2022 08:23:13 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:dceaee1b-bdbd-47f4-8291-cd77736acb68</guid><dc:creator>Edvin</dc:creator><description>&lt;p&gt;Hello,&lt;/p&gt;
&lt;p&gt;After talking with our Zigbee team, and they said that you should indeed not use the zb_buf_get_out_delayed_func(). You should rather use zb_buf_get_out_delayed(). They said that it should reduce the delay.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;The reason for the delay in the first place is that whenever the Zboss stack decides that it has nothing to do, it may suspend itself for a given amount of time. Using the ZBOSS API doesn&amp;#39;t directly resume the ZBOSS thread. If I understood them correctly, using zb_buf_get_out_delayed() (instead of zb_buf_get_out_delayed_func()) will still be thread safe, as the _func() variant also is), but it should also resume/wake up the ZBOSS thread, which should significantly improve the latency.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Note that at times of high ZBOSS activity, you still may see some delay.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;They also mentioned that because of what that is explained above, a zigbee application may actually run slower when there is less traffic (less events to wake up the ZBOSS stack).&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;BR,&lt;/p&gt;
&lt;p&gt;Edvin&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: High latency on Zigbee router</title><link>https://devzone.nordicsemi.com/thread/359681?ContentTypeID=1</link><pubDate>Wed, 23 Mar 2022 22:10:14 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:345f74b2-b3ba-45d3-87ce-28ffdbca0b40</guid><dc:creator>mytzyiay</dc:creator><description>&lt;p&gt;Are the samples wrong to be calling&amp;nbsp;zb_buf_get_out_delayed_func() from outside the Zigbee thread?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: High latency on Zigbee router</title><link>https://devzone.nordicsemi.com/thread/359676?ContentTypeID=1</link><pubDate>Wed, 23 Mar 2022 21:34:41 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:ca510b4b-dad9-4b96-bb35-d4ad7c26d598</guid><dc:creator>Edvin</dc:creator><description>&lt;p&gt;Hello,&lt;/p&gt;
&lt;p&gt;Sorry for the late reply. I also handle the other ticket that you have ongoing. I see that it is the same application, and seeing as you sort of figured this out, is this subject still something you need us to look into?&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;BR,&lt;/p&gt;
&lt;p&gt;Edvin&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: High latency on Zigbee router</title><link>https://devzone.nordicsemi.com/thread/359263?ContentTypeID=1</link><pubDate>Tue, 22 Mar 2022 04:52:54 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:2b001b8c-5ebd-42b5-b5ae-b1917ba3392e</guid><dc:creator>mytzyiay</dc:creator><description>&lt;p&gt;BTW, I did see in&amp;nbsp;&lt;a href="https://developer.nordicsemi.com/nRF_Connect_SDK/doc/zboss/3.5.2.0/zigbee_prog_principles.html"&gt;https://developer.nordicsemi.com/nRF_Connect_SDK/doc/zboss/3.5.2.0/zigbee_prog_principles.html&lt;/a&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&amp;gt;&amp;nbsp;&lt;span&gt;Except for the scheduler API, the Zigbee stack API is not thread-safe. This means that calls to the Zigbee API must be invoked through scheduler callbacks or from the same thread that runs the scheduler loop. In NCS, the scheduler API is overloaded by functions that make it interrupt- and thread-safe. These functions can be found in&amp;nbsp;&lt;/span&gt;&lt;code&gt;nrf/subsys/zigbee/osif/zb_nrf_platform.h&lt;/code&gt;&lt;span&gt;.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;which suggests that maybe I shouldn&amp;#39;t be trying to allocate ZB bufs from the main app thread.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;But I see&amp;nbsp;zb_buf_get_out_delayed_ext() being called from e.g. non-Zigbee worker threads in light_switch&amp;#39;s button_handler(), and even in the timer&amp;nbsp;callback light_switch_button_handler(), so I assumed it was safe to do.&amp;nbsp; Is that correct?&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;If I change my code to do this, the latency problem vanishes:&lt;/span&gt;&lt;/p&gt;
&lt;pre&gt;&lt;span&gt;static void tock_cb2(zb_uint8_t bufid)&lt;br /&gt;{&lt;br /&gt; LOG_INF(&amp;quot;tock %lld&amp;quot;, k_uptime_get());&lt;br /&gt; if (bufid)&lt;br /&gt; zb_buf_free(bufid);&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;static void tock_cb1(zb_uint8_t bufid)&lt;br /&gt;{&lt;br /&gt; zb_buf_get_out_delayed_func(tock_cb2);&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;/* at the end of main() */&lt;br /&gt; while (1) {&lt;br /&gt; LOG_INF(&amp;quot;tick %lld&amp;quot;, k_uptime_get());&lt;br /&gt; zb_ret_t error_code = ZB_SCHEDULE_APP_CALLBACK(tock_cb1, 0);&lt;br /&gt; if (error_code != RET_OK)&lt;br /&gt; LOG_ERR(&amp;quot;error %d&amp;quot;, error_code);&lt;br /&gt; k_sleep(K_SECONDS(2));&lt;br /&gt; }&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;/pre&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>