diff --git a/src/controllers/tanksController.js b/src/controllers/tanksController.js index 256c7dce..44f28967 100644 --- a/src/controllers/tanksController.js +++ b/src/controllers/tanksController.js @@ -5861,8 +5861,9 @@ const deviceLastSeen = new Map(); // Track last seen timestamps for devices // Connect a single global MQTT client const mqttClient = mqtt.connect(brokerUrl, { clientId: 'global_subscriber', - clean: true, + clean: false, // Retain session state reconnectPeriod: 5000, // Reconnect every 5 seconds + keepalive: 60, // Send a ping every 60 seconds }); // Event: When the MQTT client connects @@ -5884,13 +5885,10 @@ mqttClient.on('message', async (topic, message) => { try { console.log(`📩 Message received on topic ${topic}:`, message.toString()); - // Parse the message const data = JSON.parse(message.toString()); const { hw_Id, Motor_status, tanks } = data.objects; - // Log the device ID and current time - const currentTime = moment().tz('Asia/Kolkata').format('DD-MMM-YYYY - HH:mm'); - console.log(`📅 Device ${hw_Id} last seen at: ${currentTime}`); + console.log(`📅 Device ${hw_Id} last seen at: ${moment().tz('Asia/Kolkata').format('DD-MMM-YYYY - HH:mm')}`); // Update the last seen timestamp for the device deviceLastSeen.set(hw_Id, new Date().toISOString()); @@ -5902,10 +5900,10 @@ mqttClient.on('message', async (topic, message) => { tanks: tanks.map((tank) => ({ tankhardwareId: tank.Id, tankHeight: tank.level, - date: currentTime, + date: moment().tz('Asia/Kolkata').format('DD-MMM-YYYY - HH:mm'), time: moment().tz('Asia/Kolkata').format('HH:mm'), })), - date: currentTime, + date: moment().tz('Asia/Kolkata').format('DD-MMM-YYYY - HH:mm'), time: moment().tz('Asia/Kolkata').format('HH:mm'), }); @@ -5996,9 +5994,6 @@ process.on('SIGINT', () => { }); - - - exports.getPendingAndCompletedsurveyOfparticularInstaller = async (request, reply) => { try { const { installationId } = request.params;