Hi, I use a dashboard switch to trigger the recording of data to a txt file. This part work.
Now I need help to append the timestamp to the filename.
I had a couple of problem that I partly solved.
First one. This is not similar to timestamping separetad pictures. In my case, once triggered, 1hz data are recorded in the file as long as the switch state is true. I need to append the timestamp to the filename only when I first trigger the switch. The flow below is a beginning to this. Every time I toggle the switch, the Change node not only output a true/false flow that control data recording but also output once the timestamp corresponding to the switch toggling time.
Then the convert time node format the timestamp to YYYY-MM-DD HH:MM:SS.
I would prefer YYYYMMDDHHMMSS but I don't understand how to do it. This is my first question.
The second aspect is to integrate this format timestamp into the associated filename. I actually rely on Path to store the data name DataB.txt in a folder. Instead I would like to obtain DataB_YYYYMMDDHHMMSS.txt
Can you help?
[
{
"id": "765d84d40cd1a292",
"type": "tab",
"label": "Flow 2",
"disabled": false,
"info": "",
"env": []
},
{
"id": "ad97e887ff5f0bc4",
"type": "ui_switch",
"z": "765d84d40cd1a292",
"name": "",
"label": "Record switch",
"tooltip": "",
"group": "2444546f087153a2",
"order": 11,
"width": 0,
"height": 0,
"passthru": true,
"decouple": "false",
"topic": "topic",
"topicType": "msg",
"style": "",
"onvalue": "true",
"onvalueType": "bool",
"onicon": "",
"oncolor": "green",
"offvalue": "false",
"offvalueType": "bool",
"officon": "",
"offcolor": "red",
"animate": false,
"className": "",
"x": 100,
"y": 60,
"wires": [
[
"ea6da3ad4c30ff74"
]
]
},
{
"id": "ea6da3ad4c30ff74",
"type": "change",
"z": "765d84d40cd1a292",
"name": "",
"rules": [
{
"t": "set",
"p": "record",
"pt": "flow",
"to": "payload",
"tot": "msg"
},
{
"t": "set",
"p": "payload",
"pt": "msg",
"to": "",
"tot": "date"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 290,
"y": 60,
"wires": [
[
"519172c2362d78e7"
]
]
},
{
"id": "519172c2362d78e7",
"type": "function",
"z": "765d84d40cd1a292",
"name": "Convert timestamp",
"func": "msg.payload = new Date().toISOString();\nmsg.payload = msg.payload.replace(/^(.*)T(.*)Z$/, \"$1 $2\"); // with the 'T' and 'Z' removed\nmsg.payload = msg.payload.substring(0, 19)\nmsg.topic = \"File_Time\"\nreturn msg;",
"outputs": 1,
"timeout": 0,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 490,
"y": 60,
"wires": [
[
"dc8f4120f9eb9cbc"
]
]
},
{
"id": "dc8f4120f9eb9cbc",
"type": "debug",
"z": "765d84d40cd1a292",
"name": "debug 2505",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": true,
"complete": "payload",
"targetType": "msg",
"statusVal": "payload",
"statusType": "auto",
"x": 690,
"y": 60,
"wires": []
},
{
"id": "982be7311e73e46e",
"type": "switch",
"z": "765d84d40cd1a292",
"name": "True/false",
"property": "record",
"propertyType": "flow",
"rules": [
{
"t": "true"
},
{
"t": "false"
}
],
"checkall": "true",
"repair": false,
"outputs": 2,
"x": 280,
"y": 180,
"wires": [
[
"6902b885793e5ec2"
],
[]
]
},
{
"id": "6902b885793e5ec2",
"type": "file",
"z": "765d84d40cd1a292",
"name": "",
"filename": "/data/dataB.txt",
"filenameType": "str",
"appendNewline": true,
"createDir": true,
"overwriteFile": "false",
"encoding": "utf8",
"x": 500,
"y": 160,
"wires": [
[
"da05ce0f2f25af33"
]
]
},
{
"id": "da05ce0f2f25af33",
"type": "debug",
"z": "765d84d40cd1a292",
"name": "debug 2506",
"active": true,
"tosidebar": true,
"console": true,
"tostatus": true,
"complete": "payload",
"targetType": "msg",
"statusVal": "payload",
"statusType": "auto",
"x": 700,
"y": 160,
"wires": []
},
{
"id": "e1e3bcdcf7dd2717",
"type": "inject",
"z": "765d84d40cd1a292",
"name": "Data In",
"props": [
{
"p": "payload"
},
{
"p": "topic",
"vt": "str"
}
],
"repeat": "1",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "",
"payload": "this is my data to be saved in the file",
"payloadType": "str",
"x": 100,
"y": 180,
"wires": [
[
"982be7311e73e46e"
]
]
},
{
"id": "2444546f087153a2",
"type": "ui_group",
"name": "Default",
"tab": "8e29298fdb5d2d76",
"order": 1,
"disp": true,
"width": "12",
"collapse": false,
"className": ""
},
{
"id": "8e29298fdb5d2d76",
"type": "ui_tab",
"name": "Home",
"icon": "dashboard",
"disabled": false,
"hidden": false
}
]
Thank you