<?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>Wi-Fi Auto Reconnect</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/121055/wi-fi-auto-reconnect</link><description>Does Zephyr support automatic reconnection of the Wi-Fi if a connection is lost? I can&amp;#39;t find any documentation on this, or code examples. It seems like every example connects to WiFi on boot, and doesn&amp;#39;t have any provision to retry it if the connection</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Fri, 02 May 2025 16:44:15 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/121055/wi-fi-auto-reconnect" /><item><title>RE: Wi-Fi Auto Reconnect</title><link>https://devzone.nordicsemi.com/thread/533779?ContentTypeID=1</link><pubDate>Fri, 02 May 2025 16:44:15 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:819c92c6-a740-4629-b08c-abbc3a157720</guid><dc:creator>Saxman58</dc:creator><description>&lt;p&gt;Hi Elfving,&lt;/p&gt;
&lt;p&gt;You are right, the automatic reconnect works even if I remove the code to reconnect from the disconnect event handler.&lt;/p&gt;
&lt;p&gt;I saw the automatic connect feature but assumed it didn&amp;#39;t apply to our code for two reasons.&amp;nbsp; First, we are not using the Wi-Fi Credentials library and connect using an SSID and password that we manage separately.&amp;nbsp; And second, the documentation talks about automatic connection which I interpreted as just the initial connection, not reconnection after a loss of connection.&lt;/p&gt;
&lt;p&gt;I guess that explains why I couldn&amp;#39;t find any real discussion about this.&amp;nbsp; It just works, without any extra code, and even if you connect more directly without the credentials library.&lt;/p&gt;
&lt;p&gt;Thanks,&lt;/p&gt;
&lt;p&gt;Glen&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Wi-Fi Auto Reconnect</title><link>https://devzone.nordicsemi.com/thread/533431?ContentTypeID=1</link><pubDate>Tue, 29 Apr 2025 14:01:13 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:bb03633e-c623-4130-bef1-8f0ad0c0a40a</guid><dc:creator>Elfving</dc:creator><description>&lt;p&gt;Hi Glen,&lt;/p&gt;
&lt;p&gt;There should be support for automatic connections, &lt;a href="https://docs.nordicsemi.com/bundle/ncs-latest/page/nrf/libraries/networking/wifi_mgmt_ext.html"&gt;you can for instance see here&lt;/a&gt;. Though adding this yourself using the disconnect event also works. Glad to hear that you are also&amp;nbsp;using a workqueue&amp;nbsp;for this.&lt;/p&gt;
&lt;p&gt;Did you see any issues with reconnection before adding this though? Or when using any default samples. I agree that I can&amp;#39;t seem to find anything public regarding best-practices for this.&lt;/p&gt;
&lt;p&gt;Regards,&lt;/p&gt;
&lt;p&gt;Elfving&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Wi-Fi Auto Reconnect</title><link>https://devzone.nordicsemi.com/thread/533300?ContentTypeID=1</link><pubDate>Tue, 29 Apr 2025 06:40:24 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:6d2238bc-ab21-4c55-8a08-df8d562d3f70</guid><dc:creator>Saxman58</dc:creator><description>&lt;p&gt;I ended up just calling wifi_connect() from the disconnect event handler to try to reconnect after any unintentional disconnects.&amp;nbsp; I tested it by turning the Wi-Fi Access Point (hub) off for a while, and it seems to work well.&amp;nbsp; To move the wifi_connect() call out of the interrupt context, it is run from the work queue:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;static void process_reconnect(struct k_work *work) {
    wifi_connect();
}
K_WORK_DEFINE(reconnect_work, process_reconnect);
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;This is added to the work queue from the interrupt disconnect event handler:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;static void handle_wifi_disconnect_result(struct net_mgmt_event_callback *cb)
{
	const struct wifi_status *status =
		(const struct wifi_status *) cb-&amp;gt;info;

	if (context.disconnect_requested) {
		LOG_INF(&amp;quot;Disconnection request %s (%d)&amp;quot;,
			 status-&amp;gt;status ? &amp;quot;failed&amp;quot; : &amp;quot;done&amp;quot;,
					status-&amp;gt;status);
		context.disconnect_requested = false;
	} else {
		LOG_INF(&amp;quot;Disconnected&amp;quot;);
		context.connected = false;
		wifi_active_off();
        // Since disconnect was not requested, try to reconnect
        k_work_submit(&amp;amp;reconnect_work);
	}

	cmd_wifi_status();
}
&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>