27 lines
833 B
JavaScript
27 lines
833 B
JavaScript
import Client from '../src/client'
|
|
// import btc from 'better-try-catch'
|
|
const HOST='nas.kebler.net'
|
|
let mqtt = new Client({id:'example-mqtt-client', topics:'', connect:{hostname:HOST}})
|
|
|
|
// async function logit (packet) {
|
|
// if (packet.cmd === 'lights') {
|
|
// console.log(packet)
|
|
// }
|
|
// return null
|
|
// }
|
|
|
|
;
|
|
(async () => {
|
|
// mqtt.registerPacketProcessor(logit)
|
|
console.log(await mqtt.connect())
|
|
mqtt.send({cmd:'lights/status', id:'someidofalight'})
|
|
mqtt.subscribe('test')
|
|
// await mqtt.send('topic2', {cmd:'test', status:'sent to topic2 explicitly but not listening'})
|
|
// await mqtt.subscribe('topic2')
|
|
// await mqtt.send('topic2', {cmd:'test', status:'sent to topic2 with subscription'})
|
|
// now can send via some mqtt client
|
|
|
|
})().catch(err => {
|
|
console.error('FATAL: UNABLE TO START SYSTEM!\n',err)
|
|
})
|