Hi,
I'm creating a script to parse data from several teltonika devices and while saving data to Firebase I have noticed that there is a conflict between data could anyone help solve this conflict?
let server = net.createServer((c) => {
console.log("client connected");
c.on('end', () => {
console.log("client disconnected");
});
c.on('data', (data) => {
Lengthimei = data.length;
if (Lengthimei <= 17) {
this.imeidata = data;
};
imei = this.imeidata.toString();
imei = imei.slice(2, 17);
con1.query('SELECT * FROM `boitier_imei` WHERE `code_imei`=?', [imei], (err, result, fields) => {
if (err) {
console.log(err+"imei error");
}
if (result.length > 0) {
console.log("imei exist");
let buffer = data;
let parser = new Parser(buffer);
if (parser.isImei) {
c.write(Buffer.alloc(1, 1));
}
else {
let avl = parser.getAvl();
console.log("timestamp : "+avl['records'][0].timestamp);
console.log("longitude : "+avl['records'][0].gps.longitude);
console.log("latitude : "+avl['records'][0].gps.latitude);
console.log("altitude : "+avl['records'][0].gps.altitude);
console.log("angle : "+avl['records'][0].gps.angle);
console.log("satellites : "+avl['records'][0].gps.satellites);
console.log("speed : "+avl['records'][0].gps.speed);
for (i = 0; i < avl['records'][0].ioElements.length; i++) {
console.log("ID : "+avl['records'][0].ioElements[i].id);
console.log(""+avl['records'][0].ioElements[i].label);
console.log(""+avl['records'][0].ioElements[i].value);
console.log("\n");
}
let writer = new binutils.BinaryWriter();
writer.WriteInt32(avl.number_of_data);
let response = writer.ByteBuffer;
c.write(response);
c.write(Buffer.alloc(1, 0));
}
}
else {
console.log("not exist");
}
});
});
});
server.listen(3000, '', () => {
console.log("Server started");
});