-
Notifications
You must be signed in to change notification settings - Fork 19
/
index.js
49 lines (32 loc) · 1.38 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
var gps = require("gps-tracking");
var options = {
'debug' : false, //We don't want to debug info automatically. We are going to log everything manually so you can check what happens everywhere
'port' : 8090,
'device_adapter' : "TK103"
}
var server = gps.server(options,function(device,connection){
device.on("connected",function(data){
console.log("I'm a new device connected");
return data;
});
device.on("login_request",function(device_id,msg_parts){
console.log('Hey! I want to start transmiting my position. Please accept me. My name is '+device_id);
this.login_authorized(true);
console.log("Ok, "+device_id+", you're accepted!");
});
device.on("ping",function(data){
//this = device
console.log("I'm here: "+data.latitude+", "+data.longitude+" ("+this.getUID()+")");
//Look what informations the device sends to you (maybe velocity, gas level, etc)
//console.log(data);
return data;
});
device.on("alarm",function(alarm_code,alarm_data,msg_data){
console.log("Help! Something happend: "+alarm_code+" ("+alarm_data.msg+")");
});
//Also, you can listen on the native connection object
connection.on('data',function(data){
//echo raw data package
//console.log(data.toString());
})
});