Merge branch 'develop' into sherzog_dev
This commit is contained in:
commit
8a7aac6625
@ -21,3 +21,4 @@ shell-server@0.5.0 # Server-side component of the `meteor shell` comm
|
||||
insecure@1.0.7 # Allow all DB writes from clients (for prototyping)
|
||||
static-html
|
||||
react-meteor-data
|
||||
underscore
|
||||
|
||||
@ -6,6 +6,7 @@ import 'bootstrap/dist/css/bootstrap.min.css';
|
||||
|
||||
export const PlantTypesCollection = new Meteor.Collection('plantTypes');
|
||||
export const SensorDataCollection = new Meteor.Collection('sensorData');
|
||||
export const ActiveDeviceCollection = new Meteor.Collection('activeDevice');
|
||||
|
||||
Meteor.startup(() => {
|
||||
if(Meteor.isServer) {
|
||||
@ -16,14 +17,17 @@ Meteor.startup(() => {
|
||||
Meteor.publish('sensorDataCollection', function() {
|
||||
return SensorDataCollection.find();
|
||||
})
|
||||
|
||||
Meteor.publish('activeDeviceCollection', function() {
|
||||
return ActiveDeviceCollection.find();
|
||||
})
|
||||
}
|
||||
|
||||
if (Meteor.isClient) {
|
||||
Meteor.subscribe('plantTypesCollection');
|
||||
Meteor.subscribe('sensorDataCollection');
|
||||
Meteor.subscribe('activeDeviceCollection');
|
||||
}
|
||||
|
||||
Meteor.setTimeout(function() {
|
||||
ReactDOM.render(<App />, document.getElementById('root'));
|
||||
}, 1000);
|
||||
ReactDOM.render(<App />, document.getElementById('root'));
|
||||
});
|
||||
@ -1,5 +1,5 @@
|
||||
import React from 'react'
|
||||
import { Button, Form, Container, Row, Col, Table } from 'react-bootstrap';
|
||||
import { Button, Form } from 'react-bootstrap';
|
||||
|
||||
class AddPlant extends React.Component{
|
||||
|
||||
@ -69,5 +69,4 @@ class AddPlant extends React.Component{
|
||||
}
|
||||
}
|
||||
|
||||
export default AddPlant;
|
||||
|
||||
export default AddPlant;
|
||||
@ -1,71 +1,134 @@
|
||||
import React from 'react'
|
||||
import {CartesianGrid, Legend, Line, LineChart, ResponsiveContainer, Tooltip, XAxis, YAxis} from 'recharts';
|
||||
import SensorCardDeck from './SensorCardDeck'
|
||||
import {SensorDataCollection} from "../../client/main";
|
||||
import {SensorDataCollection, ActiveDeviceCollection} from "../../client/main";
|
||||
import {useTracker} from 'meteor/react-meteor-data';
|
||||
import {Col, Row} from "react-bootstrap";
|
||||
import {Col, Form, Row, Card, CardDeck} from "react-bootstrap";
|
||||
|
||||
export default function Home() {
|
||||
const sensorData = useTracker(() => {
|
||||
return SensorDataCollection.find({ device_id: 'esp-andy' }, { sort: { timestamp: -1 }, limit: 10 }).fetch().reverse();
|
||||
|
||||
const uniqueEspNames = _.uniq(SensorDataCollection.find({}, {
|
||||
sort: {device_id: 1}, fields: {device_id: true}
|
||||
}).fetch().map(function (x) {
|
||||
return x.device_id;
|
||||
}), true);
|
||||
|
||||
const deviceName = useTracker(() => {
|
||||
return ActiveDeviceCollection.find().fetch()[0];
|
||||
});
|
||||
|
||||
return (
|
||||
<>
|
||||
<SensorCardDeck/>
|
||||
const sensorData = useTracker(() => {
|
||||
if (deviceName === null || deviceName === undefined) {
|
||||
return [];
|
||||
} else {
|
||||
return SensorDataCollection.find({device_id: deviceName.deviceName}, {
|
||||
sort: {timestamp: -1},
|
||||
limit: 61
|
||||
}).fetch().reverse();
|
||||
}
|
||||
});
|
||||
|
||||
<Row>
|
||||
<Col>
|
||||
<ResponsiveContainer width='100%' height={375}>
|
||||
<LineChart data={sensorData} margin={{ top: 60, right: 60, bottom: 30, left: 5 }}>
|
||||
<Line type="monotone" dataKey="temperature" stroke="#10b5de" />
|
||||
<CartesianGrid stroke="#ccc" strokeDasharray="5 5"/>
|
||||
<XAxis dataKey="timestamp" />
|
||||
<YAxis />
|
||||
<Tooltip />
|
||||
<Legend />
|
||||
</LineChart>
|
||||
</ResponsiveContainer>
|
||||
</Col>
|
||||
<Col>
|
||||
<ResponsiveContainer width='100%' height={375}>
|
||||
<LineChart data={sensorData} margin={{ top: 60, right: 60, bottom: 30, left: 5 }}>
|
||||
<Line type="monotone" dataKey="humidity" stroke="#ff6f00" />
|
||||
<CartesianGrid stroke="#ccc" strokeDasharray="5 5"/>
|
||||
<XAxis dataKey="timestamp" />
|
||||
<YAxis />
|
||||
<Tooltip />
|
||||
<Legend />
|
||||
</LineChart>
|
||||
</ResponsiveContainer>
|
||||
</Col>
|
||||
</Row>
|
||||
<Row>
|
||||
<Col>
|
||||
<ResponsiveContainer width='100%' height={375}>
|
||||
<LineChart data={sensorData} margin={{ top: 60, right: 60, bottom: 30, left: 5 }}>
|
||||
<Line type="monotone" dataKey="brightness" stroke="#ffd500" />
|
||||
<CartesianGrid stroke="#ccc" strokeDasharray="5 5"/>
|
||||
<XAxis dataKey="timestamp" />
|
||||
<YAxis />
|
||||
<Tooltip />
|
||||
<Legend />
|
||||
</LineChart>
|
||||
</ResponsiveContainer>
|
||||
</Col>
|
||||
<Col>
|
||||
<ResponsiveContainer width='100%' height={375}>
|
||||
<LineChart data={sensorData} margin={{ top: 60, right: 60, bottom: 30, left: 5 }}>
|
||||
<Line type="monotone" dataKey="moisture" stroke="#1c4399" />
|
||||
<CartesianGrid stroke="#ccc" strokeDasharray="5 5"/>
|
||||
<XAxis dataKey="timestamp" />
|
||||
<YAxis />
|
||||
<Tooltip />
|
||||
<Legend />
|
||||
</LineChart>
|
||||
</ResponsiveContainer>
|
||||
</Col>
|
||||
</Row>
|
||||
</>
|
||||
)
|
||||
const handleChange = (e) => {
|
||||
if (e.target.value === "") {
|
||||
console.log("No device selected!");
|
||||
} else {
|
||||
var doc = ActiveDeviceCollection.findOne({deviceName: deviceName.deviceName});
|
||||
ActiveDeviceCollection.update({_id: doc._id}, {$set: {deviceName: e.target.value}});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if ((sensorData.length <= 0) || (deviceName.length <= 0)) {
|
||||
return (
|
||||
<CardDeck>
|
||||
<Card>
|
||||
<Card.Body>
|
||||
<Card.Title>Loading!</Card.Title>
|
||||
<Card.Text>Please wait...</Card.Text>
|
||||
</Card.Body>
|
||||
</Card>
|
||||
</CardDeck>
|
||||
)
|
||||
} else {
|
||||
return (
|
||||
<>
|
||||
<Row>
|
||||
<Col xs lg="2">
|
||||
<h4>Devices:</h4>
|
||||
</Col>
|
||||
</Row>
|
||||
<Row>
|
||||
<Col xs lg="2">
|
||||
<Form>
|
||||
<Form.Group>
|
||||
<Form.Control as="select" type="text" onChange={handleChange}>
|
||||
<option></option>
|
||||
{uniqueEspNames.map((espName, index) => {
|
||||
return <option key={index} value={espName}>{espName}</option>
|
||||
})}
|
||||
</Form.Control>
|
||||
</Form.Group>
|
||||
</Form>
|
||||
</Col>
|
||||
<Col>
|
||||
<h6>active device: {deviceName.deviceName}</h6>
|
||||
</Col>
|
||||
</Row>
|
||||
|
||||
<SensorCardDeck/>
|
||||
<Row>
|
||||
<Col>
|
||||
<ResponsiveContainer width='100%' height={350}>
|
||||
<LineChart data={sensorData} margin={{top: 50, right: 50, bottom: 25, left: 5}}>
|
||||
<Line type="monotone" dataKey="temperature" stroke="#10b5de"/>
|
||||
<CartesianGrid stroke="#ccc" strokeDasharray="5 5"/>
|
||||
<XAxis dataKey="timeAsString"/>
|
||||
<YAxis/>
|
||||
<Tooltip/>
|
||||
<Legend/>
|
||||
</LineChart>
|
||||
</ResponsiveContainer>
|
||||
</Col>
|
||||
<Col>
|
||||
<ResponsiveContainer width='100%' height={350}>
|
||||
<LineChart data={sensorData} margin={{top: 50, right: 50, bottom: 25, left: 5}}>
|
||||
<Line type="monotone" dataKey="humidity" stroke="#ff6f00"/>
|
||||
<CartesianGrid stroke="#ccc" strokeDasharray="5 5"/>
|
||||
<XAxis dataKey="timeAsString"/>
|
||||
<YAxis/>
|
||||
<Tooltip/>
|
||||
<Legend/>
|
||||
</LineChart>
|
||||
</ResponsiveContainer>
|
||||
</Col>
|
||||
</Row>
|
||||
<Row>
|
||||
<Col>
|
||||
<ResponsiveContainer width='100%' height={350}>
|
||||
<LineChart data={sensorData} margin={{top: 50, right: 50, bottom: 25, left: 5}}>
|
||||
<Line type="monotone" dataKey="brightness" stroke="#ffd500"/>
|
||||
<CartesianGrid stroke="#ccc" strokeDasharray="5 5"/>
|
||||
<XAxis dataKey="timeAsString"/>
|
||||
<YAxis/>
|
||||
<Tooltip/>
|
||||
<Legend/>
|
||||
</LineChart>
|
||||
</ResponsiveContainer>
|
||||
</Col>
|
||||
<Col>
|
||||
<ResponsiveContainer width='100%' height={350}>
|
||||
<LineChart data={sensorData} margin={{top: 50, right: 50, bottom: 25, left: 5}}>
|
||||
<Line type="monotone" dataKey="moisture" stroke="#1c4399"/>
|
||||
<CartesianGrid stroke="#ccc" strokeDasharray="5 5"/>
|
||||
<XAxis dataKey="timeAsString"/>
|
||||
<YAxis/>
|
||||
<Tooltip/>
|
||||
<Legend/>
|
||||
</LineChart>
|
||||
</ResponsiveContainer>
|
||||
</Col>
|
||||
</Row>
|
||||
</>
|
||||
)
|
||||
}
|
||||
}
|
||||
@ -1,39 +1,55 @@
|
||||
import React from 'react'
|
||||
import { Card, CardDeck } from 'react-bootstrap';
|
||||
import {SensorDataCollection} from "../../client/main";
|
||||
import {ActiveDeviceCollection, SensorDataCollection} from "../../client/main";
|
||||
import {useTracker} from 'meteor/react-meteor-data';
|
||||
|
||||
export default function SensorCardDeck() {
|
||||
const sensorData = useTracker(() => {
|
||||
return SensorDataCollection.find({ device_id: 'esp-andy' }, { sort: { timestamp: -1 }, limit: 1 }).fetch();
|
||||
const deviceName = useTracker(() => {
|
||||
return ActiveDeviceCollection.find().fetch()[0];
|
||||
});
|
||||
|
||||
return (
|
||||
<CardDeck>
|
||||
<Card>
|
||||
<Card.Body>
|
||||
<Card.Title>Temperature</Card.Title>
|
||||
<Card.Text>{sensorData[0].temperature} °C</Card.Text>
|
||||
</Card.Body>
|
||||
</Card>
|
||||
<Card>
|
||||
<Card.Body>
|
||||
<Card.Title>Humidity</Card.Title>
|
||||
<Card.Text>{sensorData[0].humidity} %</Card.Text>
|
||||
</Card.Body>
|
||||
</Card>
|
||||
<Card>
|
||||
<Card.Body>
|
||||
<Card.Title>Brightness</Card.Title>
|
||||
<Card.Text>{sensorData[0].brightness} lux</Card.Text>
|
||||
</Card.Body>
|
||||
</Card>
|
||||
<Card>
|
||||
<Card.Body>
|
||||
<Card.Title>Moisture</Card.Title>
|
||||
<Card.Text>{sensorData[0].moisture} %</Card.Text>
|
||||
</Card.Body>
|
||||
</Card>
|
||||
</CardDeck>
|
||||
)
|
||||
const sensorData = useTracker(() => {
|
||||
return SensorDataCollection.find({ device_id: deviceName.deviceName }, { sort: { timestamp: -1 }, limit: 1 }).fetch();
|
||||
});
|
||||
if (sensorData.length <= 0) {
|
||||
return (
|
||||
<CardDeck>
|
||||
<Card>
|
||||
<Card.Body>
|
||||
<Card.Title>Loading!</Card.Title>
|
||||
<Card.Text>Please wait...</Card.Text>
|
||||
</Card.Body>
|
||||
</Card>
|
||||
</CardDeck>
|
||||
)
|
||||
} else {
|
||||
return (
|
||||
<CardDeck>
|
||||
<Card>
|
||||
<Card.Body>
|
||||
<Card.Title>Temperature</Card.Title>
|
||||
<Card.Text>{sensorData[0].temperature} °C</Card.Text>
|
||||
</Card.Body>
|
||||
</Card>
|
||||
<Card>
|
||||
<Card.Body>
|
||||
<Card.Title>Humidity</Card.Title>
|
||||
<Card.Text>{sensorData[0].humidity} %</Card.Text>
|
||||
</Card.Body>
|
||||
</Card>
|
||||
<Card>
|
||||
<Card.Body>
|
||||
<Card.Title>Brightness</Card.Title>
|
||||
<Card.Text>{sensorData[0].brightness} lux</Card.Text>
|
||||
</Card.Body>
|
||||
</Card>
|
||||
<Card>
|
||||
<Card.Body>
|
||||
<Card.Title>Moisture</Card.Title>
|
||||
<Card.Text>{sensorData[0].moisture} %</Card.Text>
|
||||
</Card.Body>
|
||||
</Card>
|
||||
</CardDeck>
|
||||
)
|
||||
}
|
||||
}
|
||||
@ -28,10 +28,24 @@ function messageCallback(collection) {
|
||||
const id = topicElements.pop();
|
||||
|
||||
var date = new Date;
|
||||
var time;
|
||||
|
||||
if (date.getHours() <= 9) {time = "0" + date.getHours();} else {
|
||||
time = date.getHours();
|
||||
}
|
||||
if (date.getMinutes() <= 9) {time = time + ":0" + date.getMinutes();} else {
|
||||
time = time + ":" + date.getMinutes();
|
||||
}
|
||||
/*
|
||||
if (date.getSeconds() <= 9) {time = time + ":0" + date.getSeconds();} else {
|
||||
time = time + ":" + date.getSeconds();
|
||||
}
|
||||
*/
|
||||
|
||||
let doc = {
|
||||
device_id: id,
|
||||
timestamp: date,
|
||||
timeAsString: time,
|
||||
}
|
||||
try {
|
||||
doc = _.merge(doc, JSON.parse(message));
|
||||
|
||||
@ -2,7 +2,8 @@
|
||||
"name": "smart_garden_server",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"start": "meteor run",
|
||||
"start": "MONGO_URL=mongodb://garden:99009911@cloud.timovolkmann.de:27017/Smart_Garden meteor run",
|
||||
"plainstart": "meteor run",
|
||||
"test": "meteor test --once --driver-package meteortesting:mocha",
|
||||
"test-app": "TEST_WATCH=1 meteor test --full-app --driver-package meteortesting:mocha",
|
||||
"visualize": "meteor --production --extra-packages bundle-visualizer"
|
||||
|
||||
@ -2,6 +2,7 @@ import { Meteor } from 'meteor/meteor';
|
||||
|
||||
var PlantTypesCollection = new Meteor.Collection('plantTypes');
|
||||
var SensorDataCollection = new Meteor.Collection('sensorData');
|
||||
var ActiveDeviceCollection = new Meteor.Collection('activeDevice');
|
||||
|
||||
Meteor.startup(() => {
|
||||
if(Meteor.isServer) {
|
||||
@ -12,10 +13,15 @@ Meteor.startup(() => {
|
||||
Meteor.publish('sensorDataCollection', function() {
|
||||
return SensorDataCollection.find();
|
||||
})
|
||||
|
||||
Meteor.publish('activeDeviceCollection', function() {
|
||||
return ActiveDeviceCollection.find();
|
||||
})
|
||||
}
|
||||
|
||||
if (Meteor.isClient) {
|
||||
Meteor.subscribe('plantTypesCollection');
|
||||
Meteor.subscribe('sensorDataCollection');
|
||||
Meteor.subscribe('activeDeviceCollection');
|
||||
}
|
||||
});
|
||||
Loading…
Reference in New Issue
Block a user