Previously, I developed an example program using the Telus LTE-M IoT Starter Kit (available from Avnet) using the Mbed O/S. This effort is detailed in the Blog post https://www.element14.com/community/blogs/JimFlynn/2018/09/25/using-the-mbed-os-to-build-an-azure-iot-client. Recently, a request was made to add GPS functionality to this solution and demonstrate how to add and use it. The Quectel BG96 has extensive GNSS functionality so I extend my previous example with a new one that adds GNSS support.
The BG96 has extensive GNSS support (it supports geo-fencing which is pretty cool), but for this example, I limited the example to to simply obtaining and reporting the current GPS location. Hopefully with the example software and BG96 documentation (BG96 documentation is available here) it wouldn't be to tough to add other capabilities if desired. For purposes of the example program, I obtain the GPS Location of the module and report it back to Azure with each telemetry message.
Adding support for GNSS involved modifying the BG96 Device Driver (link) by adding functions to power the GNSS on/off and get the current GPS location (Lines 577 and 588 in the driver). I also added a class to allow access to the device driver. The Mbed OS implements a 'NetworkInterface' class that is used by the operating system to interact with the driver but this class doesn't know anything about the added GNSS support, so I created a class (bg96_gps) that provides access to the GNSS functions. It is a pretty simple class that only implements a gpsPower and gpsLocation capabilities using a pointer to the installed BG96 Driver. If you wanted to add geo-fencing for example, you would simply add another set of functions to the class that implemented that along with the appropriate functions in the driver itself.
With the new gp96_gps class, using the GPS capabilities involves:
1. Creating the object and a structure for GNSS:
/* create the GPS elements for example program */ gps_data gdata; bg96_gps gps;
2. Starting and obtaining the GNSS information:
printf("[ start GPS ] "); gps.gpsPower(true); printf("Successful.\r\n[get GPS loc] "); fflush(stdout); gps.gpsLocation(&gdata); printf("Latitude = %6.3f Longitude = %6.3f date=%s, time=%6.0f\n\n",gdata.lat,gdata.lon,gdata.date,gdata.utc);
To power off the GNSS system, you would simply call gpsPower(false). The gps_data type is defined in the BG96 device driver as:
typedef struct gps_data_t { float utc; //hhmmss.sss float lat; //latitude. (-)dd.ddddd float lon; //longitude. (-)dd.ddddd float hdop; // Horizontal precision: 0.5-99.9 float altitude; //altitude of antenna from sea level (meters) int fix; //GNSS position mode 2=2D, 3=3D float cog; //Course Over Ground ddd.mm float spkm; //Speed over ground (Km/h) xxxx.x float spkn; //Speed over ground (knots) xxxx.x char date[7]; //data: ddmmyy int nsat; //number of satellites 0-12 } gps_data;
This structure contains all the information you will receive from a call for GPS Location data.
This newly released example is available from https://github.com/Avnet/azure-iot-mbed-client/releases as release v1.1. With this additional GPS functionality can add a new level of sensor data that can be reported and hopefully, some great new product opportunities.
Top Comments