I created an application to show the location of a gps in real time using gprs. This application uses node.js. I have already created all the methods and in tests it works correctly. I set up the gps to an external gps server and send the data correctly. Now I configured it with my server and happens is I have the socket.io with open listening but the data does not arrive. Could someone help me to see why the data does not arrive or if it is arriving because I cannot read it?
This is the code to listen:
var socket = io.connect('http://34.226.95.13:5050', { 'forceNew': true });
socket.on('data', function(data) {
console.log(data);
})
socket.on('connection', function (socket) {
socket.on('data', function (data) {
console.log(data.toString());
var location = JSON.stringify(data);
socket.emit('data', item);
});
});
Thanks
I was searching the internet a lot and found a way to receive the information only with the DATA parameter, but I went a little further and found that the server returned an answer like this: ##, imei: 359xxxxxxxxxxxx, A;
Then, I kept investigating and had to respond to the device with LOAD, after doing my own development I found a repository that has everything very well organized and is the best to use.
To install you need to enter the following command in the console:
npm install gpstracker
And next, create index.js and copy this code:
var gpstracker = require("gpstracker");
var server = gpstracker.create().listen(5050, function(){
console.log('listening your gps trackers on port', 5050);
});
server.trackers.on("connected", function(tracker){
console.log("tracker connected with imei:", tracker.imei);
tracker.on("help me", function(){
console.log(tracker.imei + " pressed the help button!!".red);
});
tracker.on("position", function(position){
console.log("tracker {" + tracker.imei + "}: lat",
position.lat, "lng", position.lng);
});
tracker.trackEvery(10).seconds();
});
Thanks