Quantcast
Channel: Forums - Recent Threads
Viewing all articles
Browse latest Browse all 262198

CC3220S-LAUNCHXL: STA mode automatic re-connect

$
0
0

Part Number:CC3220S-LAUNCHXL

Dear Forum,

My device is operating in STA mode and is successfully connected to the network. All of a sudden the router turns off and then after some time the router turns back on. During the off period the cc3220 loses connection and when the router is back on the cc3220 doesn't reconnect automatically. What methods exist to make the cc3220 try reconnecting to router automatically?

I tried putting the following code in SimpleLinkWlanEventHandler function:

void SimpleLinkWlanEventHandler(SlWlanEvent_t *pArgs)
{
    _i16 status;

    switch (pArgs->Id) {
        case SL_WLAN_EVENT_CONNECT:
            deviceConnected = true;
            break;

        case SL_WLAN_EVENT_DISCONNECT:
            deviceConnected = false;
            UART_PRINT("[SimpleLinkWlanEventHandler] WLAN has disconnected!!!\n\r");

            // check if there are any stored profiles, if there are no stored profiles then switch to AP mode but if there are stored profiles then try re-connecting periodically
            status = checkProfiles();
            if (status < 0)
            {
                status = setAPmode();
                UART_PRINT("[SimpleLinkWlanEventHandler] Set AP mode status is %d\n\r", status);
            }
            else if (status >= 0)
                while (deviceConnected != true)
                {

                    // Set auto connect policy
                    status = sl_WlanPolicySet(SL_WLAN_POLICY_CONNECTION, SL_WLAN_CONNECTION_POLICY(1, 0, 0, 0), NULL, 0);
                    if (status < 0) {
                        UART_PRINT("[SimpleLinkWlanEventHandler] Error %d Failed to set connection policy to auto connect\n\r", status);
                        while (1);
                    }

                    // Enable DHCP client
                    status = sl_NetCfgSet(SL_NETCFG_IPV4_STA_ADDR_MODE, SL_NETCFG_ADDR_DHCP, 0, 0);
                    if (status < 0) {
                        UART_PRINT("[SimpleLinkWlanEventHandler] Error %d Could not enable DHCP client\n\r", status);
                        while (1);
                    }

                    // Restart the network processor
                    sl_Stop(200);

                    status = sl_Start(0, 0, 0);
                    UART_PRINT("[SimpleLinkWlanEventHandler] sl_Start code is %d\n\r", status);

                    usleep(500000);
                    usleep(500000);
                    usleep(500000);
                    usleep(500000);
                    usleep(500000);
                    usleep(500000);
                    usleep(500000);
                    usleep(500000);
                    usleep(500000);
                    usleep(500000);
                    usleep(500000);
                    usleep(500000);
                    usleep(500000);
                    usleep(500000);
                    usleep(500000);
                    usleep(500000);
                    usleep(500000);
                    usleep(500000);
                    usleep(500000);
                    usleep(500000);
                    usleep(500000);
                    usleep(500000);
                    usleep(500000);
                    usleep(500000);
                }
            break;

        default:
            break;
    }
}

When the router turns off the device periodically re-starts in STA mode and my assumption is that it should try connecting to the stored profile. But that doesn't seem to happen. Can you advise?

Thanks,

David


Viewing all articles
Browse latest Browse all 262198

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>