diff --git a/src/main.ts b/src/main.ts index 5ada886..8e73566 100644 --- a/src/main.ts +++ b/src/main.ts @@ -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") }