-
Notifications
You must be signed in to change notification settings - Fork 219
AP issues with latest branch #221
Comments
Has the AP API (heh) changed in the last little bit? I've seen some things regarding AP DNS changes, is that perhaps related? |
Those changes were to correctly get/set the DNS info for the access point. I assume you're using your computer WiFi to connect to the AP? Do you get proper IP / routing info over DHCP? When you connect in the browser, are you using an IP or a name? |
Yes, it's related. I'm investigating (my PR), though it's pretty weird; Might be an IDF bug. |
Opened issue with IDF: espressif/esp-idf#1257 @BasedOnTechnology You're seeing the problem you are because the AP is giving out IP addresses for the "old" IP range of 192.168.4.0/24, when it should be giving out IPs from 1.1.1.0/24. Here's a workaround for now: https://github.com/MrSurly/micropython-esp32/tree/mp_issue_221_workaround |
@MrSurly Sorry, I didn't see this before. Thank you very much for the workaround. |
Hi all. Is this just a race condition where the station is connecting to the AP before the AP is reconfigured? |
No, I tested this myself, only connecting the station well after the AP was up. By not calling |
Okay, so the IDF folks cannot reproduce this; I doubt they're running MP. I'm trying to create a minimal recreation for them, and ... I can't reproduce it, either. But it's definitely happening in MP. Can someone look at the code below, and tell me if it's pretty close to matching the code flow in MP? #include <stdio.h>
#include <esp_task_wdt.h>
#include <esp_wifi.h>
#include <esp_wifi_types.h>
#include <esp_event_loop.h>
#include <nvs_flash.h>
#include <string.h>
#define L(tag, ...) do { printf("[%8s]: ", tag); printf(__VA_ARGS__); printf("\n");} while(false)
static esp_err_t eventHandler(void *ctx, system_event_t *event) {
const char * TAG = "Event";
switch (event->event_id) {
case SYSTEM_EVENT_STA_START:
L(TAG, "STA_START");
break;
case SYSTEM_EVENT_STA_GOT_IP:
L(TAG, "got ip");
break;
case SYSTEM_EVENT_STA_DISCONNECTED:
{
// This is a workaround as ESP32 WiFi libs don't currently
// auto-reassociate.
system_event_sta_disconnected_t *disconn = &event->event_info.disconnected;
L(TAG, "STA_DISCONNECTED, reason:%d", disconn->reason);
switch (disconn->reason) {
case WIFI_REASON_BEACON_TIMEOUT:
L(TAG,"beacon timeout");
break;
case WIFI_REASON_NO_AP_FOUND:
L(TAG,"no AP found");
break;
case WIFI_REASON_AUTH_FAIL:
L(TAG,"authentication failed");
break;
default:
// Let other errors through and try to reconnect.
break;
}
}
break;
default:
L(TAG, "Some unhandled event: %d", event->event_id);
}
return ESP_OK;
}
static void wifiTask(void* ctx) {
const char * TAG = "WifiMon";
L(TAG, "starting");
tcpip_adapter_init();
esp_event_loop_init(eventHandler, NULL);
const char * ssid = "Mango";
wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
if (esp_wifi_init(&cfg) != ESP_OK) printf("init failed\n");
if (esp_wifi_set_storage(WIFI_STORAGE_RAM) != ESP_OK) printf("init failed\n");
if (esp_wifi_set_mode(0) != ESP_OK) printf("set mode 0 failed\n");
if (esp_wifi_start() != ESP_OK) printf("start\n");
{
if(esp_wifi_set_mode(WIFI_MODE_AP) != ESP_OK) printf("set mode ap failed\n");
if(esp_wifi_set_mode(WIFI_MODE_STA | WIFI_MODE_AP) != ESP_OK) printf("set mode ap + sta failed\n");
static wifi_config_t config;
if(esp_wifi_get_config(WIFI_IF_AP, &config) != ESP_OK) printf("get config failed\n");
strcpy((char *)config.ap.ssid, ssid);
config.ap.ssid_len = strlen(ssid);
config.ap.password[0] = 0;
esp_err_t e = esp_wifi_set_config(WIFI_IF_AP, &config);
if(e != ESP_OK) printf("set config failed: %d\n", e);
#if 1
tcpip_adapter_ip_info_t info;
tcpip_adapter_dns_info_t dns_info;
tcpip_adapter_get_ip_info(WIFI_IF_AP, &info);
tcpip_adapter_get_dns_info(WIFI_IF_AP, TCPIP_ADAPTER_DNS_MAIN, &dns_info);
info.ip.addr = 0x01010101; // 1.1.1.1
info.gw.addr = 0x01000000; // 1.0.0.0
info.netmask.addr = 0xFFFFFF00; // 255.255.255.0
dns_info.ip.u_addr.ip4.addr = 0x08080808; // 8.8.8.8
tcpip_adapter_dhcps_stop(WIFI_IF_AP);
tcpip_adapter_set_ip_info(WIFI_IF_AP, &info);
tcpip_adapter_set_dns_info(WIFI_IF_AP, TCPIP_ADAPTER_DNS_MAIN, &dns_info);
tcpip_adapter_dhcps_start(WIFI_IF_AP);
#endif
vTaskDelete(NULL);
}
}
void app_main() {
nvs_flash_init();
TaskHandle_t wifiTaskHandle;
xTaskCreate(wifiTask, "wifiTask", 2048, NULL, tskIDLE_PRIORITY, &wifiTaskHandle);
}; |
I have a simple Wifi AP mode setup page, which is served roughly like so:
On esp32-20170725-v1.9.1, if I try to connect to 1.1.1.1, I get:
On the latest builds, a browser can't connect to 1.1.1.1, and no connection attempt is registered.
The text was updated successfully, but these errors were encountered: