LwGPS is a lightweight, platform independent, all-constellation GNSS NMEA parser library for embedded systems, written in C11. Feed it raw characters from any GPS/GNSS receiver, byte by byte or in chunks, and read position, altitude, speed, time, fix status and satellite information from a single structure. It needs no dynamic memory and is independent of the communication interface.
📖 Documentation · Changelog · Releases
- Written in C (C11), compatible with
stdint.hdata types - Platform independent, easy to use
- Built-in support for all-constellation GNSS statements
GPGGA,G*GGAorGNGGA: GNSS fix dataGPGSA,G*GSAorGNGSA: Active satellites and dilution of precisionGPGSV,G*GSVorGNGSV: List of satellites in view zoneGPRMC,G*RMCorGNRMC: Recommended minimum specific GNSS/Transit data
- Optional support for
PUBX(uBlox proprietary) statements, includingPUBX_TIME - Optional detailed per-satellite info (elevation, azimuth, SNR) for
GSVstatement - Optional NMEA checksum validation
- Distance and bearing calculation between two coordinates
- Speed conversion helper between many units: metric, imperial and pace
- Optional per-statement processing callback
- C++ wrapper class available
- Optional
floatordoublefloating point units - Low-level layer is separated from application layer, thus allowing you to add custom communication with GPS device
- Works with operating systems
- Works with different communication interfaces
- Can be used as an ESP-IDF component
- User friendly MIT license
#include <stdio.h>
#include <string.h>
#include "lwgps/lwgps.h"
/* GPS handle */
lwgps_t hgps;
/* Data received from the GPS receiver */
const char gps_rx_data[] = "$GPRMC,183729,A,3907.356,N,12102.482,W,000.0,360.0,080301,015.5,E*6F\r\n"
"$GPGGA,183730,3907.356,N,12102.482,W,1,05,1.6,646.4,M,-24.1,M,,*75\r\n";
int
main(void) {
lwgps_init(&hgps);
/* Process received data, can be called with any chunk size */
lwgps_process(&hgps, gps_rx_data, strlen(gps_rx_data));
printf("Valid status: %d\r\n", hgps.is_valid);
printf("Latitude: %f degrees\r\n", hgps.latitude);
printf("Longitude: %f degrees\r\n", hgps.longitude);
printf("Altitude: %f meters\r\n", hgps.altitude);
printf("Speed: %f km/h\r\n", lwgps_to_speed(hgps.speed, LWGPS_SPEED_KPH));
return 0;
}lwgps_float_t dist, bear;
/* From New York to Munich */
lwgps_distance_bearing(40.685721, -73.820465, 48.150906, 11.554176, &dist, &bear);
printf("Distance: %f meters, initial bearing: %f degrees\r\n", (float)dist, (float)bear);More examples are in examples, including example_buff.c, which receives data in an interrupt through the LwRB ring buffer.
Enabled statements, checksum validation, float or double precision and other settings are configured in the lwgps_opts.h file.
Copy lwgps/src/include/lwgps/lwgps_opts_template.h to your project, rename it to lwgps_opts.h,
and override the defaults listed in lwgps_opt.h.
See Getting started in the documentation for details.
set(LWGPS_OPTS_FILE ${CMAKE_CURRENT_LIST_DIR}/lwgps_opts.h) # Optional, default options are used otherwise
add_subdirectory(path/to/lwgps/lwgps)
target_link_libraries(${PROJECT_NAME} PRIVATE lwgps)Optional compiler options and definitions can be set with LWGPS_COMPILE_OPTIONS and LWGPS_COMPILE_DEFINITIONS, see lwgps/library.cmake.
Note: ESP-IDF integration is provided as-is and is not tested as part of the library's continuous integration.
The repository is an ESP-IDF component. Add it as a managed component in your project's idf_component.yml:
dependencies:
lwgps:
git: https://github.com/MaJerle/lwgps.gitor place it in your project's components folder. To use a custom lwgps_opts.h, set LWGPS_OPTS_FILE
as described in ESP-IDF integration in the documentation.
- Copy the
lwgpsfolder to your project - Add
lwgps/src/includeto the include path - Add the source files from
lwgps/src/lwgps/to the build - Create
lwgps_opts.hin a folder on the include path (see Configuration)
LwGPS is available in the PlatformIO Registry. Add it to your platformio.ini:
lib_deps =
majerle/LwGPSFresh contributions are always welcome. Simple instructions to proceed:
- Fork Github repository
- Follow C style & coding rules and use
clang-formatto format the code - Create a pull request to
developbranch with new features or bug fixes
Alternatively you may:
- Report a bug
- Ask for a feature request
LwGPS is released under the MIT license.