<?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>Avoid automatic connection to Wi-Fi</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/102238/avoid-automatic-connection-to-wi-fi</link><description>Hi, 
 I&amp;#39;m developing an IoT device using nRF7002 with nRF5340. Now, I&amp;#39;m programming the firmware with nRF Connect SDK v2.4.99 and I test it in a nRF7002DK. 
 I provision Wi-Fi credentials via Bluetooth thanks to Wi-Fi Provisioning Service and nRF Wi-Fi</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Tue, 01 Aug 2023 09:13:48 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/102238/avoid-automatic-connection-to-wi-fi" /><item><title>RE: Avoid automatic connection to Wi-Fi</title><link>https://devzone.nordicsemi.com/thread/439200?ContentTypeID=1</link><pubDate>Tue, 01 Aug 2023 09:13:48 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:e5cfea5c-a323-4f6d-9112-7c7aafe3ad11</guid><dc:creator>ACuenca</dc:creator><description>&lt;p&gt;Finally, I have found the way to disconnect just after the automatic connection. It&amp;#39;s as simple as this:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;struct net_if *iface = net_if_get_default();
int err = net_mgmt(NET_REQUEST_WIFI_DISCONNECT, iface, NULL, 0);&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;This solves my problem.&lt;/p&gt;
&lt;p&gt;Thanks for your help Simon,&lt;/p&gt;
&lt;p&gt;Alejandro Cuenca&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Avoid automatic connection to Wi-Fi</title><link>https://devzone.nordicsemi.com/thread/438984?ContentTypeID=1</link><pubDate>Mon, 31 Jul 2023 11:13:38 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:1d7180ed-4293-427c-a384-1fbcb6102d1a</guid><dc:creator>Simonr</dc:creator><description>&lt;p&gt;Hi Alejandro&lt;/p&gt;
&lt;p&gt;Then when this button is pressed, you do want to connect to the Wi-Fi network, so this sounds like what the application is doing, you just have to make sure it disconnects and goes to low power mode after this message is sent.&lt;/p&gt;
&lt;p&gt;The fact that you can&amp;#39;t disconnect sounds like a missing config or something as this should be the way to disconnect. Please check out the &lt;a href="https://github.com/nrfconnect/sdk-nrf/blob/v2.4.0/samples/wifi/sta/src/main.c#L288-L290"&gt;STA sample&lt;/a&gt; in our SDK where it&amp;#39;s used.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Simon&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Avoid automatic connection to Wi-Fi</title><link>https://devzone.nordicsemi.com/thread/438574?ContentTypeID=1</link><pubDate>Thu, 27 Jul 2023 14:46:18 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c73179bf-adf8-43d1-af87-55a2738d4b70</guid><dc:creator>ACuenca</dc:creator><description>&lt;p&gt;Hi Simon,&lt;/p&gt;
&lt;p&gt;First of all thank you for your time. Some clarifications and doubts about your reply:&lt;/p&gt;
&lt;p&gt;&lt;em&gt;&amp;quot;By the sentence &amp;quot;my app should decide all the time when it connects to wi-fi and when it disconnects&amp;quot; what exactly do you mean?&amp;quot;&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;My IoT device will have a button, and the idea is that every time the button is pressed, the device will wake up, connect to Wi-Fi and send a message via MQTT to the broker, then it will disconnect and return to sleep mode. We expect that the button will be pressed once or twice a day, so most of the time the device will be in low power mode.&lt;/p&gt;
&lt;p&gt;&amp;quot;&lt;em&gt;In your application, can&amp;#39;t you just disconnect it from the Wi-Fi device whenever it&amp;#39;s not doing any Wi-Fi operations to reduce current consumption?&lt;/em&gt;&amp;quot;&lt;/p&gt;
&lt;p&gt;I tried to disconnect but I couldn&amp;#39;t. I think I&amp;#39;m missing something. In previous versions of the application I could connect and disconnect &amp;quot;manually&amp;quot; using this &lt;a href="https://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/zephyr/connectivity/networking/api/net_mgmt.html#c.net_mgmt"&gt;macro&lt;/a&gt;:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;// connect to Wi-Fi network
int err = net_mgmt(NET_REQUEST_WIFI_CONNECT, iface, &amp;amp;cnx_params, sizeof(struct wifi_connect_req_params));

// disconnect from Wi-Fi network
err = net_mgmt(NET_REQUEST_WIFI_DISCONNECT, iface, &amp;amp;cnx_params, sizeof(struct wifi_connect_req_params));&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;The problem now is that the application cannot recognize the variables &amp;quot;iface&amp;quot; and &amp;quot;cnx_params&amp;quot;, since the connection is automatic and I haven&amp;#39;t previously declared the variables, so, when I try to disconnect, the macro net_mgmt() fails.&lt;/p&gt;
&lt;p&gt;Is there another way to disconnect from Wi-Fi? Maybe, It could also be helpful a method to get the current iface and the current connection parameters for the variable &amp;quot;cnx_params&amp;quot;.&lt;/p&gt;
&lt;p&gt;&amp;quot;&lt;em&gt;I think you need to add some more cases to the wifi_mgmt_event_handler()&lt;/em&gt;&amp;quot;&lt;/p&gt;
&lt;p&gt;My&amp;nbsp;&lt;em&gt;wifi_mgmt_event_handler()&amp;nbsp;&lt;/em&gt;is like that:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="batchfile"&gt;void wifi_events_handler(struct net_mgmt_event_callback *cb, uint32_t mgmt_event, struct net_if *iface)
{ 
    // check connection event
    switch (mgmt_event)
    {
        case NET_EVENT_L4_CONNECTED:
            LOG_INF(&amp;quot;Connected to a Wi-Fi Network&amp;quot;);
            k_sem_give(&amp;amp;wifi_connected_sem);
            break;
        
        case NET_EVENT_L4_DISCONNECTED:
            LOG_INF(&amp;quot;Disconnected from Wi-Fi Network&amp;quot;);
            break;
        
        default:
            break;
    }
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Any suggestions to improve it would be welcome.&lt;/p&gt;
&lt;p&gt;Thanks,&lt;/p&gt;
&lt;p&gt;Alejandro Cuenca&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Avoid automatic connection to Wi-Fi</title><link>https://devzone.nordicsemi.com/thread/438538?ContentTypeID=1</link><pubDate>Thu, 27 Jul 2023 13:27:39 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:aae76206-ade6-4498-afd9-26285e032a5f</guid><dc:creator>Simonr</dc:creator><description>&lt;p&gt;Hi Alejandro&lt;/p&gt;
&lt;p&gt;Yes, I think the provisioner app is designed to immediately connect to the device you provision it for. In your application, can&amp;#39;t you just disconnect it from the Wi-Fi device whenever it&amp;#39;s not doing any Wi-Fi operations to reduce current consumption? By the sentence &amp;quot;&lt;em&gt;my app should decide all the time when it connects to wi-fi and when it disconnects&lt;/em&gt;&amp;quot; what exactly do you mean? To me this doesn&amp;#39;t sound like it will be very low-power as it will have to wake up to &amp;quot;decide&amp;quot; over and over again. I think you need to add some more cases to the wifi_mgmt_event_handler() function for example, but you might also need to make changes to the provisioner app to specifically just connect or disconnect from an access point, but that would be on the provisioner app for your phone side.&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Simon&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>