Deprecated
This library has been deprecated and its functionality is now made available in as two separate libraries: GPSParser and GPSUARTDriver.
This library is a driver for GPS modules that can be interfaced over UART. It does not support all data types received by GPS. It supports VTG, RMC, GLL, GGA, GSV and GSA. For information on these formats and other satellite data packets, please see this page.
You can view the library’s source code on GitHub. Click here to see information on the available versions of this library.
To add this library to your project, add #require "GPS.device.lib.nut:0.1.0"
to the top of your device code.
The class constructor takes two required parameters and one optional parameter. The first required parameter, uart, is an imp UART bus which need not have been previously configured.
The second required parameter, fixCallback, is a callback function that should take two arguments: a boolean indicating whether the GPS currently has a fix, and a table containing the most recent GPS data. The table contains the key type, which indicates which type of data the table contains. The table’s remaining keys will depend upon the data type, and are listed in the tables below.
The third parameter, which is optional, is the baudrate of the GPS. This defaults to 9600 baud.
Key | Description |
---|---|
type | GPS_VTG |
trackt | True track made good (degrees) |
speedkmh | Speed in kilometers per hour |
checkSum | Checksum, used to check the validity of the data |
Key | Description |
---|---|
type | GPS_RMC |
time | The timestamp of received data (minutes, hours, seconds) |
latitude | The latitude received |
longitude | The longitude received |
status | The status of the satellite, "A" for active, "V" for void |
checkSum | Checksum, used to check the validity of the data |
Key | Description |
---|---|
type | GPS_GLL |
time | The timestamp of received data (minutes, hours, seconds) |
latitude | The latitude received |
longitude | The longitude received |
status | The status of the satellite, "A" for active, "V" for void |
checkSum | Checksum, used to check the validity of the data |
Key | Description |
---|---|
type | GPS_GGA |
time | The timestamp of received data (minutes, hours, seconds) |
latitude | The latitude received |
longitude | The longitude received |
status | The status of the satellite, "A" for active, "V" for void |
fixQuality | The quality of the satellite fix |
numSatellites | The number of satellites being tracked |
altitude | Altitude, meters, above mean sea level |
checkSum | Checksum, used to check the validity of the data |
Key | Description |
---|---|
type | GPS_GSV |
numSatellites | The number of satellites in view |
checkSum | Checksum, used to check the validity of the data |
Key | Description |
---|---|
type | GPS_GSA |
threeDFix | 3D fix. Values: 1 = no fix, 2 = 2D fix, 3 = 3D fix |
PDOP | Dilution of precision |
HDOP | Horizontal dilution of precision |
PDOP | Vertical dilution of precision |
checkSum | Checksum, used to check the validity of the data |
function myCallback(gotFix, data) {
if (gotFix) {
server.log(format("I have valid %s data!", data.type));
switch(data.type) {
case GPS_RMC:
// Do something with RMC data
break;
case GPS_VTG:
// Do something with VTG data
break;
case GPS_GLL:
// Do something with GLL data
break;
case GPS_GGA:
// Do something with GGA data
break;
case GPS_GSV:
// Do something with GSV data
break;
case GPS_GSA:
// Do something with GSA data
}
}
}
myGPS <- GPS(hardware.uart1, myCallback);
The getLastLocation() method will return a table containing the last detected latitude and longitude, and a table containing the time the co-ordinates were received.
local last = myGPS.getLastLocation();
server.log(format("Last lat: %f, last long: %f. Received @%d:%d:%d", last.latitude,
last.longitude, last.time.hours, last.time.minutes, last.time.seconds));
The Electric Imp Dev Center documents the latest version of the library. For past versions, please see the Electric Imp public GitHub repos listed below.
Version | Source Code | Notes |
---|---|---|
0.1.0 | GitHub | Beta release |
The GPS library is licensed under the MIT License.