41 lines
1.0 KiB
JavaScript
41 lines
1.0 KiB
JavaScript
|
/*
|
||
|
* i2c bus unix socket and client in one for demo
|
||
|
*
|
||
|
*/
|
||
|
|
||
|
import Base from '../../uci-base/src/base'
|
||
|
|
||
|
const PATH = '/opt/sockets/mcp.sock'
|
||
|
|
||
|
const delay = time => new Promise(res=>setTimeout(()=>res(),time))
|
||
|
;
|
||
|
(async () => {
|
||
|
|
||
|
let relays = new Base({id:'relays', sockets:'uc#c>n', uc:{path:PATH}})
|
||
|
|
||
|
relays.reply = function (packet) {
|
||
|
// console.log('for request ',packet._header.request)
|
||
|
// console.log('mcp status is ',packet.status)
|
||
|
}
|
||
|
|
||
|
await relays.init()
|
||
|
console.log('=============sending============')
|
||
|
|
||
|
await relays.send({cmd:'pin.cfg', pins:'all'})
|
||
|
await relays.send({cmd:'pin.state.off', pins:'all' })
|
||
|
|
||
|
for(let i=1;i<=8;i +=2){
|
||
|
await relays.send({cmd:'pin.state.on', pins:i})
|
||
|
}
|
||
|
console.log((await relays.send({cmd:'pin.status', pins:'all'})).status)
|
||
|
console.log((await relays.send({cmd:'pin.status', pins:'3'})).status.pins)
|
||
|
await delay(3000)
|
||
|
await relays.send({cmd:'pin.state.off', pins:'all'})
|
||
|
|
||
|
process.kill(process.pid, 'SIGTERM')
|
||
|
|
||
|
|
||
|
})().catch(err => {
|
||
|
console.error('FATAL: UNABLE TO START SYSTEM!\n',err)
|
||
|
})
|