diff --git a/imports/ui/ActivatePlant.jsx b/imports/ui/ActivatePlant.jsx
deleted file mode 100644
index f953b03..0000000
--- a/imports/ui/ActivatePlant.jsx
+++ /dev/null
@@ -1,85 +0,0 @@
-import React from 'react'
-import { Button, Form} from 'react-bootstrap';
-
-class ActivatePlant extends React.Component{
-
- constructor(props){
- super(props);
- this.state = {
- name: '',
- isActivationButtonDisabled: false,
- }
- }
-
- handleChange = (e) => {
- // console.log(e.target.id, e.target.value);
-
- /*
- if (activePlant !== 'undefined'){
- if (activePlant !== this.state.name) {
- this.setState({
- isActivationButtonDisabled: false
- })
- }
- }*/
-
- this.setState({
- [e.target.id]: e.target.value
- });
- }
-
- // search for arrow function for further syntax knowledge
- handleActivation = (e) => {
- e.preventDefault();
-
- let activatedPlant
- this.props.plants.map(plant =>{
- if (plant.name === this.state.name){
- activatedPlant = plant
- }
- })
-
- // activePlant = activatedPlant.name
-
- this.props.activatePlant(activatedPlant)
-
- /*
- this.setState({
- isActivationButtonDisabled: true
- })*/
- }
-
-
-
- render (){
- return (
- <>
- {
- this.props.plants.length !== 0 ?
-
- Active plant:
-
-
- {this.props.plants.map((plant, index) =>{
- return
- })}
-
-
-
-
- :null
- }
- >
- );
- }
-}
-
-export default ActivatePlant;
-
diff --git a/imports/ui/AddPlant.jsx b/imports/ui/AddPlant.jsx
deleted file mode 100644
index 52bf770..0000000
--- a/imports/ui/AddPlant.jsx
+++ /dev/null
@@ -1,72 +0,0 @@
-import React from 'react'
-import { Button, Form } from 'react-bootstrap';
-
-class AddPlant extends React.Component{
-
- constructor(props){
- super(props);
- this.state = {
- name: '',
- type: ''
- }
- }
-
- handleChange = (e) => {
- // console.log(e.target.id, e.target.value); // e.target.id reference to the state which is changed
- this.setState({
- [e.target.id]: e.target.value
- });
- }
-
- // search for arrow function for further syntax knowledge
- handleSubmit = (e) => {
- e.preventDefault();
- //console.log(this.state)
-
- this.props.addPlant(this.state)
-
- this.setState({ // reset state
- name: '',
- type: ''
- })
- }
-
-
-
- render (){
- return (
- <>
-
- Name:
- {this.nameInput=(input)}}
- placeholder="plant"
- onChange={this.handleChange} />
-
-
- Type:
-
-
- {this.props.typeArray.map((type, index) =>{
- return
- })}
-
-
-
-
- >
- );
- }
-}
-
-export default AddPlant;
\ No newline at end of file
diff --git a/imports/ui/Home.jsx b/imports/ui/Home.jsx
index 784a2cf..81e3ed8 100644
--- a/imports/ui/Home.jsx
+++ b/imports/ui/Home.jsx
@@ -1,30 +1,10 @@
import React from 'react'
-import {
- SensorDataCollection,
- ActiveDeviceCollection,
- ConfiguredDevicesCollection,
- PlantTypesCollection
-} from "../../client/main";
+import {ConfiguredDevicesCollection, PlantTypesCollection} from "../../client/main";
import {useTracker} from 'meteor/react-meteor-data';
import { Card, CardDeck, Table } from "react-bootstrap";
import Settings from "./Settings";
export default function Home() {
- const deviceId = useTracker(() => {
- return ActiveDeviceCollection.find().fetch()[0];
- });
-
- const sensorData = useTracker(() => {
- if (deviceId === null || deviceId === undefined) {
- return [];
- } else {
- return SensorDataCollection.find({device_id: deviceId.deviceId}, {
- sort: {timestamp: -1},
- limit: 61
- }).fetch().reverse();
- }
- });
-
const configuredDevices = useTracker(() => {
return ConfiguredDevicesCollection.find().fetch();
});
@@ -55,56 +35,44 @@ export default function Home() {
}
- if ((sensorData.length <= 0)) {
- return (
-
-
-
- Loading!
- Please wait...
-
-
-
- )
- } else {
- return (
- <>
-
-
-
- | # |
- Device Nickname |
- Device ID |
- Plant Type |
- Soil Type |
- Permanent Wilting Point |
- Field Capacity |
- Min Temperature |
- Min Brightness |
+
+ return (
+ <>
+
+
+
+ | # |
+ Device Nickname |
+ Device ID |
+ Plant Type |
+ Soil Type |
+ Permanent Wilting Point |
+ Field Capacity |
+ Min Temperature |
+ Min Brightness |
+
+
+
+ {configuredDevices.map((device, index) => {
+ return
+ | {index} |
+ {device.alias} |
+ {device.deviceId} |
+ {device.type} |
+ {getSoil(device.type)} |
+ {getPermWilPoint(device.type) + " %"} |
+ {getFieldCap(device.type) + " %"} |
+ {getMinTemp(device.type) + " °C"} |
+ {getMinLux(device.type) + " lux"} |
-
-
- {configuredDevices.map((device, index) => {
- return
- | {index} |
- {device.alias} |
- {device.deviceId} |
- {device.type} |
- {getSoil(device.type)} |
- {getPermWilPoint(device.type) + " %"} |
- {getFieldCap(device.type) + " %"} |
- {getMinTemp(device.type) + " °C"} |
- {getMinLux(device.type) + " lux"} |
-
- })}
-
-
-
- If your device is not visible in the table above, configure it here below.
-
-
-
- >
- )
- }
+ })}
+
+
+
+ If your device is not visible in the table above, configure it here below.
+
+
+
+ >
+ )
}
\ No newline at end of file
diff --git a/imports/ui/Overview.jsx b/imports/ui/Overview.jsx
index d7c03a9..2019338 100644
--- a/imports/ui/Overview.jsx
+++ b/imports/ui/Overview.jsx
@@ -11,21 +11,21 @@ export default function Overview() {
return ActiveDeviceCollection.find().fetch()[0];
});
+ const configuredDevices = useTracker(() => {
+ return ConfiguredDevicesCollection.find().fetch();
+ });
+
const sensorData = useTracker(() => {
if (activeDevice === null || activeDevice === undefined) {
return [];
} else {
return SensorDataCollection.find({device_id: activeDevice.deviceId}, {
sort: {timestamp: -1},
- limit: 61
+ limit: 1441
}).fetch().reverse();
}
});
- const configuredDevices = useTracker(() => {
- return ConfiguredDevicesCollection.find().fetch();
- });
-
const handleChange = (e) => {
if (e.target.value === "") {
console.log("No device selected!");
diff --git a/imports/ui/Plants.jsx b/imports/ui/Plants.jsx
deleted file mode 100644
index 17fce26..0000000
--- a/imports/ui/Plants.jsx
+++ /dev/null
@@ -1,37 +0,0 @@
-import React from 'react'
-import { Table, Button } from 'react-bootstrap';
-
-const Plants = ({plants, deletePlant}) => {
-
- return (
- <>
- {
- plants.length !== 0 ?
-
-
-
- | Plant name |
- Plant type |
- |
-
-
-
- {
- plants.map((plant, index) => {
- return
- | {plant.name} |
- {plant.type} |
- |
-
- })
- }
-
-
- : null
- }
- >
- );
-
-}
-
-export default Plants
\ No newline at end of file
diff --git a/imports/ui/SensorCardDeck.jsx b/imports/ui/SensorCardDeck.jsx
index 7dabded..5bc8705 100644
--- a/imports/ui/SensorCardDeck.jsx
+++ b/imports/ui/SensorCardDeck.jsx
@@ -37,8 +37,6 @@ export default function SensorCardDeck() {
}
});
- console.log("Sens" + sensorData, plantType, plantTypeData, deviceId);
-
if (sensorData.length <= 0 || plantType === undefined || deviceId === undefined || plantTypeData === undefined) {
return (
diff --git a/imports/ui/Settings.jsx b/imports/ui/Settings.jsx
index 7a4f69c..fdcae9e 100644
--- a/imports/ui/Settings.jsx
+++ b/imports/ui/Settings.jsx
@@ -3,30 +3,16 @@ import {Col, Form, Row, Card, CardDeck, Button, Container} from "react-bootstrap
import { Meteor } from 'meteor/meteor';
import {getAllEspIds} from "../api/espIds";
import {getAllPlantTypes} from "../api/plantTypes";
-import {ConfiguredDevicesCollection, PlantTypesCollection, ActiveDeviceCollection, SensorDataCollection} from "../../client/main";
+import {ConfiguredDevicesCollection, PlantTypesCollection} from "../../client/main";
import {useTracker} from 'meteor/react-meteor-data';
export default function Settings() {
- const deviceId = useTracker(() => {
- return ActiveDeviceCollection.find().fetch()[0];
- });
-
- const sensorData = useTracker(() => {
- if (deviceId === null || deviceId === undefined) {
- return [];
- } else {
- return SensorDataCollection.find({device_id: deviceId.deviceId}, {
- sort: {timestamp: -1},
- limit: 61
- }).fetch().reverse();
- }
- });
-
-
const plantTypes = useTracker(() => {
return PlantTypesCollection.find();
});
+ const espIds = useTracker(getAllEspIds);
+
var selectedEspId;
var selectedAlias = "";
var selectedType;
@@ -65,12 +51,17 @@ export default function Settings() {
if (selectedType === "Cacti") {payload = JSON.stringify(payloadCacti.data.soilMoisture);}
if (selectedType === "Flowers") {payload = JSON.stringify(payloadFlower.data.soilMoisture);}
- var doc = ConfiguredDevicesCollection.findOne({deviceId: selectedEspId});
- if (doc === undefined) {ConfiguredDevicesCollection.insert({deviceId: selectedEspId, alias: selectedEspId, type: selectedType});} else {
- ConfiguredDevicesCollection.update({_id: doc._id}, {$set: {alias: selectedAlias, type: selectedType}});
- }
+ console.log("Payload: " + payload);
+ console.log("Alias: " + selectedAlias);
+ console.log("ID: " + selectedEspId);
+ console.log("Type: " + selectedType);
if ((payload === "") || (selectedEspId === undefined) || (selectedAlias === "") || (selectedType === undefined)) {alert("Nickname is empty or no device/type selected!");} else {
+ var doc = ConfiguredDevicesCollection.findOne({deviceId: selectedEspId});
+ if (doc === undefined) {ConfiguredDevicesCollection.insert({deviceId: selectedEspId, alias: selectedAlias, type: selectedType});} else {
+ ConfiguredDevicesCollection.update({_id: doc._id}, {$set: {alias: selectedAlias, type: selectedType}});
+ }
+
Meteor.call('mqttPublish', {
topic: 'smartgarden/commands/' + selectedEspId + '/soil',
payload: payload
@@ -99,7 +90,7 @@ export default function Settings() {
}
- if ((sensorData.length <= 0)) {
+ if ((plantTypes.length <= 0) || (espIds.length <= 0)) {
return (
@@ -125,12 +116,13 @@ export default function Settings() {
-
Name:
{this.nameInput=(input)}}
placeholder="Enter a device nickname..."
onChange={handleChangeAlias}/>
@@ -138,7 +130,7 @@ export default function Settings() {
Device:
- {getAllEspIds().map((espName, index) => {
+ {espIds.map((espName, index) => {
return
})}
diff --git a/imports/ui/Settings_old.jsx b/imports/ui/Settings_old.jsx
deleted file mode 100644
index 1e978fe..0000000
--- a/imports/ui/Settings_old.jsx
+++ /dev/null
@@ -1,98 +0,0 @@
-import React from 'react'
-import {Container, Row, Col, CardDeck, Card} from 'react-bootstrap';
-
-import AddPlant from './AddPlant'
-import Plants from './Plants'
-import ActivatePlant from './ActivatePlant'
-import {getAllPlantTypes} from "../api/plantTypes";
-
-class Settings_old extends React.Component{
-
- constructor(props){
- super(props);
- this.state = {
- plants: [],
- types: [],
- }
- }
-
- componentDidMount() {
- (async ()=>{
- this.setState({
- types: getAllPlantTypes(),
- })
- })();
- }
-
- // pass this function to the addplant comp as a prop
- addPlant = (plant) => {
- plant.id = this.state.plants.length + 1 // TODO rework
-
- let plants = [...this.state.plants, plant]; // create a copy of the array and add the new plant to it
-
- this.setState({
- plants: plants
- })
- }
-
- deletePlant = (id) => {
- let plants = this.state.plants.filter(plant =>{ // callback function
- return plant.id !== id // when it returns false (the id is the same), it filters this object out of the array
- })
- this.setState({
- plants: plants
- })
- }
-
- activatePlant = (plant) => {
- console.log('The plant ' + plant.name + ' will be monitored')
- // TODO head for activate logic
- }
-
- render(){
- return (
- <>
-
-
-
- Settings
-
-
-
- Configure your plant here. Based on your settings the smart garden will automate your plant environment.
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- >
- );
- }
-
-}
-
-export default Settings_old;