consider duplicate ssids in wifiscan

esp8266-bme280
noerw 8 years ago
parent 1a840c0d4a
commit ac8d10bb49

@ -3,7 +3,9 @@
/* WiFi (ESP8266) */
#define WIFI_SSID "Penaten"
#define WIFI_SSID "FRITZ!Box 7490"
#define WIFI_PASS "XXXXXX"
/* GPS reciever (uBloc NEO-7M) */
@ -19,6 +21,8 @@
#define API_KEY_LENGTH 24
#define API_KEY "XXXXXXXXXXX"
#define ID_BOX "57c7f3291421551100bf13c8"
#define ID_SENSOR_WIFI "57c7f3291421551100bf13ca"
#define ID_SENSOR_WIFI_APS "57c7f3291421551100bf13ca"
#define ID_SENSOR_WIFI_NET "57cdd4ce1421551100bf17c5"
#define ID_SENSOR_WIFI_OPEN "57cdd4ce1421551100bf17c6"
#define MEASUREMENT_INTERVAL 10000
#define MEASUREMENT_INTERVAL 20000

@ -108,6 +108,7 @@ void loop() {
// print state
DEBUG_OUT << "homeAvailable: " << wifiState.homeAvailable << EOL;
DEBUG_OUT << "numAPs: " << wifiState.numAccessPoints << EOL;
DEBUG_OUT << "numNetworks: " << wifiState.numNetworks << EOL;
DEBUG_OUT << "numUnencrypted: " << wifiState.numUnencrypted << EOL;
DEBUG_OUT.print("lat: ");
@ -116,18 +117,32 @@ void loop() {
DEBUG_OUT.println(loc.lng(), 6);
DEBUG_OUT << dateString << EOL;
// TODO. write location update to file
// write measurements to file
if (storeMeasurement(loc.lat(), loc.lng(), wifiState.numNetworks, dateString, ID_SENSOR_WIFI)) {
DEBUG_OUT.print("measurement (wifi) stored! storage size: ");
if (storeMeasurement(loc.lat(), loc.lng(), wifiState.numAccessPoints, dateString, ID_SENSOR_WIFI_APS)) {
DEBUG_OUT.print("measurement (wifi aps) stored! storage size: ");
} else {
DEBUG_OUT.print("measurement (wifi) store failed! storage size: ");
DEBUG_OUT.print("measurement (wifi aps) store failed! storage size: ");
}
DEBUG_OUT.println(storage.size());
if (storeMeasurement(loc.lat(), loc.lng(), wifiState.numNetworks, dateString, ID_SENSOR_WIFI_NET)) {
DEBUG_OUT.print("measurement (wifi nets) stored! storage size: ");
} else {
DEBUG_OUT.print("measurement (wifi nets) store failed! storage size: ");
}
DEBUG_OUT.println(storage.size());
if (storeMeasurement(loc.lat(), loc.lng(), wifiState.numUnencrypted, dateString, ID_SENSOR_WIFI_OPEN)) {
DEBUG_OUT.print("measurement (wifi open) stored! storage size: ");
} else {
DEBUG_OUT.print("measurement (wifi open) store failed! storage size: ");
}
DEBUG_OUT.println(storage.size());
// connect to wifi, if available & not connected yet
// once we are connected, upload (max) 3 stored measurements & free the storage
// once we are connected, upload (max) 4 stored measurements & free the storage
if (wifi.isConnected() || (wifiState.homeAvailable && wifi.connect(WIFI_SSID, WIFI_PASS)) ) {
uploadMeasurements(3);
uploadMeasurements(4);
}
DEBUG_OUT << EOL;

@ -4,6 +4,7 @@
struct WifiState {
bool homeAvailable;
unsigned int numAccessPoints;
unsigned int numNetworks;
unsigned int numUnencrypted;
};
@ -15,20 +16,37 @@ class Wifi {
}
WifiState scan(String homeSSID) {
// TODO: filter duplicate SSIDs!
WifiState state;
state.homeAvailable = false;
state.numNetworks = WiFi.scanNetworks(false, false);
int n = WiFi.scanNetworks(false,false);
state.numAccessPoints = n;
state.numNetworks = n;
state.numUnencrypted = 0;
state.homeAvailable = false;
int indices[n];
String ssid;
for (int i = 0; i < n; i++) indices[i] = i;
for (int i = 0; i < n; i++) {
// filter duplicates
if(indices[i] == -1) {
--state.numNetworks;
continue;
}
ssid = WiFi.SSID(indices[i]);
for (int j = i + 1; j < n; j++) {
if (ssid == WiFi.SSID(indices[j])) indices[j] = -1;
}
if (indices[i] != -1) {
if (WiFi.encryptionType(indices[i]) == ENC_TYPE_NONE)
++state.numUnencrypted;
for (unsigned int i = 0; i < state.numNetworks; i++) {
if (WiFi.encryptionType(i) == ENC_TYPE_NONE)
++state.numUnencrypted;
if (WiFi.SSID(i) == homeSSID)
state.homeAvailable = true;
if (WiFi.SSID(indices[i]) == homeSSID)
state.homeAvailable = true;
}
}
return state;
}

Loading…
Cancel
Save