npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

node-gpsd

v0.3.4

Published

Node.js gpsd client for GPS tracking device.

Downloads

1,044

Readme

node-gpsd

Interface to gpsd.

Installation

With package manager npm:

npm install node-gpsd

Code instructions

Require node-gpsd by calling:

    var gpsd = require('node-gpsd');

node-gpsd has 2 classes: Daemon and Listener.

The Daemon is a wrapper to start and stop gpsd from your program. The Listener interfaces with a running gpsd (not necessarily instantiated via the Daemon class).

Deamon

A Daemon is instantiated by calling:

var daemon = new gpsd.Daemon({
    program: 'gpsd',
    device: '/dev/ttyUSB0',
    port: 2947,
    pid: '/tmp/gpsd.pid',
    readOnly: false,
    logger: {
        info: function() {},
        warn: console.warn,
        error: console.error
    }
});

The options that are listed above are the default values so calling new gpsd.Daemon() will have the same effect. Change the options according your own setup.

The Daemon can be started and stopped by calling the appropriate methods:

daemon.start(function() {
    console.log('Started');
});

or:

daemon.stop(function() {
    console.log('Stopped');
});

The Daemon can log to the console if needed. Logging can be controlled by passing a logger property in the options when creating the Daemon or by setting the logger field:

daemon.logger = new (winston.Logger) ({ exitOnError: false });

The logger should have info, warn and error functions that all accept a single parameter.

The Daemon is an EventEmitter and will emit the following events:

  • died: when the Daemon is killed.

Listener

A Listener is instantiated by calling:

var listener = new gpsd.Listener({
    port: 2947,
    hostname: 'localhost',
    logger:  {
        info: function() {},
        warn: console.warn,
        error: console.error
    },
    parse: true
});

The options that are listed above are the default values so calling new gpsd.Listener() will have the same effect. Change the options according your own setup.

The Listener can be connected to the gpsd by calling:

listener.connect(function() {
    console.log('Connected');
});

and disconnected by calling:

listener.disconnect(function() {
    console.log('Disconnected');
});

The connection state can be queries by calling:

listener.isConnected();

To control watching gps events call the methods:

listener.watch(options);
listener.unwatch();

This will put the Listener in and out-of watching mode. The Listener is an EventEmitter and will emit the following events:

  • gpsd events like described in the gpsd documentation. All gpsd events like: TPV, SKY, INFO and DEVICE can be emitted. To receive all TPV events just add listener.on('TPV', function(tpvData)) to your code. When the parse option is set to false these events will not be emitted.
  • raw events contain the raw, unparsed input received from gpsd. Only emitted if parse option is set to false.
  • error when data in a bad format is received from gpsd.
  • disconnected when the connection with gpsd is lost.
  • connected when the connection with gpsd is established.
  • error.connection when the connection is refused.
  • error.socket on other connection errors.

You can pass options to be sent on to gpsd when issuing the watch command, the default being { class: 'WATCH', json: true, nmea: false }.

If you want to receive raw nmea data from gpsd you should create the listener with new gpsd.Listener({emitraw: true, parsejson: false}) and issue listener.watch({class: 'WATCH', nmea: true}).

It is possible to query the gps device by calling:

listener.version(); /* a INFO event will be emitted */
listener.devices(); /* a DEVICES event will be emitted */
listener.device(); /* a DEVICE event will be emitted */

The Listener can log to the console if needed. Logging can be controlled by passing a logger property in the options when creating the Listener or by setting the logger field:

listener.logger = new (winston.Logger) ({ exitOnError: false });;

Shout outs

Shout outs go to Pascal Deschenes for creating the Bancroft project that formed the basis for node-gpsd.