status message

This commit is contained in:
Wolfgang Hottgenroth 2018-04-26 16:47:33 +02:00
parent f536b7a16f
commit d37e237de2
Signed by: wn
GPG Key ID: B586EAFCDF2F65F4

View File

@ -34,6 +34,7 @@ options
class MqttMongo extends Events.EventEmitter {
private options : any
private msgCnt : number = 0
constructor(options : any) {
super()
@ -123,12 +124,11 @@ class MqttMongo extends Events.EventEmitter {
this.mqttClient.publish('MqttMongo/Status', 'hello, started up')
})
let msgCnt : number = 0
this.mqttClient.on('message', (topic : string, messageBuf : Buffer) => {
msgCnt++;
this.msgCnt++;
let message = messageBuf.toString('UTF-8')
if (this.options.verbose) {
console.info(`Message received ${msgCnt}, topic ${topic}, payload ${message}`)
console.info(`Message received ${this.msgCnt}, topic ${topic}, payload ${message}`)
}
if (topic == "MqttMongo/Command" && message == "shutdown") {
@ -146,11 +146,13 @@ class MqttMongo extends Events.EventEmitter {
setupHeartbeat() {
this.heartbeatTimer = setInterval(() => {
this.uptime++
this.mqttClient.publish('MqttMongo/Status', `{'Uptime': ${this.uptime}}`)
let statusMsg = `{'Uptime': ${this.uptime}, 'MessageCount': ${this.msgCnt}}`
this.mqttClient.publish('MqttMongo/Status', statusMsg)
console.info(`Status: ${statusMsg}`)
if (! this.dbReady) {
this.emit("reconnectDatabase")
}
}, 1000)
}, 60000)
console.info("Heartbeat timer started")
}