octopus-gps-tracking

1.0.14 • Public • Published

GPS TRACKING (WITH TK103-2 ADAPTER)| Node.js

This module let you easily create listeners for your GPS tracking devices. You can add your custom implementations to handle more protocols.

New GPS Tracker emulator:

We created a brand new gps emulator so you can start testing your app in a breeze. You can signup to save your testing devices.

http://gps-tracking-emulator.meteor.com/

You can check the code of the emulator in this repo.

https://github.com/freshworkstudio/gps-tracking-emulator

v1.0 release

We removed mongoDB dependecy for this package. Now you can use any DB to save the data you receive.

The old documentation is still available in the repository (tag v0.25)

Currently supported models

  • TK103
  • TK103-2

Installation

With package manager npm:

npm install octopus-gps-tracking

DEMO SERVER APP

You can check a basic demo app here

DEMO SERVER WEB APP

You can check a Express + Socket.io + MongoDB + Google Maps Web app to see your devices in realtime here. Also, you can see the live demo here

Usage

Once you have installed the package, you can use it like:

var gps = require("gps-tracking");
 
var options = {
    'debug'                 : true,
    'port'                  : 8090,
    'device_adapter'        : "TK103_2"
}
 
var server = gps.server(options,function(device,connection){
 
    device.on("login_request",function(device_id,msg_parts){
 
        // Some devices sends a login request before transmitting their position
        // Do some stuff before authenticate the device...
 
        // Accept the login request. You can set false to reject the device.
        this.login_authorized(true);
 
    });
 
 
    //PING -> When the gps sends their position
    device.on("ping",function(data){
 
        //After the ping is received, but before the data is saved
        //console.log(data);
        return data;
 
    });
 
});

Sending a message to device

server.send_to(device_id, 'powercar 11');

Step by step

  1. Install Node

  2. Create a folder for your project

  3. Copy the example code above in a .js file like server.js

  4. Install the package in the project folder

cd /path/to/my/project
npm install gps-tracking
  1. Run your server
node server.js

Overview

With this package you are going to create a tcp server that listens on a open port of your server/computer for a specific gps device model. For example, you are going to listen on port 8090 for 'TK103 gps-trackers'.

If you want to listen for different kind of trackers, you have to create another tcp server. You can do this in a different node.js program in the same server, but you have to listen in a different port.

So, you can listen on port 8090 for TK103 devices and listen on 8091 for TK102 devices (or any gps-tracker you want)

Options

debug

Enables console.log messages.

    "debug":false,

port

The port to listen to. Where the packages of the device will arrive.

    "port": 8080,

device_adapter

Which device adapter will be used to parse the incoming packets.

    "device_adapter": false,
    // If false, the server will throw an error.
 
    "device_adapter": "TK103_2"
    // You can create your own adapter.
 
    //FOR USING A CUSTOM DEVICE ADAPTER
     "device_adapter": require("./my_custom_adapter")

Events

Once you create a server, you can access to the connection and the device object connected. Both objects emits events you can listen on your app.

var server = gps.server(options,function(device,connection){
    //conection = net.createServer(...) object
    //device = Device object
}

connection events

Available events:

  • end
  • data
  • close
  • timeout
  • drain

You can check the documentation of node.js net object here.

//Example:
var server = gps.server(opts,function(device,connection){
    connection.on("data",function(res){
        //When raw data comes from the device
    });
});

Device object events

Every time something connects to the server, a net connection and a new device object will be created. The Device object is your interface to send & receive packets/commands.

var server = gps.server(opts,function(device,connection){
    /* Available device variables:
        ----------------------------
        device.uid -> is setted when the first packet is parsed
        device.name -> you can set a custon name for this device.
        device.ip -> ip of the device
        device.port --> device port
    */
 
    /******************************
    LOGIN
    ******************************/
    device.on("login_request",function(device_id,msg_parts){
        //Do some stuff before authenticate the device...
 
        this.login_authorized(true); //Accept the login request.
    });
    device.on("login",function(){
        //this = device
        console.log("Hi! i'm "+this.uid);
    });
    device.on("login_rejected",function(){
 
    });
 
 
    /******************************
    PING - When the gps sends their position
    ******************************/
    device.on("ping",function(data){
        //After the ping is received
        //console.log(data);
        console.log("I'm here now: "+gps_data.latitude+""+gps_data.longitude+");
        return data;
    });
 
 
    /******************************
    ALARM - When the gps sends and alarm
    ******************************/
    device.on("alarm",function(alarm_code,alarm_data,msg_data){
        console.log("Help! Something happend: "+alarm_code+" ("+alarm_data.msg+")");
        call_me();
    });
 
 
    /******************************
    MISC
    ******************************/
    device.on("handshake",function(){
 
    });
 
});

Package Sidebar

Install

npm i octopus-gps-tracking

Weekly Downloads

0

Version

1.0.14

License

none

Last publish

Collaborators

  • proyk