`[{"id":"f47194e4.69d0f8","type":"inject","z":"b166da4.4f2dc28","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":125,"y":117,"wires":[["94cadb7.9334d28"]]},{"id":"70ab6deb.0342e4","type":"debug","z":"b166da4.4f2dc28","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","x":649,"y":182,"wires":[]},{"id":"3cb35f71.9714b","type":"change","z":"b166da4.4f2dc28","name":"change","rules":[{"t":"set","p":"payload[0].logging_type","pt":"msg","to":"logging_type","tot":"str"},{"t":"set","p":"payload[0].vender","pt":"msg","to":"vender","tot":"str"},{"t":"set","p":"payload[0].station_ref","pt":"msg","to":"station_ref","tot":"str"},{"t":"set","p":"payload[0].station_id","pt":"msg","to":"station_id","tot":"str"},{"t":"set","p":"payload[0].station_name","pt":"msg","to":"station_name","tot":"str"},{"t":"set","p":"payload[0].year","pt":"msg","to":"y","tot":"msg"},{"t":"set","p":"payload[0].month","pt":"msg","to":"m","tot":"msg"},{"t":"set","p":"payload[0].day","pt":"msg","to":"d","tot":"msg"},{"t":"set","p":"payload[0].hour","pt":"msg","to":"h","tot":"msg"},{"t":"set","p":"payload[0].minute","pt":"msg","to":"min","tot":"msg"},{"t":"set","p":"payload[0].second","pt":"msg","to":"s","tot":"msg"},{"t":"set","p":"payload[0].total_data","pt":"msg","to":"4","tot":"str"},{"t":"set","p":"payload[0].data1","pt":"msg","to":"data1","tot":"msg"},{"t":"set","p":"payload[0].data2","pt":"msg","to":"data2","tot":"msg"},{"t":"set","p":"payload[0].data3","pt":"msg","to":"data3","tot":"msg"},{"t":"set","p":"payload[0].data4","pt":"msg","to":"data4","tot":"msg"},{"t":"set","p":"payload[0].message","pt":"msg","to":"Complete","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":442,"y":106,"wires":[["5621ca35.1d9b84"]]},{"id":"5621ca35.1d9b84","type":"xml","z":"b166da4.4f2dc28","name":"","property":"payload","attr":"","chr":"","x":426,"y":149,"wires":[["9bd6e5e2.ecb508"]]},{"id":"9bd6e5e2.ecb508","type":"change","z":"b166da4.4f2dc28","name":"","rules":[{"t":"change","p":"payload","pt":"msg","from":"<0>","fromt":"str","to":"<LOGGING>","tot":"str"},{"t":"change","p":"payload","pt":"msg","from":"</0>","fromt":"str","to":"</LOGGING>","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":405,"y":192,"wires":[["64777c6f.6d80f4"]]},{"id":"64777c6f.6d80f4","type":"function","z":"b166da4.4f2dc28","name":"insert <send_date><send_time>","func":"/* Program to add <Current> before every <year> and </Current> after every </day> in an XML string: */\n// loop through all the data, which is the msg.payload string:\nvar data = msg.payload;\nfor(i = 0; i < data.length; i++) {\n // make note of where the date information starts with \"<year>\":\n year = data.indexOf(\"<year>\", i);\n // if this is not found, break out of the loop:\n if (year == -1) break;\n // insert \"<Current>\" BEFORE the \"<year>\" tag:\n data = data.slice(0,year) + \"<send_date>\" + data.slice(year, data.length);\n \n // make note of where the date information ends with \"</day>\" + 6 offset:\n day = data.indexOf(\"</day>\", i);\n // if this is not found, break out of the loop:\n if (day == -1) break;\n // insert \"</Current>\" AFTER the \"</day>\" tag:\n data = data.slice(0,day+6) + \"</send_date>\" + data.slice(day+6, data.length); \n // start looking for the next date *after* this one has ended:\n i = day+6;\n \n hour = data.indexOf(\"<hour>\", i);\n // if this is not found, break out of the loop:\n if (hour == -1) break;\n // insert \"<Current>\" BEFORE the \"<year>\" tag:\n data = data.slice(0,hour) + \"<send_time>\" + data.slice(hour, data.length);\n \n // make note of where the date information ends with \"</day>\" + 6 offset:\n second = data.indexOf(\"</second>\", i);\n // if this is not found, break out of the loop:\n if (second == -1) break;\n // insert \"</Current>\" AFTER the \"</day>\" tag:\n data = data.slice(0,second+9) + \"</send_time>\" + data.slice(second+9, data.length); \n // start looking for the next date *after* this one has ended:\n i = second+9;\n \n data1 = data.indexOf(\"<data1>\", i);\n // if this is not found, break out of the loop:\n if (data1 == -1) break;\n // insert \"<Current>\" BEFORE the \"<year>\" tag:\n data = data.slice(0,data1) + \"<logging>\" + data.slice(data1, data.length);\n \n // make note of where the date information ends with \"</day>\" + 6 offset:\n data4 = data.indexOf(\"</data4>\", i);\n // if this is not found, break out of the loop:\n if (data4 == -1) break;\n // insert \"</Current>\" AFTER the \"</day>\" tag:\n data = data.slice(0,data4+8) + \"</logging>\" + data.slice(data4+8, data.length); \n // start looking for the next date *after* this one has ended:\n i = data4+8;\n \n \n message = data.indexOf(\"<message>\", i);\n // if this is not found, break out of the loop:\n if (message == -1) break;\n // insert \"<Current>\" BEFORE the \"<year>\" tag:\n data = data.slice(0,message) + \"<status>\" + data.slice(message, data.length);\n \n \n // make note of where the date information ends with \"</day>\" + 6 offset:\n message = data.indexOf(\"</message>\", i);\n // if this is not found, break out of the loop:\n if (message == -1) break;\n // insert \"</Current>\" AFTER the \"</day>\" tag:\n data = data.slice(0,message+10) + \"</status>\" + data.slice(message+10, data.length); \n // start looking for the next date *after* this one has ended:\n i = message+10;\n}\n// return the new data:\nreturn { payload : data };","outputs":1,"noerr":0,"x":401,"y":233,"wires":[["70ab6deb.0342e4"]]},{"id":"b675f835.e0c628","type":"MSSQL","z":"b166da4.4f2dc28","mssqlCN":"24efa47f.17bfec","name":"trend_data","query":"","outField":"payload","x":113,"y":206,"wires":[["ba1fc60a.937858"]]},{"id":"94cadb7.9334d28","type":"change","z":"b166da4.4f2dc28","name":"select from database","rules":[{"t":"set","p":"payload","pt":"msg","to":"SELECT[logging_type],[vender_id],[vender],[station_ref],[station_id],[station_name],[year],[month],[day],[hour],[minute],[second],[total_data],[data1],[data2],[data3],[data4],[message]FROM[trainee].[dbo].[trend]","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":143,"y":159,"wires":[["b675f835.e0c628"]]},{"id":"ba1fc60a.937858","type":"function","z":"b166da4.4f2dc28","name":"Function","func":"d = new Date();\nhour = d.getHours();\nminute = d.getMinutes(); // current minute\nyear = d.getFullYear();\nmonth = d.getMonth() +1;\nday = d.getDate();\n\nif(minute % 5 === 0) { // if 0, 5, 10, 15 etc\n last = context.get('last')||0; // last minute for RBE\n \n if(minute != last) { // if this minute is new\n context.set('last', minute);\n \n \n if(minute === 15||20||25||30||35||40||45||50||55){\n minuteFive = minute-5;\n minuteTen = minute-10;\n minuteFifteen = minute-15;\n } \n if(minute === 10){\n minuteFive = \"0\"+minute -5;\n minuteTen = \"00\";\n minuteFifteen = \"00\";\n } \n if (minute ===5){\n minuteFive = \"00\";\n minuteTen = \"00\";\n minuteFifteen = \"00\";\n }\n if(minute ===0){\n minuteFive = minute;\n minuteTen = minute;\n minuteFifteen = minute;\n }\n \n }\n else return null; // block repeat minutes\n}\nelse return null; // block non 0, 15, 30, 45\n\n\nvar msg = {\n h : hour.toString(),\n min : minute.toString(),\n s : '00',\n y : year.toString(),\n m : '0'+month.toString(),\n d : day.toString(),\n data1 : year +\"-\"+\"0\"+month+\"-\"+day+\",\"+hour+\":\"+minuteFifteen+\":\"+'00'+\",0.9999995,3.48,0,2.9,3.7,1.4,90000,90000,93110,90000,93300,90000,-0.92,-0.92,0,0,0,0,0,0,0,0,1,1,1,0,0,0,0,0,0,90000,90000,90000\",\n data2 : year +\"-\"+\"0\"+month+\"-\"+day+\",\"+hour+\":\"+minuteTen+\":\"+'00'+\",0.9999995,3.48,0,2.9,3.7,1.4,90000,90000,93110,90000,93300,90000,-0.92,-0.92,0,0,0,0,0,0,0,0,1,1,1,0,0,0,0,0,0,90000,90000,90000\",\n data3 : year +\"-\"+\"0\"+month+\"-\"+day+\",\"+hour+\":\"+minuteFive+\":\"+'00'+\",0.9999995,3.48,0,2.9,3.7,1.4,90000,90000,93110,90000,93300,90000,-0.92,-0.92,0,0,0,0,0,0,0,0,1,1,1,0,0,0,0,0,0,90000,90000,90000\",\n data4 : year +\"-\"+\"0\"+month+\"-\"+day+\",\"+hour+\":\"+minute+\":\"+'00'+\",0.9999995,3.48,0,2.9,3.7,1.4,90000,90000,93110,90000,93300,90000,-0.92,-0.92,0,0,0,0,0,0,0,0,1,1,1,0,0,0,0,0,0,90000,90000,90000\",\n}\n\nreturn msg;\n\n//min=35;\n//mins = 35 -5;\n\n//msg.send= min +\"/\"+mins+\"/\"+ \"32134\";\n//return msg;","outputs":1,"noerr":0,"x":114,"y":248,"wires":[["3cb35f71.9714b"]]},{"id":"24efa47f.17bfec","type":"MSSQL-CN","z":"","tdsVersion":"7_4","name":"trend","server":"192.168.1.102","port":"1433","encyption":true,"database":"trainee","useUTC":true,"connectTimeout":"15000","requestTimeout":"15000","cancelTimeout":"5000","pool":"5"}]`
HI, please ignore the previous what I’m asking. (because I’m confusing already)
This flow have some problems about :
1.) The month how to change to “04” because I’m hardcode and the minute for 5 how to change become “05”? Because the minute I want store in the MSSQL database.
2.) How to convert the data to XML. I think is somethings wrong with payload. The code as below :
`[{"id":"e3b0310c.77154","type":"debug","z":"b166da4.4f2dc28","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":664,"y":588,"wires":[]},{"id":"42863197.15903","type":"MSSQL","z":"b166da4.4f2dc28","mssqlCN":"24efa47f.17bfec","name":"TableTrendData","query":"with a as( SELECT TOP 4 * FROM [trainee].[dbo].[TableTrendData] ORDER BY ID DESC ) select * from a ORDER BY ID ASC","outField":"payload","x":260,"y":588,"wires":[["d22233aa.d0528"]]},{"id":"45f53bca.40e274","type":"inject","z":"b166da4.4f2dc28","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":101,"y":587,"wires":[["42863197.15903"]]},{"id":"d22233aa.d0528","type":"function","z":"b166da4.4f2dc28","name":"","func":"a = msg.payload[0]\nb = msg.payload[1]\nc = msg.payload[2]\nd = msg.payload[3]\n\nvar msg = {\n\"LOGGING\": {\n\"logging_type\":\"Trend\",\n\"vender_id\": \"Dave\",\n\"vender\":\"Reminder\",\n\"station_ref\":\"Update the website\",\n\"station_id\":\"Update the website\",\n\"station_name\":\"Update the website\",\n\"send_date\": {\n\"year\": d.Year,\n\"month\":d.Month,\n\"day\": d.Day\n},\n\"send_time\": {\n\"hour\": d.Hour,\n\"minute\":d.Minute,\n\"secound\":d.Second\n},\n\"total_data\":4,\n\"logging\": {\ndata1 : a.Year +\"-\"+ a.Month +\"-\"+ a.Day +\",\"+ a.Hour+\":\"+a.Minute+\":\"+a.Second+\",\"+a.Upstream+\",\"+a.Downstream+\",\"+a.Tidal+\",\"+a.Danger_Set_Point+\",\"+a.Alert_Set_Point+\",\"+a.Control_Level_Set_Point+\",\"+a.Gate_ConditionOnetoFour+\",\"+a.Gate_ConditionFivetoEight+\",\"+a.Gate_ModeOnetoFour+\",\"+a.Gate_ModeFivetoEight+\",\"+a.Gate_StatusOnetoFour+\",\"+a.Gate_StatusFivetoEight+\",\"+a.GateOnePosition+\",\"+a.GateTwoPosition+\",\"+a.GateThreePosition+\",\"+a.GateFourPosition+\",\"+a.GateFivePosition+\",\"+a.GateSixPosition+\",\"+a.GateSevenPosition+\",\"+a.GateEightPosition+\",\"+a.GateNinePosition+\",\"+a.GateTenPosition+\",\"+a.Red_Phase+\",\"+a.Yellow_Phase+\",\"+a.Blue_Phase+\",0,0,0,0,0,0,\"+a.Gate_ConditionNinetoTen+\",\"+a.Gate_ModeNinetoTen+\",\"+a.Gate_StatusNinetoTen,\ndata2 : b.Year +\"-\"+ b.Month +\"-\"+ b.Day+\",\"+ b.Hour+\":\"+b.Minute+\":\"+b.Second+\",\"+b.Upstream+\",\"+a.Downstream+\",\"+b.Tidal+\",\"+b.Danger_Set_Point+\",\"+b.Alert_Set_Point+\",\"+b.Control_Level_Set_Point+\",\"+b.Gate_ConditionOnetoFour+\",\"+b.Gate_ConditionFivetoEight+\",\"+b.Gate_ModeOnetoFour+\",\"+b.Gate_ModeFivetoEight+\",\"+b.Gate_StatusOnetoFour+\",\"+b.Gate_StatusFivetoEight+\",\"+b.GateOnePosition+\",\"+b.GateTwoPosition+\",\"+b.GateThreePosition+\",\"+b.GateFourPosition+\",\"+b.GateFivePosition+\",\"+b.GateSixPosition+\",\"+b.GateSevenPosition+\",\"+b.GateEightPosition+\",\"+b.GateNinePosition+\",\"+b.GateTenPosition+\",\"+b.Red_Phase+\",\"+b.Yellow_Phase+\",\"+b.Blue_Phase+\",0,0,0,0,0,0,\"+b.Gate_ConditionNinetoTen+\",\"+b.Gate_ModeNinetoTen+\",\"+b.Gate_StatusNinetoTen,\ndata3 : c.Year +\"-\"+ c.Month +\"-\"+ c.Day+\",\"+ c.Hour+\":\"+c.Minute+\":\"+c.Second+\",\"+c.Upstream+\",\"+a.Downstream+\",\"+c.Tidal+\",\"+c.Danger_Set_Point+\",\"+c.Alert_Set_Point+\",\"+c.Control_Level_Set_Point+\",\"+c.Gate_ConditionOnetoFour+\",\"+c.Gate_ConditionFivetoEight+\",\"+c.Gate_ModeOnetoFour+\",\"+c.Gate_ModeFivetoEight+\",\"+c.Gate_StatusOnetoFour+\",\"+c.Gate_StatusFivetoEight+\",\"+c.GateOnePosition+\",\"+c.GateTwoPosition+\",\"+c.GateThreePosition+\",\"+c.GateFourPosition+\",\"+c.GateFivePosition+\",\"+c.GateSixPosition+\",\"+c.GateSevenPosition+\",\"+c.GateEightPosition+\",\"+c.GateNinePosition+\",\"+c.GateTenPosition+\",\"+c.Red_Phase+\",\"+c.Yellow_Phase+\",\"+c.Blue_Phase+\",0,0,0,0,0,0,\"+c.Gate_ConditionNinetoTen+\",\"+c.Gate_ModeNinetoTen+\",\"+c.Gate_StatusNinetoTen,\ndata4 : d.Year +\"-\"+ d.Month +\"-\"+ d.Day+\",\"+ d.Hour+\":\"+d.Minute+\":\"+d.Second+\",\"+d.Upstream+\",\"+a.Downstream+\",\"+d.Tidal+\",\"+d.Danger_Set_Point+\",\"+d.Alert_Set_Point+\",\"+d.Control_Level_Set_Point+\",\"+d.Gate_ConditionOnetoFour+\",\"+d.Gate_ConditionFivetoEight+\",\"+d.Gate_ModeOnetoFour+\",\"+d.Gate_ModeFivetoEight+\",\"+d.Gate_StatusOnetoFour+\",\"+d.Gate_StatusFivetoEight+\",\"+d.GateOnePosition+\",\"+d.GateTwoPosition+\",\"+d.GateThreePosition+\",\"+d.GateFourPosition+\",\"+d.GateFivePosition+\",\"+d.GateSixPosition+\",\"+d.GateSevenPosition+\",\"+d.GateEightPosition+\",\"+d.GateNinePosition+\",\"+d.GateTenPosition+\",\"+d.Red_Phase+\",\"+d.Yellow_Phase+\",\"+d.Blue_Phase+\",0,0,0,0,0,0,\"+d.Gate_ConditionNinetoTen+\",\"+d.Gate_ModeNinetoTen+\",\"+d.Gate_StatusNinetoTen\n},\n\"status\":\"complete\"\n}\n}\nreturn msg;","outputs":1,"noerr":0,"x":411,"y":589,"wires":[["3001fb50.7d6fe4"]]},{"id":"3001fb50.7d6fe4","type":"xml","z":"b166da4.4f2dc28","name":"","property":"payload","attr":"","chr":"","x":539,"y":588,"wires":[["e3b0310c.77154"]]},{"id":"24efa47f.17bfec","type":"MSSQL-CN","z":"","tdsVersion":"7_4","name":"trend","server":"192.168.1.102","port":"1433","encyption":true,"database":"trainee","useUTC":true,"connectTimeout":"15000","requestTimeout":"15000","cancelTimeout":"5000","pool":"5"}]`
3.) How to display or debug full data because I want preview full data.
TQVM.