Skip to content

Commit b5e9a53

Browse files
committed
Remove unnecessary includes + fixup esp8266
1 parent 5c645ad commit b5e9a53

File tree

5 files changed

+34
-28
lines changed

5 files changed

+34
-28
lines changed

src/network_interfaces/Wippersnapper_AIRLIFT.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,6 @@
2626
#include "SPI.h"
2727
#include "WiFiNINA.h"
2828
#include "Wippersnapper.h"
29-
#include <algorithm>
30-
#include <vector>
3129

3230
#define NINAFWVER \
3331
"1.7.7" /*!< min. nina-fw version compatible with this library. */

src/network_interfaces/Wippersnapper_ESP32.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@
2727
#include "WiFiMulti.h"
2828
#include <NetworkClient.h>
2929
#include <NetworkClientSecure.h>
30-
#include <algorithm>
31-
#include <vector>
3230
extern Wippersnapper WS;
3331

3432
/****************************************************************************/

src/network_interfaces/Wippersnapper_ESP8266.h

Lines changed: 34 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@
2323
#include "ESP8266WiFi.h"
2424
#include "ESP8266WiFiMulti.h"
2525
#include "Wippersnapper.h"
26-
#include <algorithm>
27-
#include <vector>
2826

2927
/* NOTE - Projects that require "Secure MQTT" (TLS/SSL) also require a new
3028
* SSL certificate every year. If adding Secure MQTT to your ESP8266 project is
@@ -159,38 +157,47 @@ class Wippersnapper_ESP8266 : public Wippersnapper {
159157
return false;
160158
}
161159

162-
// Dynamically allocate memory for the network list
163-
std::vector<WiFiNetwork> networks(n);
164-
160+
WiFiNetwork networks[WS_MAX_SORTED_NETWORKS];
161+
uint8_t numSavedNetworks = 0;
165162
// Store the scanned networks in the vector
166163
for (int i = 0; i < n; ++i) {
167-
strncpy(networks[i].ssid, WiFi.SSID(i).c_str(),
168-
sizeof(networks[i].ssid) - 1);
169-
networks[i].ssid[sizeof(networks[i].ssid) - 1] =
170-
'\0'; // Ensure null termination
171-
networks[i].rssi = WiFi.RSSI(i);
164+
if (i < WS_MAX_SORTED_NETWORKS) {
165+
strncpy(networks[i].ssid, WiFi.SSID(i).c_str(),
166+
sizeof(networks[i].ssid));
167+
networks[i].ssid[sizeof(networks[i].ssid) - 1] = '\0';
168+
networks[i].rssi = WiFi.RSSI(i);
169+
numSavedNetworks++;
170+
} else {
171+
WS_DEBUG_PRINT("ERROR: Too many networks found! (>");
172+
WS_DEBUG_PRINT(WS_MAX_SORTED_NETWORKS);
173+
WS_DEBUG_PRINT(") Ignoring ");
174+
WS_DEBUG_PRINT(WiFi.SSID(i));
175+
WS_DEBUG_PRINT("(");
176+
WS_DEBUG_PRINT(WiFi.RSSI(i));
177+
WS_DEBUG_PRINTLN(")");
178+
}
172179
}
173180

174181
// Sort the networks by RSSI in descending order
175-
std::sort(networks.begin(), networks.end(), compareByRSSI);
182+
std::sort(networks, networks + numSavedNetworks, compareByRSSI);
176183

177184
// Was the network within secrets.json found?
178-
for (const auto &network : networks) {
179-
if (strcmp(_ssid, network.ssid) == 0) {
185+
for (int i = 0; i < numSavedNetworks; ++i) {
186+
if (strcmp(_ssid, networks[i].ssid) == 0) {
180187
WS_DEBUG_PRINT("SSID (");
181188
WS_DEBUG_PRINT(_ssid);
182189
WS_DEBUG_PRINT(") found! RSSI: ");
183-
WS_DEBUG_PRINTLN(network.rssi);
190+
WS_DEBUG_PRINTLN(networks[i].rssi);
184191
return true;
185192
}
186193
if (WS._isWiFiMulti) {
187194
// multi network mode
188195
for (int j = 0; j < WS_MAX_ALT_WIFI_NETWORKS; j++) {
189-
if (strcmp(WS._multiNetworks[j].ssid, network.ssid) == 0) {
196+
if (strcmp(WS._multiNetworks[j].ssid, networks[i].ssid) == 0) {
190197
WS_DEBUG_PRINT("SSID (");
191198
WS_DEBUG_PRINT(WS._multiNetworks[j].ssid);
192199
WS_DEBUG_PRINT(") found! RSSI: ");
193-
WS_DEBUG_PRINTLN(network.rssi);
200+
WS_DEBUG_PRINTLN(networks[i].rssi);
194201
return true;
195202
}
196203
}
@@ -199,11 +206,18 @@ class Wippersnapper_ESP8266 : public Wippersnapper {
199206

200207
// User-set network not found, print scan results to serial console
201208
WS_DEBUG_PRINTLN("ERROR: Your requested WiFi network was not found!");
202-
WS_DEBUG_PRINTLN("WipperSnapper found these WiFi networks: ");
203-
for (const auto &network : networks) {
204-
WS_DEBUG_PRINT(network.ssid);
209+
WS_DEBUG_PRINT("WipperSnapper found these WiFi networks");
210+
if (n > WS_MAX_SORTED_NETWORKS) {
211+
WS_DEBUG_PRINT(" (only first ");
212+
WS_DEBUG_PRINT(WS_MAX_SORTED_NETWORKS);
213+
WS_DEBUG_PRINTLN(" used):");
214+
} else {
215+
WS_DEBUG_PRINTLN(":");
216+
}
217+
for (int i = 0; i < n; ++i) {
218+
WS_DEBUG_PRINT(networks[i].ssid);
205219
WS_DEBUG_PRINT(" ");
206-
WS_DEBUG_PRINT(network.rssi);
220+
WS_DEBUG_PRINT(networks[i].rssi);
207221
WS_DEBUG_PRINTLN("dB");
208222
}
209223

src/network_interfaces/Wippersnapper_WIFININA.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@
2121
#include <Arduino.h>
2222
#include <SPI.h>
2323
#include <WiFiNINA.h>
24-
#include <algorithm>
25-
#include <vector>
2624

2725
#include "Wippersnapper.h"
2826

src/network_interfaces/ws_networking_pico.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,6 @@
2929
#include "Arduino.h"
3030
#include <WiFiClient.h>
3131
#include <WiFiClientSecure.h>
32-
#include <algorithm>
33-
#include <vector>
3432
extern Wippersnapper WS;
3533

3634
/****************************************************************************/

0 commit comments

Comments
 (0)