I've slightly modified the GPS example and installed it on a Carloop with an Electron using the 12pin extenders. I brought the device outside with direct access to the sky on a clear day. I waited for more than an hour and never got a GPS fix?
Here's the code:
// Run our code even when out of range of Wi-Fi / cellular.
SYSTEM_THREAD(ENABLED);
include
include "CANProtocolBase.h"
include "CANProtocol_OBD.h"
// Forward declerations
void printGPSInfo(TinyGPSPlus &gps);
void printCANInfo();
void printAccelerometerInfo();
String formatFloat(float val, bool valid, int len, int prec);
String formatDateTime(TinyGPSDate &d, TinyGPSTime &t);
// Blue LED
int _led1 = D7;
// Timestamp for debug messages
unsigned long _lastDebugMsg = millis();
// Threshold to trigger a publish
// 9000 is VERY sensitive, 12000 will still detect small bumps
int _accelThreshold = 40000;
// Our Carloop object
Carloop carloop;
// Our protocol object
CANProtocolBase* canProtocol = new CANProtocol_OBD();
// for publishing values
String buf;
// A FuelGauge for checking on the battery state
FuelGauge fuel;
void setup() {
// Fire up serial for debug output
Serial.begin();
// We're going to use the LED attached to D7 to indicate if we're in Simulation mode or not. It will be on
// when we are in simulation mode, off otherwise.
pinMode(_led1, OUTPUT);
/*
// Toggle the led
for(int i=0; i++ ; i<10) {
digitalWrite(_led1, HIGH);
delay(500);
digitalWrite(_led1, LOW);
delay(500);
}
*/
Serial.println("Proxi-Carloop-GPS Evaluation");
// Start up the Carloop using the default configuration.
//carloop.begin();
}
void loop() {
unsigned long now;
now = millis();
carloop.update();
//canProtocol->loop();
if (millis() - _lastDebugMsg > 1000) {
Serial.println("====Debug info====");
printGPSInfo(carloop.gps());
/*
printCANInfo();
printAccelerometerInfo();
*/
_lastDebugMsg = millis();
}
}
void printGPSInfo(TinyGPSPlus &gps) {
Serial.printf("GPS %6d chars: \n", gps.charsProcessed()); //
Serial.printf("Lat: %s\n", formatFloat(gps.location.lat(), gps.location.isValid(), 11, 6).c_str());
Serial.printf("Lon: %s\n", formatFloat(gps.location.lng(), gps.location.isValid(), 11, 6).c_str());
Serial.printf("Date/Time: %s", formatDateTime(gps.date, gps.time).c_str());
/*
String s;
s += String::format("GPS %6d chars: ", gps.charsProcessed());
s += formatFloat(gps.location.lat(), gps.location.isValid(), 11, 6);
s += formatFloat(gps.location.lng(), gps.location.isValid(), 12, 6);
s += formatDateTime(gps.date, gps.time);
Serial.println(s.c_str());
*/
}
void printCANInfo() {
}
void printAccelerometerInfo() {
}
String formatFloat(float val, bool valid, int len, int prec) {
String s;
if (!valid) {
while(len-- > 1) {
s += '*';
}
s += ' ';
}
else {
char format[10];
snprintf(format, sizeof(format), "%%%d.%df", len, prec);
s += String::format(format, val);
/* code */
}
return s;
}
String formatDateTime(TinyGPSDate &d, TinyGPSTime &t) {
String s;
// Date portion
if (!d.isValid()) {
s += "********** ";
}
else {
s += String::format("%02d/%02d/%02d", d.month(), d.day(), d.year());
}
// Time portion
if (!t.isValid()) {
s += "******** ";
}
else {
s += String::format("%02d:%02d:%02d ", t.hour(), t.minute(), t.second());
}
return s;
}