Add the connection to sensor data and display data in chart.
This commit is contained in:
parent
77323642f9
commit
8f88ebe4a4
@ -5,18 +5,28 @@ import App from '../imports/ui/App';
|
|||||||
import 'bootstrap/dist/css/bootstrap.min.css';
|
import 'bootstrap/dist/css/bootstrap.min.css';
|
||||||
|
|
||||||
export const PlantTypesCollection = new Meteor.Collection('plantTypes');
|
export const PlantTypesCollection = new Meteor.Collection('plantTypes');
|
||||||
|
export const SensorDataCollection = new Meteor.Collection('sensorData');
|
||||||
|
|
||||||
Meteor.startup(() => {
|
Meteor.startup(() => {
|
||||||
if(Meteor.isServer) {
|
if(Meteor.isServer) {
|
||||||
Meteor.publish('plantTypesCollection', function() {
|
Meteor.publish('plantTypesCollection', function() {
|
||||||
return PlantTypesCollection.find();
|
return PlantTypesCollection.find();
|
||||||
})
|
})
|
||||||
|
|
||||||
|
Meteor.publish('sensorDataCollection', function() {
|
||||||
|
return SensorDataCollection.find();
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Meteor.isClient) {
|
if (Meteor.isClient) {
|
||||||
Meteor.subscribe('plantTypesCollection');
|
Meteor.subscribe('plantTypesCollection');
|
||||||
|
Meteor.subscribe('sensorDataCollection');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Meteor.setTimeout(function() {
|
||||||
|
console.log(SensorDataCollection.find().fetch());
|
||||||
|
}, 500);
|
||||||
|
|
||||||
Meteor.setTimeout(function() {
|
Meteor.setTimeout(function() {
|
||||||
ReactDOM.render(<App />, document.getElementById('root'));
|
ReactDOM.render(<App />, document.getElementById('root'));
|
||||||
}, 500);
|
}, 500);
|
||||||
|
|||||||
14
imports/api/sensorData.js
Normal file
14
imports/api/sensorData.js
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
import {SensorDataCollection} from '../../client/main'
|
||||||
|
|
||||||
|
export function getAllSensorData() {
|
||||||
|
const sensorDataDocuments = SensorDataCollection.find();
|
||||||
|
|
||||||
|
var sensorDatas = [];
|
||||||
|
|
||||||
|
sensorDataDocuments.forEach((sensorData) => {
|
||||||
|
var brightnessInPercent = (sensorData.brightness/54000*100).toFixed(0);
|
||||||
|
sensorDatas.push({ name: sensorData.timestamp, temperature: sensorData.temperature, humidity: sensorData.humidity, light: brightnessInPercent, moisture: sensorData.moisture });
|
||||||
|
});
|
||||||
|
|
||||||
|
return sensorDatas;
|
||||||
|
}
|
||||||
@ -4,16 +4,11 @@ import Home from './Home'
|
|||||||
import About from './About'
|
import About from './About'
|
||||||
import Settings from './Settings'
|
import Settings from './Settings'
|
||||||
import {BrowserRouter as Router, Switch, Route} from 'react-router-dom'
|
import {BrowserRouter as Router, Switch, Route} from 'react-router-dom'
|
||||||
|
import {getAllSensorData} from "../api/sensorData";
|
||||||
|
|
||||||
function App() {
|
function App() {
|
||||||
|
|
||||||
const exampleData = [
|
const exampleData = getAllSensorData();
|
||||||
{ name: 'Timestamp A', temperature: 38, humidity: 66, light: 75, moisture: 21 },
|
|
||||||
{ name: 'Timestamp B', temperature: 37, humidity: 65, light: 65, moisture: 22 },
|
|
||||||
{ name: 'Timestamp C', temperature: 39, humidity: 62, light: 55, moisture: 22 },
|
|
||||||
{ name: 'Timestamp D', temperature: 40, humidity: 61, light: 85, moisture: 21 },
|
|
||||||
{ name: 'Timestamp E', temperature: 40, humidity: 60, light: 80, moisture: 21 }
|
|
||||||
];
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
|
|||||||
@ -19,7 +19,7 @@ export default function SensorCardDeck( {sensorCardValues} ) {
|
|||||||
<Card>
|
<Card>
|
||||||
<Card.Body>
|
<Card.Body>
|
||||||
<Card.Title>Light</Card.Title>
|
<Card.Title>Light</Card.Title>
|
||||||
<Card.Text>{sensorCardValues[2]} H</Card.Text>
|
<Card.Text>{sensorCardValues[2]} %</Card.Text>
|
||||||
</Card.Body>
|
</Card.Body>
|
||||||
</Card>
|
</Card>
|
||||||
<Card>
|
<Card>
|
||||||
|
|||||||
@ -1,15 +1,21 @@
|
|||||||
import { Meteor } from 'meteor/meteor';
|
import { Meteor } from 'meteor/meteor';
|
||||||
|
|
||||||
var PlantTypesCollection = new Meteor.Collection('plantTypes');
|
var PlantTypesCollection = new Meteor.Collection('plantTypes');
|
||||||
|
var SensorDataCollection = new Meteor.Collection('sensorData');
|
||||||
|
|
||||||
Meteor.startup(() => {
|
Meteor.startup(() => {
|
||||||
if(Meteor.isServer) {
|
if(Meteor.isServer) {
|
||||||
Meteor.publish('plantTypesCollection', function() {
|
Meteor.publish('plantTypesCollection', function() {
|
||||||
return PlantTypesCollection.find();
|
return PlantTypesCollection.find();
|
||||||
})
|
})
|
||||||
|
|
||||||
|
Meteor.publish('sensorDataCollection', function() {
|
||||||
|
return SensorDataCollection.find();
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Meteor.isClient) {
|
if (Meteor.isClient) {
|
||||||
Meteor.subscribe('plantTypesCollection');
|
Meteor.subscribe('plantTypesCollection');
|
||||||
|
Meteor.subscribe('sensorDataCollection');
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
Loading…
Reference in New Issue
Block a user