Add timestamps when publishing and reporting messages.

This commit is contained in:
Skylar Grant 2025-01-18 16:09:34 -05:00
parent c5fe158f16
commit 42b5ceecbc

View File

@ -148,6 +148,8 @@ module.exports = {
// this.emit('announcement', 'Message is from the frontend, updating state'); // this.emit('announcement', 'Message is from the frontend, updating state');
// Update the state // Update the state
state[msgJson.name] = msgJson; state[msgJson.name] = msgJson;
// Log the timstamp if it's there
if (msgJson.timestamp) console.log('Timestamp:', msgJson.timestamp);
// Emit the state change // Emit the state change
this.emit('stateChange', oldState, state); this.emit('stateChange', oldState, state);
} else if (topic === 'hestia/command/startup') { } else if (topic === 'hestia/command/startup') {
@ -193,6 +195,11 @@ module.exports = {
// Publish a message to the MQTT Broker // Publish a message to the MQTT Broker
send(topic, message) { 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 // Publish with retain flag set to true
this.client.publish(topic, message, { retain: true }, (err) => { this.client.publish(topic, message, { retain: true }, (err) => {
if (err) { if (err) {