I wanna do a live monitoring of energy usage. my problem is that my chart is completely empty at the dashboard. Thats my code.
[
{
"id": "36fa3994398c3c99",
"type": "tab",
"label": "Datenaufnahme",
"disabled": false,
"info": "",
"env": []
},
{
"id": "fb0560e6fbaf9f57",
"type": "inject",
"z": "36fa3994398c3c99",
"name": "",
"props": [
{
"p": "payload"
},
{
"p": "topic",
"vt": "str"
}
],
"repeat": "3600",
"crontab": "",
"once": false,
"onceDelay": "300",
"topic": "",
"payload": "",
"payloadType": "date",
"x": 190,
"y": 180,
"wires": [
[
"a59ecdd3cf7436d4"
]
]
},
{
"id": "a59ecdd3cf7436d4",
"type": "function",
"z": "36fa3994398c3c99",
"name": "Abfrage der Werte",
"func": "\n// 🌡 Werte abrufen\nlet leistung = global.get(\"Leistung\") || 0;\n\n\n\n// 🕒 Zeitstempel generieren\nlet timestamp = new Date().toISOString();\n\n// 📄 CSV-Zeile erstellen\nmsg.payload = `${timestamp},${leistung}\\n`;\nreturn msg;\n",
"outputs": 1,
"timeout": 0,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 470,
"y": 180,
"wires": [
[
"c9bac3d96d3bd19e"
]
]
},
{
"id": "c9bac3d96d3bd19e",
"type": "file",
"z": "36fa3994398c3c99",
"name": "",
"filename": "C:\\Users\\Labor\\Desktop\\messwert.csv",
"filenameType": "str",
"appendNewline": false,
"createDir": true,
"overwriteFile": "false",
"encoding": "utf8",
"x": 770,
"y": 180,
"wires": [
[]
]
},
{
"id": "b8635a54e085e25b",
"type": "inject",
"z": "36fa3994398c3c99",
"name": "",
"props": [
{
"p": "payload"
},
{
"p": "topic",
"vt": "str"
}
],
"repeat": "3600",
"crontab": "",
"once": false,
"onceDelay": "300",
"topic": "",
"payload": "",
"payloadType": "date",
"x": 190,
"y": 260,
"wires": [
[
"853caafa45a3ed6a"
]
]
},
{
"id": "7cb7dff101dec369",
"type": "function",
"z": "36fa3994398c3c99",
"name": "function 3",
"func": "let rawData = msg.payload; // JSON-Daten\n\n// Sicherstellen, dass rawData ein Array ist\nlet dataArray = Array.isArray(rawData) ? rawData : [rawData];\n\n// Initialisiere das Dataset für den Chart\nlet dataset = {\n labels: [],\n series: [[]] // Leistung\n};\n\n// Letzte 50 Werte übernehmen\nlet lastEntries = dataArray.slice(-20);\n\nlastEntries.forEach(entry => {\n if (typeof entry === \"object\" && entry.timestamp && entry.leistung !== undefined) {\n dataset.labels.push(entry.timestamp); // ✅ Korrekt: Zeitstempel extrahieren\n dataset.series[0].push(parseFloat(entry.leistung)); // ✅ Leistung\n } else {\n node.warn(\"⚠️ Ungültige Daten: \" + JSON.stringify(entry));\n }\n});\n\nmsg.payload = dataset;\nreturn msg;\n",
"outputs": 1,
"timeout": 0,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 960,
"y": 260,
"wires": [
[
"a330ecd6d7a88ca6",
"cda824069da2144a"
]
]
},
{
"id": "853caafa45a3ed6a",
"type": "file in",
"z": "36fa3994398c3c99",
"name": "",
"filename": "C:\\Users\\Labor\\Desktop\\messwert.csv",
"filenameType": "str",
"format": "utf8",
"chunk": false,
"sendError": false,
"encoding": "utf8",
"allProps": false,
"x": 490,
"y": 260,
"wires": [
[
"38f0994dc9c1ccf4"
]
]
},
{
"id": "38f0994dc9c1ccf4",
"type": "csv",
"z": "36fa3994398c3c99",
"name": "csv zu JSON",
"spec": "rfc",
"sep": ",",
"hdrin": "",
"hdrout": "none",
"multi": "mult",
"ret": "\\r\\n",
"temp": "timestamp,leistung,luftfeuchte,temperatur",
"skip": "0",
"strings": true,
"include_empty_strings": false,
"include_null_values": "",
"x": 770,
"y": 260,
"wires": [
[
"7cb7dff101dec369"
]
]
},
{
"id": "a330ecd6d7a88ca6",
"type": "debug",
"z": "36fa3994398c3c99",
"name": "debug 7",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": true,
"complete": "payload",
"targetType": "msg",
"statusVal": "payload",
"statusType": "auto",
"x": 1180,
"y": 380,
"wires": []
},
{
"id": "cda824069da2144a",
"type": "ui_chart",
"z": "36fa3994398c3c99",
"name": "",
"group": "72214d4980ae2e55",
"order": 2,
"width": 0,
"height": 0,
"label": "chart",
"chartType": "line",
"legend": "true",
"xformat": "auto",
"interpolate": "linear",
"nodata": "",
"dot": false,
"ymin": "",
"ymax": "",
"removeOlder": 1,
"removeOlderPoints": "",
"removeOlderUnit": "3600",
"cutout": 0,
"useOneColor": false,
"useUTC": true,
"colors": [
"#1f77b4",
"#aec7e8",
"#ff7f0e",
"#2ca02c",
"#98df8a",
"#d62728",
"#ff9896",
"#9467bd",
"#c5b0d5"
],
"outputs": 1,
"useDifferentColor": false,
"className": "",
"x": 1250,
"y": 260,
"wires": [
[]
]
},
{
"id": "8553351e581deca0",
"type": "ui_spacer",
"z": "36fa3994398c3c99",
"name": "spacer",
"group": "72214d4980ae2e55",
"order": 4,
"width": 1,
"height": 1
},
{
"id": "0b082a4e23d14bae",
"type": "ui_spacer",
"z": "36fa3994398c3c99",
"name": "spacer",
"group": "72214d4980ae2e55",
"order": 4,
"width": 1,
"height": 1
},
{
"id": "72214d4980ae2e55",
"type": "ui_group",
"name": "Graph",
"tab": "7d7df438f2fb4675",
"order": 4,
"disp": true,
"width": 6,
"collapse": false,
"className": ""
},
{
"id": "7d7df438f2fb4675",
"type": "ui_tab",
"name": "Microgreens Zelt",
"icon": "dashboard",
"order": 7,
"disabled": false,
"hidden": false
}
]
This is the last debug message before the data is transferred to the chart:
{"labels":["2025-03-16T11:39:48.375Z","2025-03-16T12:39:48.395Z","2025-03-16T13:39:48.406Z","2025-03-16T14:39:48.417Z","2025-03-16T15:39:48.436Z","2025-03-16T16:39:48.451Z","2025-03-16T17:39:48.470Z","2025-03-16T18:39:48.478Z","2025-03-16T19:39:48.496Z","2025-03-16T20:39:48.513Z","2025-03-16T21:39:48.532Z","2025-03-16T22:39:48.552Z","2025-03-16T23:39:48.558Z","2025-03-17T00:39:48.572Z","2025-03-17T01:39:48.580Z","2025-03-17T02:39:48.593Z","2025-03-17T03:39:48.600Z","2025-03-17T04:39:48.613Z","2025-03-17T05:39:48.622Z","2025-03-17T06:39:48.716Z"],"series":[[324,321.8,326.8,332.2,324.7,325.1,330.4,322.4,322,66.9,65.8,66.9,67.7,65.3,68.4,66.6,64.8,65.3,68,66.4]]}