consider duplicate ssids in wifiscan
This commit is contained in:
parent
1a840c0d4a
commit
ac8d10bb49
3 changed files with 56 additions and 19 deletions
10
config.h
10
config.h
|
@ -3,7 +3,9 @@
|
||||||
/* WiFi (ESP8266) */
|
/* WiFi (ESP8266) */
|
||||||
|
|
||||||
|
|
||||||
#define WIFI_SSID "Penaten"
|
|
||||||
|
|
||||||
|
#define WIFI_SSID "FRITZ!Box 7490"
|
||||||
#define WIFI_PASS "XXXXXX"
|
#define WIFI_PASS "XXXXXX"
|
||||||
|
|
||||||
/* GPS reciever (uBloc NEO-7M) */
|
/* GPS reciever (uBloc NEO-7M) */
|
||||||
|
@ -19,6 +21,8 @@
|
||||||
#define API_KEY_LENGTH 24
|
#define API_KEY_LENGTH 24
|
||||||
#define API_KEY "XXXXXXXXXXX"
|
#define API_KEY "XXXXXXXXXXX"
|
||||||
#define ID_BOX "57c7f3291421551100bf13c8"
|
#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
|
// print state
|
||||||
DEBUG_OUT << "homeAvailable: " << wifiState.homeAvailable << EOL;
|
DEBUG_OUT << "homeAvailable: " << wifiState.homeAvailable << EOL;
|
||||||
|
DEBUG_OUT << "numAPs: " << wifiState.numAccessPoints << EOL;
|
||||||
DEBUG_OUT << "numNetworks: " << wifiState.numNetworks << EOL;
|
DEBUG_OUT << "numNetworks: " << wifiState.numNetworks << EOL;
|
||||||
DEBUG_OUT << "numUnencrypted: " << wifiState.numUnencrypted << EOL;
|
DEBUG_OUT << "numUnencrypted: " << wifiState.numUnencrypted << EOL;
|
||||||
DEBUG_OUT.print("lat: ");
|
DEBUG_OUT.print("lat: ");
|
||||||
|
@ -116,18 +117,32 @@ void loop() {
|
||||||
DEBUG_OUT.println(loc.lng(), 6);
|
DEBUG_OUT.println(loc.lng(), 6);
|
||||||
DEBUG_OUT << dateString << EOL;
|
DEBUG_OUT << dateString << EOL;
|
||||||
|
|
||||||
|
// TODO. write location update to file
|
||||||
|
|
||||||
// write measurements to file
|
// write measurements to file
|
||||||
if (storeMeasurement(loc.lat(), loc.lng(), wifiState.numNetworks, dateString, ID_SENSOR_WIFI)) {
|
if (storeMeasurement(loc.lat(), loc.lng(), wifiState.numAccessPoints, dateString, ID_SENSOR_WIFI_APS)) {
|
||||||
DEBUG_OUT.print("measurement (wifi) stored! storage size: ");
|
DEBUG_OUT.print("measurement (wifi aps) stored! storage size: ");
|
||||||
} else {
|
} 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());
|
DEBUG_OUT.println(storage.size());
|
||||||
|
|
||||||
// connect to wifi, if available & not connected yet
|
// 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)) ) {
|
if (wifi.isConnected() || (wifiState.homeAvailable && wifi.connect(WIFI_SSID, WIFI_PASS)) ) {
|
||||||
uploadMeasurements(3);
|
uploadMeasurements(4);
|
||||||
}
|
}
|
||||||
|
|
||||||
DEBUG_OUT << EOL;
|
DEBUG_OUT << EOL;
|
||||||
|
|
30
wifi.h
30
wifi.h
|
@ -4,6 +4,7 @@
|
||||||
|
|
||||||
struct WifiState {
|
struct WifiState {
|
||||||
bool homeAvailable;
|
bool homeAvailable;
|
||||||
|
unsigned int numAccessPoints;
|
||||||
unsigned int numNetworks;
|
unsigned int numNetworks;
|
||||||
unsigned int numUnencrypted;
|
unsigned int numUnencrypted;
|
||||||
};
|
};
|
||||||
|
@ -15,19 +16,36 @@ class Wifi {
|
||||||
}
|
}
|
||||||
|
|
||||||
WifiState scan(String homeSSID) {
|
WifiState scan(String homeSSID) {
|
||||||
// TODO: filter duplicate SSIDs!
|
|
||||||
WifiState state;
|
WifiState state;
|
||||||
state.homeAvailable = false;
|
int n = WiFi.scanNetworks(false,false);
|
||||||
state.numNetworks = WiFi.scanNetworks(false, false);
|
state.numAccessPoints = n;
|
||||||
|
state.numNetworks = n;
|
||||||
state.numUnencrypted = 0;
|
state.numUnencrypted = 0;
|
||||||
|
state.homeAvailable = false;
|
||||||
|
int indices[n];
|
||||||
|
String ssid;
|
||||||
|
|
||||||
for (unsigned int i = 0; i < state.numNetworks; i++) {
|
for (int i = 0; i < n; i++) indices[i] = i;
|
||||||
if (WiFi.encryptionType(i) == ENC_TYPE_NONE)
|
|
||||||
|
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;
|
++state.numUnencrypted;
|
||||||
|
|
||||||
if (WiFi.SSID(i) == homeSSID)
|
if (WiFi.SSID(indices[i]) == homeSSID)
|
||||||
state.homeAvailable = true;
|
state.homeAvailable = true;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return state;
|
return state;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue