From 94e011e5c751ac8f1787e0f15fddb7e17ae95ce0 Mon Sep 17 00:00:00 2001 From: bragaz_rexita Date: Fri, 28 Nov 2025 12:49:56 +0700 Subject: [PATCH] Repair topic mqtt --- src/components/Global/MqttConnection.jsx | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/components/Global/MqttConnection.jsx b/src/components/Global/MqttConnection.jsx index ab8287c..829f598 100644 --- a/src/components/Global/MqttConnection.jsx +++ b/src/components/Global/MqttConnection.jsx @@ -2,7 +2,7 @@ import mqtt from 'mqtt'; const mqttUrl = `${import.meta.env.VITE_MQTT_SERVER ?? 'ws://localhost:1884'}`; -const topics = ['PIU_GGCP/Devices/PB']; +const topics = ['cod/air_dryer/air_dryer1']; const options = { keepalive: 30, clientId: 'react_mqtt_' + Math.random().toString(16).substr(2, 8), @@ -66,7 +66,8 @@ const listenMessage = (callback) => { const setValSvg = (listenTopic, svg) => { client.on('message', (topic, message) => { - if (topic == listenTopic) { + // console.log(topic ,' = ', listenTopic); + if (topic === listenTopic) { const objChanel = JSON.parse(message); Object.entries(objChanel).forEach(([key, value]) => { @@ -78,7 +79,7 @@ const setValSvg = (listenTopic, svg) => { } else if (value === false) { el.style.display = 'none'; } else if (!isNaN(value)) { - el.textContent = Number(value ?? 0.0); + el.textContent = Number(value ?? 0.0).toFixed(2); } else { el.textContent = value; }