skip first gps fix if in upload mode

esp8266-bme280
noerw 8 years ago
parent ceab2f70bd
commit 01c66faf79

@ -48,7 +48,7 @@ So you either..
- connect to the open network `mobile-sensebox` and run `telnet 192.168.1.1` - connect to the open network `mobile-sensebox` and run `telnet 192.168.1.1`
- connect to the same network as configured in `config.h` and run `telnet <whateverIPtheESPgets>` - connect to the same network as configured in `config.h` and run `telnet <whateverIPtheESPgets>`
Connections are not polled all the time, so you may have to wait a moment until you recieve first data. Connections are not polled all the time, so you may have to wait a moment until you receive first data.
Note that, due to the limited single-channel hardware of the ESP8266, Note that, due to the limited single-channel hardware of the ESP8266,
a reconnection to the configured WiFi network fails, a reconnection to the configured WiFi network fails,

@ -31,7 +31,7 @@ bool storeMeasurement(float lat, float lng, float value, const char* timeStamp,
void measure(WifiState& wifiState, TinyGPSLocation& loc) { void measure(WifiState& wifiState, TinyGPSLocation& loc) {
char dateString[20]; char dateString[20];
// measure WiFi // measure WiFi
wifiState = wifi.scan(WIFI_SSID); wifiState = wifi.scan(WIFI_SSID);
@ -52,13 +52,13 @@ void measure(WifiState& wifiState, TinyGPSLocation& loc) {
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: ");
DEBUG_OUT.print(loc.lat(), 6); DEBUG_OUT.print(loc.lat(), 8);
DEBUG_OUT.print(" lng: "); DEBUG_OUT.print(" lng: ");
DEBUG_OUT.println(loc.lng(), 6); DEBUG_OUT.println(loc.lng(), 8);
DEBUG_OUT << dateString << EOL; DEBUG_OUT << dateString << EOL;
// IDEA: write location update to separate file? // IDEA: write location update to separate file?
// write measurements to file // write measurements to file
if (!storeMeasurement(loc.lat(), loc.lng(), wifiState.numAccessPoints, dateString, ID_SENSOR_WIFI_APS)) if (!storeMeasurement(loc.lat(), loc.lng(), wifiState.numAccessPoints, dateString, ID_SENSOR_WIFI_APS))
DEBUG_OUT << "measurement (wifi aps) store failed!" << EOL; DEBUG_OUT << "measurement (wifi aps) store failed!" << EOL;
@ -68,7 +68,7 @@ void measure(WifiState& wifiState, TinyGPSLocation& loc) {
if (!storeMeasurement(loc.lat(), loc.lng(), wifiState.numUnencrypted, dateString, ID_SENSOR_WIFI_OPEN)) if (!storeMeasurement(loc.lat(), loc.lng(), wifiState.numUnencrypted, dateString, ID_SENSOR_WIFI_OPEN))
DEBUG_OUT << "measurement (wifi open) store failed!" << EOL; DEBUG_OUT << "measurement (wifi open) store failed!" << EOL;
DEBUG_OUT << EOL; DEBUG_OUT << EOL;
} }
@ -77,7 +77,7 @@ void upload(WifiState& wifiState) {
size_t numMeasures = storage.size(); size_t numMeasures = storage.size();
DEBUG_OUT << numMeasures << " measurements stored." << EOL; DEBUG_OUT << numMeasures << " measurements stored." << EOL;
if (!numMeasures) return; if (!numMeasures) return;
// in case we are not measuring, scan manually to detect the home network // in case we are not measuring, scan manually to detect the home network
// somehow the automatic reconnect does not work.. TODO // somehow the automatic reconnect does not work.. TODO
if (!connected && digitalRead(PIN_MEASURE_MODE) == LOW) if (!connected && digitalRead(PIN_MEASURE_MODE) == LOW)
@ -114,7 +114,7 @@ void upload(WifiState& wifiState) {
* offset may be a duration which has been "used up" before, so the delay is adaptive, * offset may be a duration which has been "used up" before, so the delay is adaptive,
* meaning that the interval of a adaptiveDelay() call is constant * meaning that the interval of a adaptiveDelay() call is constant
* returns earlier, if we moved more than MEASUREMENT_DISTANCE meters from our last fix * returns earlier, if we moved more than MEASUREMENT_DISTANCE meters from our last fix
* *
* also polls the GPS serial & telnet connections! * also polls the GPS serial & telnet connections!
*/ */
void adaptiveDelay(unsigned long ms, TinyGPSLocation& lastLoc, unsigned long offset = 0, bool checkDistance = false) { void adaptiveDelay(unsigned long ms, TinyGPSLocation& lastLoc, unsigned long offset = 0, bool checkDistance = false) {
@ -132,7 +132,7 @@ void adaptiveDelay(unsigned long ms, TinyGPSLocation& lastLoc, unsigned long off
DEBUG_OUT << "moved " << distanceToPrevLoc << "m, delay stopped." << EOL; DEBUG_OUT << "moved " << distanceToPrevLoc << "m, delay stopped." << EOL;
return; return;
} }
unsigned long now = millis(); unsigned long now = millis();
unsigned long elapsed = now - start + offset; unsigned long elapsed = now - start + offset;
if (elapsed >= ms) return; if (elapsed >= ms) return;
@ -146,21 +146,24 @@ void setup() {
digitalWrite(BUILTIN_LED, LOW); digitalWrite(BUILTIN_LED, LOW);
pinMode(PIN_MEASURE_MODE, INPUT_PULLUP); // switch for measurements (pull it down to disable) pinMode(PIN_MEASURE_MODE, INPUT_PULLUP); // switch for measurements (pull it down to disable)
pinMode(PIN_UPLOAD_MODE, INPUT_PULLUP); // switch for API uploads (pull it down to disable) pinMode(PIN_UPLOAD_MODE, INPUT_PULLUP); // switch for API uploads (pull it down to disable)
size_t bytesFree = storage.begin(); size_t bytesFree = storage.begin();
gps.begin(); gps.begin();
wifi.begin(WIFI_SSID, WIFI_PASS); wifi.begin(WIFI_SSID, WIFI_PASS);
DEBUG_OUT.begin(115200); DEBUG_OUT.begin(115200);
// wait until we got a first fix from GPS, and thus an initial *time* // wait until we got a first fix from GPS, and thus an initial time
DEBUG_OUT << "Getting GPS fix.."; // exception: measure mode is disabled (for quick upload only)
while (!gps.updateLocation()) { if (digitalRead(PIN_MEASURE_MODE) == HIGH) {
adaptiveDelay(0, location); // poll for telnet connections DEBUG_OUT << "Getting GPS fix..";
DEBUG_OUT << "."; while (!gps.updateLocation()) {
adaptiveDelay(0, location); // poll for telnet connections
DEBUG_OUT << ".";
}
location = gps.getLocation();
DEBUG_OUT << " done!" << EOL;
digitalWrite(BUILTIN_LED, HIGH);
} }
location = gps.getLocation();
DEBUG_OUT << " done!" << EOL;
digitalWrite(BUILTIN_LED, HIGH);
// DEBUG // DEBUG
//while (!wifi.isConnected()) adaptiveDelay(500, location); //while (!wifi.isConnected()) adaptiveDelay(500, location);
@ -174,22 +177,22 @@ void setup() {
void loop() { void loop() {
cycleStart = millis(); cycleStart = millis();
adaptiveDelay(0, location); // do some polling inbetween adaptiveDelay(0, location); // do some polling inbetween
if (digitalRead(PIN_MEASURE_MODE) == HIGH) if (digitalRead(PIN_MEASURE_MODE) == HIGH)
measure(wifiState, location); measure(wifiState, location);
adaptiveDelay(0, location); // do some polling inbetween adaptiveDelay(0, location); // do some polling inbetween
if (digitalRead(PIN_UPLOAD_MODE) == HIGH) if (digitalRead(PIN_UPLOAD_MODE) == HIGH)
upload(wifiState); upload(wifiState);
if (digitalRead(PIN_MEASURE_MODE) == HIGH) { // run the measurements in a fixed interval, using an adaptive delay
// run the measurements in a fixed interval, using an adaptive delay // the interval is defined by a duration and/or distance from our last fix
// the interval is defined by a duration and/or distance from our last fix if (digitalRead(PIN_MEASURE_MODE) == HIGH)
return adaptiveDelay(MEASUREMENT_INTERVAL, location, millis() - cycleStart, MEASUREMENT_DISTANCE_ENABLED); return adaptiveDelay(MEASUREMENT_INTERVAL, location, millis() - cycleStart, MEASUREMENT_DISTANCE_ENABLED);
}
// run as fast as possible when not measuring. // run as fast as possible when not measuring.
// smartDelay has to be called anyway, as some polling functions are run within // smartDelay has to be called anyway, as some polling functions are run within
adaptiveDelay(0, location); adaptiveDelay(0, location);

Loading…
Cancel
Save