Hi all. Thank you for assisting me. I did some further investigation by now and have more details now.
I followed your advice(s) and implemented a simple test flow including primitive data types. Voilá, I can see the primitive data type in the global.json file, but not the map data type!
The file looks like this:
{
"sensorDevices": {},
"simpleVar": "sVar=3",
"mapVar": {}
}
Please ignore the sensorDevices for now. I just did not want to change anything in my reports.
You can see the test flow here:
[
{
"id": "55aa4010d6d3a95c",
"type": "inject",
"z": "fe0c0f2c10548c43",
"name": "",
"props": [
{
"p": "payload"
},
{
"p": "topic",
"vt": "str"
}
],
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "",
"payload": "",
"payloadType": "date",
"x": 100,
"y": 780,
"wires": [
[
"e799324ef7b16231",
"a477bc90d0e43edf"
]
]
},
{
"id": "e799324ef7b16231",
"type": "function",
"z": "fe0c0f2c10548c43",
"name": "SetIncrGFCtest",
"func": "/*\nSet and increment global context variables\n*/\nconst me = \"[\" + node.name + \"] \";\n//node.warn(me);\n\n// Get global context simple var or create it\nvar simpleVar = global.get(\"simpleVar\", \"file\") || \"sVar=-1\";\n// Init or increment simpleVar\nlet aSV = simpleVar.split(\"=\");\nlet inx = Number(aSV[1]) + 1;\nsimpleVar = aSV[0] + \"=\" + inx;\n// Write back to global. context\nglobal.set(\"simpleVar\", simpleVar, \"file\");\nnode.warn(me + \"simpleVar = \" + simpleVar);\n\n// Get global context map var or create it\nvar mapVar = global.get(\"mapVar\", \"file\") || new Map;\nif (mapVar === undefined) {\n node.warn(me + \"mapVar === undefined\");\n global.set(\"mapVar\", null, \"file\");\n mapVar = new Map()\n};\n// Increment entry\nlet elemName = \"firstElem\";\nlet elemVal = 0;\nnode.warn(me + \"mapVar.has(elemName) = \" + mapVar.has(elemName));\nif (mapVar.has(elemName)) {\n elemVal = mapVar.get(elemName);\n elemVal++\n}\nmapVar.set(elemName, elemVal);\n// Write back to global. context\nglobal.set(\"mapVar\", mapVar, \"file\");\nnode.warn(me + \"elemVal = \" + elemVal);\n\n//Save in msg too for inspection\nmsg.simpleVar = simpleVar;\nmsg.mapVar = mapVar;\n\nnode.status({ fill: \"green\", shape: \"dot\", text: mapVar.get(\"firstElem\") + \", \" + simpleVar});\n\nreturn msg;",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 280,
"y": 780,
"wires": [
[
"d66a2aa90b3e0aeb"
]
]
},
{
"id": "d66a2aa90b3e0aeb",
"type": "debug",
"z": "fe0c0f2c10548c43",
"name": "full",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "true",
"targetType": "full",
"statusVal": "",
"statusType": "auto",
"x": 445,
"y": 780,
"wires": [],
"l": false
},
{
"id": "a477bc90d0e43edf",
"type": "function",
"z": "fe0c0f2c10548c43",
"name": "ReadGCVtest",
"func": "/*\nRead global context variables\n*/\nconst me = \"[\" + node.name + \"] \";\n//node.warn(me);\n\n// Get global context map var if available\nvar mapVar = global.get(\"mapVar\", \"file\");\nif (mapVar === undefined) {\n node.warn(me + \"mapVar undefined\");\n};\nlet elemName = \"firstElem\";\nlet elemVal = mapVar.get(elemName);\nnode.warn(me + \"elemVal = \" + elemVal);\n\n// Get global context simple var if available\nvar simpleVar = global.get(\"simpleVar\", \"file\");\nif (simpleVar === undefined) {\n node.warn(me + \"simpleVar undefined\");\n};\nnode.warn(me + \"simpleVar = \" + simpleVar);\n\nnode.status({ fill: \"green\", shape: \"dot\", text: mapVar.get(elemName) + \", \" + simpleVar });\n\nreturn msg;",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 280,
"y": 840,
"wires": [
[
"d30739a470e34f95"
]
]
},
{
"id": "d30739a470e34f95",
"type": "debug",
"z": "fe0c0f2c10548c43",
"name": "full",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "true",
"targetType": "full",
"statusVal": "",
"statusType": "auto",
"x": 445,
"y": 840,
"wires": [],
"l": false
}
]
I would be interested to see if you reproduce the behaviour. If so, has anybody any idea how to achieve saving map data in the global context file? Are maps really not serialisable? I would not really like to reprogram everything without using maps. In addition I would not know now which other data types might possibly not be supported ...
@zenofmud I think I did use ``` in my posts properly. It looks OK for me in the browser?! Am I missing something? How about the others reading this?
As always, greeting and thanks to all of you!