@@ -109,8 +109,8 @@ class Wippersnapper_AIRLIFT : public Wippersnapper {
109109 */
110110 /* ***************************************************************/
111111 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 */
114114 };
115115
116116 /* ******************************************************************/
@@ -145,38 +145,35 @@ class Wippersnapper_AIRLIFT : public Wippersnapper {
145145 return false ;
146146 }
147147
148- // Dynamically allocate memory for the network list
149- std::vector<WiFiNetwork> networks (n);
148+ WiFiNetwork networks[WS_MAX_SORTED_NETWORKS];
150149
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 ));
156153 networks[i].rssi = WiFi.RSSI (i);
157154 }
158155
159156 // 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);
161158
162159 // 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 ) {
165162 WS_DEBUG_PRINT (" SSID (" );
166163 WS_DEBUG_PRINT (_ssid);
167164 WS_DEBUG_PRINT (" ) found! RSSI: " );
168- WS_DEBUG_PRINTLN (network. rssi );
165+ WS_DEBUG_PRINTLN (WiFi. RSSI (i) );
169166 return true ;
170167 }
171168 }
172169
173170 // User-set network not found, print scan results to serial console
174171 WS_DEBUG_PRINTLN (" ERROR: Your requested WiFi network was not found!" );
175172 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) );
178175 WS_DEBUG_PRINT (" " );
179- WS_DEBUG_PRINT (network. rssi );
176+ WS_DEBUG_PRINT (WiFi. RSSI (i) );
180177 WS_DEBUG_PRINTLN (" dB" );
181178 }
182179
0 commit comments