Add timestamps when publishing and reporting messages.
This commit is contained in:
parent
c5fe158f16
commit
42b5ceecbc
@ -148,6 +148,8 @@ module.exports = {
|
||||
// this.emit('announcement', 'Message is from the frontend, updating state');
|
||||
// Update the state
|
||||
state[msgJson.name] = msgJson;
|
||||
// Log the timstamp if it's there
|
||||
if (msgJson.timestamp) console.log('Timestamp:', msgJson.timestamp);
|
||||
// Emit the state change
|
||||
this.emit('stateChange', oldState, state);
|
||||
} else if (topic === 'hestia/command/startup') {
|
||||
@ -193,6 +195,11 @@ module.exports = {
|
||||
|
||||
// Publish a message to the MQTT Broker
|
||||
send(topic, message) {
|
||||
// Append a timestamp onto the message
|
||||
const msgJson = JSON.parse(message);
|
||||
msgJson.timestamp = Date.now();
|
||||
message = JSON.stringify(msgJson);
|
||||
|
||||
// Publish with retain flag set to true
|
||||
this.client.publish(topic, message, { retain: true }, (err) => {
|
||||
if (err) {
|
||||
|
Loading…
Reference in New Issue
Block a user