Repair topic mqtt

This commit is contained in:
2025-11-28 12:49:56 +07:00
parent db9b40f2fc
commit 94e011e5c7

View File

@@ -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;
}