Skip to content
Snippets Groups Projects
Commit 92f6c1a7 authored by Gunar Schorcht's avatar Gunar Schorcht Committed by Schorcht
Browse files

cpu/esp8266: WiFi mode changed in esp_wifi

Although only the station interface is needed, the WiFi interface has to be used in SoftAP + Station mode. Otherwise the send function blocks sporadically. Since the SoftAP interface is not used, it is configured with a hidden SSID and a long beacon interval. Connections from other stations are not allowed.
parent 538aac00
Branches
No related tags found
No related merge requests found
...@@ -59,6 +59,7 @@ ...@@ -59,6 +59,7 @@
#define ESP_WIFI_STATION_MODE (STATION_MODE) #define ESP_WIFI_STATION_MODE (STATION_MODE)
#define ESP_WIFI_AP_MODE (SOFTAP_MODE) #define ESP_WIFI_AP_MODE (SOFTAP_MODE)
#define ESP_WIFI_STATION_AP_MODE (STATIONAP_MODE) #define ESP_WIFI_STATION_AP_MODE (STATIONAP_MODE)
#define ESP_WIFI_MODE (STATIONAP_MODE)
#define ESP_WIFI_STATION_IF (STATION_IF) #define ESP_WIFI_STATION_IF (STATION_IF)
#define ESP_WIFI_SOFTAP_IF (SOFTAP_IF) #define ESP_WIFI_SOFTAP_IF (SOFTAP_IF)
...@@ -95,6 +96,32 @@ static const struct station_config station_cfg = { ...@@ -95,6 +96,32 @@ static const struct station_config station_cfg = {
.password = ESP_WIFI_PASS, .password = ESP_WIFI_PASS,
}; };
#ifndef MODULE_ESP_NOW
/**
* Static const configuration for the SoftAP which is used to configure the
* SoftAP interface if ESP-NOW is not enabled.
*
* Since we need to use the WiFi interface in SoftAP + Station mode for
* stability reasons, although in fact only the station interface is required,
* we make the SoftAP interface invisible and unusable. This configuration
*
* - uses the same hidden SSID that the station interface uses to
* connect to the AP,
* - uses the same channel that the station interface uses to connect to the AP,
* - defines a very long beacon interval
* - doesn't allow any connection.
*/
static const struct softap_config softap_cfg = {
.ssid = ESP_WIFI_SSID,
.ssid_len = sizeof(ESP_WIFI_SSID) / sizeof(ESP_WIFI_SSID[0]),
.ssid_hidden = 1, /* don't make the AP visible */
.password = ESP_WIFI_PASS,
.authmode = AUTH_WPA2_PSK,
.max_connection = 0, /* don't allow connections */
.beacon_interval = 60000, /* send beacon only every 60 s */
};
#endif
extern struct netif * eagle_lwip_getif(uint8 index); extern struct netif * eagle_lwip_getif(uint8 index);
/** guard variable to avoid reentrance to _send */ /** guard variable to avoid reentrance to _send */
...@@ -249,6 +276,12 @@ static void _esp_wifi_handle_event_cb(System_Event_t *evt) ...@@ -249,6 +276,12 @@ static void _esp_wifi_handle_event_cb(System_Event_t *evt)
break; break;
case EVENT_SOFTAPMODE_STACONNECTED:
ESP_WIFI_LOG_INFO("station " MACSTR " join, aid %d",
MAC2STR(evt->event_info.sta_connected.mac),
evt->event_info.sta_connected.aid);
break;
default: default:
break; break;
} }
...@@ -295,8 +328,8 @@ static int IRAM _send(netdev_t *netdev, const iolist_t *iolist) ...@@ -295,8 +328,8 @@ static int IRAM _send(netdev_t *netdev, const iolist_t *iolist)
return -EIO; return -EIO;
} }
if (wifi_get_opmode() != ESP_WIFI_STATION_MODE) { if (wifi_get_opmode() != ESP_WIFI_MODE) {
ESP_WIFI_DEBUG("WiFi is not in station mode, cannot send"); ESP_WIFI_DEBUG("WiFi is not in correct mode, cannot send");
_in_send = false; _in_send = false;
critical_exit(); critical_exit();
return -EIO; return -EIO;
...@@ -595,13 +628,21 @@ static void _esp_wifi_setup(void) ...@@ -595,13 +628,21 @@ static void _esp_wifi_setup(void)
/* set the netdev driver */ /* set the netdev driver */
dev->netdev.driver = &_esp_wifi_driver; dev->netdev.driver = &_esp_wifi_driver;
/* set the WiFi interface to Station mode without DHCP */ #ifndef MODULE_ESP_NOW
if (!wifi_set_opmode_current(ESP_WIFI_STATION_MODE)) { /* set the WiFi interface mode */
if (!wifi_set_opmode_current(ESP_WIFI_MODE)) {
ESP_WIFI_LOG_ERROR("could not set WiFi working mode"); ESP_WIFI_LOG_ERROR("could not set WiFi working mode");
return; return;
} }
/* set the WiFi configuration */ /* set the WiFi SoftAP configuration */
if (!wifi_softap_set_config_current((struct softap_config *)&softap_cfg)) {
ESP_WIFI_LOG_ERROR("could not set WiFi configuration");
return;
}
#endif
/* set the WiFi station configuration */
if (!wifi_station_set_config_current((struct station_config *)&station_cfg)) { if (!wifi_station_set_config_current((struct station_config *)&station_cfg)) {
ESP_WIFI_LOG_ERROR("could not set WiFi configuration"); ESP_WIFI_LOG_ERROR("could not set WiFi configuration");
return; return;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment