2019-09-01 18:14:16 -07:00
|
|
|
import MQTT from '../src/mqtt'
|
2019-08-15 08:11:18 -07:00
|
|
|
// import btc from 'better-try-catch'
|
2019-09-01 18:14:16 -07:00
|
|
|
const BROKER='nas.kebler.net'
|
|
|
|
let server = new MQTT({id:'example-mqtt-server', connect:{host:BROKER}})
|
2019-08-15 08:11:18 -07:00
|
|
|
|
2019-09-01 18:14:16 -07:00
|
|
|
async function test (packet) {
|
|
|
|
console.log('in packet processor', packet)
|
|
|
|
packet.success = true
|
|
|
|
packet.cmd ='reply'
|
|
|
|
packet.msg ='this mqtt client acting like a "server" processed the test message'
|
|
|
|
this.push({cmd:'test', data:'some data'}, 'pushed')
|
|
|
|
return packet
|
|
|
|
}
|
2019-08-15 08:11:18 -07:00
|
|
|
|
|
|
|
(async () => {
|
2019-09-01 18:14:16 -07:00
|
|
|
server.registerPacketProcessor(test)
|
|
|
|
console.log(await server.connect())
|
2019-08-15 08:11:18 -07:00
|
|
|
|
|
|
|
})().catch(err => {
|
|
|
|
console.error('FATAL: UNABLE TO START SYSTEM!\n',err)
|
|
|
|
})
|