import React from 'react'
import { Card, CardDeck } from 'react-bootstrap';
import {
ActiveDeviceCollection,
ConfiguredDevicesCollection,
PlantTypesCollection,
SensorDataCollection
} from "../../client/main";
import {useTracker} from 'meteor/react-meteor-data';
export default function SensorCardDeck() {
const deviceId = useTracker(() => {
return ActiveDeviceCollection.find().fetch()[0];
});
const sensorData = useTracker(() => {
if (deviceId === null || deviceId === undefined) {
return undefined;
} else {
return SensorDataCollection.find({device_id: deviceId.deviceId}, {sort: {timestamp: -1}, limit: 1}).fetch();
}
});
const plantType = useTracker(() => {
if (deviceId === null || deviceId === undefined) {
return undefined;
} else {
return ConfiguredDevicesCollection.findOne({deviceId: deviceId.deviceId});
}
});
const plantTypeData = useTracker(() => {
if (plantType === null || plantType === undefined) {
return undefined;
} else {
return PlantTypesCollection.findOne({plantType: plantType.type});
}
});
if (sensorData.length <= 0 || plantType === undefined || deviceId === undefined || plantTypeData === undefined) {
return (
Loading!
Please wait...
)
} else {
return (
{sensorData[0].temperature < plantTypeData.data.temperature.minTemp ?
Temperature
{sensorData[0].temperature} °C
:
Temperature
{sensorData[0].temperature} °C
}
Humidity
{sensorData[0].humidity} %
Brightness
{sensorData[0].brightness} lux
{sensorData[0].moisture > plantTypeData.data.soilMoisture.sat ?
Moisture
{sensorData[0].moisture} %
:
Moisture
{sensorData[0].moisture} %
}
)
}
}