<?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>End Device reports bad behavior on low power device</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/67379/end-device-reports-bad-behavior-on-low-power-device</link><description>Hi, 
 We have been working with an end device based on nRF52840 with nRF5_SDK_for_Thread_and_Zigbee_v4.0.0_dc7186b, Softdevice and FreeRTOS. 
 We built 2 configurations for this device: normal and low power. The last one contains some considerations like</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Wed, 04 Nov 2020 18:39:34 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/67379/end-device-reports-bad-behavior-on-low-power-device" /><item><title>RE: End Device reports bad behavior on low power device</title><link>https://devzone.nordicsemi.com/thread/278515?ContentTypeID=1</link><pubDate>Wed, 04 Nov 2020 18:39:34 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:71f9f93e-6bf7-463c-be7b-dabc9a1dbc51</guid><dc:creator>Marjeris Romero</dc:creator><description>&lt;p&gt;Hi&amp;nbsp;&lt;a href="https://devzone.nordicsemi.com/members/sjf"&gt;sjf&lt;/a&gt;,&lt;/p&gt;
[quote userid="87203" url="~/f/nordic-q-a/67379/end-device-reports-bad-behavior-on-low-power-device/278492#278492"]Just to be sure: Sleepy End Devices are set by just calling&amp;nbsp;zb_set_rx_on_when_idle(ZB_FALSE)[/quote]
&lt;p&gt;Yes, and you need to enable the End Device role in the application as well of course.&lt;/p&gt;
&lt;p&gt;But sleep functionality is not implemented for OS-based applications applications in the nRF5 SDK for Thread &amp;amp; Zigbee. This is why the multisensor example with FreeRTOS is categorized as &amp;quot;experimental&amp;quot;, and the CAN_SLEEP event are overwritten in main.c to being empty.&lt;br /&gt; You may be better off migrating to NCS if you don&amp;#39;t want to go through all the work on implementing sleepy functionality yourself for RTOS in nRF5 SDK.&lt;br /&gt;&lt;br /&gt;The ZB_COMMON_SIGNAL_CAN_SLEEP signal will be sent to the application when RxOnOnWhenIdle is set to &amp;#39;False&amp;#39; anytime the scheduler finds out that the application can go to sleep, read more about this in &amp;#39;&lt;a href="https://infocenter.nordicsemi.com/topic/sdk_tz_v4.1.0/using_zigbee__z_c_l.html?cp=7_3_3_4_4#power_saving_zed"&gt;Power saving for ZED&lt;/a&gt;&amp;#39;. You need to handle this signal to suspend any tasks and then go to sleep. zb_sleep_now() must be called from the ZB_COMMON_SIGNAL_CAN_SLEEP signal.&lt;/p&gt;
&lt;p&gt;Then you need to implement your own sleep routine, as the OSIF implementation in nRF5 SDK is not written for OS implementations.&lt;br /&gt;&lt;br /&gt;If you call zb_sleep_now() the stack will call zb_nrf52_sleep(). See external/zboss/osif/zb_nrf52_common.c this function is implemented as a weak function, so you can implement it in your application without changing common components. &lt;br /&gt;&lt;br /&gt;You also need to have some signaling structures to wake up the ZBOSS task whenever is needed (as is done in NCS with zigbee_event_poll()). &lt;br /&gt;&lt;br /&gt;Comparing the implementation of zb_nrf52_sleep() on the nRF5 SDK to the zigbee sleep function on NCS &lt;span class="pl-en"&gt;zb_osif_sleep&lt;/span&gt;() we see some differences and similarities, but there are probably several things you will need to modify to make the sleep implementation in nRF5 SDK RTOS-friendly. Some points to consider:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;zb_nrf52_priph_disable() This function disables all Zigbee stack related peripherals (except the radio which is handle by the stack), but may not be correct when sharing resources with other components that may want to use these peripherals even if the radio is sleeping.&lt;/li&gt;
&lt;li&gt;zb_nrf52_sched_sleep(sleep_tmo):sets an alarm inside the radio driver so the MCU is woken up by the RTC clock after an specific timeout value. This not valid for RTOS solutions. You should lock the RTOS thread for a specific amount of time and give the context down to the idle task which implements sleep functionality.&lt;/li&gt;
&lt;li&gt;zb_osif_wait_for_event(): ZBOSS task should not be woken up upon every single event. Not needed if RTOS is in use.&lt;/li&gt;
&lt;li&gt;time_slept_ms = zb_nrf52_get_time_slept(): every implementation of zb_nrf52_sleep_has to return the actual time (in milliseconds), so the zboss timer may be fast-forward to the correct time value.&lt;/li&gt;
&lt;li&gt;zb_nrf52_priph_enable(): need to enable everything that was previously disabled.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Marjeris&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;EDIT:&lt;/strong&gt; I edited my answer to be clear that you have to call zb_sleep_now() from the ZB_COMMON_SIGNAL_CAN_SLEEP signal. It&amp;#39;s not allowed to call zboss API from other thread that the one running main loop iteration. The signal handler is the ZBOSS context (called from the main loop iteration). &lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: End Device reports bad behavior on low power device</title><link>https://devzone.nordicsemi.com/thread/278492?ContentTypeID=1</link><pubDate>Wed, 04 Nov 2020 15:19:26 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:18fe2ea9-829e-427b-9c45-f382a046290c</guid><dc:creator>sjf</dc:creator><description>&lt;p&gt;Hi Marte,&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;I will try to do some measurements with Power Profiler as well as changing the source code with your recommendations.&lt;/p&gt;
&lt;p&gt;. Just to be sure: Sleepy End Devices are set by just calling&amp;nbsp;zb_set_rx_on_when_idle(ZB_FALSE).&lt;/p&gt;
&lt;p&gt;. You suggest to implement&amp;nbsp;&lt;span&gt;ZB_COMMON_SIGNAL_CAN_SLEEP. I&amp;#39;m thinking on implement&amp;nbsp;a modified&amp;nbsp;version of&amp;nbsp;zb_osif_sleep() on&amp;nbsp;&lt;/span&gt;configPRE_SLEEP_PROCESSING and&amp;nbsp;configPOST_SLEEP_PROCESSING.&lt;/p&gt;
&lt;p&gt;Do you agree with this? Any other recommedation?&lt;/p&gt;
&lt;p&gt;Regards&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: End Device reports bad behavior on low power device</title><link>https://devzone.nordicsemi.com/thread/278443?ContentTypeID=1</link><pubDate>Wed, 04 Nov 2020 12:55:54 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a2ef818c-83c4-48bb-8ba8-e9cfabde90e7</guid><dc:creator>Marte Myrvold</dc:creator><description>&lt;p&gt;Hi Santiago,&lt;/p&gt;
&lt;p&gt;I apologize for the late response.&lt;/p&gt;
&lt;p&gt;The reason for the delay in attribute reporting might be caused by the fact that ZBOSS, or the Zigbee stack, is not aware of the fact that FreeRTOS sleeps, and as such, it will take longer time.&lt;/p&gt;
&lt;p&gt;Please note that the examples with FreeRTOS in the Zigbee SDK are experimental, and are therefore not power optimized. However, I got some tips from the Zigbee team on how to implement low power with FreeRTOS and Zigbee:&lt;/p&gt;
&lt;p&gt;In order to suspend the task, while the timer is disabled, you have to implement ZB_COMMON_SIGNAL_CAN_SLEEP ZBOSS signal handler. Otherwise, you are simply leveraging only the ZBOSS IDLE state, not the ZBOSS SLEEP state (more information about those states can be found &lt;a href="https://infocenter.nordicsemi.com/topic/sdk_tz_v4.1.0/zigbee_application_reference_component.html?cp=7_3_3_5_1#zarco_sleep"&gt;here&lt;/a&gt;).&lt;/p&gt;
&lt;p&gt;For some guidance and ideas how to implement this, it might be good to look at the OSIF implementation in NCS:&lt;/p&gt;
&lt;p&gt;- &lt;a href="https://github.com/nrfconnect/sdk-nrf/blob/v1.4.0/subsys/zigbee/common/zigbee_helpers.c#L443"&gt;CAN_SLEEP handler&lt;/a&gt;&lt;br /&gt; - &lt;a href="https://github.com/nrfconnect/sdk-nrf/blob/v1.4.0/subsys/zigbee/osif/zb_nrf_pwr_mgmt.c#L30"&gt;sleep routine&lt;/a&gt; (will be called by zb_sleep_now())&lt;br /&gt; - &lt;a href="https://github.com/nrfconnect/sdk-nrf/blob/v1.4.0/subsys/zigbee/osif/zb_nrf_platform.c#L538"&gt;Poll function&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;The signalling mechanism is used to wake up ZBOSS task by other tasks that wants to send something over Zigbee, as well as to wake up the ZBOSS task earlier than the sleep period, passed to the sleep function as an argument.&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Marte&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: End Device reports bad behavior on low power device</title><link>https://devzone.nordicsemi.com/thread/278426?ContentTypeID=1</link><pubDate>Wed, 04 Nov 2020 11:44:05 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:3a2e373b-9dc2-44d1-873d-0e0c07a24686</guid><dc:creator>sjf</dc:creator><description>&lt;p&gt;Hi Marte,&lt;/p&gt;
&lt;p&gt;Is there any comment on this?&lt;/p&gt;
&lt;p&gt;We need to get a response to get it work as soon as possible.&lt;/p&gt;
&lt;p&gt;Regards,&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: End Device reports bad behavior on low power device</title><link>https://devzone.nordicsemi.com/thread/277477?ContentTypeID=1</link><pubDate>Wed, 28 Oct 2020 19:15:41 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:b9144e35-e6df-44c4-ba80-6806e30dc7a0</guid><dc:creator>sjf</dc:creator><description>&lt;p&gt;Hi Marte, thanks for your explanation.&lt;/p&gt;
&lt;p&gt;I understand that if configUSE_TICKLESS_IDLE mode is set, then Timer3 will be stopped every time we get into deep sleep mode.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;I&amp;#39;ve checked that there is a non documented function called&amp;nbsp;zb_zcl_adjust_reporting_timer(). Maybe it is related to this issue...&lt;/p&gt;
&lt;p&gt;How can we avoid stopping Timer3 when going to sleep?&lt;/p&gt;
&lt;p&gt;regards,&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: End Device reports bad behavior on low power device</title><link>https://devzone.nordicsemi.com/thread/277423?ContentTypeID=1</link><pubDate>Wed, 28 Oct 2020 14:29:11 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:b06230a2-11d3-43c5-adb2-f091848f63df</guid><dc:creator>Marte Myrvold</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;I got a reply from the Zigbee team now. They&amp;#39;re not sure what the problem is, but they would start with these steps:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Make sure that sleepy behavior is enabled for the end device&lt;/li&gt;
&lt;li&gt;Get rid of calls to nrf_802154 radio API - Sleepy End Device manages radio state and with sleepy behavior enabled, the radio is in standby when not used by the end device&lt;/li&gt;
&lt;li&gt;ZBOSS uses TIMER3 to keep time - make sure that its configuration is not changed&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;S&lt;span&gt;ome more information about the application would be helpful, as well as the traffic dump of the End Device reporting.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Best regards,&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Marte&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: End Device reports bad behavior on low power device</title><link>https://devzone.nordicsemi.com/thread/277353?ContentTypeID=1</link><pubDate>Wed, 28 Oct 2020 10:42:59 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:bb98ab16-2ce5-4da5-afbc-11250f093930</guid><dc:creator>Marte Myrvold</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;No, sorry, I&amp;#39;m still waiting for a response from the Zigbee team. They&amp;#39;re quite busy right now, so it might take some time, but I&amp;#39;ve asked them if there are any updates dates on this case.&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Marte&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: End Device reports bad behavior on low power device</title><link>https://devzone.nordicsemi.com/thread/277189?ContentTypeID=1</link><pubDate>Tue, 27 Oct 2020 15:17:18 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:42c3aed8-b832-44ae-b6d1-a830b987114b</guid><dc:creator>sjf</dc:creator><description>&lt;p&gt;Thanks Marte,&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Is there any update on this?&lt;/p&gt;
&lt;p&gt;Regards,&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: End Device reports bad behavior on low power device</title><link>https://devzone.nordicsemi.com/thread/276395?ContentTypeID=1</link><pubDate>Thu, 22 Oct 2020 09:48:25 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:6bd4dafa-3afd-4402-87ad-e9ba33ee414f</guid><dc:creator>Marte Myrvold</dc:creator><description>&lt;p&gt;Hi Santiago,&lt;/p&gt;
&lt;p&gt;I have asked our Zigbee team internally and will come back to you when I get a response from them.&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Marte&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: End Device reports bad behavior on low power device</title><link>https://devzone.nordicsemi.com/thread/275957?ContentTypeID=1</link><pubDate>Tue, 20 Oct 2020 13:39:58 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:dc975711-808f-4f96-97b9-0d1376d26fad</guid><dc:creator>sjf</dc:creator><description>&lt;p&gt;Hi Marte,&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;The attribute reporting takes more than max time (60 seconds) and seems to increase on further reports (not random)&lt;/p&gt;
&lt;p&gt;The low power mode is implemented with&amp;nbsp;the changes detailed above.&amp;nbsp;Also we are implementing this in the Zigbee Task (FreeRTOS):&lt;/p&gt;
&lt;pre&gt;zb_void_t zb_osif_go_idle(zb_void_t)
{
    /* Intentionally empty implementation */
#ifdef LOW_POWER
    nrf_802154_sleep_if_idle();
    /*do not set long timeout if joining*/
    if(ZIGBEE_STATE_JOINING != zigbee.state)
    {
      zigbee.cmd_queue_timeout = ZIGBEE_QUEUE_LONG_TIMEOUT;
    }
#endif
}&lt;br /&gt;&lt;br /&gt;And also calling nrf_802154_sleep_if_idle() function on ZB_COMMON_SIGNAL_CAN_SLEEP signal handler.&lt;br /&gt;&lt;br /&gt;Regards,&lt;br /&gt;&lt;br /&gt;Santiago&lt;/pre&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: End Device reports bad behavior on low power device</title><link>https://devzone.nordicsemi.com/thread/275938?ContentTypeID=1</link><pubDate>Tue, 20 Oct 2020 12:59:01 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:cfce7ada-f896-4c3b-9e35-079903a53b34</guid><dc:creator>Marte Myrvold</dc:creator><description>&lt;p&gt;Hi Santiago,&lt;/p&gt;
&lt;p&gt;Is the problem that attribute reporting takes longer than 60 seconds when in low power mode? Is the time it takes&amp;nbsp;the same every time or is it a random delay, so the time it takes changes every time?&lt;/p&gt;
&lt;p&gt;How are you implementing the low power mode on the end-device?&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Marte&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>