The msg.to is pulled from the JSON node. I tried to send email after creation, but it didn't pick up msg.to.
I do not want to email the file anymore. I would like to download the file instead of emailing.
I had to have the Raspberry Pi handle the file creation, email, and deletion because I could not get Windows file deletion to work.
PC Flow:
[{"id":"63de8626.d1f168","type":"comment","z":"60f57708.6d6238","name":"Raw LH35N-3000B Data Export","info":"","x":250,"y":280,"wires":[]},{"id":"7935123f.af3b8c","type":"ui_form","z":"60f57708.6d6238","name":"","label":"Raw Machine Data Export","group":"db835013.4ce0a","order":0,"width":0,"height":0,"options":[{"label":"Email","value":"to","type":"email","required":true},{"label":"StartDate","value":"startDate","type":"text","required":true},{"label":"EndDate","value":"endDate","type":"text","required":true}],"formValue":{"to":"","startDate":"","endDate":""},"payload":"","submit":"Submit","cancel":"Cancel","topic":"","x":230,"y":320,"wires":[["65813b94.777f74"]]},{"id":"65813b94.777f74","type":"mqtt out","z":"60f57708.6d6238","name":"","topic":"LH35N3000B","qos":"2","retain":"","broker":"200dfb1c.eed1c4","x":460,"y":320,"wires":[]},{"id":"db835013.4ce0a","type":"ui_group","z":"","name":"Machine Data","tab":"7b05b022.b7aa8","disp":true,"width":"6","collapse":false},{"id":"200dfb1c.eed1c4","type":"mqtt-broker","z":"","name":"xBee","broker":"10.0.0.2","port":"1883","clientid":"","usetls":false,"compatmode":true,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","closeTopic":"","closePayload":"","willTopic":"","willQos":"0","willPayload":""},{"id":"7b05b022.b7aa8","type":"ui_tab","z":"","name":"Reports","icon":"dashboard","order":37}]
Raspberry Pi Flow:
[{"id":"d20b2bd4.2e4158","type":"comment","z":"cbfed81f.36c5d8","name":"Raw LH35N-3000B Data Export","info":"","x":170,"y":200,"wires":[]},{"id":"1f54e700.77d3b9","type":"function","z":"cbfed81f.36c5d8","name":"SQL Function","func":"stDt = msg.payload.startDate;\nedDt = msg.payload.endDate;\n\npld = \"SELECT * \";\npld = pld + \"FROM MachineData \";\npld = pld + \"WHERE Timestamp BETWEEN \";\npld = pld + \"'\"+stDt+\"' and '\"+edDt+\"' \" ;\npld = pld + \"order by timestamp \";\npld = pld;\n\nmsg.payload = pld;\nreturn msg;\n\n\n\n\n","outputs":1,"noerr":0,"x":400,"y":240,"wires":[["30599455.d9ebdc"]]},{"id":"30599455.d9ebdc","type":"MSSQL","z":"cbfed81f.36c5d8","mssqlCN":"52a98399.71474c","name":"MSSQL","query":"","outField":"payload","x":560,"y":240,"wires":[["755c43d6.c391cc"]]},{"id":"755c43d6.c391cc","type":"change","z":"cbfed81f.36c5d8","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"[\t payload[0].$join($keys(), \",\"),\t payload[].$join(*.$string(), \",\")\t]","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":720,"y":240,"wires":[["4f0c8210.eaa76c"]]},{"id":"4f0c8210.eaa76c","type":"split","z":"cbfed81f.36c5d8","name":"","splt":"\\n","spltType":"str","arraySplt":1,"arraySpltType":"len","stream":false,"addname":"","x":870,"y":240,"wires":[["634bb8b3.650128"]]},{"id":"634bb8b3.650128","type":"file","z":"cbfed81f.36c5d8","name":"","filename":"/home/pi/RawMachineData.csv","appendNewline":true,"createDir":true,"overwriteFile":"false","x":1090,"y":240,"wires":[[]]},{"id":"6d94ccdc.242cb4","type":"function","z":"cbfed81f.36c5d8","name":"","func":"msg.to = msg.payload.to;\nmsg.payload = '';\nmsg.topic = 'RawMachineData Export'\nmsg.attachments = [{\n filename: 'RawMachineData.csv',\n path: '/home/pi/RawMachineData.csv'\n}];\nreturn msg;","outputs":1,"noerr":0,"x":690,"y":280,"wires":[["1386ec1d.3a9e64","11b2bcfe.636f33"]]},{"id":"1386ec1d.3a9e64","type":"e-mail","z":"cbfed81f.36c5d8","server":"smtp.gmail.com","port":"465","secure":true,"name":"","dname":"","x":870,"y":280,"wires":[]},{"id":"11b2bcfe.636f33","type":"delay","z":"cbfed81f.36c5d8","name":"","pauseType":"delay","timeout":"20","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":880,"y":320,"wires":[["51c484ab.9df8fc"]]},{"id":"51c484ab.9df8fc","type":"exec","z":"cbfed81f.36c5d8","command":"rm /home/pi/RawMachineData.csv","addpay":true,"append":"","useSpawn":"false","timer":"","oldrc":false,"name":"","x":1180,"y":320,"wires":[[],[],[]]},{"id":"343da1d8.fda39e","type":"json","z":"cbfed81f.36c5d8","name":"","property":"payload","action":"","pretty":false,"x":250,"y":240,"wires":[["1f54e700.77d3b9","cf4cd255.b7f46"]]},{"id":"cd9fb7d3.4debd8","type":"mqtt in","z":"cbfed81f.36c5d8","name":"","topic":"LH35N3000B","qos":"2","broker":"30af8e0d.e09262","x":110,"y":240,"wires":[["343da1d8.fda39e"]]},{"id":"cf4cd255.b7f46","type":"delay","z":"cbfed81f.36c5d8","name":"","pauseType":"delay","timeout":"1","timeoutUnits":"minutes","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":380,"y":280,"wires":[["6d94ccdc.242cb4"]]},{"id":"52a98399.71474c","type":"MSSQL-CN","z":"","name":"NewDev","server":"10.0.0.11","encyption":true,"database":"Dev"},{"id":"30af8e0d.e09262","type":"mqtt-broker","z":"","name":"","broker":"10.0.0.2","port":"1883","clientid":"","usetls":false,"compatmode":true,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","willTopic":"","willQos":"0","willPayload":""}]