<?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>How to schedule events and tasks at particular time intervals</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/70711/how-to-schedule-events-and-tasks-at-particular-time-intervals</link><description>Hi Dev Team, 
 I am running a program that takes in sensor data at 10 min intervals and publishes it to my server through MQTT at 1hr intervals. 
 I have different threads running for different events (Taking data from sensor and sending data outside</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Fri, 30 Apr 2021 11:22:15 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/70711/how-to-schedule-events-and-tasks-at-particular-time-intervals" /><item><title>RE: How to schedule events and tasks at particular time intervals</title><link>https://devzone.nordicsemi.com/thread/307647?ContentTypeID=1</link><pubDate>Fri, 30 Apr 2021 11:22:15 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:2b406742-e4ff-4759-979e-ff72ffa7259c</guid><dc:creator>Carl Richard</dc:creator><description>&lt;p&gt;No problem! And that makes sense.&lt;br /&gt;&lt;br /&gt;Best regards,&lt;br /&gt;Carl Richard&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to schedule events and tasks at particular time intervals</title><link>https://devzone.nordicsemi.com/thread/307646?ContentTypeID=1</link><pubDate>Fri, 30 Apr 2021 11:21:21 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:45b572e6-b9d2-406f-ba40-5d1a34e1c334</guid><dc:creator>Adeel</dc:creator><description>&lt;p&gt;Hi Carl,&lt;/p&gt;
&lt;p&gt;Thanks. This explains why I was also getting the getaddrinfo error. Thanks for the explanation.&lt;/p&gt;
&lt;p&gt;Regards,&lt;/p&gt;
&lt;p&gt;Adeel.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to schedule events and tasks at particular time intervals</title><link>https://devzone.nordicsemi.com/thread/307608?ContentTypeID=1</link><pubDate>Fri, 30 Apr 2021 08:04:30 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d63ca9aa-4087-471f-b5bc-78a97c2d14e5</guid><dc:creator>Carl Richard</dc:creator><description>&lt;p&gt;Hello!&lt;br /&gt;&lt;br /&gt;Great! PCO stands for Protocol Configuration Options and is used for transferring various information relevant for the connection, for example DNS. The NB-IoT spec requires ePCO, but some networks still only supports regular PCO which is why this option is available. There is some more information in &lt;a href="https://devzone.nordicsemi.com/f/nordic-q-a/47486/nrf9160-nb-iot-dns-failure"&gt;this thread&lt;/a&gt;. It should not affect your application in any way!&lt;br /&gt;&lt;br /&gt;Best regards,&lt;br /&gt;Carl Richard&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to schedule events and tasks at particular time intervals</title><link>https://devzone.nordicsemi.com/thread/307423?ContentTypeID=1</link><pubDate>Thu, 29 Apr 2021 10:27:26 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:65134e6c-0799-44f2-b090-a24fc1343e81</guid><dc:creator>Adeel</dc:creator><description>&lt;p&gt;Hi Carl,&lt;/p&gt;
&lt;p&gt;Yes I was getting the NB-IoT connection.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;I was able to get past the error using :&amp;nbsp;CONFIG_LTE_LEGACY_PCO_MODE=y&lt;/p&gt;
&lt;p&gt;I wanted to understand what is the NB-IoT PCO mode and how is it different from the normal NB-IoT ?&lt;/p&gt;
&lt;p&gt;Regards,&lt;/p&gt;
&lt;p&gt;Adeel.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to schedule events and tasks at particular time intervals</title><link>https://devzone.nordicsemi.com/thread/307283?ContentTypeID=1</link><pubDate>Wed, 28 Apr 2021 13:48:22 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:1d6355b8-6ff5-42cd-a518-d76cf01175d6</guid><dc:creator>Carl Richard</dc:creator><description>&lt;p&gt;Hello again, Adeel!&lt;br /&gt;&lt;br /&gt;Are you certain that the device manages to get a connection? When changing between NB-IoT and LTE-M you need to make sure that you SIM supports both, or change to another SIM.&lt;br /&gt;&lt;br /&gt;Secondly, when changing the project configuration I suggest that you follow the steps described in the &amp;quot;&lt;a href="https://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/nrf/gs_modifying.html#configuring-your-application"&gt;Configuring your application&lt;/a&gt;&amp;quot;-documentation. Namely, changing the prj.conf or using the configuration tool in SES. By changing autoconf.h directly there may be some dependencies of the configuration that are lost.&lt;br /&gt;&lt;br /&gt;Best regards,&lt;br /&gt;Carl Richard&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to schedule events and tasks at particular time intervals</title><link>https://devzone.nordicsemi.com/thread/307208?ContentTypeID=1</link><pubDate>Wed, 28 Apr 2021 10:47:56 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:794e641f-597e-4ae5-a86d-208d53f63b4b</guid><dc:creator>Adeel</dc:creator><description>&lt;p&gt;Hi Carl,&lt;/p&gt;
&lt;p&gt;I just had another question to ask regarding the above thread.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;I am having a pretty poor reception using :&amp;nbsp;CONFIG_LTE_NETWORK_MODE_LTE_M 1&lt;/p&gt;
&lt;p&gt;So, I tried to change to NB-IoT using :&amp;nbsp;CONFIG_LTE_NETWORK_MODE_NBIOT to improve my RSRP.&lt;/p&gt;
&lt;p&gt;I did it through the autoconf.h file.&lt;/p&gt;
&lt;p&gt;The NB-IoT is configured properly as well and I can see it when I do :&amp;nbsp;&lt;span class="tx"&gt;&lt;/span&gt;&lt;/p&gt;
&lt;pre&gt;AT%XSYSTEMMODE?&lt;/pre&gt;
&lt;pre class="ctrl-char CR"&gt;&lt;/pre&gt;
&lt;pre class="ctrl-char LF"&gt;&lt;/pre&gt;
&lt;pre&gt;%XSYSTEMMODE: 0,1,0,0&lt;/pre&gt;
&lt;pre class="ctrl-char CR"&gt;&lt;/pre&gt;
&lt;pre class="ctrl-char LF"&gt;&lt;/pre&gt;
&lt;pre&gt;OK&lt;/pre&gt;
&lt;pre class="ctrl-char CR"&gt;&lt;/pre&gt;
&lt;pre class="ctrl-char LF"&gt;&lt;/pre&gt;
&lt;p&gt;This helps me understand that I have configured for NB-IoT.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;I try to run my application with NB-IoT config but I see that the date_time handler does not give me the right time.&lt;/p&gt;
&lt;p&gt;&lt;img alt=" " src="https://devzone.nordicsemi.com/resized-image/__size/640x480/__key/communityserver-discussions-components-files/4/NB_2D00_IoT-issue-for-date_5F00_time-delay.PNG" /&gt;&lt;/p&gt;
&lt;p&gt;It works perfectly with the :&amp;nbsp;&lt;span&gt;CONFIG_LTE_NETWORK_MODE_LTE_M&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Do I need to do anything else in order to set up my device with NB-IoT config ?&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;P:S : I am in Germany and NB-Iot works well here.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Regards,&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Adeel.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to schedule events and tasks at particular time intervals</title><link>https://devzone.nordicsemi.com/thread/303682?ContentTypeID=1</link><pubDate>Thu, 08 Apr 2021 08:52:50 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:4ffe013d-1542-4316-9234-bcc4fc1e1169</guid><dc:creator>Adeel</dc:creator><description>&lt;p&gt;Hi Carl,&lt;/p&gt;
&lt;p&gt;Thanks for this lead. Got it working&amp;nbsp;by using&amp;nbsp;the blocking semaphore &lt;span class="emoticon" data-url="https://devzone.nordicsemi.com/cfs-file/__key/system/emoji/1f642.svg" title="Slight smile"&gt;&amp;#x1f642;&lt;/span&gt;.&lt;/p&gt;
&lt;p&gt;Regards,&lt;/p&gt;
&lt;p&gt;Adeel.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to schedule events and tasks at particular time intervals</title><link>https://devzone.nordicsemi.com/thread/303552?ContentTypeID=1</link><pubDate>Wed, 07 Apr 2021 14:10:45 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:4c05d6c1-af04-4620-b9de-823e23e5a09c</guid><dc:creator>Carl Richard</dc:creator><description>&lt;p&gt;Hi, Adeel!&lt;br /&gt;&lt;br /&gt;You&amp;#39;re getting an error when calling date_time_now that indicates that a valid time aren&amp;#39;t available yet. Instead of busy_wait I suggest that you use a blocking semaphore that is released by a handler for date_time_update_async callbacks. This way you can ensure that a valid time is available when calling date_time_now.&lt;br /&gt;&lt;br /&gt;You can how I have done this &lt;a href="https://github.com/crfosse/ncs_projects/blob/779ccbf1a58bb2ecef45f2aa1e2c100698e0f034/cellular/mqtt_work/src/main.c#L638"&gt;here&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;Best regards,&lt;br /&gt;Carl Richard&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to schedule events and tasks at particular time intervals</title><link>https://devzone.nordicsemi.com/thread/303430?ContentTypeID=1</link><pubDate>Wed, 07 Apr 2021 10:06:22 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:2eb205f3-b44b-4fa0-958f-4c9d049f2f0c</guid><dc:creator>Adeel</dc:creator><description>&lt;p&gt;Hi Carl,&lt;/p&gt;
&lt;p&gt;I had a question regarding this ticket. The above code that you sent worked perfectly for NCS v1.3.0 .&lt;/p&gt;
&lt;p&gt;I did this in NCS v1.3.0 and this works perfectly.&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;	modem_configure();  //to get LTE connection

    date_time_update(); //To get current time

    printk(&amp;quot;Busy-wait %u s\n&amp;quot;, BUSY_WAIT_S);
    k_busy_wait(BUSY_WAIT_S * USEC_PER_SEC);  //2 seconds delay

    int64_t curr_time;     //above code
    date_time_now(&amp;amp;curr_time);

    int64_t curr_time_s = curr_time / 1000;            //Convert to seconds
    struct tm *readable_time = gmtime(&amp;amp;(curr_time_s)); //Get human readable time with time.h
    printk(&amp;quot;Curr min: %d\n&amp;quot;, readable_time-&amp;gt;tm_min);
    printk(&amp;quot;Curr sec: %d\n&amp;quot;, readable_time-&amp;gt;tm_sec);

    int32_t delay = 3600 - (readable_time-&amp;gt;tm_min) * 60 - readable_time-&amp;gt;tm_sec;
    int32_t real_time = delay + 600;
    printk(&amp;quot;Delay is: %d\n&amp;quot;, delay);
    printk(&amp;quot;Real Delay is: %d\n&amp;quot;, real_time);&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;img alt=" " src="https://devzone.nordicsemi.com/resized-image/__size/640x480/__key/communityserver-discussions-components-files/4/Date_5F00_time-no-issue-in-v1.3.0.PNG" /&gt;&lt;/p&gt;
&lt;p&gt;The above output is correct.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;But when I try to do the same in NCS v1.4.2 or NCS v1.5.0, it doesn&amp;#39;t work the way I want it to.&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;	modem_configure(); //for LTE connection

    date_time_update_async(NULL);  //to get current time

    printk(&amp;quot;Busy-wait %u s\n&amp;quot;, BUSY_WAIT_S);
    k_busy_wait(BUSY_WAIT_S * USEC_PER_SEC);  //2 seconds delay

    int64_t curr_time;   //above code
    date_time_now(&amp;amp;curr_time);

    int64_t curr_time_s = curr_time / 1000;            //Convert to seconds
    struct tm *readable_time = gmtime(&amp;amp;(curr_time_s)); //Get human readable time with time.h
    printk(&amp;quot;Curr min: %d\n&amp;quot;, readable_time-&amp;gt;tm_min);
    printk(&amp;quot;Curr sec: %d\n&amp;quot;, readable_time-&amp;gt;tm_sec);

    int32_t delay = 3600 - (readable_time-&amp;gt;tm_min) * 60 - readable_time-&amp;gt;tm_sec;
    int32_t real_time = delay + 300;
    printk(&amp;quot;Delay is: %d\n&amp;quot;, delay);
    printk(&amp;quot;Real Delay is: %d\n&amp;quot;, real_time);
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;The only change is using : date_time_update_async(NULL) as date_time_update() is not supported in higher NCS versions.&lt;/p&gt;
&lt;p&gt;I get the following in NCS v1.5.0 :&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;img alt=" " src="https://devzone.nordicsemi.com/resized-image/__size/640x480/__key/communityserver-discussions-components-files/4/Date_5F00_time-issue-for-delay.PNG" /&gt;&lt;/p&gt;
&lt;p&gt;This output is incorrect (the Curr min and Curr sec are wrong).&lt;/p&gt;
&lt;p&gt;Could you try to reproduce this in NCS v1.5.0 and verify ?&lt;/p&gt;
&lt;p&gt;Regards,&lt;/p&gt;
&lt;p&gt;Adeel.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to schedule events and tasks at particular time intervals</title><link>https://devzone.nordicsemi.com/thread/291126?ContentTypeID=1</link><pubDate>Mon, 25 Jan 2021 17:20:15 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c86dd3f8-0d43-455e-baf5-2719a9137cbe</guid><dc:creator>Adeel</dc:creator><description>&lt;p&gt;Hi Carl,&lt;/p&gt;
&lt;p&gt;Yes, I understood the logic of calculating the delay and this is what I needed.&lt;/p&gt;
&lt;p&gt;Thanks a lot, got it working at my end through the delayed work queue :).&lt;/p&gt;
&lt;p&gt;Regards,&lt;/p&gt;
&lt;p&gt;Adeel.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to schedule events and tasks at particular time intervals</title><link>https://devzone.nordicsemi.com/thread/290713?ContentTypeID=1</link><pubDate>Fri, 22 Jan 2021 11:04:54 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a80ed075-dde5-4445-9c04-c7af4decb716</guid><dc:creator>Carl Richard</dc:creator><description>&lt;p&gt;Hi, Adeel!&lt;br /&gt;&lt;br /&gt;I suggest that you do the following procedure:&lt;br /&gt;1. Start up, connect and get current time&lt;br /&gt;2. Submit a delayed work item as described in the &lt;a href="https://docs.zephyrproject.org/1.9.0/kernel/threads/workqueues.html#submitting-a-delayed-work-item"&gt;documentation&lt;/a&gt;. You can calculate the delay by converting to human readable time (see the attached code) and calculating how much time is left to, for example, the next whole hour.&amp;nbsp;&lt;br /&gt;3. You can then avoid doing this again by starting a timer with the work item that makes the device transmit at the desired interval afterwards. Note that it may drift over time, so you should calibrate after a certain amount of uploads.&lt;br /&gt;&lt;br /&gt;Delay calculation code below:&lt;br /&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;//Get timestamp
int64_t curr_time;
date_time_now(&amp;amp;curr_time);

int64_t curr_time_s = curr_time/1000;   			//Convert to seconds
struct tm * readable_time = gmtime(&amp;amp;(curr_time_s)); //Get human readable time with time.h
LOG_INF(&amp;quot;Curr min: %d&amp;quot;, readable_time-&amp;gt;tm_min);
LOG_INF(&amp;quot;Curr sec: %d&amp;quot;, readable_time-&amp;gt;tm_sec);

int delay = 3600-(readable_time-&amp;gt;tm_min)*60 - readable_time-&amp;gt;tm_sec;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;This requires the time.h library. I hope it makes sense!&lt;br /&gt;&lt;br /&gt;Best regards,&lt;br /&gt;Carl Richard&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to schedule events and tasks at particular time intervals</title><link>https://devzone.nordicsemi.com/thread/290591?ContentTypeID=1</link><pubDate>Thu, 21 Jan 2021 16:20:45 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:70f168bd-9d62-4f9d-864e-5228f8df134d</guid><dc:creator>Adeel</dc:creator><description>&lt;p&gt;Hi Carl,&lt;/p&gt;
&lt;p&gt;I am using the date_time library to get the real time using the NTP server.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;img alt=" " src="https://devzone.nordicsemi.com/resized-image/__size/640x480/__key/communityserver-discussions-components-files/4/realtime.PNG" /&gt;&lt;/p&gt;
&lt;p&gt;Can you let me know how can I use this time to synchronize my next intervals.&lt;/p&gt;
&lt;p&gt;For example, my sample starts at 17:02:09 and I want my next interval of sending data over MQTT to occur at 18:00:00.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;For some reason, even if my application sample starts at 17:25:34 , still I want it to send the first data at 18:00:00 .&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Once I send the data for the first time, then I understand that the kernel timers can schedule it as per our timer allotment.&lt;/p&gt;
&lt;p&gt;How can I schedule events like this because the kernel timers are defined for fixed intervals ?&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Ex: k_timer_start(&amp;amp;my_connect_timer, K_SECONDS(60), K_SECONDS(3600)); // To send data every hour but the start of the sample and my intervals don&amp;#39;t match now. My sample starts at 17:25:34 and I need to synchronize it to send the first data at 18:00:00. Could you help me explain how tis could be done ?&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Regards,&lt;/p&gt;
&lt;p&gt;Adeel.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to schedule events and tasks at particular time intervals</title><link>https://devzone.nordicsemi.com/thread/290578?ContentTypeID=1</link><pubDate>Thu, 21 Jan 2021 15:13:08 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:e299715b-d2c3-4a6f-ba03-6a9ed035a6d7</guid><dc:creator>Carl Richard</dc:creator><description>&lt;p&gt;Hi, Adeel!&lt;br /&gt;&lt;br /&gt;You can sample the current time using the &lt;a href="https://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/nrf/include/date_time.html"&gt;Date-Time library&lt;/a&gt;&amp;nbsp;of NCS. If you do this on startup, after connecting to LTE, you can start a timer based on the time you get or alternatively submit a &lt;a href="https://docs.zephyrproject.org/1.9.0/kernel/threads/workqueues.html#delayed-work"&gt;delayed work item&lt;/a&gt;.&amp;nbsp;&lt;br /&gt;&lt;br /&gt;Best regards,&lt;br /&gt;Carl Richard&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to schedule events and tasks at particular time intervals</title><link>https://devzone.nordicsemi.com/thread/290494?ContentTypeID=1</link><pubDate>Thu, 21 Jan 2021 12:09:30 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f33778db-b79f-47ea-911f-5c2e7eb1b980</guid><dc:creator>Adeel</dc:creator><description>&lt;p&gt;Just an addition that I forgot, my hardware is a: Thingy91 v1.4.0 .&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>