Skip to content

Commit 0cefc23

Browse files
committed
Minor fixes
1 parent 54c9037 commit 0cefc23

File tree

1 file changed

+27
-21
lines changed

1 file changed

+27
-21
lines changed

src/mgos_wifi_sta.c

+27-21
Original file line numberDiff line numberDiff line change
@@ -682,8 +682,6 @@ static void mgos_wifi_sta_run(int wifi_ev, void *ev_data, bool timeout) {
682682
if (changed) {
683683
mgos_conf_set_str(&cfg->last_bssid, bssid_s);
684684
cfg->last_channel = ape->channel;
685-
LOG(LL_INFO,
686-
("Saving AP %s %s ch %d", cfg->ssid, bssid_s, ape->channel));
687685
// Early version of this code was using bssid prefixed with '*' and
688686
// negative channel to store quick connect values.
689687
// This was a bad idea that broke backward compatibility,
@@ -692,8 +690,12 @@ static void mgos_wifi_sta_run(int wifi_ev, void *ev_data, bool timeout) {
692690
if (!mgos_conf_str_empty(cfg->bssid) && cfg->bssid[0] == '*') {
693691
mgos_conf_set_str(&cfg->bssid, NULL);
694692
}
695-
mgos_sys_config_save(&mgos_sys_config, false /* try_once */,
696-
NULL /* msg */);
693+
if (is_sys_cfg(cfg)) {
694+
LOG(LL_INFO,
695+
("Saving AP %s %s ch %d", cfg->ssid, bssid_s, ape->channel));
696+
mgos_sys_config_save(&mgos_sys_config, false /* try_once */,
697+
NULL /* msg */);
698+
}
697699
}
698700
}
699701
mgos_wifi_sta_dump_list(&s_ap_history, "history");
@@ -752,23 +754,27 @@ void mgos_wifi_sta_ev_handler(int ev, void *evd, void *cb_arg) {
752754
bool mgos_wifi_connect(void) {
753755
int ret = true;
754756
wifi_lock();
755-
switch (s_state) {
756-
case WIFI_STA_SHUTDOWN:
757-
ret = false;
758-
break;
759-
case WIFI_STA_IDLE:
760-
s_state = WIFI_STA_INIT;
761-
mgos_wifi_sta_set_timeout(true /* run_now */);
762-
break;
763-
case WIFI_STA_INIT:
764-
case WIFI_STA_SCAN:
765-
case WIFI_STA_SCANNING:
766-
case WIFI_STA_WAIT_CONNECT:
767-
case WIFI_STA_CONNECT:
768-
case WIFI_STA_CONNECTING:
769-
case WIFI_STA_CONNECTED:
770-
case WIFI_STA_IP_ACQUIRED:
771-
break;
757+
if (s_num_cfgs > 0) {
758+
switch (s_state) {
759+
case WIFI_STA_SHUTDOWN:
760+
ret = false;
761+
break;
762+
case WIFI_STA_IDLE:
763+
s_state = WIFI_STA_INIT;
764+
mgos_wifi_sta_set_timeout(true /* run_now */);
765+
break;
766+
case WIFI_STA_INIT:
767+
case WIFI_STA_SCAN:
768+
case WIFI_STA_SCANNING:
769+
case WIFI_STA_WAIT_CONNECT:
770+
case WIFI_STA_CONNECT:
771+
case WIFI_STA_CONNECTING:
772+
case WIFI_STA_CONNECTED:
773+
case WIFI_STA_IP_ACQUIRED:
774+
break;
775+
}
776+
} else {
777+
ret = false;
772778
}
773779
wifi_unlock();
774780
return ret;

0 commit comments

Comments
 (0)