|
|
|
@ -9,41 +9,57 @@
|
|
|
|
|
|
|
|
|
|
//TelnetPrint telnet = TelnetPrint();
|
|
|
|
|
Storage storage = Storage();
|
|
|
|
|
Wifi wifi = Wifi();
|
|
|
|
|
OsemApi api = OsemApi();
|
|
|
|
|
Gps gps = Gps();
|
|
|
|
|
|
|
|
|
|
/* UTILS */
|
|
|
|
|
void printState(WifiState wifi) {
|
|
|
|
|
void printState(WifiState wifiState) {
|
|
|
|
|
DEBUG_OUT.print("homeAvailable: ");
|
|
|
|
|
DEBUG_OUT.println(wifi.homeAvailable);
|
|
|
|
|
DEBUG_OUT.println(wifiState.homeAvailable);
|
|
|
|
|
DEBUG_OUT.print("numNetworks: ");
|
|
|
|
|
DEBUG_OUT.println(wifi.numNetworks);
|
|
|
|
|
DEBUG_OUT.println(wifiState.numNetworks);
|
|
|
|
|
DEBUG_OUT.print("numUnencrypted: ");
|
|
|
|
|
DEBUG_OUT.println(wifi.numUnencrypted);
|
|
|
|
|
DEBUG_OUT.println(wifiState.numUnencrypted);
|
|
|
|
|
|
|
|
|
|
DEBUG_OUT.print("lat: ");
|
|
|
|
|
//DEBUG_OUT.print(gps.location.lat(), 6);
|
|
|
|
|
DEBUG_OUT.print(" lng: ");
|
|
|
|
|
//DEBUG_OUT.println(gps.location.lng(), 6);
|
|
|
|
|
|
|
|
|
|
DEBUG_OUT.println(getISODate());
|
|
|
|
|
DEBUG_OUT.println(gps.getISODate());
|
|
|
|
|
DEBUG_OUT.println("");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool storeMeasurement(float lat, float lng, float value, char* timeStamp, char* sensorID) {
|
|
|
|
|
Measurement m;
|
|
|
|
|
m.lat = lat;
|
|
|
|
|
m.lng = lng;
|
|
|
|
|
m.value = value;
|
|
|
|
|
strcpy(m.timeStamp, timeStamp);
|
|
|
|
|
strcpy(m.sensorID, sensorID);
|
|
|
|
|
|
|
|
|
|
return storage.add(m);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* MAIN ENTRY POINTS */
|
|
|
|
|
void setup() {
|
|
|
|
|
//Serial.begin(9600); // GPS reciever
|
|
|
|
|
DEBUG_OUT.begin(115200);
|
|
|
|
|
|
|
|
|
|
WiFi.mode(WIFI_STA);
|
|
|
|
|
size_t bytesFree = storage.begin();
|
|
|
|
|
//gps.begin();
|
|
|
|
|
wifi.begin();
|
|
|
|
|
|
|
|
|
|
//connectWifi(WIFI_SSID, WIFI_PASS);
|
|
|
|
|
|
|
|
|
|
//delay(5000); // DEBUG: oportunity to connect to network logger
|
|
|
|
|
//delay(5000); // DEBUG oportunity to connect to network logger
|
|
|
|
|
|
|
|
|
|
// wait until we got a first fix from GPS, and thus an initial time
|
|
|
|
|
/*DEBUG_OUT.print("Getting GPS fix..");
|
|
|
|
|
while (!updateLocation()) { DEBUG_OUT.print("."); }
|
|
|
|
|
while (!gps.updateLocation()) { DEBUG_OUT.print("."); }
|
|
|
|
|
DEBUG_OUT.print(" done! ");*/
|
|
|
|
|
DEBUG_OUT.println(getISODate());
|
|
|
|
|
DEBUG_OUT.println(gps.getISODate());
|
|
|
|
|
|
|
|
|
|
DEBUG_OUT.println("Setup done!\n");
|
|
|
|
|
DEBUG_OUT.println("WiFi MAC WiFi IP");
|
|
|
|
@ -52,50 +68,43 @@ void setup() {
|
|
|
|
|
DEBUG_OUT.println(WiFi.localIP());
|
|
|
|
|
|
|
|
|
|
DEBUG_OUT.print("SPIFF bytes free: ");
|
|
|
|
|
DEBUG_OUT.println(storage.begin());
|
|
|
|
|
DEBUG_OUT.println(bytesFree);
|
|
|
|
|
|
|
|
|
|
digitalWrite(D9, HIGH); // DEBUG: integrated led? doesnt work
|
|
|
|
|
digitalWrite(D9, HIGH); // DEBUG: integrated led? doesnt work
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void loop() {
|
|
|
|
|
//pollGPS();
|
|
|
|
|
//DEBUG_OUT.pollClients();
|
|
|
|
|
WifiState wifi = scanWifi(WIFI_SSID);
|
|
|
|
|
WifiState wifiState = wifi.scanWifi(WIFI_SSID);
|
|
|
|
|
char* dateString = gps.getISODate();
|
|
|
|
|
|
|
|
|
|
// TODO: take other measurements (average them?)
|
|
|
|
|
/*
|
|
|
|
|
if(!updateLocation()) DEBUG_OUT.println("GPS timed out (location)");
|
|
|
|
|
if(!updateTime()) DEBUG_OUT.println("GPS timed out (time)");
|
|
|
|
|
if(!gps.updateLocation()) DEBUG_OUT.println("GPS timed out (location)");
|
|
|
|
|
if(!gps.updateTime()) DEBUG_OUT.println("GPS timed out (time)");
|
|
|
|
|
*/
|
|
|
|
|
// TODO: write measurements to file
|
|
|
|
|
|
|
|
|
|
// TODO: connect to wifi, if available & not connected yet
|
|
|
|
|
// then upload local data, clean up
|
|
|
|
|
|
|
|
|
|
printState(wifi);
|
|
|
|
|
// write measurements to file
|
|
|
|
|
if (storeMeasurement(51.2, 7.89, wifiState.numNetworks, dateString, "12341234123412341234123412341234")) {
|
|
|
|
|
DEBUG_OUT.print("measurement stored! storage size: ");
|
|
|
|
|
} else {
|
|
|
|
|
DEBUG_OUT.print("measurement store failed! storage size: ");
|
|
|
|
|
}
|
|
|
|
|
DEBUG_OUT.println(storage.size());
|
|
|
|
|
|
|
|
|
|
// recall all previous measurements
|
|
|
|
|
// TODO: connect to wifi, if available & not connected yet
|
|
|
|
|
// then upload local data, remove from storage
|
|
|
|
|
|
|
|
|
|
// DEBUG: recall all previous measurements
|
|
|
|
|
while (storage.size()) {
|
|
|
|
|
String measure = storage.pop();
|
|
|
|
|
//api.postMeasurement(measure.substring(0, 31), measure.substring(32));
|
|
|
|
|
DEBUG_OUT.println("popped a measurement: ");
|
|
|
|
|
DEBUG_OUT.println(measure.substring(0, 31)); // size of sensorID
|
|
|
|
|
DEBUG_OUT.println(measure.substring(32)); // skip the newline char
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// store new measurement
|
|
|
|
|
Measurement testMeasure;
|
|
|
|
|
testMeasure.lat = 51.2;
|
|
|
|
|
testMeasure.lng = 7.89;
|
|
|
|
|
testMeasure.value = wifi.numNetworks;
|
|
|
|
|
strcpy(testMeasure.timeStamp, getISODate());
|
|
|
|
|
strcpy(testMeasure.sensorID, "123457812345678123456781234567");
|
|
|
|
|
|
|
|
|
|
if (storage.add(testMeasure)) {
|
|
|
|
|
DEBUG_OUT.print("measurement stored! storage size: ");
|
|
|
|
|
} else {
|
|
|
|
|
DEBUG_OUT.print("measurement store failed! storage size: ");
|
|
|
|
|
}
|
|
|
|
|
DEBUG_OUT.println(storage.size());
|
|
|
|
|
|
|
|
|
|
delay(2000);
|
|
|
|
|
printState(wifiState);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|