0

I am using something like this in node js. And I am getting the correct lat lon details, so I am sure that gps device is connected properly to raspberry pi.

const SerialPort = require("serialport");
const GPS = require("gps");
const Readline = require("@serialport/parser-readline");
const gpsInfo = {};
const port = new SerialPort("/dev/ttyAMA0");

const parser = port.pipe(new Readline({ delimiter: "\n" }));

const gps = new GPS();

gps.on("data", function(data) {
  try {
    if (data.type === "RMC") {
      gpsInfo.lat = data.lat || gpsInfo.lat;
      gpsInfo.lon = data.lon || gpsInfo.lon;
      gpsInfo.speed = data.speed || gpsInfo.speed;
      gpsInfo.time = data.time.toString() || gpsInfo.time;
    }
  } catch (e) {
    console.log(
      "Exception raised while getting data from GPS",
      JSON.stringify(e)
    );
  }
});

parser.on("data", function(data) {
  try {
    gps.update(data);
  } catch (e) {
    console.log(
      "Exception raised while getting data from Serialport parser",
      JSON.stringify(e)
    );
  }
});

But after some time say 20-30 seconds then the socket hangs up and I am not getting the updated data.

Same happens in following command in terminal as well

sudo cat /dev/ttyAMA0

It gives me output in NEMA format for 20-30 seconds and then exits.

Also added here as well: https://stackoverflow.com/questions/55143947/read-real-time-data-in-node-from-neo-6m-gps-module-in-raspberry-pi-3-plus

  • Do not cross post questions to multiple Stack Exchange sites. – hardillb Mar 15 at 15:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.