Added functionality to change mode (dynamic light color).
This commit is contained in:
parent
05d41907fc
commit
88bfff57ae
@ -45,6 +45,7 @@ export default function Home() {
|
|||||||
<th key={'id'}>Device ID</th>
|
<th key={'id'}>Device ID</th>
|
||||||
<th key={'type'}>Plant Type</th>
|
<th key={'type'}>Plant Type</th>
|
||||||
<th key={'soil'}>Soil Type</th>
|
<th key={'soil'}>Soil Type</th>
|
||||||
|
<th key={'mode'}>Mode</th>
|
||||||
<th key={'pwp'}>Permanent Wilting Point</th>
|
<th key={'pwp'}>Permanent Wilting Point</th>
|
||||||
<th key={'fc'}>Field Capacity</th>
|
<th key={'fc'}>Field Capacity</th>
|
||||||
<th key={'temp'}>Min Temperature</th>
|
<th key={'temp'}>Min Temperature</th>
|
||||||
@ -59,6 +60,7 @@ export default function Home() {
|
|||||||
<td key={'id-' + index}>{device.deviceId}</td>
|
<td key={'id-' + index}>{device.deviceId}</td>
|
||||||
<td key={'type-' + index}>{device.type}</td>
|
<td key={'type-' + index}>{device.type}</td>
|
||||||
<td key={'soil-' + index}>{getSoil(device.type)}</td>
|
<td key={'soil-' + index}>{getSoil(device.type)}</td>
|
||||||
|
<td key={'mode-' + index}>{device.mode}</td>
|
||||||
<td key={'pwp-' + index}>{getPermWilPoint(device.type) + " %"}</td>
|
<td key={'pwp-' + index}>{getPermWilPoint(device.type) + " %"}</td>
|
||||||
<td key={'fc-' + index}>{getFieldCap(device.type) + " %"}</td>
|
<td key={'fc-' + index}>{getFieldCap(device.type) + " %"}</td>
|
||||||
<td key={'temp-' + index}>{getMinTemp(device.type) + " °C"}</td>
|
<td key={'temp-' + index}>{getMinTemp(device.type) + " °C"}</td>
|
||||||
|
|||||||
@ -16,6 +16,7 @@ export default function Settings() {
|
|||||||
var selectedEspId;
|
var selectedEspId;
|
||||||
var selectedAlias = "";
|
var selectedAlias = "";
|
||||||
var selectedType;
|
var selectedType;
|
||||||
|
var selectedMode = null;
|
||||||
|
|
||||||
const payloadVegi = plantTypes.fetch()[0];
|
const payloadVegi = plantTypes.fetch()[0];
|
||||||
const payloadCacti = plantTypes.fetch()[1];
|
const payloadCacti = plantTypes.fetch()[1];
|
||||||
@ -45,21 +46,34 @@ export default function Settings() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const handleChangeMode = (e) => {
|
||||||
|
if (e.target.value === "") {
|
||||||
|
console.log("No type selected!");
|
||||||
|
} else {
|
||||||
|
selectedMode = e.target.value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const handleSendData = (e) => {
|
const handleSendData = (e) => {
|
||||||
var payload = "";
|
var payload = "";
|
||||||
|
var nmValue = null;
|
||||||
if (selectedType === "Vegetables") {payload = JSON.stringify(payloadVegi.data.soilMoisture);}
|
if (selectedType === "Vegetables") {payload = JSON.stringify(payloadVegi.data.soilMoisture);}
|
||||||
if (selectedType === "Cacti") {payload = JSON.stringify(payloadCacti.data.soilMoisture);}
|
if (selectedType === "Cacti") {payload = JSON.stringify(payloadCacti.data.soilMoisture);}
|
||||||
if (selectedType === "Flowers") {payload = JSON.stringify(payloadFlower.data.soilMoisture);}
|
if (selectedType === "Flowers") {payload = JSON.stringify(payloadFlower.data.soilMoisture);}
|
||||||
|
if (selectedMode === "Growth") {nmValue = 450}
|
||||||
|
if (selectedMode === "Bloom") {nmValue = 700}
|
||||||
|
|
||||||
|
|
||||||
console.log("Payload: " + payload);
|
console.log("Payload: " + payload);
|
||||||
console.log("Alias: " + selectedAlias);
|
console.log("Alias: " + selectedAlias);
|
||||||
console.log("ID: " + selectedEspId);
|
console.log("ID: " + selectedEspId);
|
||||||
console.log("Type: " + selectedType);
|
console.log("Type: " + selectedType);
|
||||||
|
console.log("Mode: " + selectedMode);
|
||||||
|
|
||||||
if ((payload === "") || (selectedEspId === undefined) || (selectedAlias === "") || (selectedType === undefined)) {alert("Nickname is empty or no device/type selected!");} else {
|
if ((payload === "") || (nmValue === null) || (selectedEspId === undefined) || (selectedAlias === "") || (selectedType === undefined) || (selectedMode === null)) {alert("Nickname is empty or no device/type/mode selected!");} else {
|
||||||
var doc = ConfiguredDevicesCollection.findOne({deviceId: selectedEspId});
|
var doc = ConfiguredDevicesCollection.findOne({deviceId: selectedEspId});
|
||||||
if (doc === undefined) {ConfiguredDevicesCollection.insert({deviceId: selectedEspId, alias: selectedAlias, type: selectedType});} else {
|
if (doc === undefined) {ConfiguredDevicesCollection.insert({deviceId: selectedEspId, alias: selectedAlias, type: selectedType, mode: selectedMode});} else {
|
||||||
ConfiguredDevicesCollection.update({_id: doc._id}, {$set: {alias: selectedAlias, type: selectedType}});
|
ConfiguredDevicesCollection.update({_id: doc._id}, {$set: {alias: selectedAlias, type: selectedType, mode: selectedMode}});
|
||||||
}
|
}
|
||||||
|
|
||||||
Meteor.call('mqttPublish', {
|
Meteor.call('mqttPublish', {
|
||||||
@ -91,7 +105,7 @@ export default function Settings() {
|
|||||||
topic: 'smartgarden/commands/' + selectedEspId + '/light',
|
topic: 'smartgarden/commands/' + selectedEspId + '/light',
|
||||||
payload: JSON.stringify({
|
payload: JSON.stringify({
|
||||||
'minLX': 500,
|
'minLX': 500,
|
||||||
'nm': 700
|
'nm': nmValue
|
||||||
})
|
})
|
||||||
}, (err, res) => {
|
}, (err, res) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
@ -158,6 +172,14 @@ export default function Settings() {
|
|||||||
})}
|
})}
|
||||||
</Form.Control>
|
</Form.Control>
|
||||||
</Form.Group>
|
</Form.Group>
|
||||||
|
<Form.Group>
|
||||||
|
<Form.Label>Mode:</Form.Label>
|
||||||
|
<Form.Control as="select" type="text" onChange={handleChangeMode}>
|
||||||
|
<option></option>
|
||||||
|
<option key="0" value="Growth">Growth</option>
|
||||||
|
<option key="1" value="Bloom">Bloom</option>
|
||||||
|
</Form.Control>
|
||||||
|
</Form.Group>
|
||||||
<Button type={"sendData"} onClick={handleSendData} >Send</Button>
|
<Button type={"sendData"} onClick={handleSendData} >Send</Button>
|
||||||
</Form>
|
</Form>
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user