Skip to content

Commit

Permalink
Add quick connect mode
Browse files Browse the repository at this point in the history
Use `bssid` and `channel` fields of the config to store BSSID and channel of
the last AP successfulyl connected to.
These are stored with `*` prefix and as a negated value to distinguish
them from user-provided values.
When first connecting, check all configs for entries with BSSID and
channel specified and build initial conenct queue with these static
entries, bypassing the scan. If no successful connection is made, we go
back to scanning and building a new queue as before.

Signed-off-by: Deomid "rojer" Ryabkov <rojer@rojer.me>
  • Loading branch information
rojer committed Oct 23, 2021
1 parent ce1e294 commit 561baac
Show file tree
Hide file tree
Showing 4 changed files with 206 additions and 63 deletions.
3 changes: 2 additions & 1 deletion mos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ config_schema:
- ["wifi.sta.enable", "b", {title: "Connect to existing WiFi"}]
- ["wifi.sta.ssid", "s", {title: "SSID"}]
- ["wifi.sta.pass", "s", {title: "Password", type: "password"}]
- ["wifi.sta.bssid", "s", {title: "Specific AP to connect to"}]
- ["wifi.sta.bssid", "s", {title: "Specific AP to connect to. Also used to store BSSID for quick connect (prefixed with '*')."}]
- ["wifi.sta.channel", "i", {title: "Specific channel to use when connecting. Also used to store channel for quick connect (as a negative value)."}]
- ["wifi.sta.user", "s", {title: "Username for WPA-PEAP mode"}]
- ["wifi.sta.anon_identity", "s", {title: "Anonymous identity for WPA mode"}]
- ["wifi.sta.cert", "s", {title: "Client certificate for WPA-TTLS mode"}]
Expand Down
1 change: 1 addition & 0 deletions src/esp32/esp32_wifi.c
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,7 @@ bool mgos_wifi_dev_sta_setup(const struct mgos_config_wifi_sta *cfg) {
}
stacfg->bssid_set = true;
}
stacfg->channel = cfg->channel;

if (mgos_conf_str_empty(cfg->user) /* Not using EAP */ &&
!mgos_conf_str_empty(cfg->pass)) {
Expand Down
4 changes: 3 additions & 1 deletion src/esp8266/esp_wifi.c
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,7 @@ bool mgos_wifi_dev_sta_setup(const struct mgos_config_wifi_sta *cfg) {
}
sta_cfg.bssid_set = true;
}
sta_cfg.channel = cfg->channel;
strncpy((char *) sta_cfg.ssid, cfg->ssid, sizeof(sta_cfg.ssid));

if (!mgos_conf_str_empty(cfg->ip) && !mgos_conf_str_empty(cfg->netmask)) {
Expand Down Expand Up @@ -473,7 +474,8 @@ bool mgos_wifi_dev_get_ip_info(int if_instance,
struct netif *sta_if = eagle_lwip_getif(STATION_IF);
if (sta_if != NULL) {
struct dhcp *dhcp = sta_if->dhcp;
const struct mgos_config_wifi_sta *cfg = mgos_wifi_get_connected_sta_cfg();
const struct mgos_config_wifi_sta *cfg =
mgos_wifi_get_connected_sta_cfg();
if (cfg != NULL && !mgos_conf_str_empty(cfg->nameserver)) {
mgos_net_str_to_ip(cfg->nameserver, &ip_info->dns);
} else if (dhcp != NULL) {
Expand Down
Loading

0 comments on commit 561baac

Please sign in to comment.