2018-05-16 07:20:33 -07:00
|
|
|
import Client from '../src/client'
|
2018-05-24 12:31:47 -07:00
|
|
|
import btc from 'better-try-catch'
|
2018-05-16 07:20:33 -07:00
|
|
|
|
|
|
|
// let mqtt = new Client({id:'example-mqtt-client', url:'tcp://trantor:1883', topics:'test1'})
|
2018-05-24 12:31:47 -07:00
|
|
|
let mqtt = new Client({id:'example-mqtt-client', topics:'lights'})
|
2018-05-16 07:20:33 -07:00
|
|
|
|
|
|
|
;
|
|
|
|
(async () => {
|
|
|
|
|
2018-05-24 12:31:47 -07:00
|
|
|
console.log(await mqtt.connect())
|
2018-05-16 07:20:33 -07:00
|
|
|
await mqtt.send({cmd:'test', status:'sent to topic1 implicitly'})
|
|
|
|
await mqtt.subscribe('topic2')
|
|
|
|
await mqtt.send('topic2', {cmd:'test', status:'sent to topic2 explicitly'})
|
|
|
|
await mqtt.unsubscribe('topic2')
|
|
|
|
await mqtt.send('topic2', {cmd:'test', status:'sent to topic2 with subscription'})
|
2018-05-24 12:31:47 -07:00
|
|
|
// await mqtt.subscribe('lights')
|
2018-05-16 07:20:33 -07:00
|
|
|
|
|
|
|
|
|
|
|
})().catch(err => {
|
|
|
|
console.error('FATAL: UNABLE TO START SYSTEM!\n',err)
|
|
|
|
})
|