diff --git a/.meteor/packages b/.meteor/packages
index 34e9bc5..61ff3c5 100644
--- a/.meteor/packages
+++ b/.meteor/packages
@@ -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
diff --git a/client/main.jsx b/client/main.jsx
index c719b8a..a864387 100644
--- a/client/main.jsx
+++ b/client/main.jsx
@@ -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,11 +17,16 @@ 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() {
diff --git a/imports/ui/Home.jsx b/imports/ui/Home.jsx
index 1399c17..086551b 100644
--- a/imports/ui/Home.jsx
+++ b/imports/ui/Home.jsx
@@ -1,26 +1,68 @@
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} from "react-bootstrap";
-export default function Home() {
- const sensorData = useTracker(() => {
- return SensorDataCollection.find({ device_id: 'esp-andy' }, { sort: { timestamp: -1 }, limit: 10 }).fetch().reverse();
+export default function Home() {
+
+ 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];
});
+ const sensorData = useTracker(() => {
+ return SensorDataCollection.find({ device_id: deviceName.deviceName }, { sort: { timestamp: -1 }, limit: 61 }).fetch().reverse();
+ });
+
+ 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}});
+ }
+ }
+
return (
<>
+
+
+ Devices:
+
+
+
+
+
+
+
+
+ {uniqueEspNames.map((espName, index) =>{
+ return
+ })}
+
+
+
+
+
+ active device: {deviceName.deviceName}
+
+
+
-
-
+
+
-
+
@@ -28,11 +70,11 @@ export default function Home() {
-
-
+
+
-
+
@@ -42,11 +84,11 @@ export default function Home() {
-
-
+
+
-
+
@@ -54,11 +96,11 @@ export default function Home() {
-
-
+
+
-
+
diff --git a/imports/ui/SensorCardDeck.jsx b/imports/ui/SensorCardDeck.jsx
index 46709ef..6c585ec 100644
--- a/imports/ui/SensorCardDeck.jsx
+++ b/imports/ui/SensorCardDeck.jsx
@@ -1,11 +1,15 @@
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 deviceName = useTracker(() => {
+ return ActiveDeviceCollection.find().fetch()[0];
+ });
+
const sensorData = useTracker(() => {
- return SensorDataCollection.find({ device_id: 'esp-andy' }, { sort: { timestamp: -1 }, limit: 1 }).fetch();
+ return SensorDataCollection.find({ device_id: deviceName.deviceName }, { sort: { timestamp: -1 }, limit: 1 }).fetch();
});
return (
diff --git a/mongo-mqtt.js b/mongo-mqtt.js
index 66fee96..ed29047 100644
--- a/mongo-mqtt.js
+++ b/mongo-mqtt.js
@@ -36,14 +36,16 @@ function messageCallback(collection) {
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,
- timestampToString: time,
+ timeAsString: time,
}
try {
doc = _.merge(doc, JSON.parse(message));
diff --git a/server/main.js b/server/main.js
index addb8fa..b836f96 100644
--- a/server/main.js
+++ b/server/main.js
@@ -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');
}
});
\ No newline at end of file