Linux command node for dates

i'm connected to a plc and am using avrdude to save firmware. i'm using a linux command node with the following syntax, and i want to add the date to the filename, so i know when the backup was made.
ie:currently downloading as backup.hex i want backup20220714.hex

node contains as command: sudo avrdude -v -patmega2560 -cwiring -P/dev/ttyACM0 -b115200 -D -Uflash:r:/home/pi/backup.hex:i

i am also writing firmware from a source and want to rename it (again with the date appended, so it can't accidentally be uploaded again in the future.
ie: my read-in takes firmware.hex, i want to rename to firmware20220714.hex after it uploads

node contains as command:
sudo avrdude -v -patmega2560 -cwiring -P/dev/ttyACM0 -b115200 -D -Uflash:w:/home/pi/firmware.hex:i

Is there a question here? What part are you having bother with?

To make dynamic file names use moment (or change node) to generate the date part. Use a change node or function node to generate the msg.filename - put the data in msg.payload - send it to a file write node.

For generating the date part there are many options
function code new Date().toISOString().replace(/-/g,"").substring(0,8) --> "20220714"
change node (JSONata) $moment().format("YYYYMMDD") --> "20220714"

i'm using a linux command node, and i can generate the date in a function node, but i can't get that variable into the linxu command node command i have posted. (saving firmware)

second question was renaming file after i upload it to plc using hte second command (again linux command node because i'm running avrdude to upload/backup firmware on a plc)

here are the 2 nodes

[
    {
        "id": "f67bf870512d4292",
        "type": "exec",
        "z": "05078416059076a6",
        "command": "sudo  avrdude -v -patmega2560 -cwiring -P/dev/ttyACM0 -b115200 -D -Uflash:r:/home/pi/backup.hex:i",
        "addpay": false,
        "append": "",
        "useSpawn": "true",
        "timer": "",
        "winHide": false,
        "oldrc": false,
        "name": "firmwareCMDsave",
        "x": 2490,
        "y": 240,
        "wires": [
            [],
            [],
            []
        ]
    },
    {
        "id": "6c5520274b9bf30c",
        "type": "exec",
        "z": "05078416059076a6",
        "command": "sudo  avrdude -v -patmega2560 -cwiring -P/dev/ttyACM0 -b115200 -D -Uflash:w:/home/pi/firmware.hex:i",
        "addpay": false,
        "append": "",
        "useSpawn": "true",
        "timer": "",
        "winHide": false,
        "oldrc": false,
        "name": "firmwareCMDwrite",
        "x": 2490,
        "y": 400,
        "wires": [
            [],
            [],
            []
        ]
    }
]

If you want the command details to be dynamic then leave the command field in the exec node empty, select Add Payload and pass the command in msg.payload. Then you can build the payload however you like, by using a Template node for example.

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.