Un dashboard multiestación con gauges y LEDs en Node-RED
Un nodo function, tres tipos de widget
msg.color. Topics como estacion/31/gauge mantienen el enrutado explícito.El LED que vigila al vigilante
Escalar pestañas, no flujos
Un fragmento de la implementación
Tal cual del ejemplo desplegado en el Servidor (Node-RED) — cópialo libremente:
const station = msg.station;
const level = msg.alert ?? 0;
const inputs = msg.inputs || {};
const ts = msg.ts || new Date().toISOString();
// --- Output 1: alert level gauge (range 0-4) --------------------------
const msgGauge = {
topic: `station/${station}/gauge`,
payload: level
};
// --- Output 2: one ui-text per input + summary text --------------------
// node.send() accepts arrays: every element of the inner array goes out
// the same output, so we feed several ui-text widgets at once.
const textMsgs = Object.keys(inputs).map(channel => ({
topic: `station/${station}/text/${channel}`,
payload: inputs[channel] ? "ACTIVE" : "idle"
}));
textMsgs.push({
topic: `station/${station}/text/summary`,
payload: `Level ${level} — ${ts.substring(11, 19)}`
});
// --- Output 3: station status LED ---------------------------------------
// Green = normal (0-1), yellow = attention (2-3), red = critical (4).
// If the station has not reported in >3 min, the LED blinks red.
const COLORS = ["green", "green", "yellow", "yellow", "red"];
const states = flow.get("states") || {};El ejemplo completo es un programa entero — cabecera de conexionado, setup y bucle principal — listo para adaptar a tu aplicación.
Preguntas frecuentes
¿Qué paquete de dashboard usa este ejemplo?
node-red-dashboard para gauges y texto, más node-red-contrib-ui-led para los LEDs de estado. Ambos se instalan desde el gestor de paleta en un clic.
¿Aguanta una Raspberry Pi más de 90 widgets?
Sí. Los widgets solo se actualizan cuando llega un mensaje, así que cuatro estaciones reportando cada 60 segundos es una carga muy ligera. El navegador que renderiza el dashboard trabaja más que la Pi que lo sirve.
¿Cómo muestro que una estación está offline y no simplemente en calma?
Guarda el timestamp de cada lectura en el contexto de flujo y compáralo con el reloj al refrescar. En este ejemplo el LED se pone rojo y el estado del nodo muestra SIN DATOS tras tres minutos sin reporte.