Skip to main content

gnss-session.readnmea(infoCallback, sentenceType)

Get NMEA sentences from the GNSS sub-system

Availability

Device
Only available on imps with cellular modems

Parameters

Name Type Description
infoCallback Function The information delivery callback
sentenceType String The format for returned sentences

Returns

Nothing

Description

This method retrieves NMEA sentence data from the GNSS sub-system, which must be enabled before this call can be made. Additionally, the GNSS sub-system must have been configured to output NMEA sentences — see gnss-session.configure(). This is the default but if you have changed the value of the NMEA setting key nmeasrc to 0, you must set it to 1 before calling gnss-session.readnmea().

Note It is also possible to disable sentence output by passing the value of 0 for any of the following NMEA settings:

  • gpsnmeatype
  • glonassnmeatype
  • galileonmeatype
  • beidounmeatype

In this case, it is still possible to retrieve NMEA sentence data, but you will only receive the most recently acquired data and then only if sentences have been acquired in this session.

The value passed into the optional parameter sentenceType is a string which specifies the format of the sentences to be returned. The possible values are:

  • GGA
  • RMC
  • GSV
  • GSA
  • VTG
  • GNS

For more information on the meaning of these values, please see NMEA Revealed: Standard Sentences.

The data is returned in a table which is passed to the supplied infoCallback function. The table contains at least two keys: status and nmea. The value of status will be zero if no error occurred, or an error code (see gnss-session for details).

The value of the key nmea will be an array containing the strings returned by the modem.

Example Code

The following code retrieves sentences of the GSV type — they describe the sky positions of GNSS satellites the modem can see. Each sentence has the following field structure:

$<TID>GSV,<F1>,<F2>,<F3>,<F4>,<F5>,<F6>,<F7>,...*<CS>

The fields are:

  1. <TID> — Talker ID: the source of the information, eg. GP for GPS.
  2. Total number of GSV sentences to be transmitted in this group.
  3. Sentence number, 1-9 of this GSV message within current group.
  4. Total number of satellites in view.
  5. Satellite ID number.
  6. Elevation in degrees (-90 to 90).
  7. Azimuth in degrees to true north (000 to 359).
  8. Signal:noise in dB (00-99).
  9. <CS> — checksum.

The code uses an existing gnss-session object, gnssSession. See gnss-session.enable() for example code showing session object instantiation.