Manage WiFi connectivity using SDK

Hello

I have a question about managing WiFi connectivity. First of all, I found this question:  RE: Connect wifi and control wifi connection using code in da16200 , but it wasn't entirely helpful.

Namely, as I see it, the wlanInit() function performs initialization and connects to WiFi. If I’m not mistaken, the same function also enables the chip's Soft AP mode. However, I need the connection to WiFi / activation of Soft AP mode to happen in a different place — specifically, after my part of the code starts executing (the my_function(); shown in the image below).

Inside my function, there's an if-else condition that determines whether to connect to the network or activate Soft AP mode. However, when I move the wlanInit() function to another place, the program never reaches my_function; it gets stuck where the original wlanInit() function was located.

How can I manage the WiFi connection / enable Soft AP mode so that it happens within my my_function instead?

Thanks for your help.

Parents
  • Hi There,

    Thank you for posting your question online.
    The wlanInit() function handles the device after a Wake-up. The Wake-up can be due to Power ON, DPM, RTC , GPIO interrupt etc.
    Ideally you should not modify it neither move it on another file.
    Please refer on UM-WI-046 DA16200 DA16600 FreeRTOS SDK Programmer Guide section 9.2.2 Configure Soft AP Interface
    The device will be configured into Soft AP mode inside the factory_reset_ap_mode function. Inside the wlaninit function there is an if statement that checks if the Factory Reset button was pressed in order to trigger the factory_reset_ap_mode function.

    I would suggest you check the factory_reset_default:

    I would suggest you make sure that these macros are not defined, so the factory_reset_user_define function will be get executed. 
    You can continue without initializing the device into Soft AP mode. 
    Then inside your own custom function you can call the function as shown in the UM-WI-046.

    Best Regards,
    OV_Renesas

  • Thank you for the response,

    I'm not sure how useful this method will be either, but let's try another approach (without the factory reset button).
    Let's go back to my function my_function();



    Instead of the factory reset button, let's assume that I'm using another button in my_function, and I have the following:
    if (button_hold)
    {
       // Soft AP mode
    }
    else
    {
       // Connect to WiFi
    }

    The button is connected to a standard GPIO pin that is not configured for interrupts.

    And this approach is fine, because regardless of what the wlaninit() function does (whether it connects to Wi-Fi or starts a Soft AP), I can always configure a new mode (station or Soft AP) from within my my_function(), and then perform a reboot — as shown in section 9.1.3 (Sample Code) of the UM-WI-046 DA16200 DA16600 FreeRTOS SDK Programmer Guide.

    1. However, what’s the problem here?
    If the Wi-Fi network whose credentials (SSID and password) are stored in memory is not currently available, then within the wlaninit() function, the DA16200 will continuously try to reconnect. This means that as long as that network is unavailable and the chip keeps retrying the connection, the program will never reach my my_function() — is that correct (see image below)?



    2. What happens if the WiFi network becomes unavailable after the device has successfully connected?
    If, during device operation (after successfully connecting to Wi-Fi), the Wi-Fi network becomes unavailable, a CTRL-EVENT-DISCONNECTED will occur. In that case, what happens? Does the entire device stop functioning until it reconnects to Wi-Fi?


    3. What do I need?
    What I need now is for the DA16200 to function even without a WiFi network - even when no network is available.

    More precisely:

    • If case 1 is true — that the program never reaches my my_function() when no WiFi network is found — then I need to make sure that the program reaches my function regardless, and that the DA16200 continues to operate normally.

    • Likewise, in case 2 — if the device loses the WiFi connection during normal operation — it’s acceptable to receive a disconnect event, but the device should still be able to perform all other tasks as usual.

  •  

    Hello, do you have any updates on this topic, please? Is it possible?

  • Hi There,

    Thank you for the reply.


    1. However, what’s the problem here?
    If the Wi-Fi network whose credentials (SSID and password) are stored in memory is not currently available, then within the wlaninit() function, the DA16200 will continuously try to reconnect. This means that as long as that network is unavailable and the chip keeps retrying the connection, the program will never reach my my_function() — is that correct (see image below)?

    Yes, that is the expected operation by default.
    On events.c file:

    You can modify this file in order to not constantly retry to connect to the network.

    3. What do I need?
    What I need now is for the DA16200 to function even without a WiFi network - even when no network is available.

    More precisely:

    • If case 1 is true — that the program never reaches my my_function() when no WiFi network is found — then I need to make sure that the program reaches my function regardless, and that the DA16200 continues to operate normally.

    You will need to modify the reconnection retries on the FreeRTOS SDK. You will need to make sure you have handled the DPM as well for this.


    Likewise, in case 2 — if the device loses the WiFi connection during normal operation — it’s acceptable to receive a disconnect event, but the device should still be able to perform all other tasks as usual.

    Please check on events.c file the following fucntion:

    static void wpa_supplicant_event_disassoc(struct wpa_supplicant *wpa_s,
    					  u16 reason_code,
    					  int locally_generated)

    It will be triggered when there is a disconnect. 
    On the events.c file you can find the wpa_supplicant_event function which handles all the events. You should search the case for EVENT_DISASSOC and implement your case scenario there.

    Best Regards,
    OV_Renesas

  • Hi,

    Thank you for your response.

    Should the ce_set_conn_try_result_status() function already be defined in the SDK, or is it something I’m supposed to implement myself? I’m asking because when I define the __SUPPORT_CON_EASY__ macro and try to build the project, I get an "undefined reference to ce_set_conn_try_result_status()" error. From what I understand, I need to call that function to prevent the DA16200 from continuously trying to reconnect to Wi-Fi. Or is there something else that specifically needs to be modified?

    Could you please help me with this problem in more detail so that I don’t damage the DPM? What I need is for the device to try connecting three times, and if it fails, it should proceed as if operating normally. I don’t want the device to be blocked on startup if there is no Wi-Fi connection.

    Best regards,
    TT

Reply
  • Hi,

    Thank you for your response.

    Should the ce_set_conn_try_result_status() function already be defined in the SDK, or is it something I’m supposed to implement myself? I’m asking because when I define the __SUPPORT_CON_EASY__ macro and try to build the project, I get an "undefined reference to ce_set_conn_try_result_status()" error. From what I understand, I need to call that function to prevent the DA16200 from continuously trying to reconnect to Wi-Fi. Or is there something else that specifically needs to be modified?

    Could you please help me with this problem in more detail so that I don’t damage the DPM? What I need is for the device to try connecting three times, and if it fails, it should proceed as if operating normally. I don’t want the device to be blocked on startup if there is no Wi-Fi connection.

    Best regards,
    TT

Children
  • Hi TT,

    Thank you for the reply and apologies for the delay.

    Should the ce_set_conn_try_result_status() function already be defined in the SDK, or is it something I’m supposed to implement myself? I’m asking because when I define the __SUPPORT_CON_EASY__ macro and try to build the project, I get an "undefined reference to ce_set_conn_try_result_status()" error. From what I understand, I need to call that function to prevent the DA16200 from continuously trying to reconnect to Wi-Fi. Or is there something else that specifically needs to be modified?

    This specific function, ce_set_conn_try_result_status(), is considered a dead function and will be removed from the FreeRTOS SDK in next releases.
    The __SUPPORT_CON_EASY__ macro is undefined by default and should not be defined.


    What I need is for the device to try connecting three times, and if it fails, it should proceed as if operating normally. I don’t want the device to be blocked on startup if there is no Wi-Fi connection.

    Please refer on UM-WI-030 DA16200 DA16600 DPM User Manual on section 4.2 Getting Started with DPM Manager


    Please also check section 3.4 DPM Connection Retry State

    And the Connection Retry time is defined on da16x_dpm.h file:

    /* Wait time to get connected in DPM Connection Retry State */
    #define MAX_INIT_WIFI_CONN_TIME	30 /* Unit: Second */
    

    The default operation works with time and not retry counts. 
    However, you can modify this on your end by using the following variable:

    dpm_wifi_conn_retry_cnt

    From the typedef struct dpm_monitor_info_t 

    You can use also the next API to get the retry count and then terminate the procedure:

    int dpm_get_wifi_conn_retry_cnt(void)
    {
        if (dpm_monitor_info_ptr != NULL) {
            return dpm_monitor_info_ptr->wifi_conn_retry_cnt;
        } else {
            return 0;
        }
    }


    Best Regards,
    OV_Renesas