In the FMCOO3 GPRS settings there is server settings. I’ve considered that it is my backend server so I have added my nodejs server(domain name) as it is app platform deployed in digitalocean and its port. And set the Protocol TCP in configurator tool.
Now, I’m not sure how to get the IMEI and AVL datas as in the configurator tool-> status -> GSM Info, socket is closed. The last sent record is : 01/01/1970
const net = require("net");
const logger = require("./helpers/logger");
require("dotenv").config();
const port = process.env.PORT;
// TCP Server for handling Teltonika devices
const tcpServer = net.createServer((socket) => {
logger.info("TCP Client connected");
let buffer = Buffer.alloc(0);
socket.on("data", async (data) => {
buffer = Buffer.concat([buffer, data]);
// Log received data for debugging
console.log("Received data:", buffer.toString("hex"));
logger.info({ buffer }, "Data received from tracker");
// Handle IMEI processing if buffer is at least 17 bytes
if (buffer.length >= 17) {
const imeiProcessed = await handleIMEI(buffer, socket);
logger.info({ imeiProcessed }, "imeiProcessed is:");
}
// Handle AVL Data if buffer contains more data
if (buffer.length > 0) {
handleAVLData(buffer, socket);
buffer = Buffer.alloc(0); // Clear buffer after processing
}
});
socket.on("close", () => {
logger.info("TCP Client disconnected");
});
socket.on("error", (err) => {
logger.error(`Socket error: ${err.message}`);
});
});
tcpServer.listen(port, () => {
logger.info("TCP Server is running on port 8080");
});
async function handleIMEI(buffer, socket) {
const imeiLength = buffer.readUInt16BE(0);
const imei = buffer.slice(2, 2 + imeiLength).toString("ascii");
logger.info({ imei }, "Received IMEI:");
const isAccepted = await validateIMEI(imei); // Implement IMEI validation logic
if (isAccepted) {
socket.write(Buffer.from([0x01])); // Send acknowledgment
logger.info("IMEI accepted and acknowledgment sent");
return true;
} else {
socket.write(Buffer.from([0x00])); // Send rejection
logger.info("IMEI rejected and rejection sent");
return false;
}
}
New contributor