<?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>LWM2M Client - Power Management/callback functions</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/94904/lwm2m-client---power-management-callback-functions</link><description>Good day 
 
 I have noticed that when using a callback functions certain limitations exist. For example, adding functions to the callback function will run into an error or a timeout. Firstly, I wanted to ask what the limitations when using a callback</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Wed, 21 Dec 2022 13:11:10 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/94904/lwm2m-client---power-management-callback-functions" /><item><title>RE: LWM2M Client - Power Management/callback functions</title><link>https://devzone.nordicsemi.com/thread/401720?ContentTypeID=1</link><pubDate>Wed, 21 Dec 2022 13:11:10 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:cc86402a-8862-4459-8b6b-d538dedcc88a</guid><dc:creator>dejans</dc:creator><description>&lt;p&gt;Hi,&lt;br /&gt;&lt;br /&gt;Could you specify your NCS and modem firmware version?&lt;br /&gt;&lt;br /&gt;Could you describe in more detail what was expected to happen in the first (&amp;quot;working&amp;quot;) and second (&amp;quot;not working&amp;quot;) case? What actually happened? Could you elaborate on &amp;quot;modem is used again&amp;quot;? When the function was not working, what actually happened? Do you have any log or modem trace?&lt;br /&gt;&lt;br /&gt;I have noticed that you have 4 open and 5 closed curly braces in non-working part of the code.&lt;br /&gt;&lt;br /&gt;Best regards,&lt;br /&gt;Dejan&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: LWM2M Client - Power Management/callback functions</title><link>https://devzone.nordicsemi.com/thread/401632?ContentTypeID=1</link><pubDate>Wed, 21 Dec 2022 06:30:13 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:dcc24b15-2fae-43f5-a21a-534aec7842ef</guid><dc:creator>Hkhan7861</dc:creator><description>&lt;p&gt;Good day&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;I will have to contact them to make sure.&amp;nbsp; However, XRAI works well.&amp;nbsp; Have you any idea how I can get in functional for the callback function?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: LWM2M Client - Power Management/callback functions</title><link>https://devzone.nordicsemi.com/thread/401542?ContentTypeID=1</link><pubDate>Tue, 20 Dec 2022 14:23:30 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:663c9d32-2e40-479c-bbe8-f6dfee6f60cf</guid><dc:creator>dejans</dc:creator><description>&lt;p&gt;Hi,&lt;br /&gt;&lt;br /&gt;Which network operator do you have? Does it support AS RAI?&lt;br /&gt;&lt;br /&gt;Best regards,&lt;br /&gt;Dejan&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: LWM2M Client - Power Management/callback functions</title><link>https://devzone.nordicsemi.com/thread/401528?ContentTypeID=1</link><pubDate>Tue, 20 Dec 2022 13:40:44 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:ed233373-caf0-4d15-9c8e-a067f584224d</guid><dc:creator>Hkhan7861</dc:creator><description>&lt;p&gt;Good day&lt;/p&gt;
&lt;p&gt;yes I do use the latest firmware.&amp;nbsp; When I use&lt;/p&gt;
&lt;div&gt;
&lt;div&gt;&lt;span&gt;CONFIG_LWM2M_CLIENT_UTILS_RAI&lt;/span&gt;&lt;span&gt;=y in the prj file I do not see RAI being used.&amp;nbsp; I have to wait 60s before entering edrx mode.&amp;nbsp; Is there more I need to do to ensure it works as&amp;nbsp;&lt;/span&gt;required?&lt;/div&gt;
&lt;/div&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: LWM2M Client - Power Management/callback functions</title><link>https://devzone.nordicsemi.com/thread/401513?ContentTypeID=1</link><pubDate>Tue, 20 Dec 2022 12:54:53 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:883b9053-16f5-483c-b75e-bc05421ec09b</guid><dc:creator>dejans</dc:creator><description>&lt;p&gt;Hi,&lt;br /&gt;&lt;br /&gt;Which modem firmware version and SDK do you use?&lt;br /&gt;&lt;br /&gt;If you use modem firmware v1.3.x and NCS v2.2.0, you could have a look at&amp;nbsp;&lt;a href="https://developer.nordicsemi.com/nRF_Connect_SDK/doc/2.2.0/nrf/libraries/networking/lwm2m_client_utils.html#additional-configuration"&gt;additional configuration&lt;/a&gt;&amp;nbsp;in&amp;nbsp;&lt;a href="https://developer.nordicsemi.com/nRF_Connect_SDK/doc/2.2.0/nrf/libraries/networking/lwm2m_client_utils.html#lwm2m-client-utils"&gt;LwM2M Client Utils&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;Best regards,&lt;br /&gt;Dejan&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: LWM2M Client - Power Management/callback functions</title><link>https://devzone.nordicsemi.com/thread/401410?ContentTypeID=1</link><pubDate>Tue, 20 Dec 2022 06:54:25 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:cd327643-6615-4c31-bc5b-5d5a6e51cc2c</guid><dc:creator>Hkhan7861</dc:creator><description>&lt;p&gt;Hello&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Its from my understanding, that the command can be used dynamically (I may be wring) so I&amp;#39;m using it whenever the an event is triggered.&amp;nbsp; This way when an update is triggered the command is sent.&amp;nbsp; This part works fine.&lt;pre class="ui-code" data-mode="text"&gt;tatic void rd_client_event(struct lwm2m_ctx *client, enum lwm2m_rd_client_event client_event)
{
	k_mutex_lock(&amp;amp;lte_mutex, K_FOREVER);

	if (client_state == LTE_OFFLINE &amp;amp;&amp;amp;
	    client_event != LWM2M_RD_CLIENT_EVENT_ENGINE_SUSPENDED) {
		LOG_DBG(&amp;quot;Drop network event %d at LTE offline state&amp;quot;, client_event);
		k_mutex_unlock(&amp;amp;lte_mutex);
		return;
	}
   
	UART_multiple_handler();
	RAI_init();
	
	switch (client_event) {
	case LWM2M_RD_CLIENT_EVENT_NONE:
		/* do nothing */
		k_mutex_unlock(&amp;amp;lte_mutex);
		break;

	case LWM2M_RD_CLIENT_EVENT_BOOTSTRAP_REG_FAILURE:
		LOG_DBG(&amp;quot;Bootstrap registration failure!&amp;quot;);
		state_trigger_and_unlock(NETWORK_ERROR);
		break;

	case LWM2M_RD_CLIENT_EVENT_BOOTSTRAP_REG_COMPLETE:
		LOG_DBG(&amp;quot;Bootstrap registration complete&amp;quot;);
		update_session_lifetime = true;
		state_trigger_and_unlock(BOOTSTRAP);
		break;

	case LWM2M_RD_CLIENT_EVENT_BOOTSTRAP_TRANSFER_COMPLETE:
		LOG_DBG(&amp;quot;Bootstrap transfer complete&amp;quot;);
		k_mutex_unlock(&amp;amp;lte_mutex);
		break;

	case LWM2M_RD_CLIENT_EVENT_REGISTRATION_FAILURE:
		LOG_WRN(&amp;quot;Registration failure!&amp;quot;);
		state_trigger_and_unlock(NETWORK_ERROR);
		break;

	case LWM2M_RD_CLIENT_EVENT_REGISTRATION_COMPLETE:
		LOG_DBG(&amp;quot;Registration complete&amp;quot;);
		state_trigger_and_unlock(CONNECTED);
		RAI_init();
		break;

	case LWM2M_RD_CLIENT_EVENT_REG_TIMEOUT:
		LOG_DBG(&amp;quot;Registration update failure!&amp;quot;);
		state_trigger_and_unlock(NETWORK_ERROR);
		break;

	case LWM2M_RD_CLIENT_EVENT_REG_UPDATE_COMPLETE:
	    
		LOG_DBG(&amp;quot;Registration update complete&amp;quot;);
		state_trigger_and_unlock(CONNECTED);
		RAI_init();
		break;

	case LWM2M_RD_CLIENT_EVENT_DEREGISTER_FAILURE:
		LOG_DBG(&amp;quot;Deregister failure!&amp;quot;);
		reconnect = true;
		state_trigger_and_unlock(NETWORK_ERROR);
		break;

	case LWM2M_RD_CLIENT_EVENT_DISCONNECT:
		LOG_DBG(&amp;quot;Disconnected&amp;quot;);
		state_set_and_unlock(START);
		break;

	case LWM2M_RD_CLIENT_EVENT_QUEUE_MODE_RX_OFF:
		LOG_DBG(&amp;quot;Queue mode RX window closed&amp;quot;);
		if (IS_ENABLED(CONFIG_LWM2M_CLIENT_UTILS_RAI)) {
			lwm2m_rai_last();
		}
		k_mutex_unlock(&amp;amp;lte_mutex);
		break;

	case LWM2M_RD_CLIENT_EVENT_ENGINE_SUSPENDED:
		LOG_DBG(&amp;quot;LwM2M engine suspended&amp;quot;);
		k_mutex_unlock(&amp;amp;lte_mutex);
		break;

	case LWM2M_RD_CLIENT_EVENT_NETWORK_ERROR:
		LOG_ERR(&amp;quot;LwM2M engine reported a network error.&amp;quot;);
		reconnect = true;
		state_trigger_and_unlock(NETWORK_ERROR);
		break;
	}
}

void RAI_init()
{
	// RAI Setup
	//****************************//
	static char response[200] = { 0 };
	response[0] = &amp;#39;\0&amp;#39;;

	 k_sleep(K_MSEC(100));
	nrf_modem_at_cmd(response, sizeof(response), &amp;quot;AT%%XRAI=3&amp;quot;);
	k_sleep(K_MSEC(100));
	
	LOG_WRN(&amp;quot;RAI RESPONSE: %d&amp;quot;,response );
    // // *****************************


}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;However, when I do the same thing at the end of the callback function i don&amp;#39;t get the same result.&amp;nbsp; It seems as though the modem is used immediately after the indication is sent (Some code was redacted)&lt;pre class="ui-code" data-mode="text"&gt;static void *read_cb(uint16_t obj_inst_id, uint16_t res_id, uint16_t res_inst_id, size_t *data_len)
{
	
	uart_enable();
		int c, d;
   
 


	LOG_WRN(&amp;quot;IN CUSTOM READ_CB&amp;quot;);
	LOG_WRN(&amp;quot;obj_inst_id: %d&amp;quot;, obj_inst_id);
	if (obj_inst_id != 1) {
		*data_len = 0;
		return NULL;
	}

	

	int err = lwm2m_engine_set_float(&amp;quot;3300/1/5700&amp;quot;, &amp;amp;sensor_value);
	
	

	LOG_WRN(&amp;quot;sensor value string: %d&amp;quot;, err);
	LOG_WRN(&amp;quot;sensor value string: %s&amp;quot;, numC);
	LOG_WRN(&amp;quot;sensor value double: %f&amp;quot;, sensor_value);
	

	

	
	


	if (err) {
		LOG_ERR(&amp;quot;Could not set custom sensor value: %d&amp;quot;, err);
		*data_len = 0;
		return NULL;
	}
	*data_len = sizeof(sensor_value);
	
	RAI_init();
	return &amp;amp;sensor_value;

   
	
		
	}
	else if(ret&amp;lt;0)
	{
		sensor_value = 0;
		 RAI_init();
		return &amp;amp;sensor_value;
		

	}
	
	
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Do you have any suggestions of where to add the XRAI command to get the same result with the callback function?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: LWM2M Client - Power Management/callback functions</title><link>https://devzone.nordicsemi.com/thread/401288?ContentTypeID=1</link><pubDate>Mon, 19 Dec 2022 13:30:38 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:db38f2d8-d8b0-4305-a316-715ee7ba2fbf</guid><dc:creator>dejans</dc:creator><description>&lt;p&gt;Hi Hassan,&lt;br /&gt;&lt;br /&gt;Could you show code samples of both working and non-working case when you use XRAI?&amp;nbsp;&lt;br /&gt;&lt;br /&gt;Best regards,&lt;br /&gt;Dejan&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: LWM2M Client - Power Management/callback functions</title><link>https://devzone.nordicsemi.com/thread/401248?ContentTypeID=1</link><pubDate>Mon, 19 Dec 2022 12:25:31 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c5147a46-7882-4103-a86d-c2410238d853</guid><dc:creator>Hkhan7861</dc:creator><description>&lt;p&gt;Thank you for this! will definitely attempt using this.&amp;nbsp; Another issue I am having as well is&amp;nbsp; RAI. Using the XRAI commands around my code has been working fine. however, it looks like after the callback function is used, the modem is used again and therefore putting the command at the end of this function doesn&amp;#39;t work.&amp;nbsp; Have you any suggestions for this?&lt;/p&gt;
&lt;p&gt;Kind regards,&lt;/p&gt;
&lt;p&gt;Hassan&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: LWM2M Client - Power Management/callback functions</title><link>https://devzone.nordicsemi.com/thread/401215?ContentTypeID=1</link><pubDate>Mon, 19 Dec 2022 10:57:14 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a1c87cd6-6012-4c8d-8f7a-1ab9f139f8e1</guid><dc:creator>dejans</dc:creator><description>&lt;p&gt;Hi Hassan,&lt;br /&gt;&lt;br /&gt;There is a configuration option&amp;nbsp;&lt;a href="https://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/kconfig/index.html#CONFIG_LWM2M_ENGINE_DEFAULT_LIFETIME"&gt;CONFIG_LWM2M_ENGINE_DEFAULT_LIFETIME&lt;/a&gt;&amp;nbsp;which specifies how often client sends &amp;quot;I am alive&amp;quot; messages to the server. If the value of this option is set to more than 60 seconds, this may eventually cause timeout. You can have a look at the note in&amp;nbsp;&lt;a href="https://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/nrf/samples/nrf9160/lwm2m_client/sample_description.html#additional-configuration"&gt;additional configuration&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;Best regards,&lt;br /&gt;Dejan&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: LWM2M Client - Power Management/callback functions</title><link>https://devzone.nordicsemi.com/thread/401171?ContentTypeID=1</link><pubDate>Mon, 19 Dec 2022 06:48:15 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:4b0cf22c-f9bf-47b3-a6eb-b3e256de69e1</guid><dc:creator>Hkhan7861</dc:creator><description>&lt;p&gt;Good day Dejan&lt;/p&gt;
&lt;p&gt;I am using the latest toolchain and am modifying the lwm2m client sample. I am using a temperature sensor via a UART to receive information using low power measures and publish onto a lwm2m servers.&amp;nbsp; As a result, I need to turn on and off the UART when a callback is initiated via the server.&amp;nbsp; Initially I had a problem whereby the UART wouldn&amp;#39;t switch off even after &lt;span&gt;pm_device_action_run(uart_dev,&amp;nbsp;PM_DEVICE_ACTION_SUSPEND was used.&amp;nbsp; However now, the UART doesnt switch on in time and there callback will result in a timeout server side.&amp;nbsp; Ive noticed that adding long functions to this callback (or even a delay) will result in a timeout.&amp;nbsp; Which makes me wonder if this callback has limitations&amp;nbsp;i&amp;#39;m not aware of.&amp;nbsp; Thank you in advance!&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Kind regards,&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Hassan&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: LWM2M Client - Power Management/callback functions</title><link>https://devzone.nordicsemi.com/thread/400877?ContentTypeID=1</link><pubDate>Thu, 15 Dec 2022 14:22:18 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:8b6c69ab-3edf-4af0-afec-8a6a64a1610b</guid><dc:creator>dejans</dc:creator><description>&lt;p&gt;Hi Hassan,&lt;br /&gt;&lt;br /&gt;I would need additional information.&lt;br /&gt;&lt;br /&gt;Which NCS version do you use? Do you use lwm2m client sample? Have you modified the sample?&lt;/p&gt;
[quote user=""]I have noticed that when using a callback functions certain limitations exist.&amp;nbsp; For example, adding functions to the callback function will run into an error or a timeout.&amp;nbsp; Firstly, I wanted to ask what the limitations when using a callback function(specifically lwm2m ).[/quote]
&lt;p&gt;Could you elaborate on this? What are you trying to achieve? Could you provide an example?&lt;br /&gt;&lt;br /&gt;&lt;/p&gt;
[quote user=""]I was able to switch the UART on but when I&amp;nbsp;use&amp;nbsp;pm_device_action_run(uart_dev,&amp;nbsp;PM_DEVICE_ACTION_SUSPEND at the end of the function, the UART does not switch off despite the function returning a 0.&amp;nbsp; What could be the cause of this?[/quote]
&lt;p&gt;Could you specify more precisely what is currently working and what is not working? Does RESUME work, but SUSPEND not? Could you describe/show where and how you use pm_device_action_run() in your code? What is expected behavior and what actually happens?&lt;br /&gt;&lt;br /&gt;Best regards,&lt;br /&gt;Dejan&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>