Right now I am starting up my esp32-c3 in APSTA mode using esp-idf. This serves a captive portal where a user can select a wifi network and connect to it, similar to how tasmota and wifimanager work. I am able to connect to a network if I call esp_wifi_stop();, then reconfigure, then start the network, but this closes the captive portal. I am would like to start in APSTA mode, but only configure the AP part, then configure the STA later, confirm the STA is working, then shut down the AP, all without rebooting or shutting off wifi or loosing AP connection.
Is this possible and if so how would I do it?
How to connect to wifi network while in APSTA mode?
-
- Posts: 3
- Joined: Wed Feb 23, 2022 11:48 pm
Re: How to connect to wifi network while in APSTA mode?
I am doing something similar (captive portal for Wi-Fi provisioning) in my project and I'd also like an answer to this question.
When operating in APSTA mode, I want to be able to bring up or shut down the AP without affecting the STA connection status, or connect/disconnect the STA without affecting AP operation.
Is this possible?
When operating in APSTA mode, I want to be able to bring up or shut down the AP without affecting the STA connection status, or connect/disconnect the STA without affecting AP operation.
Is this possible?
Re: How to connect to wifi network while in APSTA mode?
This is still relevant. Is it possible?
Re: How to connect to wifi network while in APSTA mode?
Yes, you can freely change WiFi mode without needing to completely stop and restart the driver.
eg.
eg.
Code: Select all
esp_wifi_start();
esp_wifi_set_mode(AP);
esp_wifi_set_config(AP, &ap_config);
/* ... Receive WiFi credentials from user ... */
esp_wifi_set_mode(APSTA);
esp_wifi_set_config(STA, &user_sta_config);
esp_wifi_connect();
/* ... Connection succeeded, we decide we don't need AP any more ... */
esp_wifi_set_mode(STA);
/* ... Do things, then when done ... */
esp_wifi_disconnect();
esp_wifi_stop();
Re: How to connect to wifi network while in APSTA mode?
Hi, any one from this post has a good source code about this?
I am also trying to make something "similar" to wifimanager but in esp-idf framework.
Thanks a lot
I am also trying to make something "similar" to wifimanager but in esp-idf framework.
Thanks a lot
-
- Posts: 3
- Joined: Fri Sep 27, 2024 11:03 am
Re: How to connect to wifi network while in APSTA mode?
Hi All,
I am trying to communicate to external IP address in WIFI_MODE_APSTA which is not working. Terminal log mentions that station is already connected and assigned with a IP adderss. Code snippet as given below:
As provided in the above, I tried changing the mode to WIFI_MODE_STA and tried to communicate. Socket is created successfully and bind to the port. But I am getting an error "Error Code 118" while sending the payload. Do I need to disconnect using esp_wifi_disconnect(); before changing the mode?
Thanks in advance.
I am trying to communicate to external IP address in WIFI_MODE_APSTA which is not working. Terminal log mentions that station is already connected and assigned with a IP adderss. Code snippet as given below:
Code: Select all
//public DNS server address
struct sockaddr_in public_dns;
public_dns.sin_addr.s_addr = inet_addr(DEFAULT_DNS);
public_dns.sin_family = AF_INET;
public_dns.sin_port = htons(DNS_PORT);
address_family = AF_INET;
ip_protocol = IPPROTO_IP;
// Create socket for UDP
if ((sockfd = socket(address_family, SOCK_DGRAM,ip_protocol)) < 0) {
ESP_LOGI(TAG,"Socket creation failed");
exit(EXIT_FAILURE);
}
ESP_LOGI(TAG,"Socket creation success");
int err = bind(sockfd, (struct sockaddr *)&public_dns, sizeof(public_dns));
if (err < 0) {
ESP_LOGE(TAG, "Public DNS Socket unable to bind: errno %d", errno);
shutdown(sockfd, 0);
close(sockfd);
return -1;
}
ESP_LOGI(TAG, "Public DNS Socket bound to port %d", DNS_PORT);
// Send the query to the Public DNS server
socklen_t public_socklen = sizeof(public_dns);
err = sendto(sockfd, payload,50, 0, (struct sockaddr *)&public_dns,sizeof(public_dns));
if (err < 0) {
ESP_LOGE(TAG, "Error occurred during sending to query to Public DNS: errno %d", errno);
shutdown(sockfd, 0);
close(sockfd);
return -1;
}
Thanks in advance.
Who is online
Users browsing this forum: kaxx1975 and 94 guests