35 lines
928 B
JavaScript
35 lines
928 B
JavaScript
import Gpios from '../src/gpios'
|
|
import hahooks from './homeassistant.js'
|
|
|
|
const PINS = [80,73,69,230,229,75,74,70]
|
|
const ALL_PIN_OPTS = {activeLow:true, init:1}
|
|
|
|
let relays = new Gpios(PINS, {pinOpts:ALL_PIN_OPTS,69:{init:0}})
|
|
|
|
relays.announce = function () {
|
|
for (let pin of Object.keys(relays.pins)) {
|
|
relays.push({cmd:'status', pin:pin, state:relays.pins[pin].value})
|
|
}
|
|
}
|
|
|
|
const BROKER = 'nas.kebler.net'
|
|
const TCP_PORT = 9075
|
|
const WS_PORT = 8090
|
|
|
|
;
|
|
(async () => {
|
|
await relays.addSocket('web','s','w',{ wsport:WS_PORT })
|
|
await relays.addSocket('mqs','s','m', {host:BROKER, topics:['relay/set/+']})
|
|
hahooks.call(relays,'mqs')
|
|
await relays.addSocket('tcp','s','t', {port:TCP_PORT})
|
|
await relays.init()
|
|
|
|
relays.announce()
|
|
|
|
// await relays.getSocket('mqs').subscribe(['relays/#'])
|
|
|
|
})().catch(err => {
|
|
console.error('FATAL: UNABLE TO START SYSTEM!\n',err)
|
|
// process.kill(process.pid, 'SIGTERM')
|
|
})
|