mirror of
https://github.com/martin-ger/esp_wifi_repeater.git
synced 2026-07-27 19:56:03 +00:00
Merge pull request #306 from bchabrier/small_fixes
Allow specifying an ap_ssid (and possibly password) in Automesh mode
This commit is contained in:
@@ -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.
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
+18
-4
@@ -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,12 +3675,13 @@ 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;
|
||||
|
||||
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",
|
||||
@@ -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) {
|
||||
@@ -3888,8 +3897,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_password, "none") == 0) {
|
||||
os_memcpy(config.ap_password, config.password, sizeof(config.password));
|
||||
}
|
||||
}
|
||||
|
||||
if (config.automesh_mode == AUTOMESH_LEARNING) {
|
||||
config.ap_on = 0;
|
||||
|
||||
Reference in New Issue
Block a user