This commit is contained in:
parent
41dfe61afd
commit
cedee871a5
@ -1,7 +1,7 @@
|
||||
[
|
||||
{
|
||||
"name": "tomato",
|
||||
"daylightHours": 16,
|
||||
"daylightHours": 12,
|
||||
"soilMoisture": 75
|
||||
}
|
||||
]
|
@ -7,12 +7,12 @@ const HTTP_PORT = process.env.HTTP_PORT ? parseInt(process.env.HTTP_PORT, 10) :
|
||||
const WS_PORT = process.env.WS_PORT ? parseInt(process.env.WS_PORT, 10) : 3003;
|
||||
const STATIC_ROOT = process.cwd() + "/dist/static";
|
||||
const TV_DEV_0 = process.env.TV_DEV_0 ?? '/dev/video0'
|
||||
const GPIO_LIGHTS = parseInt(process.env.GPIO_LIGHTS) ?? 17;
|
||||
const GPIO_HEAT = parseInt(process.env.GPIO_HEAT) ?? 22;
|
||||
const START_HOUR = parseInt(process.env.START_HOUR) ?? 8;
|
||||
const GPIO_LIGHTS = process.env.GPIO_LIGHTS ? parseInt(process.env.GPIO_LIGHTS) : 17;
|
||||
const GPIO_HEAT = process.env.GPIO_HEAT ? parseInt(process.env.GPIO_HEAT) : 22;
|
||||
const START_HOUR = process.env.START_HOUR ? parseInt(process.env.START_HOUR) : 9;
|
||||
|
||||
interface IProgram {
|
||||
name:string,
|
||||
name: string,
|
||||
daylightHours: number,
|
||||
soilMoisture: number
|
||||
}
|
||||
@ -32,22 +32,25 @@ const test = (device: string) => {
|
||||
|
||||
}
|
||||
|
||||
const runProgram = async (ID = 0) =>{
|
||||
const runProgram = (ID = 0) => {
|
||||
let state = false;
|
||||
const program: IProgram = programs[ID];
|
||||
const {daylightHours, soilMoisture} = program;
|
||||
const { daylightHours, soilMoisture } = program;
|
||||
const now = new Date();
|
||||
const startTime = new Date();
|
||||
startTime.setHours(START_HOUR, 0, 0, 0);
|
||||
const endTime = new Date(startTime.getTime());
|
||||
endTime.setHours(startTime.getHours() + daylightHours);
|
||||
if(now >= startTime && now <= endTime){
|
||||
if (now >= startTime && now <= endTime) {
|
||||
state = true;
|
||||
}
|
||||
io.setPower(state,GPIO_LIGHTS);
|
||||
io.setPower(state,GPIO_HEAT);
|
||||
io.setPower(state, GPIO_LIGHTS);
|
||||
io.setPower(state, GPIO_HEAT);
|
||||
}
|
||||
runProgram();
|
||||
setInterval(() => {
|
||||
runProgram();
|
||||
}, 60000)
|
||||
|
||||
|
||||
const httpServer = new HttpServer(HTTP_PORT, STATIC_ROOT, test);
|
||||
const videoSocket = new VideoSocket(WS_PORT, TV_DEV_0, getSensors);
|
||||
|
Loading…
Reference in New Issue
Block a user