Skip to content

Commit

Permalink
Merge pull request #12 from RehanShakir/WebApp
Browse files Browse the repository at this point in the history
Updated
  • Loading branch information
Nauman3S authored Dec 31, 2021
2 parents 9d5c02b + 5f921ea commit 2599433
Show file tree
Hide file tree
Showing 11 changed files with 189 additions and 68 deletions.
Binary file removed Web App/Backend/Backend.tar
Binary file not shown.
46 changes: 23 additions & 23 deletions Web App/Backend/db/connection.js
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);
// });
2 changes: 1 addition & 1 deletion Web App/Backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"version": "0.0.0",
"private": true,
"scripts": {
"start": "nodemon ./bin/www"
"start": "node ./bin/www"
},
"dependencies": {
"axios": "^0.22.0",
Expand Down
Binary file modified Web App/Frontend/Frontend.tar
Binary file not shown.
20 changes: 20 additions & 0 deletions Web App/Frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Web App/Frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"react-dom": "^17.0.2",
"react-router-dom": "^5.2.0",
"react-scripts": "4.0.3",
"state-pool": "^0.6.0",
"styled-components": "^5.3.0",
"web-vitals": "^1.1.2"
},
Expand Down
18 changes: 9 additions & 9 deletions Web App/Frontend/src/api/smartAgri.js
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",
});
49 changes: 18 additions & 31 deletions Web App/Frontend/src/components/chart/LineChart.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,17 +52,17 @@ const LineChart = ({ enData, soilData, data }) => {
series: [
{
name: "Termperature",
data: temperature,
data: temperature.reverse(),
offsetY: 0,
},
{
name: "Humidity",
data: humidity,
data: humidity.reverse(),
offsetY: 0,
},
{
name: "Atmosphereic Pressure",
data: atmosphericPressure,
data: atmosphericPressure.reverse(),
offsetY: 0,
},
],
Expand Down Expand Up @@ -110,17 +110,7 @@ const LineChart = ({ enData, soilData, data }) => {
fontSize: "10px",
fontWeight: 600,
cssClass: "apex-x-axis",
colors: [
"#8c8c8c",
"#8c8c8c",
"#8c8c8c",
"#8c8c8c",
"#8c8c8c",
"#8c8c8c",
"#8c8c8c",
"#8c8c8c",
"#8c8c8c",
],
colors: ["#2E93fA", "#66DA26", "#546E7A"],
},
itemMargin: {
horizontal: 15,
Expand All @@ -144,32 +134,32 @@ const LineChart = ({ enData, soilData, data }) => {
series: [
{
name: "Soil Moisture",
data: soilMoisture,
data: soilMoisture.reverse(),
offsetY: 0,
},
{
name: "EC",
data: eC,
data: eC.reverse(),
offsetY: 0,
},
{
name: "pH",
data: pH,
data: pH.reverse(),
offsetY: 0,
},
{
name: "Nitrogen",
data: nitrogen,
data: nitrogen.reverse(),
offsetY: 0,
},
{
name: "Phosphorus",
data: phosphorus,
data: phosphorus.reverse(),
offsetY: 0,
},
{
name: "Potassium",
data: potassium,
data: potassium.reverse(),
offsetY: 0,
},
],
Expand Down Expand Up @@ -210,21 +200,18 @@ const LineChart = ({ enData, soilData, data }) => {
style: {
fontSize: "10px",
fontWeight: 600,
colors: [
"#8c8c8c",
"#8c8c8c",
"#8c8c8c",
"#8c8c8c",
"#8c8c8c",
"#8c8c8c",
"#8c8c8c",
"#8c8c8c",
"#8c8c8c",
],
},
},
categories: enTime,
},
colors: [
"#FD6544",
"#FDA044 ",
"#857463",
"#6264A3",
"#A45493",
"#3FB863",
],

tooltip: {
y: {
Expand Down
46 changes: 43 additions & 3 deletions Web App/Frontend/src/components/layout/Sidenav.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,20 @@ import React, { useState } from "react";
import { NavLink, useLocation } from "react-router-dom";
import logo from "../../assets/images/logo.png";
import smartAgri from "../../api/smartAgri";
import { store, useGlobalState } from "state-pool";

function Sidenav({ color }) {
const { pathname } = useLocation();
const page = pathname.replace("/", "");
const [dta, setDta] = useState(null);
const [re1, setRe1] = useState(null);
const [uploadList, setUploadList] = useState(true);

const [handleRe1Data, setHandleR1Data] = useGlobalState("handleRe1");
const [handleRe2Data, setHandleR2Data] = useGlobalState("handleRe2");
const [handleRe3Data, setHandleR3Data] = useGlobalState("handleRe3");
const [handleMsg, setHandleMsg] = useGlobalState("handleMsg");

const uploadFile = () => {
const data = new FormData();

Expand Down Expand Up @@ -79,19 +86,51 @@ function Sidenav({ color }) {
console.log(err);
});
};

const handleRe1 = () => {
publishToMqtt("relay", "1");

// localStorage.setItem("relay1Btn","")
handleRe1Data();
};

// store.setState("relay1", handleRe1Data);
const handleRe2 = () => {
publishToMqtt("relay", "2");

handleRe2Data();
// if (relay2On) {
// setRelay2N(true);
// localStorage.setItem(`${localStorage.getItem("macAddress")}Relay2`, "on");
// relay2On = false;
// } else {
// localStorage.setItem(
// `${localStorage.getItem("macAddress")}Relay2`,
// "off"
// );
// setRelay2N(false);
// relay2On = true;
// }
};
const handleRe3 = () => {
publishToMqtt("relay", "3");
handleRe3Data();
// if (relay3On) {
// setRelay3N(true);
// localStorage.setItem(`${localStorage.getItem("macAddress")}Relay3`, "on");
// relay3On = false;
// } else {
// localStorage.setItem(
// `${localStorage.getItem("macAddress")}Relay3`,
// "off"
// );
// setRelay3N(false);
// relay3On = true;
// }
};
const onFinish = (values) => {
console.log(values.settings);
// console.log(values.settings);
publishToMqtt("settings", values.settings);
handleMsg();
};

const onFinishFailed = () => {};
Expand All @@ -102,6 +141,7 @@ function Sidenav({ color }) {

return false;
};

const btnPublish = {
marginTop: "20px",
// marginLeft: "0px",
Expand Down Expand Up @@ -197,7 +237,7 @@ function Sidenav({ color }) {
htmlType="submit"
style={btnPublish}
// onClick={executeScroll}
style={{ marginTop: "0px", borderRadius: "50px", width: "100%" }}
// style={{ marginTop: "0px", borderRadius: "50px", width: "100%" }}
>
Send Settings
</Button>
Expand Down
Loading

0 comments on commit 2599433

Please sign in to comment.