fix env issue
All checks were successful
Plant Growing Automation / deploy (push) Successful in 6s

This commit is contained in:
David Westgate 2025-04-25 22:09:37 -07:00
parent 41dfe61afd
commit cedee871a5
2 changed files with 15 additions and 12 deletions

View File

@ -1,7 +1,7 @@
[ [
{ {
"name": "tomato", "name": "tomato",
"daylightHours": 16, "daylightHours": 12,
"soilMoisture": 75 "soilMoisture": 75
} }
] ]

View File

@ -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 WS_PORT = process.env.WS_PORT ? parseInt(process.env.WS_PORT, 10) : 3003;
const STATIC_ROOT = process.cwd() + "/dist/static"; const STATIC_ROOT = process.cwd() + "/dist/static";
const TV_DEV_0 = process.env.TV_DEV_0 ?? '/dev/video0' const TV_DEV_0 = process.env.TV_DEV_0 ?? '/dev/video0'
const GPIO_LIGHTS = parseInt(process.env.GPIO_LIGHTS) ?? 17; const GPIO_LIGHTS = process.env.GPIO_LIGHTS ? parseInt(process.env.GPIO_LIGHTS) : 17;
const GPIO_HEAT = parseInt(process.env.GPIO_HEAT) ?? 22; const GPIO_HEAT = process.env.GPIO_HEAT ? parseInt(process.env.GPIO_HEAT) : 22;
const START_HOUR = parseInt(process.env.START_HOUR) ?? 8; const START_HOUR = process.env.START_HOUR ? parseInt(process.env.START_HOUR) : 9;
interface IProgram { interface IProgram {
name:string, name: string,
daylightHours: number, daylightHours: number,
soilMoisture: number soilMoisture: number
} }
@ -32,22 +32,25 @@ const test = (device: string) => {
} }
const runProgram = async (ID = 0) =>{ const runProgram = (ID = 0) => {
let state = false; let state = false;
const program: IProgram = programs[ID]; const program: IProgram = programs[ID];
const {daylightHours, soilMoisture} = program; const { daylightHours, soilMoisture } = program;
const now = new Date(); const now = new Date();
const startTime = new Date(); const startTime = new Date();
startTime.setHours(START_HOUR, 0, 0, 0); startTime.setHours(START_HOUR, 0, 0, 0);
const endTime = new Date(startTime.getTime()); const endTime = new Date(startTime.getTime());
endTime.setHours(startTime.getHours() + daylightHours); endTime.setHours(startTime.getHours() + daylightHours);
if(now >= startTime && now <= endTime){ if (now >= startTime && now <= endTime) {
state = true; state = true;
} }
io.setPower(state,GPIO_LIGHTS); io.setPower(state, GPIO_LIGHTS);
io.setPower(state,GPIO_HEAT); io.setPower(state, GPIO_HEAT);
} }
runProgram(); setInterval(() => {
runProgram();
}, 60000)
const httpServer = new HttpServer(HTTP_PORT, STATIC_ROOT, test); const httpServer = new HttpServer(HTTP_PORT, STATIC_ROOT, test);
const videoSocket = new VideoSocket(WS_PORT, TV_DEV_0, getSensors); const videoSocket = new VideoSocket(WS_PORT, TV_DEV_0, getSensors);