I have a graph that saves JSON data to a text on a Raspberry Pi and that works as it should.
When I restart Node-Red I want to retrieve that data and repopulate the graph.
I'm able to fetch the data but I get an error when I try to put it in a graph.
"Unexpected token [ in JSON at position 4747"
Is this the best way to do this? Would it be better to store/retrieve the data in MYSQL? CSV file?
Here is my flow
[
{
"id": "13f270994f6c5e18",
"type": "ui_button",
"z": "30dc9a8aad2d70a1",
"name": "",
"group": "212b7f06.b4731",
"order": 2,
"width": "2",
"height": "1",
"passthru": false,
"label": "Inject",
"tooltip": "",
"color": "",
"bgcolor": "",
"className": "",
"icon": "",
"payload": "",
"payloadType": "str",
"topic": "",
"topicType": "str",
"x": 490,
"y": 920,
"wires": [
[
"fbdb6408e9583ccf"
]
]
},
{
"id": "c7d0cd72e5c99dea",
"type": "ui_button",
"z": "30dc9a8aad2d70a1",
"name": "",
"group": "212b7f06.b4731",
"order": 4,
"width": "2",
"height": "1",
"passthru": false,
"label": "restore",
"tooltip": "",
"color": "",
"bgcolor": "",
"className": "",
"icon": "",
"payload": "",
"payloadType": "str",
"topic": "",
"topicType": "str",
"x": 480,
"y": 1040,
"wires": [
[
"39c67627238ee8ec"
]
]
},
{
"id": "fbdb6408e9583ccf",
"type": "random",
"z": "30dc9a8aad2d70a1",
"name": "",
"low": "0",
"high": "10",
"inte": "true",
"property": "payload",
"x": 640,
"y": 920,
"wires": [
[
"db55d33591c4fad2"
]
]
},
{
"id": "db55d33591c4fad2",
"type": "ui_chart",
"z": "30dc9a8aad2d70a1",
"name": "",
"group": "212b7f06.b4731",
"order": 1,
"width": 0,
"height": 0,
"label": "chart",
"chartType": "line",
"legend": "false",
"xformat": "HH:mm:ss",
"interpolate": "bezier",
"nodata": "",
"ymin": "",
"ymax": "",
"removeOlder": "15",
"removeOlderPoints": "100",
"removeOlderUnit": "60",
"cutout": 0,
"outputs": 2,
"x": 790,
"y": 920,
"wires": [
[],
[
"50191a22b99f5085"
]
]
},
{
"id": "50191a22b99f5085",
"type": "json",
"z": "30dc9a8aad2d70a1",
"name": "",
"property": "payload",
"action": "",
"pretty": false,
"x": 930,
"y": 920,
"wires": [
[
"81a4cad39186b94a"
]
]
},
{
"id": "d118be10ab2db950",
"type": "json",
"z": "30dc9a8aad2d70a1",
"name": "Convert to JSON",
"property": "payload",
"action": "",
"pretty": true,
"x": 970,
"y": 1040,
"wires": [
[
"2b34cec3bd204b99"
]
]
},
{
"id": "81a4cad39186b94a",
"type": "function",
"z": "30dc9a8aad2d70a1",
"name": "",
"func": "if (msg.topic === \"save\") {\n msg.payload = context.last;\n return msg;\n}\nelse {\n context.last = msg.payload;\n}\nreturn null;",
"outputs": 1,
"noerr": 0,
"x": 660,
"y": 980,
"wires": [
[
"f299d075174ca8bb"
]
]
},
{
"id": "f61f82547089abcd",
"type": "ui_button",
"z": "30dc9a8aad2d70a1",
"name": "",
"group": "212b7f06.b4731",
"order": 3,
"width": "2",
"height": "1",
"label": "save",
"color": "",
"bgcolor": "",
"icon": "",
"payload": "",
"payloadType": "str",
"topic": "save",
"x": 480,
"y": 980,
"wires": [
[
"81a4cad39186b94a"
]
]
},
{
"id": "f299d075174ca8bb",
"type": "file",
"z": "30dc9a8aad2d70a1",
"name": "",
"filename": "/home/pi/scripts/chartData/chart.log",
"filenameType": "str",
"appendNewline": true,
"createDir": false,
"overwriteFile": "false",
"encoding": "setbymsg",
"x": 910,
"y": 980,
"wires": [
[]
]
},
{
"id": "39c67627238ee8ec",
"type": "file in",
"z": "30dc9a8aad2d70a1",
"name": "",
"filename": "/home/pi/scripts/chartData/chart.log",
"filenameType": "str",
"format": "utf8",
"encoding": "none",
"allProps": false,
"x": 700,
"y": 1040,
"wires": [
[
"d118be10ab2db950",
"8d6f0176364cb65b"
]
]
},
{
"id": "2b34cec3bd204b99",
"type": "debug",
"z": "30dc9a8aad2d70a1",
"name": "chart debug",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "payload",
"targetType": "msg",
"statusVal": "",
"statusType": "auto",
"x": 1170,
"y": 1040,
"wires": []
},
{
"id": "8d6f0176364cb65b",
"type": "ui_chart",
"z": "30dc9a8aad2d70a1",
"name": "",
"group": "212b7f06.b4731",
"order": 1,
"width": 0,
"height": 0,
"label": "Restored Data",
"chartType": "line",
"legend": "false",
"xformat": "HH:mm:ss",
"interpolate": "bezier",
"nodata": "",
"dot": false,
"ymin": "",
"ymax": "",
"removeOlder": "15",
"removeOlderPoints": "100",
"removeOlderUnit": "60",
"cutout": 0,
"useOneColor": false,
"useUTC": false,
"colors": [
"#1f77b4",
"#aec7e8",
"#ff7f0e",
"#2ca02c",
"#98df8a",
"#d62728",
"#ff9896",
"#9467bd",
"#c5b0d5"
],
"outputs": 1,
"useDifferentColor": false,
"className": "",
"x": 1140,
"y": 1140,
"wires": [
[]
]
},
{
"id": "212b7f06.b4731",
"type": "ui_group",
"name": "Gauge",
"tab": "e7f7ff66.2de07",
"order": 2,
"disp": true,
"width": "6"
},
{
"id": "e7f7ff66.2de07",
"type": "ui_tab",
"name": "Restore",
"icon": "dashboard"
}
]```