C library for parsing NMEA 0183 sentences, such as GPS data, into C structs.

What is libnmea?

Libnmea is a lightweight library that parses NMEA 0183 sentence strings into C structs. It is written in C and using a modular architecture to dynamically load a parser module for each implemented sentence type. This way, new sentences can easily be added to the library without modifying the core code.

Install it:

$ git clone
$ cd libnmea
$ make & make check
$ sudo make install
$ make unit-tests & make system-tests

Use it:

#include <stdlib.h>
#include <stdio.h>
#include <string.h>

#include <nmea.h>
#include <nmea/gpgll.h>
#include <nmea/gpgga.h>

int main(void)
	// Sentence string to be parsed
	char *sentence = strdup("$GPGLL,4916.45,N,12311.12,W,225444,A\n\n");

	printf("Parsing NMEA sentence: %s", sentence);

	// Pointer to struct containing the parsed data. Should be freed manually.
	nmea_s *data;

	// Parse...
	data = nmea_parse(sentence, strlen(sentence), 0);

	if (NMEA_GPGLL == data->type) {
		nmea_gpgll_s *gpgll = (nmea_gpgll_s *) data;

		printf("GPGLL Sentence\n");
		printf("  Degrees: %d\n", gpgll->longitude.degrees);
		printf("  Minutes: %f\n", gpgll->longitude.minutes);
		printf("  Cardinal: %c\n", (char) gpgll->longitude.cardinal);
		printf("  Degrees: %d\n", gpgll->latitude.degrees);
		printf("  Minutes: %f\n", gpgll->latitude.minutes);
		printf("  Cardinal: %c\n", (char) gpgll->latitude.cardinal);


	return 0;

Compile with '-lnmea':

$ gcc main.c -lnmea -o main

© 2016 Jack Engqvist Johansson

Fork me on GitHub