ashok 9 months ago
commit b36058304c

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

Loading…
Cancel
Save