Events and command execution examples.
Designed to handle tracker connections. Accepts timeout
option, that is automatically passed to Tracker
objects.
var gprs = require('gprs-server');
var server = new gprs.Server({ timeout: 120000 });
Is emitted when tracker establishes connect with Server
. Parameters:
tracker
:Tracker
object
Is emitted when tracker closes connection. Parameters:
tracker
:Tracker
object
Bind server to the specified port.
Parameter | Type | Description |
---|---|---|
port | integer | Port number |
callback | function | User callback |
server.listen(20180, function(error) {
if (error) throw error;
console.log('gps server is listening');
});
Designed to iteract with GPS trackers. Accepts timeout
option, (which is passed automatically by Server
).
var gprs = require('gprs-server');
var server = new gprs.Server({
timeout: 120000
}).listen(20180, function(error) {
if (error) throw error;
console.log('gps server is listening');
});
server.on('connect', function(tracker) {
console.log('tracker connected!');
});
Heartbeat is message with command code 22
sent by tracker over time. You can configure it's interval using tracker.setHeartbeatInterval
method.
Is emitted when it is not possible to parse tracker's message. Parameters:
Error
: object with error descriptonBuffer
: unparseable message
Is emitted every time message is received from tracker, very useful for debugging. Parameters:
Message
: message received from tracker
Is emitted every time message is passed to tracker, is useful for debugging. Parameters:
Message
: message sent to tracker
Is emitted after tracker sent login request with command code 20
& successful login confirmation with command code 20
was sent back. In fact, login request can not be used for real authentication, it tells that data sent by tracker will be accepted by server.
Is emitted every time tracker sends alarm or report. Parameters:
Object
with following data:type
: message type (seeMessage.types
)data
: parsed resultraw
: raw data
Is emitted after connection was closed.
Is emitted after connection is timed out (timeout can be configured in Tracker options).
Close tracker connection.
var gprs = require('gprs-server');
var server = new gprs.Server().listen(20180, function(error) {
if (error) throw error;
console.log('gps server is listening');
});
server.on('connect', function(tracker) {
tracker.on('disconnect', function() {
console.log('tracker disconnected');
})
console.log('tracker connected!');
tracker.disconnect();
});
Set reporting time interval (internal cmd code: 02
).
Parameter | Type | Description |
---|---|---|
interval | string | Hours:Minutes:Seconds |
callback | function | User callback |
tracker.setReportTimeInterval("00:00:10", function(err, result){
if (err) {
console.log('SET REPORT TIME INTERVAL ERROR: ', err);
} else {
console.log('SET REPORT TIME INTERVAL: ', result);
}
});
Not functional (everything below is not adapted from original meiligao server implementation)
Request GPS report (internal: track on demand 0x4101
)
Parameter | Type | Description |
---|---|---|
callback | function | User callback |
tracker.requestReport(function(err, data) {
if (err) {
console.log('REQUEST REPORT ERROR: ', err);
} else {
console.log('REQUEST REPORT: ', data);
}
});
Request serial number & IMEI from tracker (internal: 0x9001
).
Parameter | Type | Description |
---|---|---|
callback | function | User callback |
tracker.getSnImei(function(err, data) {
if (err) {
console.log('GET SN IMEI ERROR: ', err);
} else {
console.log('GET SN IMEI: ', data);
}
});
Revert all settings (except for the password, IP, Port, APN, ID and GPRS interval) back to factory default (internal: 0x4110
).
Parameter | Type | Description |
---|---|---|
callback | function | User callback |
tracker.resetConfiguration(function(err, result){
if (err) {
console.log('RESET CONFIGURATION ERROR: ', err);
} else {
console.log('RESET CONFIGURATION: ', result);
}
});
Reboot the GPS module of the tracker (internal: 0x4902
).
Parameter | Type | Description |
---|---|---|
callback | function | User callback |
tracker.rebootGps(function(err, result){
if (err) {
console.log('REBOOT GPS ERROR: ', err);
} else {
console.log('REBOOT GPS: ', result);
}
});
Set extended tracker settings (internal: 0x4108
).
Parameter | Type | Default | Description |
---|---|---|---|
setting.smsReplyOnCall | boolean | true | Send position report by sms after call is made to the tracker. |
setting.useGPRMSFormat | boolean | false | Use NMEA 0183 GPRMC or normal text (for sms only). |
setting.hangUpAfter5Rings | boolean | false | Hang up after 5 rings. |
setting.enableCallBuzzer | boolean | false | Turn on/off buzzer for the incoming call. |
setting.enableLedLights | boolean | true | When is set to false, lights stop flashing when the tracker is working. |
setting.alarmPowerOn | boolean | true | Send sms alarm to the authorized phone number for SOS, and a GPRS alarm to the server, when the tracker is turned on. |
setting.alarmPowerCut | boolean | false | Send sms alarm to the authorized phone number for SOS when the power of the vehicle tracker is cut. |
setting.alarmGpsBlindArea | boolean | false | Send sms alarm when the tracker enters GPS blind area. |
callback | function | - | User callback |
tracker.setExtendedSettings({
smsReplyOnCall : true,
useGPRMSFormat : false, // works for sms only
hangUpAfter5Rings : false,
enableCallBuzzer : false,
enableLedLights : true,
alarmPowerOn : true,
alarmPowerCut : false,
alarmGpsBlindArea : false,
}, function(err, result){
if (err) {
console.log('SET EXTENDED SETTINGS ERROR: ', err);
} else {
console.log('SET EXTENDED SETTINGS: ', result);
}
});
Sets specified time interval for heartbeat message (internal: 0x5199
).
Parameter | Type | Description |
---|---|---|
interval | integer | Interval in minutes |
callback | function | User callback |
tracker.setHeartbeatInterval(1, function(err, result){
if (err) {
console.log('SET HEARTBEAT INTERVAL ERROR: ', err);
} else {
console.log('SET HEARTBEAT INTERVAL: ', result);
}
});
Delete total mileage (internal: 0x4351
).
Parameter | Type | Description |
---|---|---|
callback | function | User callback |
tracker.clearMileage(function(err, result){
if (err) {
console.log('CLEAR MILEAGE ERROR: ', err);
} else {
console.log('CLEAR MILEAGE: ', result);
}
});
Set inactivity timeout, after which tracker will go to energy saving mode (internal: 0x4126
).
Parameter | Type | Description |
---|---|---|
interval | integer | Interval in minutes, possible values: 0 - 99, 0 disables timeout. |
callback | function | User callback |
tracker.setPowerDownTimeout(15, function(err, result){
if (err) {
console.log('SET POWER DOWN TIMEOUT ERROR: ', err);
} else {
console.log('SET POWER DOWN TIMEOUT: ', result);
}
});
Read logged data and returns reports array (high-level wrapper for internal command 0x9016
).
Parameter | Type | Description |
---|---|---|
callback | function | User callback |
tracker.getMemoryReports(function(err, reports){
if (err) {
console.log('GET MEMORY REPORTS ERROR: ', err);
} else {
console.log('GET MEMORY REPORTS: ', reports);
}
});
Set interval for saving coordinates in memory, when internet is not available (internal: 0x4131
).
Parameter | Type | Description |
---|---|---|
interval | integer | Interval in seconds, possible values: 1 - 65535, 0 - disable. |
callback | function | User callback |
tracker.setMemoryReportInterval(1, function(err, result){
if (err) {
console.log('SET MEMORY REPORT INTERVAL ERROR: ', err);
} else {
console.log('SET MEMORY REPORT INTERVAL: ', result);
}
});
Clear reports stored in memory (internal: 0x5503
).
Parameter | Type | Description |
---|---|---|
callback | function | User callback |
tracker.clearMemoryReports(function(err, result){
if (err) {
console.log('CLEAR MEMORY REPORTS ERROR: ', err);
} else {
console.log('CLEAR MEMORY REPORTS: ', result);
}
});
Return authorized phone numbers (internal: 0x9003
).
Parameter | Type | Description |
---|---|---|
callback | function | User callback |
tracker.getAuthorizedPhones(function(err, phones){
if (err) {
console.log('GET AUTHORIZED PHONES ERROR: ', err);
} else {
console.log('GET AUTHORIZED PHONES: ', phones);
}
});
Set authorized phone for sos button, for receiving sms & calls (internal: 0x4103
).
Parameter | Type | Description |
---|---|---|
smsPhone | string | Authorized phone number for receiving sms. |
callPhone | string | Authorized phone number for receiving phone call. |
callback | function | User callback |
tracker.setAuthorizedPhones(79991234567, 79991234567, function(err, result){
if (err) {
console.log('SET AUTHORIZED PHONE ERROR: ', err);
} else {
console.log('SET AUTHORIZED PHONE: ', result);
}
});
Retrieve reporting time interval from tracker, 1 unit = 10 seconds (internal: 0x9002
).
Parameter | Type | Description |
---|---|---|
callback | function | User callback |
tracker.getReportTimeInterval(function(err, interval){
if (err) {
console.log('GET REPORT TIME INTERVAL ERROR: ', err);
} else {
console.log('GET REPORT TIME INTERVAL: ', interval);
}
});
#### setReportDistanceInterval
Set distance report as per pre-set interval. Sends out alarm when the car is moving and stops sending the report when the car is stationary (internal: `0x4303`).
Parameter | Type | Description
----------|----------|------------
meters | integer | Distance interval, is suggested to be set above 300 meters.
callback | function | User callback
```js
tracker.setReportDistanceInterval(300, function(err, result){
if (err) {
console.log('SET REPORT DISTANCE INTERVAL ERROR: ', err);
} else {
console.log('SET REPORT DISTANCE INTERVAL: ', result);
}
});
Set speeding alarm (internal: 0x4105
).
Parameter | Type | Description |
---|---|---|
limit | integer | Speed limit, 1 unit = 10 kmph. |
callback | function | User callback |
tracker.setAlarmSpeeding(15, function(err, result){
if (err) {
console.log('SET ALARM SPEEDING ERROR: ', err);
} else {
console.log('SET ALARM SPEEDING: ', result);
}
});
Set movement alarm (internal: 0x4106
).
Parameter | Type | Description |
---|---|---|
area | integer | For supported values please see documentation |
callback | function | User callback |
tracker.setAlarmMovement(0x03, function(err, result){
if (err) {
console.log('SET ALARM MOVEMENT ERROR: ', err);
} else {
console.log('SET ALARM MOVEMENT: ', result);
}
});
Set geo-fence alarm (internal: 0x4302
).
Parameter | Type | Description |
---|---|---|
latitude | number | Center point latitude |
longitude | number | Center point longitude |
radius | integer | Circle radius, possible values: 1 - 4294967295 |
callback | function | User callback |
tracker.setAlarmGeofence(55.753905, 37.620872, 200, function(err, result){
if (err) {
console.log('SET ALARM GEOFENCE ERROR: ', err);
} else {
console.log('SET ALARM GEOFENCE: ', result);
}
});
Command names mapping, message types list & all other stuff related to message processing is located in Message.js file. Original protocol documentation is also included in case you will need deep understanding how this particular GPRS protocol works.