WiFi APSTA Mode with WIFI_PROTOCOL_LR on STA only

iParcelBox
Posts: 31
Joined: Sun Oct 27, 2019 3:12 pm

WiFi APSTA Mode with WIFI_PROTOCOL_LR on STA only

Postby iParcelBox » Tue Nov 12, 2024 7:05 am

Hello,

I'm trying to enable provisioning of an ESP32-S3 over WiFi AP mode from a phone, to enable the user to configure the device to connect to another ESP32 device in LR mode.

However, it seems that as soon as add `WIFI_PROTOCOL_LR` to `ÈSP_IF_WIFI_STA`, the device is no longer visible as an AP to standard devices.

Code: Select all

    
    ESP_ERROR_CHECK(esp_wifi_set_mode(WIFI_MODE_APSTA));
    ESP_ERROR_CHECK(esp_wifi_set_protocol(ESP_IF_WIFI_STA, WIFI_PROTOCOL_11B | WIFI_PROTOCOL_11G | WIFI_PROTOCOL_11N | WIFI_PROTOCOL_LR));
    ESP_ERROR_CHECK(esp_wifi_set_config(ESP_IF_WIFI_STA, &wifi_config));
    ESP_ERROR_CHECK(esp_wifi_start());
   
Is there any way to allow a standard device to connect to an ESP32-S3 as an AP from a standard device, and then allow the ESP32 to scan for and connect to another ESP device in LR mode (I'm aware I can do it via BLE provisioning, but I also want the WiFi AP available for wifi provisioning and other Local API calls.

aliarifat794
Posts: 198
Joined: Sun Jun 23, 2024 6:18 pm

Re: WiFi APSTA Mode with WIFI_PROTOCOL_LR on STA only

Postby aliarifat794 » Tue Nov 12, 2024 9:24 am

You need to stop and restart the Wi-Fi interface (esp_wifi_stop() and esp_wifi_start()) when switching protocols, as changes to protocol settings require a restart to take effect.

You can edit your code like this:

Code: Select all



#include "esp_wifi.h"

void setup_wifi_ap_sta() {
    wifi_config_t ap_config = {
        .ap = {
            .ssid = "YourAPSSID",
            .password = "YourAPPassword",
            .ssid_len = 0,
            .channel = 1,
            .max_connection = 4,
            .authmode = WIFI_AUTH_WPA_WPA2_PSK,
        },
    };

    wifi_config_t sta_config = {
        .sta = {
            .ssid = "YourSTA_SSID",
            .password = "YourSTA_Password",
        },
    };

    // Initialize WiFi
    ESP_ERROR_CHECK(esp_netif_init());
    ESP_ERROR_CHECK(esp_event_loop_create_default());
    esp_netif_create_default_wifi_ap();
    esp_netif_create_default_wifi_sta();

    wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
    ESP_ERROR_CHECK(esp_wifi_init(&cfg));

    // Set mode to AP+STA
    ESP_ERROR_CHECK(esp_wifi_set_mode(WIFI_MODE_APSTA));

    // Configure the AP
    ESP_ERROR_CHECK(esp_wifi_set_config(WIFI_IF_AP, &ap_config));

    // Configure the STA (standard protocols during provisioning)
    ESP_ERROR_CHECK(esp_wifi_set_protocol(ESP_IF_WIFI_STA, WIFI_PROTOCOL_11B | WIFI_PROTOCOL_11G | WIFI_PROTOCOL_11N));
    ESP_ERROR_CHECK(esp_wifi_set_config(WIFI_IF_STA, &sta_config));

    // Start WiFi
    ESP_ERROR_CHECK(esp_wifi_start());
}

void switch_to_lr_mode() {
    // Reconfigure STA to use LR mode
    ESP_ERROR_CHECK(esp_wifi_stop());
    ESP_ERROR_CHECK(esp_wifi_set_protocol(ESP_IF_WIFI_STA, WIFI_PROTOCOL_LR));
    ESP_ERROR_CHECK(esp_wifi_start());
}




iParcelBox
Posts: 31
Joined: Sun Oct 27, 2019 3:12 pm

Re: WiFi APSTA Mode with WIFI_PROTOCOL_LR on STA only

Postby iParcelBox » Tue Nov 12, 2024 11:40 am

I don’t think that will work: during the provisioning process whilst connected to the AP eg from an iPhone, I need the esp to scan for (and test the connection to) the other device in LR mode, so would need AP mode (no LR) and STA mode (with LR) at the same time.

Who is online

Users browsing this forum: No registered users and 425 guests