uci-mqtt/example/example.js

20 lines
702 B
JavaScript

import Client from '../src/client'
// import btc from 'better-try-catch'
// let mqtt = new Client({id:'example-mqtt-client', url:'tcp://trantor:1883', topics:'test1'})
let mqtt = new Client({id:'example-mqtt-client', topics:'lights'})
;
(async () => {
console.log(await mqtt.connect())
await mqtt.send({cmd:'lights/on', status:'sent to topics lights'})
// 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)
})