|
|
@ -2002,18 +2002,20 @@ else if (currentWaterLevel >= highWaterThreshold) {
|
|
|
|
reply.code(200).send({ message: "Motor started successfully." });
|
|
|
|
reply.code(200).send({ message: "Motor started successfully." });
|
|
|
|
} else if (action === "stop") {
|
|
|
|
} else if (action === "stop") {
|
|
|
|
motorStopStatus = "1"; // If action is stop, set stop status to "1"
|
|
|
|
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 {
|
|
|
|
} else {
|
|
|
|
throw new Error("Invalid action provided.");
|
|
|
|
throw new Error("Invalid action provided.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// If action is stop, immediately update motor status and perform stop operations
|
|
|
|
// If action is stop, immediately update motor status and perform stop operations
|
|
|
|
if (action === "stop") {
|
|
|
|
if (action === "stop") {
|
|
|
|
|
|
|
|
console.log("enterted stop")
|
|
|
|
await Tank.updateOne(
|
|
|
|
await Tank.updateOne(
|
|
|
|
{ customerId, "connections.inputConnections.motor_id": motorId },
|
|
|
|
{ customerId, "connections.inputConnections.motor_id": motorId },
|
|
|
|
{
|
|
|
|
{
|
|
|
|
$set: {
|
|
|
|
$set: {
|
|
|
|
"connections.inputConnections.$.motor_stop_status": "1",
|
|
|
|
"connections.inputConnections.$.motor_stop_status": "1",
|
|
|
|
|
|
|
|
"connections.inputConnections.$.motor_on_type": "manual",
|
|
|
|
"connections.inputConnections.$.stopTime": req.body.stopTime,
|
|
|
|
"connections.inputConnections.$.stopTime": req.body.stopTime,
|
|
|
|
"connections.inputConnections.$.threshold_type": null,
|
|
|
|
"connections.inputConnections.$.threshold_type": null,
|
|
|
|
"connections.inputConnections.$.manual_threshold_time": null,
|
|
|
|
"connections.inputConnections.$.manual_threshold_time": null,
|
|
|
@ -2112,6 +2114,7 @@ else if (currentWaterLevel >= highWaterThreshold) {
|
|
|
|
{
|
|
|
|
{
|
|
|
|
$set: {
|
|
|
|
$set: {
|
|
|
|
"connections.inputConnections.$.motor_stop_status": "1",
|
|
|
|
"connections.inputConnections.$.motor_stop_status": "1",
|
|
|
|
|
|
|
|
|
|
|
|
"connections.inputConnections.$.threshold_type": null,
|
|
|
|
"connections.inputConnections.$.threshold_type": null,
|
|
|
|
"connections.inputConnections.$.manual_threshold_time": null,
|
|
|
|
"connections.inputConnections.$.manual_threshold_time": null,
|
|
|
|
"connections.inputConnections.$.manual_threshold_percentage": null
|
|
|
|
"connections.inputConnections.$.manual_threshold_percentage": null
|
|
|
@ -3358,6 +3361,7 @@ exports.IotDevice = async (req, reply) => {
|
|
|
|
|
|
|
|
|
|
|
|
exports.IotDeviceforstandalonedevice = async (req, reply) => {
|
|
|
|
exports.IotDeviceforstandalonedevice = async (req, reply) => {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
|
|
|
|
console.log("entered post for iotstandalone")
|
|
|
|
const { hardwareId, Motor_status, tanks } = req.body;
|
|
|
|
const { hardwareId, Motor_status, tanks } = req.body;
|
|
|
|
|
|
|
|
|
|
|
|
// create a new tank document with the current date and time
|
|
|
|
// 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
|
|
|
|
// Find the inputConnection with the specified motor_id
|
|
|
|
const inputConnection = tank.connections.inputConnections.find(conn => conn.motor_id === hardwareId);
|
|
|
|
const inputConnection = tank.connections.inputConnections.find(conn => conn.motor_id === hardwareId);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (inputConnection) {
|
|
|
|
// Update the motor_status of the inputConnection
|
|
|
|
// Update the motor_status of the inputConnection
|
|
|
|
inputConnection.motor_status = status;
|
|
|
|
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
|
|
|
|
// Save the updated tank
|
|
|
|
await tank.save();
|
|
|
|
await tank.save();
|
|
|
@ -4173,7 +4200,7 @@ exports.motorstatus = async (req, reply) => {
|
|
|
|
exports.readMotorStatus = async (req, reply) => {
|
|
|
|
exports.readMotorStatus = async (req, reply) => {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
const motor_id = req.query.motor_id;
|
|
|
|
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)
|
|
|
|
// 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 inputConnections = tank.connections.inputConnections;
|
|
|
|
const motorConnection = inputConnections.find(conn => conn.motor_id === motor_id);
|
|
|
|
const motorConnection = inputConnections.find(conn => conn.motor_id === motor_id);
|
|
|
|
if (motorConnection) {
|
|
|
|
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;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (!motor_stop_status) {
|
|
|
|
if (!motor_stop_status) {
|
|
|
|