Hello Cameo69,
I've used your proposal, as it (to me) seems a lot simpler. But still no luck.
I can send an attachment (created by the "Auto Logger") if I specify it manually.
As soon as I try to automate the sending of an attachment from the location generated by the "Auto Logger", this falls apart as the debug on the email node shows the msg.filename does not carry through, it returns "undefined" and the email does not have an attachment.
I did read up about msg.attachment being used by the email node, however, from what I can see this is "translated" to msg.filename.
Can you or any members offer me any advice on where to look next?
[
{
"id": "f2c6efab076989ba",
"type": "comment",
"z": "516ef0a12415588a",
"name": "Auto Logger",
"info": "https://www.youtube.com/watch?v=E2aBIqssQLM",
"x": 1390,
"y": 80,
"wires": []
},
{
"id": "bedf609f70c6d011",
"type": "debug",
"z": "516ef0a12415588a",
"name": "",
"active": false,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "false",
"x": 2290,
"y": 200,
"wires": []
},
{
"id": "2c97982bef6b85e5",
"type": "switch",
"z": "516ef0a12415588a",
"name": "",
"property": "$count(msg.payload)",
"propertyType": "jsonata",
"rules": [
{
"t": "eq",
"v": "0",
"vt": "num"
},
{
"t": "else"
}
],
"checkall": "true",
"repair": false,
"outputs": 2,
"x": 2269,
"y": 291,
"wires": [
[
"52b1ca19298874cd"
],
[
"427b5eae31792d01"
]
]
},
{
"id": "c174a28ada387d00",
"type": "csv",
"z": "516ef0a12415588a",
"name": "",
"sep": ";",
"hdrin": "",
"hdrout": "once",
"multi": "one",
"ret": "\\n",
"temp": "TimeStamp",
"skip": "0",
"strings": true,
"include_empty_strings": false,
"include_null_values": false,
"x": 2609,
"y": 271,
"wires": [
[
"467a7deec3b7c73c"
]
]
},
{
"id": "467a7deec3b7c73c",
"type": "file",
"z": "516ef0a12415588a",
"name": "",
"filename": "filename",
"filenameType": "msg",
"appendNewline": false,
"createDir": true,
"overwriteFile": "false",
"encoding": "none",
"x": 2779,
"y": 271,
"wires": [
[]
]
},
{
"id": "06c5c57b19f66235",
"type": "csv",
"z": "516ef0a12415588a",
"name": "",
"sep": ";",
"hdrin": "",
"hdrout": "none",
"multi": "one",
"ret": "\\n",
"temp": "TimeStamp",
"skip": "0",
"strings": true,
"include_empty_strings": false,
"include_null_values": false,
"x": 2609,
"y": 311,
"wires": [
[
"467a7deec3b7c73c"
]
]
},
{
"id": "52b1ca19298874cd",
"type": "change",
"z": "516ef0a12415588a",
"name": "Get file content",
"rules": [
{
"t": "set",
"p": "payload",
"pt": "msg",
"to": "filecontent",
"tot": "msg"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 2469,
"y": 271,
"wires": [
[
"c174a28ada387d00"
]
]
},
{
"id": "427b5eae31792d01",
"type": "change",
"z": "516ef0a12415588a",
"name": "Get file content",
"rules": [
{
"t": "set",
"p": "payload",
"pt": "msg",
"to": "filecontent",
"tot": "msg"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 2469,
"y": 311,
"wires": [
[
"06c5c57b19f66235"
]
]
},
{
"id": "f67ced8bc8f39445",
"type": "fs-file-lister",
"z": "516ef0a12415588a",
"name": "",
"start": "/home/pi/datalog/",
"pattern": "",
"folders": "*",
"hidden": true,
"lstype": "files",
"path": true,
"single": true,
"depth": 0,
"stat": true,
"showWarnings": false,
"x": 2020,
"y": 200,
"wires": [
[
"bedf609f70c6d011",
"2c97982bef6b85e5"
]
]
},
{
"id": "1073ba61d10f141d",
"type": "function",
"z": "516ef0a12415588a",
"name": "data",
"func": "//if (mesg.topic === \"temp_sp_500_3\") {\nvar now = new Date();\nmsg.payload = {\n \"TimeStamp\" : flow.get(\"temp_sp_500_3\")\n}\n//}\nreturn msg;",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 1550,
"y": 140,
"wires": [
[
"0ab9950b7eddc2fa",
"ae784c99b23d6277"
]
]
},
{
"id": "0ab9950b7eddc2fa",
"type": "debug",
"z": "516ef0a12415588a",
"name": "",
"active": false,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "true",
"targetType": "full",
"statusVal": "",
"statusType": "auto",
"x": 1710,
"y": 140,
"wires": []
},
{
"id": "ae784c99b23d6277",
"type": "function",
"z": "516ef0a12415588a",
"name": "Filename generator",
"func": "// Get the current time and convert it to text\nvar now = new Date();\nvar yyyy = now.getFullYear();\nvar mm = now.getMonth() < 9 ? \"0\" + (now.getMonth() + 1) : (now.getMonth() + 1); // getMonth() is zero-based\nvar dd = now.getDate() < 10 ? \"0\" + now.getDate() : now.getDate();\nvar hh = now.getHours() < 10 ? \"0\" + now.getHours() : now.getHours();\nvar mmm = now.getMinutes() < 10 ? \"0\" + now.getMinutes() : now.getMinutes();\nvar ss = now.getSeconds() < 10 ? \"0\" + now.getSeconds() : now.getSeconds();\n\n// Generate out file name pattern\nmsg.fname = \"Peter_\"+ yyyy + mm + dd + \".csv\";\n// Full filename with path for the file node later\nmsg.filename = \"/home/pi/datalog/\"+ msg.fname;\n\n// We save the current payload into a different place on the msg object\nmsg.filecontent = msg.payload;\n\n// We are passing the file name search pattern to fs node to tell us if the file exists or not\nmsg.payload = {\"pattern\":msg.fname};\n\nnode.status({fill:\"blue\",shape:\"ring\",text:msg.fname});\nreturn msg;",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 1750,
"y": 200,
"wires": [
[
"f67ced8bc8f39445",
"b23c17ba7a16c626",
"eba83855da952a33"
]
]
},
{
"id": "34f4337b338d4461",
"type": "inject",
"z": "516ef0a12415588a",
"name": "",
"props": [
{
"p": "payload"
}
],
"repeat": "5",
"crontab": "",
"once": true,
"onceDelay": 0.1,
"topic": "",
"payload": "",
"payloadType": "date",
"x": 1390,
"y": 140,
"wires": [
[
"1073ba61d10f141d"
]
]
},
{
"id": "90f8ecd7dacd7f43",
"type": "inject",
"z": "516ef0a12415588a",
"name": "Scheduled Trigger",
"props": [
{
"p": "payload"
},
{
"p": "topic",
"vt": "str"
}
],
"repeat": "36000",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "Subjectline Datalog",
"payload": "",
"payloadType": "date",
"x": 1420,
"y": 480,
"wires": [
[
"dddd6ec2987b97d0",
"eba83855da952a33",
"b9603c2529d42790"
]
]
},
{
"id": "b9603c2529d42790",
"type": "file in",
"z": "516ef0a12415588a",
"name": "",
"filename": "/home/pi/datalog/Peter_20230226.csv",
"filenameType": "str",
"format": "",
"chunk": false,
"sendError": false,
"encoding": "none",
"allProps": false,
"x": 1810,
"y": 780,
"wires": [
[
"a80c5ec5f294e8e5",
"0ce04207c238e1ba"
]
]
},
{
"id": "0ce04207c238e1ba",
"type": "e-mail",
"z": "516ef0a12415588a",
"d": true,
"server": "ahosting.com",
"port": "465",
"secure": true,
"tls": true,
"name": "mail@gmail.com",
"dname": "SendMail Node",
"x": 2300,
"y": 780,
"wires": []
},
{
"id": "a80c5ec5f294e8e5",
"type": "debug",
"z": "516ef0a12415588a",
"name": "debug 2",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "filename",
"targetType": "msg",
"statusVal": "",
"statusType": "auto",
"x": 2100,
"y": 860,
"wires": []
},
{
"id": "b23c17ba7a16c626",
"type": "debug",
"z": "516ef0a12415588a",
"name": "debug 3",
"active": false,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "filename",
"targetType": "msg",
"statusVal": "",
"statusType": "auto",
"x": 2020,
"y": 280,
"wires": []
},
{
"id": "eba83855da952a33",
"type": "function",
"z": "516ef0a12415588a",
"name": "",
"func": "if (msg.filename) {\n context.set('filename', msg.filename);\n}\n\nif (msg.payload > 0) {\n let filename = context.get('filename') || \"\";\n msg.payload = filename;\n return msg;\n}\n",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 2080,
"y": 480,
"wires": [
[
"05af7840011df897",
"2eeeeec2d102eecf",
"bfc54ccad06088ba",
"c39c8092cd03705c"
]
]
},
{
"id": "c65ab5a1ff7eea6c",
"type": "inject",
"z": "516ef0a12415588a",
"d": true,
"name": "",
"props": [
{
"p": "payload"
}
],
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "",
"payload": "",
"payloadType": "date",
"x": 1820,
"y": 440,
"wires": [
[
"eba83855da952a33"
]
]
},
{
"id": "e68c6e63794480a1",
"type": "inject",
"z": "516ef0a12415588a",
"d": true,
"name": "filename",
"props": [
{
"p": "payload"
},
{
"p": "filename",
"v": "/my_log_file.log",
"vt": "str"
}
],
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "",
"payload": "0",
"payloadType": "num",
"x": 1820,
"y": 540,
"wires": [
[
"eba83855da952a33"
]
]
},
{
"id": "05af7840011df897",
"type": "debug",
"z": "516ef0a12415588a",
"name": "",
"active": false,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "payload",
"targetType": "msg",
"statusVal": "",
"statusType": "auto",
"x": 2310,
"y": 540,
"wires": []
},
{
"id": "dddd6ec2987b97d0",
"type": "debug",
"z": "516ef0a12415588a",
"name": "debug 4",
"active": false,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "filename",
"targetType": "msg",
"statusVal": "",
"statusType": "auto",
"x": 1640,
"y": 400,
"wires": []
},
{
"id": "2eeeeec2d102eecf",
"type": "e-mail",
"z": "516ef0a12415588a",
"d": true,
"server": "hosting.com",
"port": "465",
"secure": true,
"tls": false,
"name": "mail@gmail.com",
"dname": "SendMail Node",
"credentials": {},
"x": 2300,
"y": 480,
"wires": []
},
{
"id": "bfc54ccad06088ba",
"type": "debug",
"z": "516ef0a12415588a",
"name": "msg.filename",
"active": false,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "filename",
"targetType": "msg",
"statusVal": "",
"statusType": "auto",
"x": 2310,
"y": 600,
"wires": []
},
{
"id": "c39c8092cd03705c",
"type": "debug",
"z": "516ef0a12415588a",
"name": "msg.topic",
"active": false,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "topic",
"targetType": "msg",
"statusVal": "",
"statusType": "auto",
"x": 2300,
"y": 660,
"wires": []
},
{
"id": "8a9bd5d150854882",
"type": "comment",
"z": "516ef0a12415588a",
"name": "Send Attachment",
"info": "",
"x": 1400,
"y": 360,
"wires": []
},
{
"id": "ae34cf2f677e0369",
"type": "comment",
"z": "516ef0a12415588a",
"name": "Send Attachment - manual filename",
"info": "",
"x": 1460,
"y": 780,
"wires": []
}
]