@@ -109,8 +109,8 @@ class Wippersnapper_AIRLIFT : public Wippersnapper {
109
109
*/
110
110
/* ***************************************************************/
111
111
struct WiFiNetwork {
112
- char ssid[33 ]; /* !< SSID (Max 32 characters + null terminator */
113
- int rssi; /* !< Received Signal Strength Indicator */
112
+ String ssid[32 ]; /* !< SSID (Max 32 characters + null terminator */
113
+ int32_t rssi = - 99 ; /* !< Received Signal Strength Indicator */
114
114
};
115
115
116
116
/* ******************************************************************/
@@ -145,38 +145,35 @@ class Wippersnapper_AIRLIFT : public Wippersnapper {
145
145
return false ;
146
146
}
147
147
148
- // Dynamically allocate memory for the network list
149
- std::vector<WiFiNetwork> networks (n);
148
+ WiFiNetwork networks[WS_MAX_SORTED_NETWORKS];
150
149
151
- // Store the scanned networks in the vector
152
- for (int i = 0 ; i < n; ++i) {
153
- strncpy (networks[i].ssid , WiFi.SSID (i), sizeof (networks[i].ssid ) - 1 );
154
- networks[i].ssid [sizeof (networks[i].ssid ) - 1 ] =
155
- ' \0 ' ; // Ensure null termination
150
+ // Store the scanned networks in the array
151
+ for (int i = 0 ; i < n && i < WS_MAX_SORTED_NETWORKS; ++i) {
152
+ strncpy (networks[i].ssid ->c_str (), WiFi.SSID (i), sizeof (networks[i].ssid ));
156
153
networks[i].rssi = WiFi.RSSI (i);
157
154
}
158
155
159
156
// Sort the networks by RSSI in descending order
160
- std::sort (networks. begin () , networks. end ( ), compareByRSSI);
157
+ std::sort (networks, networks + std::min (n, WS_MAX_SORTED_NETWORKS ), compareByRSSI);
161
158
162
159
// Was the network within secrets.json found?
163
- for (const auto &network : networks ) {
164
- if (strcmp (_ssid, network. ssid ) == 0 ) {
160
+ for (int i = 0 ; i < n; ++i ) {
161
+ if (strcmp (_ssid, WiFi. SSID (i) ) == 0 ) {
165
162
WS_DEBUG_PRINT (" SSID (" );
166
163
WS_DEBUG_PRINT (_ssid);
167
164
WS_DEBUG_PRINT (" ) found! RSSI: " );
168
- WS_DEBUG_PRINTLN (network. rssi );
165
+ WS_DEBUG_PRINTLN (WiFi. RSSI (i) );
169
166
return true ;
170
167
}
171
168
}
172
169
173
170
// User-set network not found, print scan results to serial console
174
171
WS_DEBUG_PRINTLN (" ERROR: Your requested WiFi network was not found!" );
175
172
WS_DEBUG_PRINTLN (" WipperSnapper found these WiFi networks: " );
176
- for (const auto &network : networks ) {
177
- WS_DEBUG_PRINT (network. ssid );
173
+ for (int i = 0 ; i < n; ++i ) {
174
+ WS_DEBUG_PRINT (WiFi. SSID (i) );
178
175
WS_DEBUG_PRINT (" " );
179
- WS_DEBUG_PRINT (network. rssi );
176
+ WS_DEBUG_PRINT (WiFi. RSSI (i) );
180
177
WS_DEBUG_PRINTLN (" dB" );
181
178
}
182
179
0 commit comments