Feat: Added config file

This commit is contained in:
Ipmake 2024-05-14 08:02:35 +02:00
parent 4be1fa7f02
commit 0ccb9b5278
3 changed files with 36 additions and 7 deletions

9
server/config.json Normal file
View File

@ -0,0 +1,9 @@
{
"mqtt": {
"url": "mqtt://192.168.188.11",
"username": "mqtt-user",
"password": "hivi1234hivi",
"port": 1883
},
"camUrl": "http://192.168.188.60/capture"
}

View File

@ -6,16 +6,23 @@ import { connect } from "mqtt";
import { getSync } from '@andreekeberg/imagedata'
import axios from 'axios'
if(!fs.existsSync('./config.json')) {
console.log("Config file not found")
process.exit(1)
}
const config = JSON.parse(fs.readFileSync('./config.json').toString()) as Types.Config
type states = "close" | "open"
let state: states = "close";
(async () => {
console.log("Starting...")
const client = connect('mqtt://192.168.188.11', {
username: 'mqtt-user',
password: 'hivi1234hivi',
port: 1883,
connectTimeout: 1000,
const client = connect(config.mqtt.url, {
username: config.mqtt.username,
password: config.mqtt.password,
port: config.mqtt.port,
connectTimeout: 5000,
manualConnect: true
})
@ -61,7 +68,7 @@ let state: states = "close";
async function detectFace() {
process.stdout.write("\n")
process.stdout.write("Run : ")
const req = await axios.get("http://192.168.188.60/capture", {
const req = await axios.get(config.camUrl, {
responseType: 'arraybuffer'
}) // returns a 800x600 jpeg img

13
server/src/types.d.ts vendored
View File

@ -1 +1,14 @@
declare module '@andreekeberg/imagedata';
declare namespace Types {
interface Config {
mqtt: {
url: string;
username: string;
password: string;
port: number;
};
camUrl: string;
}
}