Downloading CSV File of data from MySQL between 2 dates

Hi All after read this thread Downloading SQL Thread , I try to my code to download database mysql, but this make me felling frustated because the output csv of my data is same with the example code from @Steve-Mcl , but still not working to download the data.

Maybe someone can help my problem, Thanks for your help, greatly appreciated.

[{"id":"53cb80.1fbbb48","type":"ui_date_picker","z":"24ae593d.edf0de","name":"","label":"Start Date","group":"f26fc68d.b2996","order":1,"width":"5","height":"5","passthru":true,"topic":"start_date","x":390,"y":2020,"wires":[["5b8389e0.371f88"]]},{"id":"1d1317a5.ebe9c8","type":"ui_date_picker","z":"24ae593d.edf0de","name":"","label":"End Date","group":"f26fc68d.b2996","order":2,"width":"5","height":"5","passthru":true,"topic":"end_date","x":320,"y":2100,"wires":[["5492cbec.551d34"]]},{"id":"7267e3a7.103e1c","type":"ui_button","z":"24ae593d.edf0de","name":"","group":"f26fc68d.b2996","order":4,"width":"8","height":"1","passthru":false,"label":"<font size=6>Refresh","tooltip":"","color":"","bgcolor":"","icon":"","payload":"","payloadType":"date","topic":"","x":140,"y":2080,"wires":[["53cb80.1fbbb48","1d1317a5.ebe9c8"]]},{"id":"7bb17c6a.e09a04","type":"function","z":"24ae593d.edf0de","name":"My SQL Database Request","func":"context.data = context.data || {};\nvar port= \"dewa_10\"; //replace with port no\n\nswitch (msg.topic) {\n     case\"start_date\":\n        context.data.start_date= msg.payload;\n            msg = null;\n                 break;\n     case\"end_date\":\n        context.data.end_date= msg.payload;\n            msg = null;\n                 break;\n}\n\nmsg2 = {};\nmsg2.topic=\"select * from (select substr(datetime, 1, 13) as waktu, `pi`,`ti`,status,mode,engine_volt,motor_frequency,`motor_voltage`,`motor_current`,`dts` from \"+port+\" WHERE datetime BETWEEN '\"+context.data.start_date+\"' AND '\"+context.data.end_date+\"' order by datetime ) t GROUP BY waktu\"\nreturn msg2;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":400,"y":2200,"wires":[["945ff5a7.c21988"]]},{"id":"ae93bc35.859958","type":"inject","z":"24ae593d.edf0de","name":"","repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":160,"y":2170,"wires":[["7bb17c6a.e09a04"]]},{"id":"158cf6bf.f3ca49","type":"debug","z":"24ae593d.edf0de","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":1170,"y":2260,"wires":[]},{"id":"cd8e581.20defa8","type":"mysql","z":"24ae593d.edf0de","mydb":"ebf52c2e.a8b058","name":"","x":760,"y":2230,"wires":[["1dd8ce73.d23dca"]]},{"id":"5492cbec.551d34","type":"moment","z":"24ae593d.edf0de","name":"","topic":"","input":"payload","inputType":"msg","inTz":"Asia/Bangkok","adjAmount":0,"adjType":"days","adjDir":"add","format":"YYYY-MM-DD","locale":"en_GB","output":"payload","outputType":"msg","outTz":"Asia/Bangkok","x":580,"y":2140,"wires":[["ccf6b668.da49a","7bb17c6a.e09a04"]]},{"id":"5b8389e0.371f88","type":"moment","z":"24ae593d.edf0de","name":"","topic":"","input":"payload","inputType":"msg","inTz":"Asia/Bangkok","adjAmount":0,"adjType":"days","adjDir":"add","format":"YYYY-MM-DD","locale":"en_GB","output":"payload","outputType":"msg","outTz":"Asia/Bangkok","x":600,"y":2060,"wires":[["7bb17c6a.e09a04","ccf6b668.da49a"]]},{"id":"10e7cfe.3dc5cb","type":"csv","z":"24ae593d.edf0de","name":"","sep":",","hdrin":"","hdrout":"all","multi":"mult","ret":"\\r\\n","temp":"waktu,pi,ti,status,mode,engine_volt,motor_frequency,motor_voltage,motor_current,dts","skip":"0","strings":false,"include_empty_strings":"","include_null_values":"","x":950,"y":2360,"wires":[["158cf6bf.f3ca49","216a4830.f7526"]]},{"id":"d8d04990.bd0d28","type":"csv","z":"24ae593d.edf0de","name":"","sep":",","hdrin":"","hdrout":"all","multi":"mult","ret":"\\r\\n","temp":"ID_and_s,V_izq,V_der,F_izq,F_der,tiempo_mili,timestamp","skip":"0","strings":false,"x":570,"y":2440,"wires":[["e463f489.86051"]]},{"id":"6815af8f.c938c8","type":"http response","z":"24ae593d.edf0de","name":"","statusCode":"","headers":{},"x":990,"y":2500,"wires":[]},{"id":"d5cbfb5a.4fe68","type":"catch","z":"24ae593d.edf0de","name":"","scope":null,"uncaught":false,"x":220,"y":2560,"wires":[["9808c14b.60f0f","56c02bc6.f48c54"]]},{"id":"9808c14b.60f0f","type":"function","z":"24ae593d.edf0de","name":"Set 404","func":"msg.payload = msg.error;\nmsg.statusCode = 404;//resource not found\nreturn msg;","outputs":1,"noerr":0,"x":780,"y":2560,"wires":[["6815af8f.c938c8"]]},{"id":"56c02bc6.f48c54","type":"debug","z":"24ae593d.edf0de","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":250,"y":2620,"wires":[]},{"id":"cf1dc7e6.d577e8","type":"ui_template","z":"24ae593d.edf0de","group":"f26fc68d.b2996","name":"ui_temlplate - present download link on dashboard","order":0,"width":0,"height":0,"format":"<div >\n    <a href=\"/data\">HAZ CLICK PARA DESCARGAR</a>\n</div>","storeOutMessages":true,"fwdInMessages":true,"resendOnRefresh":false,"templateScope":"local","x":590,"y":2620,"wires":[[]]},{"id":"5721ab4c.15e954","type":"http in","z":"24ae593d.edf0de","name":"","url":"/data","method":"get","upload":false,"swaggerDoc":"","x":180,"y":2320,"wires":[["7bb17c6a.e09a04"]]},{"id":"216a4830.f7526","type":"function","z":"24ae593d.edf0de","name":"Set Headers","func":"msg.headers = {}\nmsg.headers[\"Content-type\"] = \"text/csv\";\nmsg.headers[\"Content-Disposition\"] = \"attachment; filename=data.csv\";\nmsg.headers[\"Pragma\"] = \"no-cache\";\nmsg.headers[\"Expires\"] = \"0\";\nreturn msg;","outputs":1,"noerr":0,"x":770,"y":2500,"wires":[["6815af8f.c938c8"]]},{"id":"d6de4416.a8ee4","type":"inject","z":"24ae593d.edf0de","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":180,"y":2460,"wires":[["64774ca6.b32374"]]},{"id":"64774ca6.b32374","type":"function","z":"24ae593d.edf0de","name":"** Database Call **","func":"msg.payload =[{\"ID_and_s\":1,\"V_izq\":66,\"V_der\":10,\"F_izq\":130,\"F_der\":109,\"tiempo_mili\":1597228949544,\"timestamp\":\"2020-08-12T10:42:29.000Z\"},{\"ID_and_s\":1,\"V_izq\":66,\"V_der\":10,\"F_izq\":62,\"F_der\":109,\"tiempo_mili\":1597228949544,\"timestamp\":\"2020-08-12T10:42:29.000Z\"},{\"ID_and_s\":1,\"V_izq\":58,\"V_der\":10,\"F_izq\":62,\"F_der\":109,\"tiempo_mili\":1597228949547,\"timestamp\":\"2020-08-12T10:42:29.000Z\"},{\"ID_and_s\":1,\"V_izq\":58,\"V_der\":10,\"F_izq\":62,\"F_der\":68,\"tiempo_mili\":1597228949687,\"timestamp\":\"2020-08-12T10:42:29.000Z\"},{\"ID_and_s\":1,\"V_izq\":58,\"V_der\":10,\"F_izq\":62,\"F_der\":45,\"tiempo_mili\":1597228950690,\"timestamp\":\"2020-08-12T10:42:30.000Z\"},{\"ID_and_s\":1,\"V_izq\":58,\"V_der\":10,\"F_izq\":62,\"F_der\":45,\"tiempo_mili\":1597228951545,\"timestamp\":\"2020-08-12T10:42:31.000Z\"},{\"ID_and_s\":1,\"V_izq\":58,\"V_der\":10,\"F_izq\":58,\"F_der\":45,\"tiempo_mili\":1597228951546,\"timestamp\":\"2020-08-12T10:42:31.000Z\"},{\"ID_and_s\":1,\"V_izq\":22,\"V_der\":10,\"F_izq\":58,\"F_der\":45,\"tiempo_mili\":1597228951548,\"timestamp\":\"2020-08-12T10:42:31.000Z\"},{\"ID_and_s\":1,\"V_izq\":22,\"V_der\":10,\"F_izq\":58,\"F_der\":83,\"tiempo_mili\":1597228951692,\"timestamp\":\"2020-08-12T10:42:31.000Z\"},{\"ID_and_s\":1,\"V_izq\":22,\"V_der\":10,\"F_izq\":58,\"F_der\":73,\"tiempo_mili\":1597228952695,\"timestamp\":\"2020-08-12T10:42:32.000Z\"},{\"ID_and_s\":1,\"V_izq\":22,\"V_der\":10,\"F_izq\":58,\"F_der\":73,\"tiempo_mili\":1597228953548,\"timestamp\":\"2020-08-12T10:42:33.000Z\"},{\"ID_and_s\":1,\"V_izq\":22,\"V_der\":10,\"F_izq\":79,\"F_der\":73,\"tiempo_mili\":1597228953548,\"timestamp\":\"2020-08-12T10:42:33.000Z\"},{\"ID_and_s\":1,\"V_izq\":97,\"V_der\":10,\"F_izq\":79,\"F_der\":73,\"tiempo_mili\":1597228953550,\"timestamp\":\"2020-08-12T10:42:33.000Z\"},{\"ID_and_s\":1,\"V_izq\":97,\"V_der\":10,\"F_izq\":79,\"F_der\":114,\"tiempo_mili\":1597228953696,\"timestamp\":\"2020-08-12T10:42:33.000Z\"},{\"ID_and_s\":1,\"V_izq\":97,\"V_der\":10,\"F_izq\":79,\"F_der\":126,\"tiempo_mili\":1597228954701,\"timestamp\":\"2020-08-12T10:42:34.000Z\"},{\"ID_and_s\":1,\"V_izq\":97,\"V_der\":10,\"F_izq\":79,\"F_der\":126,\"tiempo_mili\":1597228955549,\"timestamp\":\"2020-08-12T10:42:35.000Z\"},{\"ID_and_s\":1,\"V_izq\":97,\"V_der\":10,\"F_izq\":124,\"F_der\":126,\"tiempo_mili\":1597228955550,\"timestamp\":\"2020-08-12T10:42:35.000Z\"},{\"ID_and_s\":1,\"V_izq\":68,\"V_der\":10,\"F_izq\":124,\"F_der\":126,\"tiempo_mili\":1597228955552,\"timestamp\":\"2020-08-12T10:42:35.000Z\"},{\"ID_and_s\":1,\"V_izq\":68,\"V_der\":10,\"F_izq\":124,\"F_der\":101,\"tiempo_mili\":1597228955702,\"timestamp\":\"2020-08-12T10:42:35.000Z\"},{\"ID_and_s\":1,\"V_izq\":68,\"V_der\":10,\"F_izq\":124,\"F_der\":69,\"tiempo_mili\":1597228956706,\"timestamp\":\"2020-08-12T10:42:36.000Z\"},{\"ID_and_s\":1,\"V_izq\":68,\"V_der\":10,\"F_izq\":124,\"F_der\":69,\"tiempo_mili\":1597228957553,\"timestamp\":\"2020-08-12T10:42:37.000Z\"},{\"ID_and_s\":1,\"V_izq\":68,\"V_der\":10,\"F_izq\":57,\"F_der\":69,\"tiempo_mili\":1597228957555,\"timestamp\":\"2020-08-12T10:42:37.000Z\"},{\"ID_and_s\":1,\"V_izq\":144,\"V_der\":10,\"F_izq\":57,\"F_der\":69,\"tiempo_mili\":1597228957556,\"timestamp\":\"2020-08-12T10:42:37.000Z\"},{\"ID_and_s\":1,\"V_izq\":144,\"V_der\":10,\"F_izq\":57,\"F_der\":31,\"tiempo_mili\":1597228957707,\"timestamp\":\"2020-08-12T10:42:37.000Z\"},{\"ID_and_s\":1,\"V_izq\":144,\"V_der\":10,\"F_izq\":57,\"F_der\":121,\"tiempo_mili\":1597228958710,\"timestamp\":\"2020-08-12T10:42:38.000Z\"},{\"ID_and_s\":1,\"V_izq\":144,\"V_der\":10,\"F_izq\":57,\"F_der\":121,\"tiempo_mili\":1597228959554,\"timestamp\":\"2020-08-12T10:42:39.000Z\"},{\"ID_and_s\":1,\"V_izq\":144,\"V_der\":10,\"F_izq\":94,\"F_der\":121,\"tiempo_mili\":1597228959556,\"timestamp\":\"2020-08-12T10:42:39.000Z\"},{\"ID_and_s\":1,\"V_izq\":49,\"V_der\":10,\"F_izq\":94,\"F_der\":121,\"tiempo_mili\":1597228959556,\"timestamp\":\"2020-08-12T10:42:39.000Z\"},{\"ID_and_s\":1,\"V_izq\":49,\"V_der\":10,\"F_izq\":94,\"F_der\":144,\"tiempo_mili\":1597228959712,\"timestamp\":\"2020-08-12T10:42:39.000Z\"},{\"ID_and_s\":1,\"V_izq\":49,\"V_der\":10,\"F_izq\":94,\"F_der\":49,\"tiempo_mili\":1597228960715,\"timestamp\":\"2020-08-12T10:42:40.000Z\"},{\"ID_and_s\":1,\"V_izq\":49,\"V_der\":10,\"F_izq\":94,\"F_der\":49,\"tiempo_mili\":1597228961556,\"timestamp\":\"2020-08-12T10:42:41.000Z\"},{\"ID_and_s\":1,\"V_izq\":49,\"V_der\":10,\"F_izq\":112,\"F_der\":49,\"tiempo_mili\":1597228961558,\"timestamp\":\"2020-08-12T10:42:41.000Z\"},{\"ID_and_s\":1,\"V_izq\":102,\"V_der\":10,\"F_izq\":112,\"F_der\":49,\"tiempo_mili\":1597228961558,\"timestamp\":\"2020-08-12T10:42:41.000Z\"},{\"ID_and_s\":1,\"V_izq\":102,\"V_der\":10,\"F_izq\":112,\"F_der\":106,\"tiempo_mili\":1597228961715,\"timestamp\":\"2020-08-12T10:42:41.000Z\"},{\"ID_and_s\":1,\"V_izq\":102,\"V_der\":10,\"F_izq\":112,\"F_der\":77,\"tiempo_mili\":1597228962720,\"timestamp\":\"2020-08-12T10:42:42.000Z\"},{\"ID_and_s\":1,\"V_izq\":102,\"V_der\":10,\"F_izq\":112,\"F_der\":77,\"tiempo_mili\":1597228963557,\"timestamp\":\"2020-08-12T10:42:43.000Z\"},{\"ID_and_s\":1,\"V_izq\":102,\"V_der\":10,\"F_izq\":50,\"F_der\":77,\"tiempo_mili\":1597228963557,\"timestamp\":\"2020-08-12T10:42:43.000Z\"},{\"ID_and_s\":1,\"V_izq\":90,\"V_der\":10,\"F_izq\":50,\"F_der\":77,\"tiempo_mili\":1597228963559,\"timestamp\":\"2020-08-12T10:42:43.000Z\"},{\"ID_and_s\":1,\"V_izq\":90,\"V_der\":10,\"F_izq\":50,\"F_der\":121,\"tiempo_mili\":1597228963721,\"timestamp\":\"2020-08-12T10:42:43.000Z\"},{\"ID_and_s\":1,\"V_izq\":90,\"V_der\":10,\"F_izq\":50,\"F_der\":133,\"tiempo_mili\":1597228964725,\"timestamp\":\"2020-08-12T10:42:44.000Z\"},{\"ID_and_s\":1,\"V_izq\":90,\"V_der\":10,\"F_izq\":50,\"F_der\":133,\"tiempo_mili\":1597228965559,\"timestamp\":\"2020-08-12T10:42:45.000Z\"},{\"ID_and_s\":1,\"V_izq\":90,\"V_der\":10,\"F_izq\":122,\"F_der\":133,\"tiempo_mili\":1597228965559,\"timestamp\":\"2020-08-12T10:42:45.000Z\"},{\"ID_and_s\":1,\"V_izq\":124,\"V_der\":10,\"F_izq\":122,\"F_der\":133,\"tiempo_mili\":1597228965561,\"timestamp\":\"2020-08-12T10:42:45.000Z\"},{\"ID_and_s\":1,\"V_izq\":124,\"V_der\":10,\"F_izq\":122,\"F_der\":118,\"tiempo_mili\":1597228965726,\"timestamp\":\"2020-08-12T10:42:45.000Z\"},{\"ID_and_s\":1,\"V_izq\":124,\"V_der\":10,\"F_izq\":122,\"F_der\":42,\"tiempo_mili\":1597228966730,\"timestamp\":\"2020-08-12T10:42:46.000Z\"},{\"ID_and_s\":1,\"V_izq\":124,\"V_der\":10,\"F_izq\":122,\"F_der\":42,\"tiempo_mili\":1597228967561,\"timestamp\":\"2020-08-12T10:42:47.000Z\"},{\"ID_and_s\":1,\"V_izq\":124,\"V_der\":10,\"F_izq\":135,\"F_der\":42,\"tiempo_mili\":1597228967561,\"timestamp\":\"2020-08-12T10:42:47.000Z\"},{\"ID_and_s\":1,\"V_izq\":111,\"V_der\":10,\"F_izq\":135,\"F_der\":42,\"tiempo_mili\":1597228967563,\"timestamp\":\"2020-08-12T10:42:47.000Z\"},{\"ID_and_s\":1,\"V_izq\":111,\"V_der\":10,\"F_izq\":135,\"F_der\":118,\"tiempo_mili\":1597228967733,\"timestamp\":\"2020-08-12T10:42:47.000Z\"},{\"ID_and_s\":1,\"V_izq\":111,\"V_der\":10,\"F_izq\":135,\"F_der\":62,\"tiempo_mili\":1597228968736,\"timestamp\":\"2020-08-12T10:42:48.000Z\"},{\"ID_and_s\":1,\"V_izq\":111,\"V_der\":10,\"F_izq\":135,\"F_der\":62,\"tiempo_mili\":1597228969563,\"timestamp\":\"2020-08-12T10:42:49.000Z\"},{\"ID_and_s\":1,\"V_izq\":111,\"V_der\":10,\"F_izq\":68,\"F_der\":62,\"tiempo_mili\":1597228969563,\"timestamp\":\"2020-08-12T10:42:49.000Z\"},{\"ID_and_s\":1,\"V_izq\":79,\"V_der\":10,\"F_izq\":68,\"F_der\":62,\"tiempo_mili\":1597228969565,\"timestamp\":\"2020-08-12T10:42:49.000Z\"},{\"ID_and_s\":1,\"V_izq\":79,\"V_der\":10,\"F_izq\":68,\"F_der\":53,\"tiempo_mili\":1597228969737,\"timestamp\":\"2020-08-12T10:42:49.000Z\"},{\"ID_and_s\":1,\"V_izq\":79,\"V_der\":10,\"F_izq\":68,\"F_der\":56,\"tiempo_mili\":1597228970741,\"timestamp\":\"2020-08-12T10:42:50.000Z\"},{\"ID_and_s\":1,\"V_izq\":79,\"V_der\":10,\"F_izq\":68,\"F_der\":56,\"tiempo_mili\":1597228971564,\"timestamp\":\"2020-08-12T10:42:51.000Z\"},{\"ID_and_s\":1,\"V_izq\":79,\"V_der\":10,\"F_izq\":131,\"F_der\":56,\"tiempo_mili\":1597228971565,\"timestamp\":\"2020-08-12T10:42:51.000Z\"},{\"ID_and_s\":1,\"V_izq\":34,\"V_der\":10,\"F_izq\":131,\"F_der\":56,\"tiempo_mili\":1597228971589,\"timestamp\":\"2020-08-12T10:42:51.000Z\"},{\"ID_and_s\":1,\"V_izq\":34,\"V_der\":10,\"F_izq\":131,\"F_der\":83,\"tiempo_mili\":1597228971743,\"timestamp\":\"2020-08-12T10:42:51.000Z\"},{\"ID_and_s\":1,\"V_izq\":34,\"V_der\":10,\"F_izq\":131,\"F_der\":61,\"tiempo_mili\":1597228972747,\"timestamp\":\"2020-08-12T10:42:52.000Z\"},{\"ID_and_s\":1,\"V_izq\":34,\"V_der\":10,\"F_izq\":131,\"F_der\":61,\"tiempo_mili\":1597228973569,\"timestamp\":\"2020-08-12T10:42:53.000Z\"},{\"ID_and_s\":1,\"V_izq\":34,\"V_der\":10,\"F_izq\":115,\"F_der\":61,\"tiempo_mili\":1597228973569,\"timestamp\":\"2020-08-12T10:42:53.000Z\"},{\"ID_and_s\":1,\"V_izq\":95,\"V_der\":10,\"F_izq\":115,\"F_der\":61,\"tiempo_mili\":1597228973573,\"timestamp\":\"2020-08-12T10:42:53.000Z\"},{\"ID_and_s\":1,\"V_izq\":95,\"V_der\":10,\"F_izq\":115,\"F_der\":53,\"tiempo_mili\":1597228973750,\"timestamp\":\"2020-08-12T10:42:53.000Z\"},{\"ID_and_s\":1,\"V_izq\":95,\"V_der\":10,\"F_izq\":115,\"F_der\":44,\"tiempo_mili\":1597228974752,\"timestamp\":\"2020-08-12T10:42:54.000Z\"}]\nreturn msg;","outputs":1,"noerr":0,"x":390,"y":2460,"wires":[["d8d04990.bd0d28"]]},{"id":"e463f489.86051","type":"debug","z":"24ae593d.edf0de","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":670,"y":2380,"wires":[]},{"id":"1dd8ce73.d23dca","type":"change","z":"24ae593d.edf0de","name":"","rules":[{"t":"set","p":"topic","pt":"msg","to":"","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":850,"y":2280,"wires":[["85aeb7e2.b499a8"]]},{"id":"85aeb7e2.b499a8","type":"function","z":"24ae593d.edf0de","name":"","func":"var newMsg = { _msgid:msg._msgid,payload: msg.payload,topic:msg.topic };\nreturn newMsg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":910,"y":2320,"wires":[["10e7cfe.3dc5cb"]]},{"id":"945ff5a7.c21988","type":"delay","z":"24ae593d.edf0de","name":"","pauseType":"delay","timeout":"1000","timeoutUnits":"milliseconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":580,"y":2260,"wires":[["cd8e581.20defa8"]]},{"id":"f26fc68d.b2996","type":"ui_group","name":"DEWA-10 Chart-Logger","tab":"48814208.274a2c","order":1,"disp":false,"width":"50","collapse":false},{"id":"ebf52c2e.a8b058","type":"MySQLdatabase","name":"","host":"127.0.0.1","port":"3306","db":"field_adera","tz":"","charset":""},{"id":"48814208.274a2c","type":"ui_tab","name":"DEWA-10 Chart-Logger","icon":"dashboard","order":397,"disabled":false,"hidden":true}]

No it is not.

You try to trigger database ~~> http out node from the dashboard (this WONT work - a http out needs to be triggered by a http in)

whereas the solution I gave the other user was to store the values until they were needed

image

Why dont you import the example from that post & change the queries.

Hi Steve! Thank you very much to reply my problem.

I've change my code like your said. But still cannot get the download data. Here is my output CSV Node

And this is my updated node, after update set.flow:

[{"id":"53cb80.1fbbb48","type":"ui_date_picker","z":"24ae593d.edf0de","name":"","label":"Start Date","group":"f26fc68d.b2996","order":1,"width":"5","height":"5","passthru":true,"topic":"start_date","x":390,"y":2020,"wires":[["5b8389e0.371f88"]]},{"id":"1d1317a5.ebe9c8","type":"ui_date_picker","z":"24ae593d.edf0de","name":"","label":"End Date","group":"f26fc68d.b2996","order":2,"width":"5","height":"5","passthru":true,"topic":"end_date","x":320,"y":2100,"wires":[["5492cbec.551d34"]]},{"id":"7267e3a7.103e1c","type":"ui_button","z":"24ae593d.edf0de","name":"","group":"f26fc68d.b2996","order":4,"width":"8","height":"1","passthru":false,"label":"<font size=6>Refresh","tooltip":"","color":"","bgcolor":"","icon":"","payload":"","payloadType":"date","topic":"","x":140,"y":2080,"wires":[["53cb80.1fbbb48","1d1317a5.ebe9c8"]]},{"id":"7bb17c6a.e09a04","type":"function","z":"24ae593d.edf0de","name":"My SQL Database Request","func":"var port= \"dewa_10\"; //replace with port no\nvar startDate = flow.get(\"startDate\");\nvar endDate = flow.get(\"endDate\");\n\nmsg2 = {};\nmsg2.topic=\"select * from (select substr(datetime, 1, 13) as waktu, `pi`,`ti`,status,mode,engine_volt,motor_frequency,`motor_voltage`,`motor_current`,`dts` from \"+port+\" WHERE datetime BETWEEN '\"+startDate+\"' AND '\"+endDate+\"' order by datetime ) t GROUP BY waktu\"\nreturn msg2;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":400,"y":2200,"wires":[["cd8e581.20defa8"]]},{"id":"ae93bc35.859958","type":"inject","z":"24ae593d.edf0de","name":"","repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":160,"y":2170,"wires":[["7bb17c6a.e09a04"]]},{"id":"cd8e581.20defa8","type":"mysql","z":"24ae593d.edf0de","mydb":"ebf52c2e.a8b058","name":"","x":760,"y":2230,"wires":[["d8d04990.bd0d28","ac42262f.104ef"]]},{"id":"5492cbec.551d34","type":"moment","z":"24ae593d.edf0de","name":"","topic":"","input":"payload","inputType":"msg","inTz":"Asia/Bangkok","adjAmount":0,"adjType":"days","adjDir":"add","format":"YYYY-MM-DD","locale":"en_GB","output":"payload","outputType":"msg","outTz":"Asia/Bangkok","x":580,"y":2140,"wires":[["7c014c58.e8d504"]]},{"id":"5b8389e0.371f88","type":"moment","z":"24ae593d.edf0de","name":"","topic":"","input":"payload","inputType":"msg","inTz":"Asia/Bangkok","adjAmount":0,"adjType":"days","adjDir":"add","format":"YYYY-MM-DD","locale":"en_GB","output":"payload","outputType":"msg","outTz":"Asia/Bangkok","x":600,"y":2060,"wires":[["3668080d.9e73e8"]]},{"id":"d8d04990.bd0d28","type":"csv","z":"24ae593d.edf0de","name":"","sep":",","hdrin":"","hdrout":"all","multi":"mult","ret":"\\r\\n","temp":"waktu,pi,ti,status,mode,engine,mf,mv,mc,dts","skip":"0","strings":false,"include_empty_strings":false,"include_null_values":false,"x":570,"y":2440,"wires":[["216a4830.f7526","c768a229.381808"]]},{"id":"6815af8f.c938c8","type":"http response","z":"24ae593d.edf0de","name":"","statusCode":"","headers":{},"x":990,"y":2500,"wires":[]},{"id":"d5cbfb5a.4fe68","type":"catch","z":"24ae593d.edf0de","name":"","scope":null,"uncaught":false,"x":220,"y":2560,"wires":[["9808c14b.60f0f","56c02bc6.f48c54"]]},{"id":"9808c14b.60f0f","type":"function","z":"24ae593d.edf0de","name":"Set 404","func":"msg.payload = msg.error;\nmsg.statusCode = 404;//resource not found\nreturn msg;","outputs":1,"noerr":0,"x":780,"y":2560,"wires":[["6815af8f.c938c8"]]},{"id":"56c02bc6.f48c54","type":"debug","z":"24ae593d.edf0de","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":250,"y":2620,"wires":[]},{"id":"cf1dc7e6.d577e8","type":"ui_template","z":"24ae593d.edf0de","group":"f26fc68d.b2996","name":"ui_temlplate - present download link on dashboard","order":0,"width":0,"height":0,"format":"<div >\n    <a href=\"/data\">HAZ CLICK PARA DESCARGAR</a>\n</div>","storeOutMessages":true,"fwdInMessages":true,"resendOnRefresh":false,"templateScope":"local","x":590,"y":2620,"wires":[[]]},{"id":"5721ab4c.15e954","type":"http in","z":"24ae593d.edf0de","name":"","url":"/data","method":"get","upload":false,"swaggerDoc":"","x":180,"y":2320,"wires":[["7bb17c6a.e09a04"]]},{"id":"216a4830.f7526","type":"function","z":"24ae593d.edf0de","name":"Set Headers","func":"msg.headers = {}\nmsg.headers[\"Content-type\"] = \"text/csv\";\nmsg.headers[\"Content-Disposition\"] = \"attachment; filename=data.csv\";\nmsg.headers[\"Pragma\"] = \"no-cache\";\nmsg.headers[\"Expires\"] = \"0\";\nreturn msg;","outputs":1,"noerr":0,"x":770,"y":2500,"wires":[["6815af8f.c938c8"]]},{"id":"d6de4416.a8ee4","type":"inject","z":"24ae593d.edf0de","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":180,"y":2460,"wires":[["64774ca6.b32374"]]},{"id":"64774ca6.b32374","type":"function","z":"24ae593d.edf0de","name":"** Database Call **","func":"msg.payload =[{\"ID_and_s\":1,\"V_izq\":66,\"V_der\":10,\"F_izq\":130,\"F_der\":109,\"tiempo_mili\":1597228949544,\"timestamp\":\"2020-08-12T10:42:29.000Z\"},{\"ID_and_s\":1,\"V_izq\":66,\"V_der\":10,\"F_izq\":62,\"F_der\":109,\"tiempo_mili\":1597228949544,\"timestamp\":\"2020-08-12T10:42:29.000Z\"},{\"ID_and_s\":1,\"V_izq\":58,\"V_der\":10,\"F_izq\":62,\"F_der\":109,\"tiempo_mili\":1597228949547,\"timestamp\":\"2020-08-12T10:42:29.000Z\"},{\"ID_and_s\":1,\"V_izq\":58,\"V_der\":10,\"F_izq\":62,\"F_der\":68,\"tiempo_mili\":1597228949687,\"timestamp\":\"2020-08-12T10:42:29.000Z\"},{\"ID_and_s\":1,\"V_izq\":58,\"V_der\":10,\"F_izq\":62,\"F_der\":45,\"tiempo_mili\":1597228950690,\"timestamp\":\"2020-08-12T10:42:30.000Z\"},{\"ID_and_s\":1,\"V_izq\":58,\"V_der\":10,\"F_izq\":62,\"F_der\":45,\"tiempo_mili\":1597228951545,\"timestamp\":\"2020-08-12T10:42:31.000Z\"},{\"ID_and_s\":1,\"V_izq\":58,\"V_der\":10,\"F_izq\":58,\"F_der\":45,\"tiempo_mili\":1597228951546,\"timestamp\":\"2020-08-12T10:42:31.000Z\"},{\"ID_and_s\":1,\"V_izq\":22,\"V_der\":10,\"F_izq\":58,\"F_der\":45,\"tiempo_mili\":1597228951548,\"timestamp\":\"2020-08-12T10:42:31.000Z\"},{\"ID_and_s\":1,\"V_izq\":22,\"V_der\":10,\"F_izq\":58,\"F_der\":83,\"tiempo_mili\":1597228951692,\"timestamp\":\"2020-08-12T10:42:31.000Z\"},{\"ID_and_s\":1,\"V_izq\":22,\"V_der\":10,\"F_izq\":58,\"F_der\":73,\"tiempo_mili\":1597228952695,\"timestamp\":\"2020-08-12T10:42:32.000Z\"},{\"ID_and_s\":1,\"V_izq\":22,\"V_der\":10,\"F_izq\":58,\"F_der\":73,\"tiempo_mili\":1597228953548,\"timestamp\":\"2020-08-12T10:42:33.000Z\"},{\"ID_and_s\":1,\"V_izq\":22,\"V_der\":10,\"F_izq\":79,\"F_der\":73,\"tiempo_mili\":1597228953548,\"timestamp\":\"2020-08-12T10:42:33.000Z\"},{\"ID_and_s\":1,\"V_izq\":97,\"V_der\":10,\"F_izq\":79,\"F_der\":73,\"tiempo_mili\":1597228953550,\"timestamp\":\"2020-08-12T10:42:33.000Z\"},{\"ID_and_s\":1,\"V_izq\":97,\"V_der\":10,\"F_izq\":79,\"F_der\":114,\"tiempo_mili\":1597228953696,\"timestamp\":\"2020-08-12T10:42:33.000Z\"},{\"ID_and_s\":1,\"V_izq\":97,\"V_der\":10,\"F_izq\":79,\"F_der\":126,\"tiempo_mili\":1597228954701,\"timestamp\":\"2020-08-12T10:42:34.000Z\"},{\"ID_and_s\":1,\"V_izq\":97,\"V_der\":10,\"F_izq\":79,\"F_der\":126,\"tiempo_mili\":1597228955549,\"timestamp\":\"2020-08-12T10:42:35.000Z\"},{\"ID_and_s\":1,\"V_izq\":97,\"V_der\":10,\"F_izq\":124,\"F_der\":126,\"tiempo_mili\":1597228955550,\"timestamp\":\"2020-08-12T10:42:35.000Z\"},{\"ID_and_s\":1,\"V_izq\":68,\"V_der\":10,\"F_izq\":124,\"F_der\":126,\"tiempo_mili\":1597228955552,\"timestamp\":\"2020-08-12T10:42:35.000Z\"},{\"ID_and_s\":1,\"V_izq\":68,\"V_der\":10,\"F_izq\":124,\"F_der\":101,\"tiempo_mili\":1597228955702,\"timestamp\":\"2020-08-12T10:42:35.000Z\"},{\"ID_and_s\":1,\"V_izq\":68,\"V_der\":10,\"F_izq\":124,\"F_der\":69,\"tiempo_mili\":1597228956706,\"timestamp\":\"2020-08-12T10:42:36.000Z\"},{\"ID_and_s\":1,\"V_izq\":68,\"V_der\":10,\"F_izq\":124,\"F_der\":69,\"tiempo_mili\":1597228957553,\"timestamp\":\"2020-08-12T10:42:37.000Z\"},{\"ID_and_s\":1,\"V_izq\":68,\"V_der\":10,\"F_izq\":57,\"F_der\":69,\"tiempo_mili\":1597228957555,\"timestamp\":\"2020-08-12T10:42:37.000Z\"},{\"ID_and_s\":1,\"V_izq\":144,\"V_der\":10,\"F_izq\":57,\"F_der\":69,\"tiempo_mili\":1597228957556,\"timestamp\":\"2020-08-12T10:42:37.000Z\"},{\"ID_and_s\":1,\"V_izq\":144,\"V_der\":10,\"F_izq\":57,\"F_der\":31,\"tiempo_mili\":1597228957707,\"timestamp\":\"2020-08-12T10:42:37.000Z\"},{\"ID_and_s\":1,\"V_izq\":144,\"V_der\":10,\"F_izq\":57,\"F_der\":121,\"tiempo_mili\":1597228958710,\"timestamp\":\"2020-08-12T10:42:38.000Z\"},{\"ID_and_s\":1,\"V_izq\":144,\"V_der\":10,\"F_izq\":57,\"F_der\":121,\"tiempo_mili\":1597228959554,\"timestamp\":\"2020-08-12T10:42:39.000Z\"},{\"ID_and_s\":1,\"V_izq\":144,\"V_der\":10,\"F_izq\":94,\"F_der\":121,\"tiempo_mili\":1597228959556,\"timestamp\":\"2020-08-12T10:42:39.000Z\"},{\"ID_and_s\":1,\"V_izq\":49,\"V_der\":10,\"F_izq\":94,\"F_der\":121,\"tiempo_mili\":1597228959556,\"timestamp\":\"2020-08-12T10:42:39.000Z\"},{\"ID_and_s\":1,\"V_izq\":49,\"V_der\":10,\"F_izq\":94,\"F_der\":144,\"tiempo_mili\":1597228959712,\"timestamp\":\"2020-08-12T10:42:39.000Z\"},{\"ID_and_s\":1,\"V_izq\":49,\"V_der\":10,\"F_izq\":94,\"F_der\":49,\"tiempo_mili\":1597228960715,\"timestamp\":\"2020-08-12T10:42:40.000Z\"},{\"ID_and_s\":1,\"V_izq\":49,\"V_der\":10,\"F_izq\":94,\"F_der\":49,\"tiempo_mili\":1597228961556,\"timestamp\":\"2020-08-12T10:42:41.000Z\"},{\"ID_and_s\":1,\"V_izq\":49,\"V_der\":10,\"F_izq\":112,\"F_der\":49,\"tiempo_mili\":1597228961558,\"timestamp\":\"2020-08-12T10:42:41.000Z\"},{\"ID_and_s\":1,\"V_izq\":102,\"V_der\":10,\"F_izq\":112,\"F_der\":49,\"tiempo_mili\":1597228961558,\"timestamp\":\"2020-08-12T10:42:41.000Z\"},{\"ID_and_s\":1,\"V_izq\":102,\"V_der\":10,\"F_izq\":112,\"F_der\":106,\"tiempo_mili\":1597228961715,\"timestamp\":\"2020-08-12T10:42:41.000Z\"},{\"ID_and_s\":1,\"V_izq\":102,\"V_der\":10,\"F_izq\":112,\"F_der\":77,\"tiempo_mili\":1597228962720,\"timestamp\":\"2020-08-12T10:42:42.000Z\"},{\"ID_and_s\":1,\"V_izq\":102,\"V_der\":10,\"F_izq\":112,\"F_der\":77,\"tiempo_mili\":1597228963557,\"timestamp\":\"2020-08-12T10:42:43.000Z\"},{\"ID_and_s\":1,\"V_izq\":102,\"V_der\":10,\"F_izq\":50,\"F_der\":77,\"tiempo_mili\":1597228963557,\"timestamp\":\"2020-08-12T10:42:43.000Z\"},{\"ID_and_s\":1,\"V_izq\":90,\"V_der\":10,\"F_izq\":50,\"F_der\":77,\"tiempo_mili\":1597228963559,\"timestamp\":\"2020-08-12T10:42:43.000Z\"},{\"ID_and_s\":1,\"V_izq\":90,\"V_der\":10,\"F_izq\":50,\"F_der\":121,\"tiempo_mili\":1597228963721,\"timestamp\":\"2020-08-12T10:42:43.000Z\"},{\"ID_and_s\":1,\"V_izq\":90,\"V_der\":10,\"F_izq\":50,\"F_der\":133,\"tiempo_mili\":1597228964725,\"timestamp\":\"2020-08-12T10:42:44.000Z\"},{\"ID_and_s\":1,\"V_izq\":90,\"V_der\":10,\"F_izq\":50,\"F_der\":133,\"tiempo_mili\":1597228965559,\"timestamp\":\"2020-08-12T10:42:45.000Z\"},{\"ID_and_s\":1,\"V_izq\":90,\"V_der\":10,\"F_izq\":122,\"F_der\":133,\"tiempo_mili\":1597228965559,\"timestamp\":\"2020-08-12T10:42:45.000Z\"},{\"ID_and_s\":1,\"V_izq\":124,\"V_der\":10,\"F_izq\":122,\"F_der\":133,\"tiempo_mili\":1597228965561,\"timestamp\":\"2020-08-12T10:42:45.000Z\"},{\"ID_and_s\":1,\"V_izq\":124,\"V_der\":10,\"F_izq\":122,\"F_der\":118,\"tiempo_mili\":1597228965726,\"timestamp\":\"2020-08-12T10:42:45.000Z\"},{\"ID_and_s\":1,\"V_izq\":124,\"V_der\":10,\"F_izq\":122,\"F_der\":42,\"tiempo_mili\":1597228966730,\"timestamp\":\"2020-08-12T10:42:46.000Z\"},{\"ID_and_s\":1,\"V_izq\":124,\"V_der\":10,\"F_izq\":122,\"F_der\":42,\"tiempo_mili\":1597228967561,\"timestamp\":\"2020-08-12T10:42:47.000Z\"},{\"ID_and_s\":1,\"V_izq\":124,\"V_der\":10,\"F_izq\":135,\"F_der\":42,\"tiempo_mili\":1597228967561,\"timestamp\":\"2020-08-12T10:42:47.000Z\"},{\"ID_and_s\":1,\"V_izq\":111,\"V_der\":10,\"F_izq\":135,\"F_der\":42,\"tiempo_mili\":1597228967563,\"timestamp\":\"2020-08-12T10:42:47.000Z\"},{\"ID_and_s\":1,\"V_izq\":111,\"V_der\":10,\"F_izq\":135,\"F_der\":118,\"tiempo_mili\":1597228967733,\"timestamp\":\"2020-08-12T10:42:47.000Z\"},{\"ID_and_s\":1,\"V_izq\":111,\"V_der\":10,\"F_izq\":135,\"F_der\":62,\"tiempo_mili\":1597228968736,\"timestamp\":\"2020-08-12T10:42:48.000Z\"},{\"ID_and_s\":1,\"V_izq\":111,\"V_der\":10,\"F_izq\":135,\"F_der\":62,\"tiempo_mili\":1597228969563,\"timestamp\":\"2020-08-12T10:42:49.000Z\"},{\"ID_and_s\":1,\"V_izq\":111,\"V_der\":10,\"F_izq\":68,\"F_der\":62,\"tiempo_mili\":1597228969563,\"timestamp\":\"2020-08-12T10:42:49.000Z\"},{\"ID_and_s\":1,\"V_izq\":79,\"V_der\":10,\"F_izq\":68,\"F_der\":62,\"tiempo_mili\":1597228969565,\"timestamp\":\"2020-08-12T10:42:49.000Z\"},{\"ID_and_s\":1,\"V_izq\":79,\"V_der\":10,\"F_izq\":68,\"F_der\":53,\"tiempo_mili\":1597228969737,\"timestamp\":\"2020-08-12T10:42:49.000Z\"},{\"ID_and_s\":1,\"V_izq\":79,\"V_der\":10,\"F_izq\":68,\"F_der\":56,\"tiempo_mili\":1597228970741,\"timestamp\":\"2020-08-12T10:42:50.000Z\"},{\"ID_and_s\":1,\"V_izq\":79,\"V_der\":10,\"F_izq\":68,\"F_der\":56,\"tiempo_mili\":1597228971564,\"timestamp\":\"2020-08-12T10:42:51.000Z\"},{\"ID_and_s\":1,\"V_izq\":79,\"V_der\":10,\"F_izq\":131,\"F_der\":56,\"tiempo_mili\":1597228971565,\"timestamp\":\"2020-08-12T10:42:51.000Z\"},{\"ID_and_s\":1,\"V_izq\":34,\"V_der\":10,\"F_izq\":131,\"F_der\":56,\"tiempo_mili\":1597228971589,\"timestamp\":\"2020-08-12T10:42:51.000Z\"},{\"ID_and_s\":1,\"V_izq\":34,\"V_der\":10,\"F_izq\":131,\"F_der\":83,\"tiempo_mili\":1597228971743,\"timestamp\":\"2020-08-12T10:42:51.000Z\"},{\"ID_and_s\":1,\"V_izq\":34,\"V_der\":10,\"F_izq\":131,\"F_der\":61,\"tiempo_mili\":1597228972747,\"timestamp\":\"2020-08-12T10:42:52.000Z\"},{\"ID_and_s\":1,\"V_izq\":34,\"V_der\":10,\"F_izq\":131,\"F_der\":61,\"tiempo_mili\":1597228973569,\"timestamp\":\"2020-08-12T10:42:53.000Z\"},{\"ID_and_s\":1,\"V_izq\":34,\"V_der\":10,\"F_izq\":115,\"F_der\":61,\"tiempo_mili\":1597228973569,\"timestamp\":\"2020-08-12T10:42:53.000Z\"},{\"ID_and_s\":1,\"V_izq\":95,\"V_der\":10,\"F_izq\":115,\"F_der\":61,\"tiempo_mili\":1597228973573,\"timestamp\":\"2020-08-12T10:42:53.000Z\"},{\"ID_and_s\":1,\"V_izq\":95,\"V_der\":10,\"F_izq\":115,\"F_der\":53,\"tiempo_mili\":1597228973750,\"timestamp\":\"2020-08-12T10:42:53.000Z\"},{\"ID_and_s\":1,\"V_izq\":95,\"V_der\":10,\"F_izq\":115,\"F_der\":44,\"tiempo_mili\":1597228974752,\"timestamp\":\"2020-08-12T10:42:54.000Z\"}]\nreturn msg;","outputs":1,"noerr":0,"x":390,"y":2460,"wires":[[]]},{"id":"3668080d.9e73e8","type":"change","z":"24ae593d.edf0de","name":"","rules":[{"t":"set","p":"startDate","pt":"flow","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":910,"y":2060,"wires":[[]]},{"id":"7c014c58.e8d504","type":"change","z":"24ae593d.edf0de","name":"","rules":[{"t":"set","p":"endDate","pt":"flow","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":890,"y":2140,"wires":[[]]},{"id":"ac42262f.104ef","type":"debug","z":"24ae593d.edf0de","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":980,"y":2300,"wires":[]},{"id":"c768a229.381808","type":"debug","z":"24ae593d.edf0de","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":640,"y":2320,"wires":[]},{"id":"f26fc68d.b2996","type":"ui_group","name":"DEWA-10 Chart-Logger","tab":"48814208.274a2c","order":1,"disp":false,"width":"50","collapse":false},{"id":"ebf52c2e.a8b058","type":"MySQLdatabase","name":"","host":"127.0.0.1","port":"3306","db":"field_adera","tz":"","charset":""},{"id":"48814208.274a2c","type":"ui_tab","name":"DEWA-10 Chart-Logger","icon":"dashboard","order":397,"disabled":false,"hidden":true}]

How did you trigger this? from the dashboard link? or node-red inject?

Ok, i spotted your issue - you discard the incomming msg in function "My SQL Database Request" and instead send a new msg2 object.

As i said earlier...

... you are effectively removing the necessary parts of the msg for it to respond to the caller.

try this...

[{"id":"53cb80.1fbbb48","type":"ui_date_picker","z":"30e2e9e0.eeaab6","name":"","label":"Start Date","group":"f26fc68d.b2996","order":1,"width":"5","height":"5","passthru":true,"topic":"start_date","x":180,"y":920,"wires":[["5b8389e0.371f88"]]},{"id":"1d1317a5.ebe9c8","type":"ui_date_picker","z":"30e2e9e0.eeaab6","name":"","label":"End Date","group":"f26fc68d.b2996","order":2,"width":"5","height":"5","passthru":true,"topic":"end_date","x":180,"y":960,"wires":[["5492cbec.551d34"]]},{"id":"7bb17c6a.e09a04","type":"function","z":"30e2e9e0.eeaab6","name":"My SQL Database Request","func":"var port= \"dewa_10\"; //replace with port no\nvar startDate = flow.get(\"startDate\");\nvar endDate = flow.get(\"endDate\");\nmsg.topic=\"select * from (select substr(datetime, 1, 13) as waktu, `pi`,`ti`,status,mode,engine_volt,motor_frequency,`motor_voltage`,`motor_current`,`dts` from \"+port+\" WHERE datetime BETWEEN '\"+startDate+\"' AND '\"+endDate+\"' order by datetime ) t GROUP BY waktu\"\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":240,"y":1120,"wires":[["cd8e581.20defa8"]]},{"id":"cd8e581.20defa8","type":"mysql","z":"30e2e9e0.eeaab6","mydb":"ebf52c2e.a8b058","name":"","x":470,"y":1120,"wires":[["d8d04990.bd0d28","ac42262f.104ef"]]},{"id":"d8d04990.bd0d28","type":"csv","z":"30e2e9e0.eeaab6","name":"","sep":",","hdrin":"","hdrout":"all","multi":"mult","ret":"\\r\\n","temp":"waktu,pi,ti,status,mode,engine,mf,mv,mc,dts","skip":"0","strings":false,"include_empty_strings":false,"include_null_values":false,"x":650,"y":1120,"wires":[["216a4830.f7526","c768a229.381808"]]},{"id":"6815af8f.c938c8","type":"http response","z":"30e2e9e0.eeaab6","name":"","statusCode":"","headers":{},"x":970,"y":1120,"wires":[]},{"id":"d5cbfb5a.4fe68","type":"catch","z":"30e2e9e0.eeaab6","name":"","scope":null,"uncaught":false,"x":200,"y":1180,"wires":[["9808c14b.60f0f","56c02bc6.f48c54"]]},{"id":"9808c14b.60f0f","type":"function","z":"30e2e9e0.eeaab6","name":"Set 404","func":"msg.payload = msg.error;\nmsg.statusCode = 404;//resource not found\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":800,"y":1180,"wires":[["6815af8f.c938c8"]]},{"id":"56c02bc6.f48c54","type":"debug","z":"30e2e9e0.eeaab6","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":230,"y":1240,"wires":[]},{"id":"cf1dc7e6.d577e8","type":"ui_template","z":"30e2e9e0.eeaab6","group":"f26fc68d.b2996","name":"ui_temlplate - present download link on dashboard","order":0,"width":0,"height":0,"format":"<div >\n    <a href=\"/data\">CLICK TO DOWNLOAD</a>\n</div>","storeOutMessages":true,"fwdInMessages":true,"resendOnRefresh":false,"templateScope":"local","x":570,"y":1240,"wires":[[]]},{"id":"5721ab4c.15e954","type":"http in","z":"30e2e9e0.eeaab6","name":"","url":"/data","method":"get","upload":false,"swaggerDoc":"","x":180,"y":1060,"wires":[["7bb17c6a.e09a04"]]},{"id":"216a4830.f7526","type":"function","z":"30e2e9e0.eeaab6","name":"Set Headers","func":"msg.headers = {}\nmsg.headers[\"Content-type\"] = \"text/csv\";\nmsg.headers[\"Content-Disposition\"] = \"attachment; filename=data.csv\";\nmsg.headers[\"Pragma\"] = \"no-cache\";\nmsg.headers[\"Expires\"] = \"0\";\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":810,"y":1120,"wires":[["6815af8f.c938c8"]]},{"id":"3668080d.9e73e8","type":"change","z":"30e2e9e0.eeaab6","name":"","rules":[{"t":"set","p":"startDate","pt":"flow","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":590,"y":920,"wires":[[]]},{"id":"7c014c58.e8d504","type":"change","z":"30e2e9e0.eeaab6","name":"","rules":[{"t":"set","p":"endDate","pt":"flow","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":580,"y":960,"wires":[[]]},{"id":"ac42262f.104ef","type":"debug","z":"30e2e9e0.eeaab6","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":470,"y":1060,"wires":[]},{"id":"c768a229.381808","type":"debug","z":"30e2e9e0.eeaab6","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":670,"y":1060,"wires":[]},{"id":"5492cbec.551d34","type":"moment","z":"30e2e9e0.eeaab6","name":"","topic":"","input":"payload","inputType":"msg","inTz":"Asia/Bangkok","adjAmount":0,"adjType":"days","adjDir":"add","format":"YYYY-MM-DD","locale":"en_GB","output":"payload","outputType":"msg","outTz":"Asia/Bangkok","x":370,"y":960,"wires":[["7c014c58.e8d504"]]},{"id":"5b8389e0.371f88","type":"moment","z":"30e2e9e0.eeaab6","name":"","topic":"","input":"payload","inputType":"msg","inTz":"Asia/Bangkok","adjAmount":0,"adjType":"days","adjDir":"add","format":"YYYY-MM-DD","locale":"en_GB","output":"payload","outputType":"msg","outTz":"Asia/Bangkok","x":370,"y":920,"wires":[["3668080d.9e73e8"]]},{"id":"f26fc68d.b2996","type":"ui_group","name":"DEWA-10 Chart-Logger","tab":"48814208.274a2c","order":1,"disp":false,"width":"50","collapse":false},{"id":"ebf52c2e.a8b058","type":"MySQLdatabase","name":"","host":"127.0.0.1","port":"3306","db":"field_adera","tz":""},{"id":"48814208.274a2c","type":"ui_tab","name":"DEWA-10 Chart-Logger","icon":"dashboard","order":397,"disabled":false,"hidden":true}]
1 Like

Oh My God!
Thank you very much man!

I'm not noticed this part msg2 will make problem.
Thank you once again!