ashok 10 months ago
commit 09e70ea8a9

@ -2002,18 +2002,20 @@ else if (currentWaterLevel >= highWaterThreshold) {
reply.code(200).send({ message: "Motor started successfully." });
} else if (action === "stop") {
motorStopStatus = "1"; // If action is stop, set stop status to "1"
eventEmitter.emit('motorStop', fcmToken, motorId, currentWaterLevel,blockName, tankName,stopTime,motorOnType);
// eventEmitter.emit('motorStop', fcmToken, motorId, currentWaterLevel,blockName, tankName,stopTime,motorOnType);
} else {
throw new Error("Invalid action provided.");
}
// If action is stop, immediately update motor status and perform stop operations
if (action === "stop") {
console.log("enterted stop")
await Tank.updateOne(
{ customerId, "connections.inputConnections.motor_id": motorId },
{
$set: {
"connections.inputConnections.$.motor_stop_status": "1",
"connections.inputConnections.$.motor_on_type": "manual",
"connections.inputConnections.$.stopTime": req.body.stopTime,
"connections.inputConnections.$.threshold_type": null,
"connections.inputConnections.$.manual_threshold_time": null,
@ -2112,6 +2114,7 @@ else if (currentWaterLevel >= highWaterThreshold) {
{
$set: {
"connections.inputConnections.$.motor_stop_status": "1",
"connections.inputConnections.$.threshold_type": null,
"connections.inputConnections.$.manual_threshold_time": null,
"connections.inputConnections.$.manual_threshold_percentage": null
@ -3358,6 +3361,7 @@ exports.IotDevice = async (req, reply) => {
exports.IotDeviceforstandalonedevice = async (req, reply) => {
try {
console.log("entered post for iotstandalone")
const { hardwareId, Motor_status, tanks } = req.body;
// create a new tank document with the current date and time
@ -3448,9 +3452,32 @@ exports.IotDeviceforstandalonedevice = async (req, reply) => {
// Find the inputConnection with the specified motor_id
const inputConnection = tank.connections.inputConnections.find(conn => conn.motor_id === hardwareId);
if (inputConnection) {
// Update the motor_status of the inputConnection
inputConnection.motor_status = status;
// Check if motor_stop_status is "1" and status is "2"
if (inputConnection.motor_stop_status === "1" && status === "2") {
// Check if motor_on_type is not already "forced_manual"
if (inputConnection.motor_on_type !== "forced_manual") {
inputConnection.motor_on_type = "forced_manual";
// Update startTime to the current time in the specified format
const currentTime = new Date();
const formattedTime = currentTime.toLocaleString('en-GB', {
day: '2-digit',
month: 'short',
year: 'numeric',
hour: '2-digit',
minute: '2-digit',
hour12: false,
}).replace(',', '');
inputConnection.startTime = formattedTime;
}
}
}
// Save the updated tank
await tank.save();
@ -4173,7 +4200,7 @@ exports.motorstatus = async (req, reply) => {
exports.readMotorStatus = async (req, reply) => {
try {
const motor_id = req.query.motor_id;
console.log(motor_id)
console.log("entered read api for iot")
// Perform any necessary logic based on action (1: Start, 2: Stop)
@ -4187,9 +4214,16 @@ exports.readMotorStatus = async (req, reply) => {
const inputConnections = tank.connections.inputConnections;
const motorConnection = inputConnections.find(conn => conn.motor_id === motor_id);
if (motorConnection) {
motor_stop_status = motorConnection.motor_stop_status;
// Check if motor_on_type is "forced_manual" and motor_stop_status is "1"
if (motorConnection.motor_on_type === "forced_manual" && motorConnection.motor_stop_status === "1") {
motor_stop_status = "2"; // Send motor_stop_status as "2"
} else {
motor_stop_status = motorConnection.motor_stop_status; // Otherwise, assign its original value
}
break;
}
}
if (!motor_stop_status) {

@ -76,12 +76,16 @@ module.exports = function (fastify, opts, next) {
// required: ['phone'],
properties: {
blockName: { type: "string", default: null },
tankhardwareId: { type: "string" },
hardwareId: { type: "string" },
tankName: { type: "string" },
blockName: { type: "string"},
capacity: { type: "string" },
typeOfWater: { type: "string", default: null },
type: { type: "string" },
tankLocation: { type: "string", default: null },
// customerId: { type: "string" },
typeOfWater: { type: "string" },
waterCapacityPerCm:{ type: "string" },
tankLocation: { type: "string" },
height:{ type: "string" },
},
},
security: [

Loading…
Cancel
Save