From 73a1bcdd603f919e9362ef896a276dc139c13cfb Mon Sep 17 00:00:00 2001 From: Bruno Chabrier Date: Wed, 8 May 2019 08:57:29 +0200 Subject: [PATCH 1/4] Allow specifying a ap_ssid (and possibly password) in Automesh mode --- user/user_main.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/user/user_main.c b/user/user_main.c index 4afe99a..af9a222 100644 --- a/user/user_main.c +++ b/user/user_main.c @@ -3680,7 +3680,7 @@ void ICACHE_FLASH_ATTR automesh_scan_done(void *arg, STATUS status) for (bss_link = (struct bss_info *)arg; bss_link != NULL; bss_link = bss_link->next.stqe_next) { - if (os_strcmp(bss_link->ssid, config.ssid) == 0) { + if (os_strcmp(bss_link->ssid, config.ssid) == 0 || os_strcmp(bss_link->ssid, config.ap_ssid) == 0) { uint8_t this_mesh_level; os_printf("Found: %d,\"%s\",%d,\""MACSTR"\",%d", @@ -3888,8 +3888,13 @@ struct espconn *pCon; // In Automesh STA and AP passwords and credentials are the same if (config.automesh_mode != AUTOMESH_OFF) { + if (os_strcmp(config.ap_ssid, "none") == 0) { os_memcpy(config.ap_ssid, config.ssid, sizeof(config.ssid)); + } else { + if (os_strcmp(config.ap_ssid, "none") == 0) { os_memcpy(config.ap_password, config.password, sizeof(config.password)); + } + } if (config.automesh_mode == AUTOMESH_LEARNING) { config.ap_on = 0; From 9e78ec87b62d54206932e2402d84add2dec28b58 Mon Sep 17 00:00:00 2001 From: Bruno Chabrier Date: Wed, 8 May 2019 10:03:55 +0200 Subject: [PATCH 2/4] Updated README --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 2ccbb2f..72f3768 100644 --- a/README.md +++ b/README.md @@ -205,6 +205,8 @@ Now each esp_wifi_repeater can learn which other esp_wifi_repeater is the closes For convenience, the esp_wifi_repeater after "automesh" configuration first tries to check, whether it can connect to an uplink AP. If this fails, even when an AP with the correct SSID has been found, it assumes, the user did a mistake with the password and resets to factory defaults. After it had connected successfully once, it will assume config is correct and keep on trying after connection loss or reset as long as it takes (to avoid a DOS attack with a misconfigured AP). +An option is to set a specific ap_ssid (and possibly ap_password). In that case, the "automesh" mode will create a dedicated WiFi network where each ESP will be connected either to the orginal network or to the dedicated network, but will be reachable only through the ap_ssid. This can be useful if you want a dedicated network for your ESPs (e.g. for IoT). + ## Tuning Automesh If there are more than one ESP in range, there might be a trade-off between a shorter "bad" path and a longer "good" path (good and bad in terms of link quality). The parameter _am_threshold_ determines what a bad connection is: if the RSSI in a scan is less than this threshold, a connection is bad and path with one more hop is prefered. I.e. given _am_threshold_ is 85 and there are two automesh nodes detected in the scan: A with level 1 and RSSI -88 dB and B with level 2 and RSSI -60 dB, then a link to A is considered as too bad (-88 dB < -_am_threshold_) and B is preferred. The new node will become a level 3 node with uplink via B. _am_threshold_ is given as a positive value but means a negative dB. A smaller value is better. From b9e759f89d2f3a04f290eae3d39a2daee4a8e832 Mon Sep 17 00:00:00 2001 From: Bruno Chabrier Date: Sun, 12 May 2019 00:27:33 +0200 Subject: [PATCH 3/4] Fixed bug that ap password was not used in automesh mode --- user/user_main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/user/user_main.c b/user/user_main.c index af9a222..38e1559 100644 --- a/user/user_main.c +++ b/user/user_main.c @@ -3891,7 +3891,7 @@ struct espconn *pCon; if (os_strcmp(config.ap_ssid, "none") == 0) { os_memcpy(config.ap_ssid, config.ssid, sizeof(config.ssid)); } else { - if (os_strcmp(config.ap_ssid, "none") == 0) { + if (os_strcmp(config.ap_password, "none") == 0) { os_memcpy(config.ap_password, config.password, sizeof(config.password)); } } From d3fd950ace206a698aaa43b914ab72870565c5b7 Mon Sep 17 00:00:00 2001 From: Bruno Chabrier Date: Sun, 12 May 2019 00:30:03 +0200 Subject: [PATCH 4/4] Added automesh_use_ap_ssid in flash to indicate if ap_ssid should be used in automesh mode --- user/config_flash.c | 1 + user/config_flash.h | 1 + user/user_main.c | 15 ++++++++++++--- 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/user/config_flash.c b/user/config_flash.c index d74d912..df62423 100644 --- a/user/config_flash.c +++ b/user/config_flash.c @@ -81,6 +81,7 @@ uint32_t reg0, reg1, reg3; config->automesh_threshold = 85; config->am_scan_time = 0; config->am_sleep_time = 0; + config->automesh_use_ap_ssid= 0; config->nat_enable = 1; config->tcp_timeout = 0; // use default diff --git a/user/config_flash.h b/user/config_flash.h index 94af01a..54b0a15 100644 --- a/user/config_flash.h +++ b/user/config_flash.h @@ -70,6 +70,7 @@ typedef struct { int8_t automesh_threshold; // RSSI limit uint32_t am_scan_time; // Seconds for scanning uint32_t am_sleep_time; // Seconds for sleeping + uint8_t automesh_use_ap_ssid; // Indicates if ssid or ap_ssid has to be used uint8_t nat_enable; // Enable NAT on the AP netif; uint32_t tcp_timeout; // NAT timeout of TCP connections diff --git a/user/user_main.c b/user/user_main.c index 38e1559..89b1e57 100644 --- a/user/user_main.c +++ b/user/user_main.c @@ -3613,8 +3613,8 @@ void ICACHE_FLASH_ATTR user_set_station_config(void) //char hostname[40]; /* Setup AP credentials */ - os_sprintf(stationConf.ssid, "%s", config.ssid); - os_sprintf(stationConf.password, "%s", config.password); + os_sprintf(stationConf.ssid, "%s", config.automesh_use_ap_ssid?config.ap_ssid:config.ssid); + os_sprintf(stationConf.password, "%s", config.automesh_use_ap_ssid?config.ap_password:config.password); if (*(int*)config.bssid != 0) { stationConf.bssid_set = 1; os_memcpy(stationConf.bssid, config.bssid, 6); @@ -3675,6 +3675,7 @@ void ICACHE_FLASH_ATTR automesh_scan_done(void *arg, STATUS status) { mesh_level = 0xff; int rssi = -1000; + bool automesh_use_ap_ssid = false; struct bss_info *bss_link; @@ -3704,6 +3705,7 @@ void ICACHE_FLASH_ATTR automesh_scan_done(void *arg, STATUS status) rssi = bss_link->rssi; mesh_level = this_mesh_level; os_memcpy(config.bssid, bss_link->bssid, 6); + automesh_use_ap_ssid = os_strcmp(bss_link->ssid, config.ap_ssid) == 0; } } } @@ -3716,6 +3718,7 @@ void ICACHE_FLASH_ATTR automesh_scan_done(void *arg, STATUS status) config.AP_MAC_address[2] = mesh_level+1; os_get_random(&config.AP_MAC_address[3], 3); + config.automesh_use_ap_ssid = automesh_use_ap_ssid; wifi_set_macaddr(SOFTAP_IF, config.AP_MAC_address); user_set_softap_wifi_config(); @@ -3738,7 +3741,13 @@ void ICACHE_FLASH_ATTR automesh_scan_done(void *arg, STATUS status) os_printf("Scan fail !!!\r\n"); } - os_printf("No AP with ssid %s found\r\n", config.ssid); + char *nor = ""; + char *apssid = ""; + if (os_strcmp(config.ap_ssid, "none") != 0) { + nor = " nor "; + apssid = config.ap_ssid; + } + os_printf("No AP with ssid %s%s%s found\r\n", config.ssid, nor, apssid); #if ALLOW_SLEEP if (config.am_scan_time && config.am_sleep_time) {