Hey Guys,
i have a problem with node-red and the dashboard.
I have a working flow, which shows me the values of scanned RFID-TAGs (TagNr, Count, Time)
I used a template-node to visualize the received Data. It looked like this:
Here's the flow:
[
{
"id": "aeaac8000d31373d",
"type": "tcp in",
"z": "bda3ee9e841198c7",
"name": "",
"server": "server",
"host": "192.168.40.46",
"port": "10011",
"datamode": "stream",
"datatype": "buffer",
"newline": "",
"topic": "",
"trim": false,
"base64": false,
"tls": "",
"x": 110,
"y": 260,
"wires": [
[
"ecb02aeb341c548a"
]
]
},
{
"id": "2c52e3c9ed712f92",
"type": "debug",
"z": "bda3ee9e841198c7",
"name": "",
"active": true,
"tosidebar": true,
"console": true,
"tostatus": false,
"complete": "payload",
"targetType": "msg",
"statusVal": "",
"statusType": "auto",
"x": 920,
"y": 220,
"wires": []
},
{
"id": "53bf4121b438bbbc",
"type": "ui_button",
"z": "bda3ee9e841198c7",
"name": "",
"group": "dc3e8cbe2c286a9c",
"order": 1,
"width": 0,
"height": 0,
"passthru": false,
"label": "Read/Clear",
"tooltip": "",
"color": "",
"bgcolor": "",
"className": "",
"icon": "",
"payload": "",
"payloadType": "str",
"topic": "topic",
"topicType": "msg",
"x": 250,
"y": 320,
"wires": [
[
"90abb872bda98f34",
"f9478d55658941e3"
]
]
},
{
"id": "90abb872bda98f34",
"type": "function",
"z": "bda3ee9e841198c7",
"name": "function 2-Reset",
"func": "if (msg.payload === \"clearDataArray\") {\n flow.set('dataArray', []);\n node.warn('Data array cleared.');\n return null;\n} else {\n const tagNr = msg.payload.slice(16, 22).toString('hex', 0, 6);\n const timestamp = Date.now();\n if (!flow.get('dataArray')) {\n flow.set('dataArray', []);\n }\n\n const dataArray = flow.get('dataArray');\n const indexOfCurrentData = dataArray.findIndex((data) => data.tagNr === tagNr);\n\n if (indexOfCurrentData === -1) {\n dataArray.push({\n tagNr,\n timestamp: new Date(timestamp).toLocaleString(),\n });\n } else {\n dataArray[indexOfCurrentData].timestamp = new Date(timestamp).toLocaleString();\n }\n\n flow.set('dataArray', dataArray);\n\n msg.payload = JSON.stringify(dataArray);\n \n flow.set('dataArray', []);\n return msg;\n}\n",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 460,
"y": 320,
"wires": [
[
"4388f20fc0dc5a81"
]
]
},
{
"id": "ecb02aeb341c548a",
"type": "function",
"z": "bda3ee9e841198c7",
"name": "Funktion Zähler+Bereinigung",
"func": "const tagNr = msg.payload.slice(16, 22).toString('hex', 0, 6);\nconst timestamp = Date.now();\n\nif (!flow.get('tagCounts')) {\n flow.set('tagCounts', {});\n}\n\nconst tagCounts = flow.get('tagCounts');\ntagCounts[tagNr] = (tagCounts[tagNr] || 0) + 1;\n\nif (!flow.get('dataArray')) {\n flow.set('dataArray', []);\n}\n\nconst dataArray = flow.get('dataArray');\nconst indexOfCurrentData = dataArray.findIndex((data) => data.tagNr === tagNr);\n\nif (indexOfCurrentData === -1) {\n dataArray.push({\n tagNr,\n count: tagCounts[tagNr],\n timestamp: new Date(timestamp).toLocaleString(),\n });\n} else {\n dataArray[indexOfCurrentData].count = tagCounts[tagNr];\n dataArray[indexOfCurrentData].timestamp = new Date(timestamp).toLocaleString();\n}\n\nflow.set('dataArray', dataArray);\nflow.set('tagCounts', tagCounts);\n\nmsg.payload = dataArray;\nreturn msg;\n",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 360,
"y": 260,
"wires": [
[
"53bf4121b438bbbc"
]
]
},
{
"id": "f9478d55658941e3",
"type": "function",
"z": "bda3ee9e841198c7",
"name": "function 3-Reset counter",
"func": "flow.set('dataArray', []);\nflow.set('tagCounts', {});\nnode.warn('Data array and tagCounts cleared.');\nreturn null;\n",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 450,
"y": 400,
"wires": [
[
"4388f20fc0dc5a81"
]
]
},
{
"id": "4388f20fc0dc5a81",
"type": "ui_template",
"z": "bda3ee9e841198c7",
"group": "dc3e8cbe2c286a9c",
"name": "",
"order": 1,
"width": "6",
"height": "14",
"format": "<table>\n <thead>\n <tr>\n <th>Tag-Nr</th>\n <th>Count</th>\n <th>Time</th>\n </tr>\n </thead>\n <tbody>\n <tr ng-repeat=\"data in msg.payload\">\n <td>{{$index + 1}}</td>\n <td>{{data.tagNr}}</td>\n <td>{{data.count}}</td>\n <td>{{data.timestamp}}</td>\n </tr>\n </tbody>\n</table>\n\n\n\n<div ng-bind-html=\"msg.payload\"></div>\n\n",
"storeOutMessages": true,
"fwdInMessages": true,
"resendOnRefresh": false,
"templateScope": "local",
"className": "",
"x": 700,
"y": 220,
"wires": [
[
"2c52e3c9ed712f92"
]
]
},
{
"id": "dc3e8cbe2c286a9c",
"type": "ui_group",
"name": "Scanned TAGs",
"tab": "9dadb6060f5c7071",
"order": 1,
"disp": true,
"width": "10",
"collapse": false,
"className": ""
},
{
"id": "9dadb6060f5c7071",
"type": "ui_tab",
"name": "RFID-Gate, oi!",
"icon": "dashboard",
"order": 1,
"disabled": false,
"hidden": false
}
]
but instead of a template-node, i want to use a table-node, with this flow:
[
{
"id": "283c27741654954d",
"type": "function",
"z": "bda3ee9e841198c7",
"name": "function 5",
"func": "const tagNr = msg.payload\nconst tagCounts = flow.get('tagCounts');\nconst timestamp = Date.now();\n\nmsg.payload = [\n {\n \"tagNr\": tagNr,\n \"tagCounts\": tagCounts,\n \"timestamp\": new Date(timestamp).toLocaleString()\n }\n];\n\nreturn msg;\n",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 720,
"y": 180,
"wires": [
[
"7235bcc508b0a893"
]
]
},
{
"id": "dbfe045eead58233",
"type": "tcp in",
"z": "bda3ee9e841198c7",
"name": "",
"server": "server",
"host": "192.168.40.46",
"port": "10011",
"datamode": "stream",
"datatype": "buffer",
"newline": "",
"topic": "",
"trim": false,
"base64": false,
"tls": "",
"x": 130,
"y": 240,
"wires": [
[
"948f310e026cd3c3"
]
]
},
{
"id": "3c4752674f137c9f",
"type": "debug",
"z": "bda3ee9e841198c7",
"name": "",
"active": true,
"tosidebar": true,
"console": true,
"tostatus": false,
"complete": "payload",
"targetType": "msg",
"statusVal": "",
"statusType": "auto",
"x": 935,
"y": 165,
"wires": []
},
{
"id": "02f235b402b49d99",
"type": "ui_button",
"z": "bda3ee9e841198c7",
"name": "",
"group": "dc3e8cbe2c286a9c",
"order": 1,
"width": 0,
"height": 0,
"passthru": false,
"label": "Read/Clear",
"tooltip": "",
"color": "",
"bgcolor": "",
"className": "",
"icon": "",
"payload": "",
"payloadType": "str",
"topic": "topic",
"topicType": "msg",
"x": 370,
"y": 240,
"wires": [
[
"504335430f688fd4",
"20ed885051473bc6"
]
]
},
{
"id": "504335430f688fd4",
"type": "function",
"z": "bda3ee9e841198c7",
"name": "function 2-Reset",
"func": "if (msg.payload === \"clearDataArray\") {\n flow.set('dataArray', []);\n node.warn('Data array cleared.');\n return null;\n} else {\n const tagNr = msg.payload.slice(16, 22).toString('hex', 0, 6);\n const timestamp = Date.now();\n if (!flow.get('dataArray')) {\n flow.set('dataArray', []);\n }\n\n const dataArray = flow.get('dataArray');\n const indexOfCurrentData = dataArray.findIndex((data) => data.tagNr === tagNr);\n\n if (indexOfCurrentData === -1) {\n dataArray.push({\n tagNr,\n timestamp: new Date(timestamp).toLocaleString(),\n });\n } else {\n dataArray[indexOfCurrentData].timestamp = new Date(timestamp).toLocaleString();\n }\n\n flow.set('dataArray', dataArray);\n\n msg.payload = JSON.stringify(dataArray);\n \n flow.set('dataArray', []);\n return msg;\n}\n",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 610,
"y": 240,
"wires": [
[
"283c27741654954d"
]
]
},
{
"id": "948f310e026cd3c3",
"type": "function",
"z": "bda3ee9e841198c7",
"name": "Funktion Zähler+Bereinigung",
"func": "const tagNr = msg.payload.slice(16, 22).toString('hex', 0, 6);\nconst timestamp = Date.now();\n\nif (!flow.get('tagCounts')) {\n flow.set('tagCounts', {});\n}\n\nconst tagCounts = flow.get('tagCounts');\ntagCounts[tagNr] = (tagCounts[tagNr] || 0) + 1;\n\nif (!flow.get('dataArray')) {\n flow.set('dataArray', []);\n}\n\nconst dataArray = flow.get('dataArray');\nconst indexOfCurrentData = dataArray.findIndex((data) => data.tagNr === tagNr);\n\nif (indexOfCurrentData === -1) {\n dataArray.push({\n tagNr,\n count: tagCounts[tagNr],\n timestamp: new Date(timestamp).toLocaleString(),\n });\n} else {\n dataArray[indexOfCurrentData].count = tagCounts[tagNr];\n dataArray[indexOfCurrentData].timestamp = new Date(timestamp).toLocaleString();\n}\n\nflow.set('dataArray', dataArray);\nflow.set('tagCounts', tagCounts);\n\nmsg.payload = dataArray;\nreturn msg;\n",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 165,
"y": 315,
"wires": [
[
"02f235b402b49d99"
]
]
},
{
"id": "20ed885051473bc6",
"type": "function",
"z": "bda3ee9e841198c7",
"name": "function 3-Reset counter",
"func": "flow.set('dataArray', []);\nflow.set('tagCounts', {});\nnode.warn('Data array and tagCounts cleared.');\nreturn null;\n",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 460,
"y": 315,
"wires": [
[]
]
},
{
"id": "7235bcc508b0a893",
"type": "ui_table",
"z": "bda3ee9e841198c7",
"group": "dc3e8cbe2c286a9c",
"name": "",
"order": 2,
"width": 0,
"height": 0,
"columns": [],
"outputs": 1,
"cts": true,
"x": 820,
"y": 255,
"wires": [
[
"3c4752674f137c9f"
]
]
},
{
"id": "dc3e8cbe2c286a9c",
"type": "ui_group",
"name": "Scanned TAGs",
"tab": "9dadb6060f5c7071",
"order": 1,
"disp": true,
"width": "6",
"collapse": false,
"className": ""
},
{
"id": "9dadb6060f5c7071",
"type": "ui_tab",
"name": "RFID-Gate, oi!",
"icon": "dashboard",
"order": 1,
"disabled": false,
"hidden": false
}
]
but i dont receive any data, exept the date. Now my dashboard looks like this:
Does anyone of you know why this problem occurs?
Thanks in advance