import React from 'react'
import {
SensorDataCollection,
ActiveDeviceCollection,
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();
});
function getSoil(type) {
const plantType = PlantTypesCollection.findOne({plantType: type});
return plantType.dirtType
}
function getPermWilPoint(type) {
const plantType = PlantTypesCollection.findOne({plantType: type});
return plantType.data.soilMoisture.pwp
}
function getFieldCap(type) {
const plantType = PlantTypesCollection.findOne({plantType: type});
return plantType.data.soilMoisture.fc
}
function getMinTemp(type) {
const plantType = PlantTypesCollection.findOne({plantType: type});
return plantType.data.temperature.minTemp
}
function getMinLux(type) {
const plantType = PlantTypesCollection.findOne({plantType: type});
return plantType.data.light.minLux
}
if ((sensorData.length <= 0)) {
return (
| # | Device Nickname | Device ID | Plant Type | Soil Type | Permanent Wilting Point | Field Capacity | Min Temperature | Min Brightness |
|---|---|---|---|---|---|---|---|---|
| {index} | {device.alias} | {device.deviceId} | {device.type} | {getSoil(device.type)} | {getPermWilPoint(device.type) + " %"} | {getFieldCap(device.type) + " %"} | {getMinTemp(device.type) + " °C"} | {getMinLux(device.type) + " lux"} |