diff --git a/src/http.ts b/src/http.ts index 0c0113a..67047a6 100644 --- a/src/http.ts +++ b/src/http.ts @@ -1,15 +1,14 @@ import * as http from "http"; import * as fs from "fs"; import * as path from "path"; -import IO, { ISensors } from "./io"; +import IO from "./io"; -export default class HttpServer { + class HttpServer { private httpServer: http.Server; private port: number; private root: string; - // public constructor(port: number, root: string, tune: (ch: string, adp?: number) => void, getChannels: ()=>string[], getSignal: (adapter:number)=>object) { public constructor(port: number, root: string, io: IO) { this.port = port; @@ -46,7 +45,7 @@ export default class HttpServer { // tune(channel, adapter); status = 202; break; - + } } @@ -76,10 +75,6 @@ export default class HttpServer { } - - - - - -} +}; +export default HttpServer; diff --git a/src/io.ts b/src/io.ts index 308504c..1c6706c 100644 --- a/src/io.ts +++ b/src/io.ts @@ -35,7 +35,7 @@ export default class IO { this.gpioLights = new pigpio.Gpio(LIGHTS_GPIO, { mode: pigpio.Gpio.OUTPUT }); const readHeat = new pigpio.Gpio(HEAT_GPIO, { mode: pigpio.Gpio.INPUT }); - this.lights = readHeat.digitalRead() == ON ? true : false + this.heat = readHeat.digitalRead() == ON ? true : false this.gpioHeat = new pigpio.Gpio(HEAT_GPIO, { mode: pigpio.Gpio.OUTPUT }); diff --git a/src/serial.ts b/src/serial.ts index 3a564fa..126ae3a 100644 --- a/src/serial.ts +++ b/src/serial.ts @@ -14,16 +14,20 @@ export default class Serial { const readline = new serialport.ReadlineParser({ delimiter }); const parser = port.pipe(readline); parser.on('data', line => { - const data = JSON.parse(line) - const moisture0 = parseInt(data['A0'], 10); - const moisture1 = parseInt(data['A1'], 10); - if (!isNaN(moisture0) && !isNaN(moisture1)) { + try{ + const data = JSON.parse(line) + const moisture0 = parseInt(data['A0'], 10); + const moisture1 = parseInt(data['A1'], 10); + if (isNaN(moisture0) || isNaN(moisture1)){ + throw new Error("isNan " + moisture0 + " " + moisture1) + } this.moisture0 = moisture0; this.moisture1 = moisture1; } - else { - console.error("Error reading analog data") + catch(e){ + console.log(e) } + }); port.on('error', err => { console.error('Serial Error:', err.message); diff --git a/src/server.ts b/src/server.ts index 3275c97..d99eedb 100644 --- a/src/server.ts +++ b/src/server.ts @@ -7,32 +7,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 zap = new Zap(); - - -// const tune = (reqChannel: string, reqAdapter?: number) => { -// const adapter = reqAdapter === 0 || reqAdapter === 1 ? reqAdapter : 0; -// zap.zapTo(reqChannel, adapter).then((zap: IZap) => { -// console.log(`Tuned ${zap.adapter} to ${zap.channel}`) -// }).catch((err: Error) => { -// console.error(err.message); -// }); -// } - -// const getChannels = () => -// zap.getChannels(); - -// const getSignal = (adapter: number) => -// zap.getSignal(adapter) const io = new IO(); const getSensors: ()=>ISensors = io.getSensors.bind(io); -// setTimeout(()=>{ -// console.log("sen ",io.getSensors()) -// console.log("sen2 ",getSensors()) -// },200) -// const setPower = io.setPower.bind(this, true) -// const togglePower = io.togglePower.bind(this) + const httpServer = new HttpServer(HTTP_PORT, STATIC_ROOT, io); const videoSocket = new VideoSocket(WS_PORT, TV_DEV_0, getSensors); diff --git a/src/static/index.html b/src/static/index.html index 032a7b6..101f432 100644 --- a/src/static/index.html +++ b/src/static/index.html @@ -5,18 +5,15 @@ WebRTC Stream - +
-

Video streams

-

WebRTC

-