Feat: Added config file
This commit is contained in:
parent
4be1fa7f02
commit
0ccb9b5278
|
@ -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"
|
||||||
|
}
|
|
@ -6,16 +6,23 @@ import { connect } from "mqtt";
|
||||||
import { getSync } from '@andreekeberg/imagedata'
|
import { getSync } from '@andreekeberg/imagedata'
|
||||||
import axios from 'axios'
|
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"
|
type states = "close" | "open"
|
||||||
let state: states = "close";
|
let state: states = "close";
|
||||||
|
|
||||||
(async () => {
|
(async () => {
|
||||||
console.log("Starting...")
|
console.log("Starting...")
|
||||||
const client = connect('mqtt://192.168.188.11', {
|
const client = connect(config.mqtt.url, {
|
||||||
username: 'mqtt-user',
|
username: config.mqtt.username,
|
||||||
password: 'hivi1234hivi',
|
password: config.mqtt.password,
|
||||||
port: 1883,
|
port: config.mqtt.port,
|
||||||
connectTimeout: 1000,
|
connectTimeout: 5000,
|
||||||
manualConnect: true
|
manualConnect: true
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -61,7 +68,7 @@ let state: states = "close";
|
||||||
async function detectFace() {
|
async function detectFace() {
|
||||||
process.stdout.write("\n")
|
process.stdout.write("\n")
|
||||||
process.stdout.write("Run : ")
|
process.stdout.write("Run : ")
|
||||||
const req = await axios.get("http://192.168.188.60/capture", {
|
const req = await axios.get(config.camUrl, {
|
||||||
responseType: 'arraybuffer'
|
responseType: 'arraybuffer'
|
||||||
}) // returns a 800x600 jpeg img
|
}) // returns a 800x600 jpeg img
|
||||||
|
|
||||||
|
|
|
@ -1 +1,14 @@
|
||||||
declare module '@andreekeberg/imagedata';
|
declare module '@andreekeberg/imagedata';
|
||||||
|
|
||||||
|
|
||||||
|
declare namespace Types {
|
||||||
|
interface Config {
|
||||||
|
mqtt: {
|
||||||
|
url: string;
|
||||||
|
username: string;
|
||||||
|
password: string;
|
||||||
|
port: number;
|
||||||
|
};
|
||||||
|
camUrl: string;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue