Boron LTE & google-maps-device-locator

cellular
boron
Tags: #<Tag:0x00007fe225e98d60> #<Tag:0x00007fe225e983b0>

#1

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


#2

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();
}

#3

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.