Reformat DB data.
This commit is contained in:
parent
e45f4c6faa
commit
f95a396440
@ -8,15 +8,15 @@ import { getAllEspNames } from "../api/espNames";
|
||||
import moment from 'moment'
|
||||
|
||||
export default function Home() {
|
||||
const deviceName = useTracker(() => {
|
||||
const deviceId = useTracker(() => {
|
||||
return ActiveDeviceCollection.find().fetch()[0];
|
||||
});
|
||||
|
||||
const sensorData = useTracker(() => {
|
||||
if (deviceName === null || deviceName === undefined) {
|
||||
if (deviceId === null || deviceId === undefined) {
|
||||
return [];
|
||||
} else {
|
||||
return SensorDataCollection.find({device_id: deviceName.deviceName}, {
|
||||
return SensorDataCollection.find({device_id: deviceId.deviceId}, {
|
||||
sort: {timestamp: -1},
|
||||
limit: 61
|
||||
}).fetch().reverse();
|
||||
@ -27,8 +27,8 @@ export default function Home() {
|
||||
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}});
|
||||
var doc = ActiveDeviceCollection.findOne({deviceId: deviceId.deviceId});
|
||||
ActiveDeviceCollection.update({_id: doc._id}, {$set: {deviceId: e.target.value}});
|
||||
}
|
||||
}
|
||||
|
||||
@ -70,7 +70,7 @@ export default function Home() {
|
||||
</Form>
|
||||
</Col>
|
||||
<Col>
|
||||
<h6>active device: {deviceName.deviceName}</h6>
|
||||
<h6>active device: {deviceId.deviceId}</h6>
|
||||
</Col>
|
||||
</Row>
|
||||
|
||||
|
||||
@ -9,15 +9,15 @@ import {useTracker} from 'meteor/react-meteor-data';
|
||||
import { Card, CardDeck, Table } from "react-bootstrap";
|
||||
|
||||
export default function Overview() {
|
||||
const deviceName = useTracker(() => {
|
||||
const deviceId = useTracker(() => {
|
||||
return ActiveDeviceCollection.find().fetch()[0];
|
||||
});
|
||||
|
||||
const sensorData = useTracker(() => {
|
||||
if (deviceName === null || deviceName === undefined) {
|
||||
if (deviceId === null || deviceId === undefined) {
|
||||
return [];
|
||||
} else {
|
||||
return SensorDataCollection.find({device_id: deviceName.deviceName}, {
|
||||
return SensorDataCollection.find({device_id: deviceId.deviceId}, {
|
||||
sort: {timestamp: -1},
|
||||
limit: 61
|
||||
}).fetch().reverse();
|
||||
|
||||
@ -4,12 +4,12 @@ import {ActiveDeviceCollection, SensorDataCollection} from "../../client/main";
|
||||
import {useTracker} from 'meteor/react-meteor-data';
|
||||
|
||||
export default function SensorCardDeck() {
|
||||
const deviceName = useTracker(() => {
|
||||
const deviceId = useTracker(() => {
|
||||
return ActiveDeviceCollection.find().fetch()[0];
|
||||
});
|
||||
|
||||
const sensorData = useTracker(() => {
|
||||
return SensorDataCollection.find({ device_id: deviceName.deviceName }, { sort: { timestamp: -1 }, limit: 1 }).fetch();
|
||||
return SensorDataCollection.find({ device_id: deviceId.deviceId }, { sort: { timestamp: -1 }, limit: 1 }).fetch();
|
||||
});
|
||||
|
||||
|
||||
|
||||
@ -7,15 +7,15 @@ import {ConfiguredDevicesCollection, PlantTypesCollection, ActiveDeviceCollectio
|
||||
import {useTracker} from 'meteor/react-meteor-data';
|
||||
|
||||
export default function Settings() {
|
||||
const deviceName = useTracker(() => {
|
||||
const deviceId = useTracker(() => {
|
||||
return ActiveDeviceCollection.find().fetch()[0];
|
||||
});
|
||||
|
||||
const sensorData = useTracker(() => {
|
||||
if (deviceName === null || deviceName === undefined) {
|
||||
if (deviceId === null || deviceId === undefined) {
|
||||
return [];
|
||||
} else {
|
||||
return SensorDataCollection.find({device_id: deviceName.deviceName}, {
|
||||
return SensorDataCollection.find({device_id: deviceId.deviceId}, {
|
||||
sort: {timestamp: -1},
|
||||
limit: 61
|
||||
}).fetch().reverse();
|
||||
@ -68,8 +68,8 @@ export default function Settings() {
|
||||
}
|
||||
})
|
||||
|
||||
var doc = ConfiguredDevicesCollection.findOne({deviceName: selectedEspName});
|
||||
if (doc === undefined) {ConfiguredDevicesCollection.insert({deviceName: selectedEspName, type: selectedType});} else {
|
||||
var doc = ConfiguredDevicesCollection.findOne({deviceId: selectedEspName});
|
||||
if (doc === undefined) {ConfiguredDevicesCollection.insert({deviceId: selectedEspName, type: selectedType});} else {
|
||||
ConfiguredDevicesCollection.update({_id: doc._id}, {$set: {type: selectedType}});
|
||||
}
|
||||
}
|
||||
|
||||
@ -25,7 +25,7 @@ Meteor.startup(() => {
|
||||
return ConfiguredDevicesCollection.find();
|
||||
})
|
||||
|
||||
//startMqttObserver()
|
||||
startMqttObserver()
|
||||
|
||||
Meteor.methods({
|
||||
'mqttPublish'({ topic, payload }) {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user