<?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>aws_iot sample: the purpose of delayed connect_work</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/113965/aws_iot-sample-the-purpose-of-delayed-connect_work</link><description>I have been trying the aws_iot sample in nRF Connect SDK v2.7.0 for build target nrf7002dk/nrf5340/cpuapp, in which connect_work is scheduled with a 5 second delay in the function on_net_event_l4_connected. What is the purpose of this delay? 
 As a test</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Wed, 21 Aug 2024 12:35:12 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/113965/aws_iot-sample-the-purpose-of-delayed-connect_work" /><item><title>RE: aws_iot sample: the purpose of delayed connect_work</title><link>https://devzone.nordicsemi.com/thread/499206?ContentTypeID=1</link><pubDate>Wed, 21 Aug 2024 12:35:12 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:608daf27-9d94-4d60-afa3-7117d3c2dcc5</guid><dc:creator>H&amp;#229;kon Alseth</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
[quote user="Johan Kopra"]At first I tried concatenating&amp;nbsp;NET_EVENT_IPV4_DHCP_BOUND to the L4_EVENT_MASK and adding a corresponding log message to l4_event_handler, but did not see evidence of&amp;nbsp;NET_EVENT_IPV4_DHCP_BOUND events. Eventually I was able to see&amp;nbsp;&lt;span&gt;NET_EVENT_IPV4_DHCP_BOUND events by using a separate callback for them.&lt;/span&gt;[/quote]
&lt;p&gt;My apologies, I should have given an example here, but I&amp;#39;m glad to hear that you found a solution to this.&lt;/p&gt;
[quote user="Johan Kopra"]With a little testing&amp;nbsp;I have observed up to a 10 second delay between the l4-connected event and&amp;nbsp;NET_EVENT_IPV4_DHCP_BOUND event. AWS connection seems to work when attempted after&amp;nbsp;NET_EVENT_IPV4_DHCP_BOUND without adding a delay.[/quote]
&lt;p&gt;Glad to hear that the initial connection is more stable now. This is an interesting find. I tested a couple of networks, and got both of these events almost simultaneously (milliseconds apart). I&amp;#39;ll report your findings back to the team responsible for these samples.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Kind regards,&lt;/p&gt;
&lt;p&gt;Håkon&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: aws_iot sample: the purpose of delayed connect_work</title><link>https://devzone.nordicsemi.com/thread/499149?ContentTypeID=1</link><pubDate>Wed, 21 Aug 2024 07:07:59 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d42677ca-4343-4dc4-8854-9fd0df5f4e37</guid><dc:creator>Johan Kopra</dc:creator><description>&lt;p&gt;At first I tried concatenating&amp;nbsp;NET_EVENT_IPV4_DHCP_BOUND to the L4_EVENT_MASK and adding a corresponding log message to l4_event_handler, but did not see evidence of&amp;nbsp;NET_EVENT_IPV4_DHCP_BOUND events. Eventually I was able to see&amp;nbsp;&lt;span&gt;NET_EVENT_IPV4_DHCP_BOUND events by using a separate callback for them. With a little testing&amp;nbsp;I have observed up to a 10 second delay between the l4-connected event and&amp;nbsp;NET_EVENT_IPV4_DHCP_BOUND event. AWS connection seems to work when attempted after&amp;nbsp;NET_EVENT_IPV4_DHCP_BOUND without adding a delay.&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: aws_iot sample: the purpose of delayed connect_work</title><link>https://devzone.nordicsemi.com/thread/499062?ContentTypeID=1</link><pubDate>Tue, 20 Aug 2024 12:58:18 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:7ceb93b1-786c-4354-8c2d-81275da54040</guid><dc:creator>H&amp;#229;kon Alseth</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Sorry, I see the same issue as you wrt. the DNS events. If you have several IPs being reported from your router, you cannot use the DNS event.&lt;/p&gt;
&lt;p&gt;Could you try the DHCP bound event and see if this works better on your end? at my end, this arrives approx. the same time as the l4-connected event, but the connection procedure&amp;nbsp;always goes through here. Your timing might be different.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Kind regards,&lt;/p&gt;
&lt;p&gt;Håkon&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: aws_iot sample: the purpose of delayed connect_work</title><link>https://devzone.nordicsemi.com/thread/498750?ContentTypeID=1</link><pubDate>Mon, 19 Aug 2024 06:07:55 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:faa129a9-bec9-42d2-97cc-6dfee0567960</guid><dc:creator>Johan Kopra</dc:creator><description>&lt;p&gt;I have&amp;nbsp;observed&amp;nbsp;NET_EVENT_DNS_SERVER_ADD events, but not&amp;nbsp;NET_EVENT_IPV4_DHCP_BOUND events. By inspecting zephyr/subsys/net/lib/dns/resolve.c i found out that the NET_EVENT_DNS_SERVER_ADD event comes with a pointer to struct sockaddr, let&amp;#39;s call this dns_server. It seems that if aws_iot_connect is attempted after just&amp;nbsp;&lt;span&gt;NET_EVENT_DNS_SERVER_ADD with dns_server -&amp;gt; sa_family == AF_INET6, then aws_iot_connect fails with&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;[00:00:22.392,333] &amp;lt;err&amp;gt; mqtt_helper: mqtt_connect, error: -116&lt;br /&gt;[00:00:22.401,123] &amp;lt;err&amp;gt; aws_iot: mqtt_helper_connect, error: -116&lt;br /&gt;[00:00:22.410,186] &amp;lt;err&amp;gt; aws_iot_sample: aws_iot_connect, error: -116&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;and if aws_iot_connect is attempted after just&amp;nbsp;NET_EVENT_DNS_SERVER_ADD with dns_server -&amp;gt; sa_family == AF_INET, then aws_iot_connect fails with&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;[00:00:23.339,416] &amp;lt;err&amp;gt; mqtt_helper: getaddrinfo() failed, error -11&lt;br /&gt;[00:00:23.348,724] &amp;lt;err&amp;gt; aws_iot: mqtt_helper_connect, error: 11&lt;br /&gt;[00:00:23.357,604] &amp;lt;err&amp;gt; aws_iot_sample: aws_iot_connect, error: 11&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Calling&amp;nbsp;aws_iot_connect is successful if it is attempted only after both kinds of NET_EVENT_DNS_SERVER_ADD events have been generated.&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: aws_iot sample: the purpose of delayed connect_work</title><link>https://devzone.nordicsemi.com/thread/498433?ContentTypeID=1</link><pubDate>Thu, 15 Aug 2024 10:38:11 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:b9310626-c673-44b4-a40f-60b10d9b71f2</guid><dc:creator>H&amp;#229;kon Alseth</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;By default, the sample waits for the layer 4 to be connected, but this does not mean that you&amp;#39;ve gotten everything you need (DNS, DHCP etc).&lt;/p&gt;
&lt;p&gt;Instead of having a delay, you can wait for the DNS to be added for instance, or when the DHCP is bound, like done here in the TWT sample:&lt;/p&gt;
&lt;p&gt;&lt;a href="https://github.com/nrfconnect/sdk-nrf/blob/v2.6.1/samples/wifi/twt/src/main.c#L408-L410"&gt;https://github.com/nrfconnect/sdk-nrf/blob/v2.6.1/samples/wifi/twt/src/main.c#L408-L410&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;The events you can listen to is listed here:&lt;/p&gt;
&lt;p&gt;&lt;a href="https://github.com/nrfconnect/sdk-zephyr/blob/v3.5.99-ncs1/include/zephyr/net/net_event.h"&gt;https://github.com/nrfconnect/sdk-zephyr/blob/v3.5.99-ncs1/include/zephyr/net/net_event.h&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Kind regards,&lt;/p&gt;
&lt;p&gt;Håkon&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>