lavoce #24
@@ -2,7 +2,7 @@
|
|||||||
import mqtt from 'mqtt';
|
import mqtt from 'mqtt';
|
||||||
|
|
||||||
const mqttUrl = `${import.meta.env.VITE_MQTT_SERVER ?? 'ws://localhost:1884'}`;
|
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 = {
|
const options = {
|
||||||
keepalive: 30,
|
keepalive: 30,
|
||||||
clientId: 'react_mqtt_' + Math.random().toString(16).substr(2, 8),
|
clientId: 'react_mqtt_' + Math.random().toString(16).substr(2, 8),
|
||||||
@@ -66,7 +66,8 @@ const listenMessage = (callback) => {
|
|||||||
|
|
||||||
const setValSvg = (listenTopic, svg) => {
|
const setValSvg = (listenTopic, svg) => {
|
||||||
client.on('message', (topic, message) => {
|
client.on('message', (topic, message) => {
|
||||||
if (topic == listenTopic) {
|
// console.log(topic ,' = ', listenTopic);
|
||||||
|
if (topic === listenTopic) {
|
||||||
const objChanel = JSON.parse(message);
|
const objChanel = JSON.parse(message);
|
||||||
|
|
||||||
Object.entries(objChanel).forEach(([key, value]) => {
|
Object.entries(objChanel).forEach(([key, value]) => {
|
||||||
@@ -78,7 +79,7 @@ const setValSvg = (listenTopic, svg) => {
|
|||||||
} else if (value === false) {
|
} else if (value === false) {
|
||||||
el.style.display = 'none';
|
el.style.display = 'none';
|
||||||
} else if (!isNaN(value)) {
|
} else if (!isNaN(value)) {
|
||||||
el.textContent = Number(value ?? 0.0);
|
el.textContent = Number(value ?? 0.0).toFixed(2);
|
||||||
} else {
|
} else {
|
||||||
el.textContent = value;
|
el.textContent = value;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user