This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

CC3220SF: Reconnect to WiFi AP after disconnection

Part Number: CC3220SF
Other Parts Discussed in Thread: UNIFLASH

Dear TI support,

I have read multiple threads here in forum and tried to understand how should be re-connection to WiFi Access Point from the CC322SF device done.

I see 2 options for manually controlled connection:

  1. call sl_WlanConnect(..) in the way described here: link (so trying to connect in some cycles)
  2. use sl_WlanGetNetworkList(..) to sniff if network I want to connect to is on and use sl_WlanConnect(..) once this is the case (found some info here)

Am I correct with what I have written above?
If yes, what is better (more correct) option?

Thank you for response!

Regards
Jiří

  • Hi Jiří,

    Unfortunately, your links were not added correctly. Can you add them again or copy and paste the source code you are referring to?

    Based just on your description, both options using sl_WlanConnect() sound reasonable.

    Best regards,

    Sarah

  • Hello Sarah,

    first link: https://e2e.ti.com/support/wireless-connectivity/wifi/f/968/t/783546

    Citation: 

    My suggestion for you is to not rely on autoconnect or fastconnect to reconnect you to an AP after a extended period of disconnection. I would do a check for the disconnection event, and if this occurs, then i would periodically try to reconnect to the AP using application code. This way you can devise your own scheme for how to handle this event.

    For example, you could do a telescoping approach and try to reconnect first every 10 seconds, then every minute, then every hour, depending how you want the device to go into power savings modes while waiting.

    Second link: https://e2e.ti.com/support/wireless-connectivity/wifi/f/968/p/926857/3426629?tisearch=e2e-sitesearch&keymatch=CC3220SF%2525252525252520reconnect#3426629

    No specific citation here, I have seen here mentioned function sl_WlanGetNetworkList(..), which I have checked in swru455h PDF.

    Regards
    Jiří

    PS: If both ways are possible I will prefer sniffing before trying to reconnect. I may have additional question to return values of mentioned functions, as unfortunately this is usually not well documented.

  • I will need to clarify something from documentation.

    In swru455h PDF is mentioned (page 79):

    sl_WlanGetNetworkList triggers a one-shot scan if there are no scan results in the system, or if the
    scan results which exist are old (aging is defined as 20 seconds if the scan policy is disabled, or twice
    the scan interval if the policy is enabled).
    An example of getting scan results from index 0 to 29:

    SlWlanNetworkEntry_t netEntries[30];
    _i16 resultsCount = sl_WlanGetNetworkList(0,30,&netEntries[0]);

    In SDK documentation is mentioned: 

    Warning 
    This command do not initiate any active scanning action

    So what shall be the correct procedure?
    Do I need to call some other function(s) before calling sl_WlanGetNetworkList(..)? Do I need to configure something?

  • Hi Jiří,

    If you expect to connect to the same AP, you can call sl_WlanConnect() without first checking a network list. But in your application, you should consider how to handle if the AP is not available: https://e2e.ti.com/support/wireless-connectivity/wifi/f/968/t/786576

    A one-shot scan means that is will not enable a scan policy, and there will be a delay while you run a scan before it returns the network list (assuming there are no recent results). The one-shot scan is an active scan with no connection purpose. The latest version of SWRU455 has cleared up the wording: https://www.ti.com/lit/swru455

    Best regards,

    Sarah

  • Hi Sarah,

    I have discussed with my IT colleague and we both agree, that the clean way how to connect to any WiFi AP is to check if the AP is on and try to connect to it after that. So "blind" call of sl_WlanConnect(..) is not what we will do.

    My procedure that is not working correctly:

    #define MAXIMUM_WLANS_TO_SCAN 30

    sl_Start(NULL, NULL, NULL); ... sl_WlanPolicySet(SL_WLAN_POLICY_CONNECTION, SL_WLAN_CONNECTION_POLICY(0, 1, 0, 0), NULL, 0); sl_WlanProfileDel(SL_WLAN_DEL_ALL_PROFILES); ... uint8_t u8L_intervalInSeconds = 20; sl_WlanPolicySet(SL_WLAN_POLICY_SCAN, SL_WLAN_SCAN_POLICY(1, 0), &u8L_intervalInSeconds, sizeof(u8L_intervalInSeconds)); ... SlWlanNetworkEntry_t objPL_networkEntries[MAXIMUM_WLANS_TO_SCAN]; int16_t s16L_networksCount; s16L_networksCount = sl_WlanGetNetworkList(0, MAXIMUM_WLANS_TO_SCAN, objPL_networkEntries); /* wait 20s if SL_ERROR_WLAN_GET_NETWORK_LIST_EAGAIN was returned before trying again */ /* search for SSID I want to connect to */

    Problems that occurred here are 2:

    • SSID was not found even it is clear that it is running
    • SSID was found even it is clear that it is shut down (this is permanent state, even after minutes of waiting, the SSID is always found by function sl_WlanGetNetworkList(..))

    Using my mobile phone and another CC3220SF device running in AP mode.

    Regards
    Jiří

    PS: Thank for the provided link. I didn't know that I have to wait for 2 different events to consider connection as valid.

  • I did some modifications and at least case 

    • SSID was not found even it is clear that it is running

    works ok now. I call now sl_WlanPolicySet(..) always just before calling sl_WlanGetNetworkList(..).

    Case

    • SSID was found even it is clear that it is shut down

    has still the same problem. So SSID is found even WiFi AP (mobile phone) is off.

  • Hi Jiří,

    The network list may be returning the results from the last scan. If you wait for the results to age (twice the time of the scan policy), do you see that SSID drop from the list?

    Best regards,

    Sarah

  • Hello Sarah,

    I have added delay 40s before call of sl_WlanGetNetworkList(..) in the code above.
    I am still getting the same results. So SSID which is off is in the list of found.

    I have even tried 60s with the same result.

    Regards

    Jiří

  • The previous problem with not found WiFi is happening again.
    I have only 2 running SSIDs. One is on before device is turned on
    and another one is turned on after device turned on. Result of sl_WlanGetNetworkList(..)
    shows only the SSID that was on before device has started.

    Jiří

    PS: using TI CC32xx SDK v3.20.0.6

  • Hi Jiří,

    Can you share your code snippet where you are setting the scan policy and getting the network list? I also suggest flashing the latest servicepack and testing that.

    Best regards,

    Sarah

  • Hi Sarah,

    by calling wifiSta_isNetworkActive(..) with SSID name as parameter, I expect to get info (true / false) if the SSID is found nearby.

    /**
     * @brief Enable/disable WiFi scanning with defined interval.
     * @param b_state Turn On/Off scanning
     * @param u8L_intervalInSeconds
     * @note Seems to be that function sl_WlanPolicySet(..) must be called shortly
     * before sl_WlanGetNetworkList(..) is called to obtain results of scan
     * e2e.ti.com/.../930380
     */
    static void wifiScanning(bool b_state, uint8_t u8L_intervalInSeconds)
    {
        /* minimum defined by TI documentation */
        if (u8L_intervalInSeconds < 10)
        {
            u8L_intervalInSeconds = 10;
            ASSERT_ALWAYS();
        }
        if (b_state == true)
        {
            /* enable and immediately trigger WLAN scan */
            if (sl_WlanPolicySet(
                SL_WLAN_POLICY_SCAN,
                SL_WLAN_SCAN_POLICY(1, 0),  /* scanning excludes networks with hidden SSID */
                &u8L_intervalInSeconds,
                sizeof(u8L_intervalInSeconds)) != SL_RET_CODE_OK)
            {
                ASSERT_ALWAYS();
            }
        }
        else
        {
            /* disable WLAN scan */
            u8L_intervalInSeconds = 0;
            if (sl_WlanPolicySet(
                SL_WLAN_POLICY_SCAN,
                SL_WLAN_DISABLE_SCAN,
                &u8L_intervalInSeconds,
                sizeof(u8L_intervalInSeconds)) != SL_RET_CODE_OK)
            {
                ASSERT_ALWAYS();
            }
        }
    }
    bool wifiSta_isNetworkActive(char* cPL_ssid) { SlWlanNetworkEntry_t objPL_networkEntries[MAXIMUM_WLANS_TO_SCAN]; int16_t s16L_networksCount; wifiScanning(true, 20); /* 20s is WiFi WLAN scanning interval */ do { s16L_networksCount = sl_WlanGetNetworkList(0, MAXIMUM_WLANS_TO_SCAN, objPL_networkEntries); if (s16L_networksCount >= 0) { break; } else if (s16L_networksCount == SL_ERROR_WLAN_GET_NETWORK_LIST_EAGAIN) { (void)sleep(20); } else { s16L_networksCount = 0; ASSERT_ALWAYS(); } } while (s16L_networksCount == SL_ERROR_WLAN_GET_NETWORK_LIST_EAGAIN); uint8_t u8L_i = 0; while (u8L_i < s16L_networksCount) { if (strncmp( cPL_ssid, (char*)objPL_networkEntries[u8L_i].Ssid, SL_WLAN_SSID_MAX_LENGTH) == 0) { return true; } u8L_i++; } return false; }

    Regarding SDK update:
    Do you have any release notes evidence that it is worth migrating to later SDK that will impact issue I am having?

    Thanks for your reply!

    Regards
    Jiří

  • Hi Jiří,

    All servicepacks are backwards compatible, so you can test the latest servicepack without updating the SDK version or your application. We are constantly improving interoperability, and there have been changes to the scan policy since sp_3.12.0.1.

    Does the desired SSID appear in the network list later? Are you able to connect regardless?

    Best regards,

    Sarah

  • Hello Sarah,

    I will write some kind of summary

    • if WiFi network is turned on before trying to connect CC3220SF device to it, SSID is found (this is expected) 
    • if WiFi network is off before trying to connect CC3220SF device to it, SSID is not found (this is really expected)
    • if WiFi network is off before starting CC3220SF device to it and the WiFi network is turned on after CC3220SF started, SSID is not found
      (this is not expected)
    • if WiFi network is turned off after CC3220SF device found it, SSID is still found (this is not expected)

    No time matters. Situation doesn't change after minutes.

    I am not trying to connect to SSID that is not found. I am trying to connect only to found SSID.
    So my device will never connect to WiFi that was off before device started.

    Regarding SDKs:
    We had to fix problems of TI SDK v3.20.0.6 which unfortunately TI didn't accepted to be fixed
    (MQTT problem and UART problem at least I still remember).

    Because of these changes we cannot simply import new SDK. So we have to see real evidence
    that fix exists and is doing what is expected. Alternatively I can try to import only those files that
    are impacted by WLAN scanning updated.

    Are you able to tell me exactly what changes in which files should fix those described WiFi scanning problems?
    I expect that this problem I am describing is not reproducible on your side, as it is easy to implement and test.

    Thank you for further support!

    Regards
    Jiří

  • Hi Jiří,

    Again, I am not asking you to use a new SDK. I am only asking you to flash a new servicepack using UniFlash ImageCreator. Do you know how to do that?

    If not, please see this training: https://dev.ti.com/tirex/explore/node?node=AH9w8QwBrpt-RLlf.VRAvg__fc2e6sr__LATEST

    No, your issue is not reproducible. The next step will be to pull additional logs, but first you need to test the latest servicepack.

    Best regards,

    Sarah

  • Hi Sarah,

    I sincerely apologize, I am bad reader. :-(

    I will pick the latest SP, I know how to do that.
    Thank you for this advice! I will keep you informed.

    Regards
    Jiří

  • Hello Sarah,

    no update yet, I am waiting for my code to be reviewed and merged to be able to test it integrated.
    I hope to make it next week.

    Regards
    Jiří

  • Hello Sarah,
    sorry for the delay. I finally found time to test your proposal.

    With SP sp_3.12.0.1_2.0.0.0_2.2.0.6.bin taken from SDK v3.20.0.6 I can reproduce the problem.
    So SSID is found even that AP is no more active.

    With SP sp_3.13.0.3_2.0.0.0_2.2.0.6.bin taken from SDK v4.20.0.7 I can reproduce the problem too.
    So SSID is found even AP is off.

    Can you tell me if I can verify version of SP in use from source code of CC3220SF?
    Just be sure about that I am using.

    Regards
    Jiří

    PS: Problem that SSID was not found when AP is active was not reproduced (tried just twice).

  • Hi Jiří,

    Are you still running the test where you wait two scan cycles before checking the network list again? What scan cycle are you using?

    You can see your servicepack verison by calling sl_DeviceGet(). You can use the DisplayAppBanner() function from the mqtt_client or network_terminal examples to print this to the terminal.

    Best regards,

    Sarah

  • Hello Sarah,

    I will be testing this issue sooner or later, but currently having other prio tasks
    and also we are internally discussing to migrate to latest SDK / SP.
    Please keep this topic open, I will provide update ASAP.

    Thanks for info regarding obtaining SP version!

    Jiří

  • Hi Jiří,

    No worries. The forum threads do lock to replies automatically after a few weeks, so if you notice that happen, click "Ask a related question" at the top of this page. It will start a new thread with a link to this one so you do not lose any progress.

    Best regards,

    Sarah

  • Hi Sarah,

    it was decided to not use WiFi scanning functionality. If I understand well, when trying to find SSID that may be hidden on AP side, it will always fail even hidden SSIDs will be included in the search results.

    So if I will compare my SSID I am looking for with results of scan, it will never be found if AP is hiding the network SSID.

    Regards
    Jiří