Hi,
After reading many forum entries, I’m still not certain whether or not it’s possible to do location tracking with the Boron LTE (Device OS: 1.2.1). I’m based in Sydney Australia using Telstra as a 3rd party sim provider.
When printing to serial I get :
publishLocation
valid=false
scanData=
I’ve tried locator.withOperator(oper, mcc, mnc); in order to give the library an approximate location, and it still doesn’t work.
Here is my current code:
// This #include statement was automatically added by the Particle IDE.
#include <google-maps-device-locator.h>
#include "google-maps-device-locator.h"
SerialLogHandler logHandler;
GoogleMapsDeviceLocator locator;
float glat;
float glon;
float gaccuracy;
int mcc=505;
int mnc=01; //11, 72, 71, 01
const char *oper= "AT&T";
void setup() {
Serial.begin(9600);
locator.withOperator(oper, mcc, mnc);
//locator.withLocatePeriodic(20);
locator.withSubscribe(locationCallback).withLocatePeriodic(30);
}
void loop() {
locator.loop();
char locate_data[128];
snprintf(locate_data, sizeof(locate_data), "{\"latitude\":\"%.15f\",\"longitude\":\"%.15f\",\"accuracy\":\"%.2f\"}", glat, glon, gaccuracy);
Particle.publish("locate_data", locate_data, PRIVATE);
delay(10000); // to ensure adhering to rate limit
}
void locationCallback(float lat, float lon, float accuracy) {
Particle.publish("location callback","test1");
// Handle the returned location data for the device. This method is passed three arguments:
// - Latitude
// - Longitude
// - Accuracy of estimated location (in meters)
glat = lat;
glon = lon;
gaccuracy = accuracy;
}
I would much appreciate some help in getting this to work.
Thank you in advance
A couple of quick observations - I am not using a Boron with Google Location API nor am I in Australia!
You don’t want to have Particle.publish() in the locationCallback - all that should be doing is putting the lat , lon and accuracy into some global variables. You should then have a timed function in the loop() which is publishing.
You don’t need both #includes.
The locationCallback() function needs to be pre-declared.
In setup() you need to call locator.withLocatePeriodic or locator.withLocateOnce.
Example below works:
GoogleMapsDeviceLocator locator;
void locationCallback(float lat, float lon, float accuracy);
void setup()
{
Serial.begin(9600);
while (!Serial.available()) delay(100);
Serial.println("Setup - Device Locator");
// Scan for visible networks and publish to the cloud every 60 seconds
// Pass the returned location to be handled by the locationCallback() method
Serial.println("Setup - subscribe with locationCallback");
locator.withSubscribe(locationCallback);
Serial.println("Setup - locator runs every 60 seconds");
//locator.withLocateOnce();
locator.withLocatePeriodic(60);
}
// subscription handler
// Handle the returned location data for the device. This method is passed three arguments:
// - Latitude
// - Longitude
// - Accuracy of estimated location (in meters)
void locationCallback(float lat, float lon, float accuracy)
{
Serial.printlnf("Lat: %f Lon: %f Acc (m): %f", lat, lon, accuracy);
}
void loop()
{
delay(1000);
Serial.println("Loop - locator.loop called every second");
locator.loop();
}
Version 0.0.5 of the google-maps-device-locator library now supports the Boron LTE and B Series B402 LTE SoM when using Device OS 1.2.1 or later!
The library still works with older Device OS (back to 0.7.0) on other devices.
For the E Series LTE and Electron LTE using 1.2.1 or later is recommended, otherwise the library won’t work in Canada or Mexico properly unless you manually configure it. With 1.2.1 it works properly everywhere automatically.
Error 429 is request limit exceeded. Make sure you are not requesting too frequently. Also verify that your API is correctly set, and that you’ve enabled billing.
The Google Maps API is rejecting the request because the rate limit is exceeded. This could be because too many requests have been made, or a problem with the API key or API key permissions. The Google Maps geolocation service doesn’t return any coordinates on errors, so you need to fix the rate limit problem before it will return coordinates.
Ok, I got it finally to work, it was the Google Side/API, even though I added credit card, I had to enable Billing for Project.
Somehow Lattitude/Longtitude is really way off, it shows position of the device about 20 streets away, I assume its picking up a nearest Cell Tower not my actual GPS Position am I right?
Is there anyway to catch that Lattitude/Longtitude which is sent back to me from Google and write it to variable which is sent back to lets say to IFTTT Webhooks.
Somehow Lattitude/Longtitude is really way off, it shows position of the device about 20 streets away, I assume its picking up a nearest Cell Tower not my actual GPS Position am I right?
Yes, it's the location of the serving tower, and it's not triangulated, so it's going to be pretty far off.
Is there anyway to catch that Lattitude/Longtitude which is sent back to me from Google and write it to variable which is sent back to lets say to IFTTT Webhooks.
Yes, adding a subscription callback will allow the device to get the location result, which would then allow you do something else, possibly trigger another event.
You can't directly chain an event off the response to a webhook, so the only way to accomplish that is to send it to the device first, or use the server-sent-events stream and your own server.