|
|
|
@ -768,7 +768,7 @@ exports.getByHardwareAndTankId = async (req, reply) => {
|
|
|
|
|
const tankHeight = parseFloat(matchedTank.tankHeight || "0");
|
|
|
|
|
const isLoraConnected = isGSMConnected && tankHeight > 0;
|
|
|
|
|
|
|
|
|
|
// Format date and time from matched tank
|
|
|
|
|
// Format date and time
|
|
|
|
|
const matchedTankDateObj = new Date(matchedTank.date);
|
|
|
|
|
const formattedDate = moment(matchedTankDateObj).tz("Asia/Kolkata").format("DD-MM-YYYY");
|
|
|
|
|
const formattedTime = matchedTank.time || moment(matchedTankDateObj).tz("Asia/Kolkata").format("HH:mm:ss");
|
|
|
|
@ -783,14 +783,24 @@ exports.getByHardwareAndTankId = async (req, reply) => {
|
|
|
|
|
lora_last_check_time: moment().tz("Asia/Kolkata").format("DD-MM-YYYY HH:mm:ss")
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// Check if Insensors document exists before updating
|
|
|
|
|
const sensorDoc = await Insensors.findOne({ connected_to: hardwareId, hardwareId: tankhardwareId });
|
|
|
|
|
// Find and update Insensors
|
|
|
|
|
const sensorDoc = await Insensors.findOne({
|
|
|
|
|
hardwareId: tankhardwareId,
|
|
|
|
|
connected_to: hardwareId
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if (!sensorDoc) {
|
|
|
|
|
console.warn("⚠️ No Insensors doc found with:", { connected_to: hardwareId, hardwareId: tankhardwareId });
|
|
|
|
|
console.warn("⚠️ No Insensors doc found for LoRa update:", { tankhardwareId, connected_to: hardwareId });
|
|
|
|
|
|
|
|
|
|
// Optional fallback update only by hardwareId
|
|
|
|
|
const fallbackDoc = await Insensors.findOne({ hardwareId: tankhardwareId });
|
|
|
|
|
if (fallbackDoc) {
|
|
|
|
|
await Insensors.updateOne({ _id: fallbackDoc._id }, { $set: updateFields });
|
|
|
|
|
console.log("⚠️ Fallback Insensors updated by hardwareId:", fallbackDoc._id);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
const updated = await Insensors.findByIdAndUpdate(sensorDoc._id, { $set: updateFields }, { new: true });
|
|
|
|
|
console.log("✅ Insensors updated:", updated._id);
|
|
|
|
|
await Insensors.updateOne({ _id: sensorDoc._id }, { $set: updateFields });
|
|
|
|
|
console.log("✅ Insensors LoRa status updated:", sensorDoc._id);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return reply.send({
|
|
|
|
@ -812,6 +822,7 @@ exports.getByHardwareAndTankId = async (req, reply) => {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
exports.getByHardwareAndTankIdSupport = async (req, reply) => {
|
|
|
|
|
try {
|
|
|
|
|
const { hardwareId, tankhardwareId } = req.params;
|
|
|
|
|