-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #11 from RehanShakir/WebApp
Web app
- Loading branch information
Showing
14 changed files
with
689 additions
and
73 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,36 @@ | ||
//FOR LIVE SERVER CAPROVER Uncomment it | ||
const mongoose = require("mongoose"); | ||
|
||
mongoose | ||
.connect( | ||
"mongodb://srv-captain--smart-agri-database/mydatabase?authSource=admin", | ||
{ | ||
user: "smartAgriDatabase", | ||
pass: "sma$r$t$Agr$iD$a$%tabase", | ||
useNewUrlParser: true, | ||
useUnifiedTopology: true, | ||
} | ||
) | ||
.then(() => { | ||
console.log("DB Connected"); | ||
}) | ||
.catch((err) => { | ||
console.log("Error Connecting to Database"); | ||
console.log(err); | ||
}); | ||
|
||
// mongoose | ||
// .connect( | ||
// "mongodb+srv://rehan:rehan@cluster0.qhfay.mongodb.net/sensors?retryWrites=true&w=majority", | ||
// "mongodb://srv-captain--smart-agri-database/mydatabase?authSource=admin", | ||
// { | ||
// user: "smartAgriDatabase", | ||
// pass: "sma$r$t$Agr$iD$a$%tabase", | ||
// useNewUrlParser: true, | ||
// useUnifiedTopology: true, | ||
// } | ||
// ) | ||
// .then(() => { | ||
// console.log("Connected To MongoDB"); | ||
// console.log("DB Connected"); | ||
// }) | ||
// .catch((error) => { | ||
// console.log("Error while connecting to Database"); | ||
// console.log(error.message); | ||
// .catch((err) => { | ||
// console.log("Error Connecting to Database"); | ||
// console.log(err); | ||
// }); | ||
|
||
mongoose | ||
.connect( | ||
"mongodb+srv://rehan:rehan@cluster0.qhfay.mongodb.net/sensors?retryWrites=true&w=majority", | ||
{ | ||
useNewUrlParser: true, | ||
useUnifiedTopology: true, | ||
} | ||
) | ||
.then(() => { | ||
console.log("Connected To MongoDB"); | ||
}) | ||
.catch((error) => { | ||
console.log("Error while connecting to Database"); | ||
console.log(error.message); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
const mongoose = require("mongoose"); | ||
|
||
// let date = new Date(); | ||
|
||
let alarmSchema = mongoose.Schema({ | ||
macAddress: { | ||
type: String, | ||
required: true, | ||
}, | ||
temperature: { | ||
max: Number, | ||
min: Number, | ||
}, | ||
humidity: { | ||
max: Number, | ||
min: Number, | ||
}, | ||
atmosphereicPressure: { | ||
max: Number, | ||
min: Number, | ||
}, | ||
soilMoisture: { | ||
max: Number, | ||
min: Number, | ||
}, | ||
ec: { | ||
max: Number, | ||
min: Number, | ||
}, | ||
ph: { | ||
max: Number, | ||
min: Number, | ||
}, | ||
nitrogen: { | ||
max: Number, | ||
min: Number, | ||
}, | ||
phosphorus: { | ||
max: Number, | ||
min: Number, | ||
}, | ||
potassium: { | ||
max: Number, | ||
min: Number, | ||
}, | ||
}); | ||
let alarmModel = new mongoose.model("Alarm", alarmSchema); | ||
|
||
module.exports = alarmModel; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
const express = require("express"); | ||
const router = express.Router(); | ||
const _ = require("lodash"); | ||
const alarmModel = require("../../models/alarm"); | ||
|
||
router.get("/:macAddress", async (req, res) => { | ||
let macAddress = req.params.macAddress; | ||
let alarm = await alarmModel.findOne({ macAddress }); | ||
return res.send(alarm); | ||
}); | ||
|
||
router.post("/set/:macAddress", async (req, res) => { | ||
try { | ||
let { max, min } = req.body; | ||
console.log(max); | ||
console.log(min); | ||
console.log(req.params.col); | ||
|
||
let alarmSet = new alarmModel(); | ||
alarmSet.macAddress = req.params.macAddress; | ||
alarmSet.temperature.max = max; | ||
alarmSet.temperature.min = min; | ||
alarmSet.humidity.max = max; | ||
alarmSet.humidity.min = min; | ||
alarmSet.atmosphereicPressure.max = max; | ||
alarmSet.atmosphereicPressure.min = min; | ||
alarmSet.soilMoisture.max = max; | ||
alarmSet.soilMoisture.min = min; | ||
alarmSet.ec.max = max; | ||
alarmSet.ec.min = min; | ||
alarmSet.ph.max = max; | ||
alarmSet.ph.min = min; | ||
alarmSet.nitrogen.max = max; | ||
alarmSet.nitrogen.min = min; | ||
alarmSet.phosphorus.max = max; | ||
alarmSet.phosphorus.min = min; | ||
alarmSet.potassium.max = max; | ||
alarmSet.potassium.min = min; | ||
|
||
await alarmSet.save(); | ||
return res.send("added"); | ||
} catch (err) { | ||
console.error(err); | ||
} | ||
}); | ||
router.put("/set/:col/:macAddress", async (req, res) => { | ||
try { | ||
let { max, min } = req.body; | ||
|
||
let macAddress = req.params.macAddress; | ||
|
||
// let col = req.params.col; | ||
console.log(max); | ||
console.log(min); | ||
console.log(req.params.col); | ||
let alarm = await alarmModel.findOneAndUpdate({ macAddress }); | ||
|
||
if (req.params.col === "temperature") { | ||
alarm.temperature.max = max; | ||
alarm.temperature.min = min; | ||
await alarm.save(); | ||
return res.send("Updated"); | ||
} else if (req.params.col === "humidity") { | ||
alarm.humidity.max = max; | ||
alarm.humidity.min = min; | ||
await alarm.save(); | ||
return res.send("Updated"); | ||
} else if (req.params.col === "atmosphereicPressure") { | ||
alarm.atmosphereicPressure.max = max; | ||
alarm.atmosphereicPressure.min = min; | ||
await alarm.save(); | ||
return res.send("Updated"); | ||
} else if (req.params.col === "soilMoisture") { | ||
alarm.soilMoisture.max = max; | ||
alarm.soilMoisture.min = min; | ||
await alarm.save(); | ||
return res.send("Updated"); | ||
} else if (req.params.col === "ec") { | ||
alarm.ec.max = max; | ||
alarm.ec.min = min; | ||
await alarm.save(); | ||
return res.send("Updated"); | ||
} else if (req.params.col === "ph") { | ||
alarm.ph.max = max; | ||
alarm.ph.min = min; | ||
await alarm.save(); | ||
return res.send("Updated"); | ||
} else if (req.params.col === "nitrogen") { | ||
alarm.nitrogen.max = max; | ||
alarm.nitrogen.min = min; | ||
await alarm.save(); | ||
return res.send("Updated"); | ||
} else if (req.params.col === "phosphorus") { | ||
alarm.phosphorus.max = max; | ||
alarm.phosphorus.min = min; | ||
await alarm.save(); | ||
return res.send("Updated"); | ||
} else if (req.params.col === "potassium") { | ||
alarm.potassium.max = max; | ||
alarm.potassium.min = min; | ||
await alarm.save(); | ||
return res.send("Updated"); | ||
} | ||
} catch (err) { | ||
console.error(err); | ||
} | ||
}); | ||
|
||
module.exports = router; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,13 @@ | ||
import axios from "axios"; | ||
|
||
// export default axios.create({ | ||
// baseURL: "http://localhost:3001", | ||
// // withCredentials: false, | ||
// // headers: { | ||
// // "Access-Control-Allow-Origin": "*", | ||
// // "Access-Control-Allow-Methods": "GET,PUT,POST,DELETE,PATCH,OPTIONS", | ||
// // }, | ||
// }); | ||
export default axios.create({ | ||
baseURL: "https://smart-agri-backend.iot.intelligadgets.me", | ||
baseURL: "http://localhost:3001", | ||
// withCredentials: false, | ||
// headers: { | ||
// "Access-Control-Allow-Origin": "*", | ||
// "Access-Control-Allow-Methods": "GET,PUT,POST,DELETE,PATCH,OPTIONS", | ||
// }, | ||
}); | ||
// export default axios.create({ | ||
// baseURL: "https://smart-agri-backend.iot.intelligadgets.me", | ||
// }); |
Oops, something went wrong.