uci-mqtt/examples/server.js

22 lines
623 B
JavaScript
Raw Normal View History

import MQTT from '../src/mqtt'
// import btc from 'better-try-catch'
const BROKER='nas.kebler.net'
let server = new MQTT({id:'example-mqtt-server', connect:{host:BROKER}})
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
}
(async () => {
server.registerPacketProcessor(test)
console.log(await server.connect())
})().catch(err => {
console.error('FATAL: UNABLE TO START SYSTEM!\n',err)
})