status message
This commit is contained in:
parent
f536b7a16f
commit
d37e237de2
12
src/main.ts
12
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")
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user