Skip to content

Commit 10afca0

Browse files
committed
Add default SSID to multi wifi list + Cleanup formatting
1 parent e1dc72f commit 10afca0

File tree

5 files changed

+32
-13
lines changed

5 files changed

+32
-13
lines changed

src/network_interfaces/Wippersnapper_ESP32.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,9 @@ class Wippersnapper_ESP32 : public Wippersnapper {
278278
// multi network mode
279279
_wifiMulti.APlistClean();
280280
_wifiMulti.setAllowOpenAP(false);
281+
// add default network
282+
_wifiMulti.addAP(_ssid, _pass);
283+
// add array of alternative networks
281284
for (int i = 0; i < 5; i++) {
282285
if (strlen(WS._multiNetworks[i].ssid) > 0) {
283286
_wifiMulti.addAP(WS._multiNetworks[i].ssid,

src/network_interfaces/Wippersnapper_ESP8266.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,9 +257,14 @@ class Wippersnapper_ESP8266 : public Wippersnapper {
257257
WS._multiNetworks[i].pass);
258258
}
259259
}
260+
// add default network
261+
if (_wifiMulti.existsAP(_ssid) == false){
262+
_wifiMulti.addAP(_ssid, _pass);
263+
}
260264
long startRetry = millis();
261265
WS_DEBUG_PRINTLN("CONNECTING");
262-
while (_wifiMulti.run(5000) != WL_CONNECTED && millis() - startRetry < 10000) {
266+
while (_wifiMulti.run(5000) != WL_CONNECTED &&
267+
millis() - startRetry < 10000) {
263268
// ESP8266 WDT requires yield() during a busy-loop so it doesn't bite
264269
yield();
265270
}

src/network_interfaces/ws_networking_pico.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,9 @@ class ws_networking_pico : public Wippersnapper {
283283
if (strlen(WS._multiNetworks[0].ssid) > 0) {
284284
// multi network mode
285285
_wifiMulti.clearAPList();
286+
// add default network
287+
_wifiMulti.addAP(_ssid, _pass);
288+
// add array of alternative networks
286289
for (int i = 0; i < 5; i++) {
287290
_wifiMulti.addAP(WS._multiNetworks[i].ssid,
288291
WS._multiNetworks[i].pass);

src/provisioning/littlefs/WipperSnapper_LittleFS.cpp

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -73,24 +73,28 @@ void WipperSnapper_LittleFS::parseSecrets() {
7373
convertFromJson(doc["network_type_wifi"], WS._config.network);
7474

7575
if (!doc["network_type_wifi"].containsKey("alternate_networks")) {
76+
// do nothing extra, we already have the only network
7677
WS_DEBUG_PRINTLN("Found single wifi network in secrets.json");
7778

78-
} else if (doc["network_type_wifi"]["alternative_networks"].is<JsonArray>()) {
79+
} else if (doc["network_type_wifi"]["alternative_networks"]
80+
.is<JsonArray>()) {
81+
7982
WS_DEBUG_PRINTLN("Found multiple wifi networks in secrets.json");
8083
// Parse network credentials from array in secrets
8184
JsonArray networks = doc["network_type_wifi"]["alternative_networks"];
8285
int8_t networkCount = networks.size();
8386
WS_DEBUG_PRINT("Network count: ");
8487
WS_DEBUG_PRINTLN(networkCount);
8588
if (networkCount == 0) {
86-
fsHalt("ERROR: No networks found in network_type_wifi in secrets.json!");
89+
fsHalt(
90+
"ERROR: No networks found in network_type_wifi in secrets.json!");
8791
}
8892
// check if over 5, warn user and take first five
8993
for (int i = 0; i < networkCount; i++) {
9094
if (i >= 3) {
9195
WS_DEBUG_PRINT("WARNING: More than 3 networks in secrets.json, "
92-
"only the first 3 will be used. Not using ");
93-
WS_DEBUG_PRINTLN(networks[i]["ssid"].as<const char*>());
96+
"only the first 3 will be used. Not using ");
97+
WS_DEBUG_PRINTLN(networks[i]["ssid"].as<const char *>());
9498
break;
9599
}
96100
convertFromJson(networks[i], WS._multiNetworks[i]);
@@ -100,8 +104,8 @@ void WipperSnapper_LittleFS::parseSecrets() {
100104
WS_DEBUG_PRINTLN(WS._multiNetworks[i].pass);
101105
}
102106
} else {
103-
fsHalt("ERROR: Unrecognised value type for network_type_wifi in "
104-
"secrets.json!");
107+
fsHalt("ERROR: Unrecognised value type for "
108+
"network_type_wifi.alternative_networks in secrets.json!");
105109
}
106110
} else {
107111
fsHalt("ERROR: Could not find network_type_wifi in secrets.json!");

src/provisioning/tinyusb/Wippersnapper_FS.cpp

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -356,24 +356,28 @@ void Wippersnapper_FS::parseSecrets() {
356356
convertFromJson(doc["network_type_wifi"], WS._config.network);
357357

358358
if (!doc["network_type_wifi"].containsKey("alternate_networks")) {
359+
// do nothing extra, we already have the only network
359360
WS_DEBUG_PRINTLN("Found single wifi network in secrets.json");
360361

361-
} else if (doc["network_type_wifi"]["alternative_networks"].is<JsonArray>()) {
362+
} else if (doc["network_type_wifi"]["alternative_networks"]
363+
.is<JsonArray>()) {
364+
362365
WS_DEBUG_PRINTLN("Found multiple wifi networks in secrets.json");
363366
// Parse network credentials from array in secrets
364367
JsonArray networks = doc["network_type_wifi"]["alternative_networks"];
365368
int8_t networkCount = networks.size();
366369
WS_DEBUG_PRINT("Network count: ");
367370
WS_DEBUG_PRINTLN(networkCount);
368371
if (networkCount == 0) {
369-
fsHalt("ERROR: No networks found in network_type_wifi in secrets.json!");
372+
fsHalt(
373+
"ERROR: No networks found in network_type_wifi in secrets.json!");
370374
}
371375
// check if over 5, warn user and take first five
372376
for (int i = 0; i < networkCount; i++) {
373377
if (i >= 3) {
374378
WS_DEBUG_PRINT("WARNING: More than 3 networks in secrets.json, "
375-
"only the first 3 will be used. Not using ");
376-
WS_DEBUG_PRINTLN(networks[i]["ssid"].as<const char*>());
379+
"only the first 3 will be used. Not using ");
380+
WS_DEBUG_PRINTLN(networks[i]["ssid"].as<const char *>());
377381
break;
378382
}
379383
convertFromJson(networks[i], WS._multiNetworks[i]);
@@ -383,8 +387,8 @@ void Wippersnapper_FS::parseSecrets() {
383387
WS_DEBUG_PRINTLN(WS._multiNetworks[i].pass);
384388
}
385389
} else {
386-
fsHalt("ERROR: Unrecognised value type for network_type_wifi in "
387-
"secrets.json!");
390+
fsHalt("ERROR: Unrecognised value type for "
391+
"network_type_wifi.alternative_networks in secrets.json!");
388392
}
389393
} else {
390394
fsHalt("ERROR: Could not find network_type_wifi in secrets.json!");

0 commit comments

Comments
 (0)