From ba0ce0722843ec7452bec1343e807e9de02be99f Mon Sep 17 00:00:00 2001 From: Giona Righini Date: Sun, 15 Sep 2024 10:42:34 +0200 Subject: [PATCH] light data on mqtt and socket --- src/manager.js | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/manager.js b/src/manager.js index c536e85..a7a22f2 100644 --- a/src/manager.js +++ b/src/manager.js @@ -93,9 +93,15 @@ const share = async () => { }, }); - io.emit("data", app._data); + app._dataFlat = { + system, + dayWeek: dayWeek[dayWeek.length - 1], + realtime: realtime[realtime.length - 1], + }; + + io.emit("data", app._dataFlat); - mqttClient.publish("data", JSON.stringify(app._data), { + mqttClient.publish("data", JSON.stringify(app._dataFlat), { qos: 1, retain: true, }); @@ -118,7 +124,7 @@ const share = async () => { cron.schedule(shareInterval, share); share(); -app.get("/data", async (req, res) => res.json(await db.realTime())); +app.get("/data", (req, res) => res.json(app._dataFlat)); // BUTTONS if (process.env.ENABLE_BUTTONS === "true") {