-
Notifications
You must be signed in to change notification settings - Fork 0
/
posco-kr-flow.json
1 lines (1 loc) · 138 KB
/
posco-kr-flow.json
1
[{"id":"54fead13.e0d974","type":"tab","label":"Simulator","disabled":false,"info":""},{"id":"f41712ff.dd9de","type":"tab","label":"Data Receive ","disabled":false,"info":""},{"id":"11c5be82.e35261","type":"tab","label":"TEMP","disabled":true,"info":""},{"id":"c45e3888.e82a68","type":"tab","label":"Flow 1","disabled":true,"info":""},{"id":"a28692d4.03579","type":"MySQLdatabase","z":"","host":"127.0.0.1","port":"3306","db":"posco","tz":"30"},{"id":"536d87d3.cb0088","type":"mqtt-broker","z":"","name":"KR MQTT","broker":"localhost","port":"1883","clientid":"","usetls":false,"compatmode":true,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","willTopic":"","willQos":"0","willPayload":""},{"id":"85a94193.17dfb","type":"influxdb","z":"","hostname":"localhost","port":"8086","protocol":"http","database":"thingspin","name":"InfluxDB Localhost","usetls":false,"tls":""},{"id":"d6cadf0a.6e81","type":"mqtt-broker","z":"","name":"KR MQTT","broker":"localhost","port":"1883","clientid":"","usetls":false,"compatmode":true,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","willTopic":"","willQos":"0","willPayload":""},{"id":"fa98ec3b.aa1b8","type":"mqtt-broker","z":"","name":"KR MQTT","broker":"localhost","port":"1883","clientid":"","usetls":false,"compatmode":true,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","willTopic":"","willQos":"0","willPayload":""},{"id":"b48cad1a.c9913","type":"mqtt-broker","z":"","name":"KR MQTT","broker":"localhost","port":"1883","clientid":"","usetls":false,"compatmode":true,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","willTopic":"","willQos":"0","willPayload":""},{"id":"497a31af.88192","type":"comment","z":"54fead13.e0d974","name":"L2 Data Sender (Disable)","info":"","x":130,"y":480,"wires":[]},{"id":"1ab3a350.084bcd","type":"inject","z":"54fead13.e0d974","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":140,"y":520,"wires":[["2827308e.7ef5"]]},{"id":"2827308e.7ef5","type":"function","z":"54fead13.e0d974","name":"Make-Data-Set Ver 1.0","func":"//Function Area -----------------------------------------------------------------------------------------\nDate.prototype.yyyymmdd = function() {\n function pad2(n) { // always returns a string\n return (n < 10 ? '0' : '') + n;\n }\n\n return this.getFullYear() +\n pad2(this.getMonth() + 1) + \n pad2(this.getDate()) +\n pad2(this.getHours()) +\n pad2(this.getMinutes()) +\n pad2(this.getSeconds());\n};\n\nfunction getUID(len){\n var chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789',\n out = '';\n\n for(var i=0, clen=chars.length; i<len; i++){\n out += chars.substr(0|Math.random() * clen, 1);\n }\n return out;\n}\n\nfunction getUIDwithSize(len,size){\n var chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789',\n out = '';\n\n for(var i=0, clen=chars.length; i<len; i++){\n out += chars.substr(0|Math.random() * clen, 1);\n }\n return checkLengthString(out, size);\n}\n\nfunction checkLengthString(str, len) {\n var check = str.length;\n if (check === undefined) {\n check = (str.toString()).length;\n }\n console.log(str +\":\"+ len +\":\"+ check)\n if (check < len) {\n for (var i = 0 ; i < (len - check) ; i++) {\n str += \" \";\n }\n } else if(check > len) {\n str = str.slice(0, len)\n }\n return str;\n}\n\nfunction getRandomShort(size) {\n var result =0;\n if (size === 2)\n result = Math.round(Math.random() *100);\n else if (size === 3)\n result = Math.round(Math.random() *1000);\n else if (size === 4)\n result = Math.round(Math.random() *10000);\n\n return checkLengthString(result, size);\n}\n\nfunction getRandomInt(multiple,size) {\n var value = Math.round(Math.random() * multiple);\n return checkLengthString(value, size);\n}\n\nfunction getBooleanData(value) {\n if (value) {\n return Math.round((Math.random() * 1) + 0) === 0; \n } else {\n var resultStr = Math.round((Math.random() * 1) + 0) === 0;\n if (resultStr === true)\n return 1;\n else\n return 0;\n }\n}\n\nfunction makeData(msgType, format, lastClose) {\n console.log(format);\n var size = format.title.length;\n var output = \"\";\n for (var i=0; i<size; i++) {\n switch(format.type[i]) {\n case 'char' :\n {\n if (format.title[i] === \"Process\") {\n output += msgType.Process;\n } else if (format.title[i] === \"Time\") {\n var date = new Date();\n output += date.yyyymmdd();\n } else if (format.title[i] === \"Spare\") {\n output += checkLengthString(\"\",format.len[i]);\n } else if (format.title[i] === \"CHARGE_NO\") {\n output += getUIDwithSize(8, format.len[i]);\n } else if (format.title[i] === \"TC_CODE\") {\n output += msgType.TC_CODE;\n } else if (format.title[i] === \"Length\") {\n var length = msgType.DataLength;\n output += checkLengthString(length,format.len[i]);\n } else {\n output += getUID(format.len[i]);\n }\n break;\n }\n case 'short' :\n output += getRandomShort(format.len[i]);\n break;\n case 'boolean' :\n output += getBooleanData(false);\n continue;\n case 'int' :\n if (format.len[i] === 2)\n output += getRandomInt(100, format.len[i]);\n else if (format.len[i] === 3)\n output += getRandomInt(1000, format.len[i]);\n else if (format.len[i] === 4)\n output += getRandomInt(10000, format.len[i]);\n break;\n case 'datetime' :\n var date = new Date();\n output += date.yyyymmdd(); \n break;\n }\n }\n if (lastClose === true)\n output += \"\\n\";\n console.log(output);\n console.log(output.length);\n return output;\n}\n//Main Area ---------------------------------------------------------------------------------------------\nvar size = context.global.FormatData.length;\nvar formatArray = [];\nfor (var i=0; i<size; i++) {\n var format = context.global.FormatData[i];\n formatArray.push(format);\n}\nvar randomValue = Math.floor(Math.random()*(formatArray.length));\nconsole.log(randomValue);\nconsole.log(formatArray);\nmsg.payload = makeData(formatArray[randomValue], context.global.FormatObjMap.get(formatArray[randomValue].TC_CODE), false);\nreturn msg;","outputs":1,"noerr":0,"x":360,"y":520,"wires":[["9dea94b3.b63518"]]},{"id":"8318bcd3.34e85","type":"comment","z":"54fead13.e0d974","name":"DDS AI Server Sender","info":"","x":120,"y":280,"wires":[]},{"id":"d6560ef.5046ef","type":"inject","z":"54fead13.e0d974","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":140,"y":320,"wires":[["d2795d42.5c4ef"]]},{"id":"4a344b11.c984f4","type":"function","z":"54fead13.e0d974","name":"Make Data","func":"function getUID(len){\n var chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789',\n out = '';\n\n for(var i=0, clen=chars.length; i<len; i++){\n out += chars.substr(0|Math.random() * clen, 1);\n if (i+1 == 8) {\n out += \".\"; \n }\n }\n // ensure that the uid is unique for this page\n return out;\n}\n\nfunction getSNO() {\n return \"CAM01\";\n}\n\nfunction getRandom() {\n var bottomValue = Math.round(Math.random() *1000);\n var topValue = Math.round(Math.random() *1000);\n return topValue + \".\" + bottomValue;\n}\nvar base64Image = JSON.parse(msg.payload);\nvar strImage = base64Image[0].value;\nvar postLadleData = {\n id : getSNO(),\n distance : parseFloat(getRandom()),\n image : strImage\n};\n\nmsg.payload = postLadleData;\n\nmsg.headers = {\n \"contents-Type\": \"application/json\"\n};\n\nreturn msg;","outputs":1,"noerr":0,"x":710,"y":320,"wires":[["1d8c363e.ba98ea"]]},{"id":"1d8c363e.ba98ea","type":"http request","z":"54fead13.e0d974","name":"Post KR","method":"POST","ret":"obj","url":"http://localhost:1880/thingspin/api/kr","tls":"","x":880,"y":320,"wires":[["e7814e68.61b64"]]},{"id":"e7814e68.61b64","type":"debug","z":"54fead13.e0d974","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":1050,"y":320,"wires":[]},{"id":"9dea94b3.b63518","type":"tcp request","z":"54fead13.e0d974","server":"localhost","port":"50000","out":"sit","splitc":" ","name":"L2 Data Simulator (Disalble)","x":620,"y":520,"wires":[["3e408a78.336056"]]},{"id":"3e408a78.336056","type":"function","z":"54fead13.e0d974","name":"Response Data Convert","func":"var resultStrData = msg.payload.toString('utf-8');\nmsg.dataLength = msg.payload.length;\nmsg.payload = resultStrData;\nreturn msg;","outputs":1,"noerr":0,"x":890,"y":520,"wires":[["80664747.617f48"]]},{"id":"80664747.617f48","type":"debug","z":"54fead13.e0d974","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":1090,"y":520,"wires":[]},{"id":"d2795d42.5c4ef","type":"function","z":"54fead13.e0d974","name":"Set Type","func":"msg.type = \"KR\"\nreturn msg;","outputs":1,"noerr":0,"x":320,"y":320,"wires":[[]]},{"id":"3ebe2726.f59f58","type":"http in","z":"f41712ff.dd9de","name":"KR","url":"/thingspin/api/kr","method":"post","upload":false,"swaggerDoc":"","x":150,"y":160,"wires":[["aa8b846f.2ac8d8"]]},{"id":"aa8b846f.2ac8d8","type":"json","z":"f41712ff.dd9de","name":"","property":"payload","action":"obj","pretty":false,"x":370,"y":160,"wires":[["3fa8b6f.f4c104a","80cd13ce.94d74","b66bba6b.4e1958"]]},{"id":"c887e0bf.a6522","type":"config","z":"f41712ff.dd9de","name":"Config","properties":[{"p":"basePath","pt":"global","to":"D:\\\\thingspin\\\\server\\\\data\\\\thingspin\\\\images\\\\","tot":"str"},{"p":"filePrefix","pt":"global","to":"KR","tot":"str"},{"p":"fileLadlePrefix","pt":"global","to":"LADEL","tot":"str"},{"p":"mlPrefix","pt":"global","to":"mlexam","tot":"str"},{"p":"basePath-ORG","pt":"flow","to":"D:\\\\thingspin\\\\server\\\\data\\\\thingspin\\\\images\\\\","tot":"str"},{"p":"baseDataPath","pt":"global","to":"D:\\\\thingspin\\\\data\\\\","tot":"str"},{"p":"baseDataPath-ORG","pt":"global","to":"D:\\\\thingspin\\\\data\\\\","tot":"str"},{"p":"SendTccode","pt":"global","to":"[\"3020\",\"3021\",\"3022\",\"3023\"]","tot":"json"},{"p":"PublishTime","pt":"global","to":"[\"3184\",\"0\",\"0\",\"0\"]","tot":"json"}],"active":true,"x":90,"y":40,"wires":[]},{"id":"3a4db9c3.af6e76","type":"tcp in","z":"f41712ff.dd9de","name":"TCP Server","server":"server","host":"","port":"50000","datamode":"stream","datatype":"buffer","newline":"\\n","topic":"","base64":false,"x":150,"y":440,"wires":[["cd6afc81.de2b8","96543948.563648"]]},{"id":"4ebde6c2.bbb228","type":"comment","z":"f41712ff.dd9de","name":"Data Slice and Insert to DB","info":"","x":410,"y":500,"wires":[]},{"id":"7092aab1.b6dd04","type":"comment","z":"f41712ff.dd9de","name":"Input Infomation Insert to DB","info":"","x":420,"y":400,"wires":[]},{"id":"af37812f.6f477","type":"comment","z":"f41712ff.dd9de","name":"HTTP KR POST Process","info":"","x":150,"y":120,"wires":[]},{"id":"be09d705.39f868","type":"comment","z":"f41712ff.dd9de","name":"TCP Server Process","info":"","x":130,"y":380,"wires":[]},{"id":"c28b4f15.c857e","type":"comment","z":"f41712ff.dd9de","name":"MQTT Process","info":"","x":120,"y":1000,"wires":[]},{"id":"acef7045.c2923","type":"function","z":"f41712ff.dd9de","name":"Create insert mariadb query ","func":"//Function Area -----------------------------------------------------------------------------------------\nfunction makeColumnString(dataType, valueData) {\n var title = dataType.dbsechma;\n var type = dataType.type;\n var columns = \"(\";\n var values = \"(\";\n console.log(title);\n for (var i=0; i<title.length;i++) {\n if (i+1 == title.length) {\n columns += title[i] + \")\";\n if (title[i] === 'UUID') {\n values += \"'\" + msg._msgid + \"')\";\n } else {\n if (type[i] !== 'char')\n values += valueData.get(title[i]) + \")\";\n else\n values += \"'\" + valueData.get(title[i]) + \"')\";\n }\n } else {\n columns += title[i] + \",\";\n if (type[i] !== 'char')\n values += valueData.get(title[i]) + \",\";\n else \n values += \"'\" + valueData.get(title[i]) + \"',\";\n }\n }\n var result = {\n columnStr : columns,\n valueStr : values\n };\n console.log(result);\n return result;\n}\n\n//Main Area -----------------------------------------------------------------------------------------\nvar dataMap = context.global.dataMap;\nvar dataFormat = context.global.FormatObjMap.get(msg.tag);\n// console.log(dataMap);\n// console.log(msg.tag);\n// console.log(dataFormat);\nvar queryInputData = makeColumnString(dataFormat, dataMap);\nvar queryStr = \"insert into \" + dataFormat.db + queryInputData.columnStr + \" values \" + queryInputData.valueStr;\n\nmsg.topic = queryStr;\n\nreturn msg;","outputs":1,"noerr":0,"x":700,"y":540,"wires":[["21342357.0f670c","8efb858d.069a48","42ca21a7.a68d6"]]},{"id":"ff33c5a3.ce4298","type":"function","z":"f41712ff.dd9de","name":"Influx Data Process","func":"//Main Area -----------------------------------------------------------------------------------------\nlet YYYYMMDD = context.global.todaydate;\nif (!YYYYMMDD) {\n YYYYMMDD = \"20180101\";\n}\n\n// msg.measurement = `posco-slab-${YYYYMMDD}`;\n\nmsg.payload = [{\n measurement:`posco-msg-${YYYYMMDD}`,\n fields:msg.fields,\n tags: {TC_CODE:msg.tag}\n}]\n\ndelete msg.fields;\nreturn msg;","outputs":1,"noerr":0,"x":670,"y":600,"wires":[["ed2436b5.6f2288"]]},{"id":"ed2436b5.6f2288","type":"influxdb batch","z":"f41712ff.dd9de","influxdb":"85a94193.17dfb","precision":"ms","retentionPolicy":"","name":"","x":1010,"y":600,"wires":[]},{"id":"21342357.0f670c","type":"mysql","z":"f41712ff.dd9de","mydb":"a28692d4.03579","name":"","x":970,"y":540,"wires":[[]]},{"id":"2a4ef654.70bfba","type":"http response","z":"f41712ff.dd9de","name":"","statusCode":"","headers":{},"x":1010,"y":100,"wires":[]},{"id":"b66bba6b.4e1958","type":"function","z":"f41712ff.dd9de","name":"construct-by-WIN","func":"function checkZeroTime(value) {\n return (value>9 ? '' : '0') + value\n}\n\nfunction nowDateFormat() {\n var nowTime = new Date();\n return nowTime.getFullYear() + checkZeroTime(nowTime.getMonth()+1) + checkZeroTime(nowTime.getDate());\n}\n\nvar p = msg.payload;\nvar metric = {};\n\nvar path = global.get(\"basePath\");\nconsole.log(path);\n\nif (context.global.todaydate === undefined) {\n context.global.todaydate = nowDateFormat();\n}\n\nvar date = context.global.todaydate;\nvar img = [];\nvar cameraID = p.id;\n\nObject.keys(p).filter((value) => { return (value !== 'image') }).map( (k) => {\n metric[k] = p[k];\n});\n\nvar data = {\n // path: path + date + \"\\\\\\\\\",\n path: path + date + \"\\\\\\\\\" + cameraID + \"\\\\\\\\\",\n directory : date,\n image: p.image,\n metric: metric\n};\n\ndelete msg.payload;\nmsg.statusCode = 200;\n\nreturn [msg, data];\n\n","outputs":2,"noerr":0,"x":570,"y":160,"wires":[["6441d114.b3bfa"],["c0c498dc.6d95e8"]]},{"id":"c0c498dc.6d95e8","type":"function","z":"f41712ff.dd9de","name":"img","func":"var fs = global.get(\"mkdirp\");\n\nfs(msg.path, function(e) {\n if (!e || (e && e.code === 'EEXIST')) {\n } else {\n console.log(e);\n }\n});\n\nvar b = global.get(\"base64-to-image\");\n// var b = global.get(\"base64-img\");\n// console.log(b);\n\nvar filePrefix = global.get(\"filePrefix\");\n\nvar image = msg.image;\nvar path = msg.path;\n\nvar t = Date.now();\nvar fileName = filePrefix + t;\n\nvar option = {\n fileName: fileName,\n type: 'jpg'\n};\n\nvar imageInfo = b(image, path, option);\n// console.log(msg);\nmsg.info = imageInfo;\nmsg.info.fullPath = path + fileName + \".\" + imageInfo.imageType;\ndelete msg.image;\ndelete msg.path;\n\nreturn msg;","outputs":1,"noerr":0,"x":810,"y":160,"wires":[["e1789fe5.7655","87f22f2c.cbbd5","b369b9e7.58d428"]]},{"id":"af433dbc.89d69","type":"mysql","z":"f41712ff.dd9de","mydb":"a28692d4.03579","name":"posco-ai","x":1180,"y":140,"wires":[[]]},{"id":"e1789fe5.7655","type":"function","z":"f41712ff.dd9de","name":"SQL","func":"var sql = \"INSERT INTO t_kr_capture (sno, uuid, distance, fileName, absPath, directory) values \";\n\nvar r = {\n sno: msg.metric.id,\n uuid: msg._msgid,\n distance: msg.metric.distance,\n fileName: msg.info.fileName,\n absPath: msg.info.fullPath,\n directory: msg.directory\n};\nconsole.log(msg.directory);\nvar values = \"\\\"\" + r.sno + \"\\\"\" + \",\"\nvalues += \"\\\"\" + r.uuid + \"\\\"\" + \",\"\nvalues += r.distance + \",\"\nvalues += \"\\\"\" + r.fileName + \"\\\"\" + \",\"\nvalues += \"\\\"\" + r.absPath + \"\\\"\" + \",\"\nvalues += \"\\\"\" + r.directory + \"\\\"\"\n\nsql = sql + \"(\" + values + \");\"\n\nmsg.topic = sql;\n\nreturn msg;","outputs":1,"noerr":0,"x":1010,"y":140,"wires":[["af433dbc.89d69"]]},{"id":"6441d114.b3bfa","type":"function","z":"f41712ff.dd9de","name":"response-kr","func":"delete msg.payload;\ndelete msg.topic;\n\nmsg.statusCode = 200;\nmsg.headers = {\n \"contents-Type\": \"application/json\"\n};\n\nmsg.payload = {\n Result:\"OK\"\n};\n\nreturn msg;","outputs":1,"noerr":0,"x":810,"y":100,"wires":[["2a4ef654.70bfba"]]},{"id":"3c928099.7cf49","type":"mqtt in","z":"f41712ff.dd9de","name":"","topic":"#","qos":"0","broker":"536d87d3.cb0088","x":150,"y":1040,"wires":[["849c79ac.b88c08","b9d1d45b.825b48"]]},{"id":"96543948.563648","type":"function","z":"f41712ff.dd9de","name":"Influx Data Process","func":"//Main Area -----------------------------------------------------------------------------------------\nlet YYYYMMDD = context.global.todaydate;\nif (!YYYYMMDD) {\n YYYYMMDD = \"20180101\";\n}\n\nsender_ip = msg.ip.slice(7, msg.ip.length);\nvar strData = msg.payload.toString('utf-8');\n\nmsg.payload = [{\n measurement:`posco-recv-${YYYYMMDD}`,\n fields:{\n Data:strData\n },\n tags: {\n TcNo:msg.tag,\n IP:sender_ip\n }\n}]\n\ndelete msg.fields;\nreturn msg;","outputs":1,"noerr":0,"x":390,"y":440,"wires":[["749054b6.3a7bfc"]]},{"id":"749054b6.3a7bfc","type":"influxdb batch","z":"f41712ff.dd9de","influxdb":"85a94193.17dfb","precision":"ms","retentionPolicy":"","name":"","x":690,"y":440,"wires":[]},{"id":"cd6afc81.de2b8","type":"function","z":"f41712ff.dd9de","name":"Buffer Parsing Process","func":"/* \n Return Map Data (format.title, value)\n*/\nfunction translateData(str, format) {\n if (context.global.dataMap === undefined || context.global.dataMap === null)\n context.global.dataMap = new Map();\n else \n context.global.dataMap.clear();\n \n if (context.global.dataType === undefined || context.global.dataType === null)\n context.global.dataType = new Map();\n else\n context.global.dataType.clear();\n // console.log(format);\n var sumTotal = 0;\n for (var i=0;i< format.title.length;i++) {\n if (i === 0) {\n sumTotal += (format.len[i])\n if (format.type[i] === 'char') {\n context.global.dataMap.set(format.title[i],msg.payload.slice(i, sumTotal).toString('utf-8'));\n } else if (format.type[i] === 'short') {\n var buff = new Buffer(format.len[i]);\n buff = msg.payload.slice(i, sumTotal);\n var inputValue = (buff.readUInt8(1) << 8) + buff.readUInt8(0);\n context.global.dataMap.set(format.title[i], inputValue);\n delete buff;\n } else if (format.type[i] === 'int') {\n var buff = new Buffer(format.len[i]);\n buff = msg.payload.slice(i, sumTotal);\n var inputValue = (buff.readUInt8(3) << 24) + (buff.readUInt8(2) << 16) + (buff.readUInt8(1) << 8) + buff.readUInt8(0);\n context.global.dataMap.set(format.title[i], inputValue);\n delete buff;\n } \n context.global.dataType.set(format.title[i], format.type[i]);\n } else {\n // console.log(\"first :\" +sumTotal + \" cut :\" + ((sumTotal) + format.len[i]));\n var buff = new Buffer(format.len[i]);\n buff = msg.payload.slice(sumTotal, (sumTotal) + format.len[i]);\n\n if (format.type[i] === 'char') {\n context.global.dataMap.set(format.title[i], buff.toString('utf-8'));\n } else if (format.type[i] === 'short') {\n var inputValue = (buff.readUInt8(1) << 8) + buff.readUInt8(0);\n context.global.dataMap.set(format.title[i], inputValue);\n } else if (format.type[i] === 'int') {\n var inputValue = (buff.readUInt8(3) << 24) + (buff.readUInt8(2) << 16) + (buff.readUInt8(1) << 8) + buff.readUInt8(0);\n context.global.dataMap.set(format.title[i], inputValue); \n }\n sumTotal += format.len[i];\n context.global.dataType.set(format.title[i], format.type[i]);\n delete buff;\n }\n }\n}\n\nfunction confirmMsg(strData) {\n var formatDatas = global.get(\"FormatData\");\n var size = formatDatas.length;\n for (var i=0; i<size; i++) {\n var format = formatDatas[i];\n if (strData.length === format.DataLength) {\n var defineData = context.global.FormatObjMap.get(format.TC_CODE);\n translateData(strData, defineData);\n } else {\n continue;\n }\n }\n}\n\nconfirmMsg(msg.payload);\n\nString.prototype.trim = function() {\n return this.replace(/^\\s+|\\s+$/g,\"\");\n}\n\nvar object = {};\ncontext.global.dataMap.forEach((value, key) => {\n if (context.global.dataType.get(key) !== 'char') {\n // console.log(value);\n // object[key] = value.trim();\n object[key] = parseFloat(value);\n } else {\n if (key === 'TC_CODE')\n msg.tag = value;\n else if (key === 'Length') {\n // object[key] = value.trim();\n object[key] = parseInt(value);\n } else\n object[key] = value;\n }\n});\n\nmsg.fields = object;\ncontext.global.dataType = null;\n\nreturn msg;","outputs":1,"noerr":0,"x":400,"y":540,"wires":[["acef7045.c2923","ff33c5a3.ce4298","e8c5af80.38573","89c6320d.27be9","bc244621.7f62d8"]]},{"id":"e8c5af80.38573","type":"function","z":"f41712ff.dd9de","name":"Make Data to Media Server","func":"function checkLengthString(str, len, type) {\n if (type === \"char\") {\n var check = str.length;\n if (check === undefined) {\n str = String(str);\n check = str.length;\n }\n if (check < len) {\n for (var i = 0 ; i < (len - check) ; i++) {\n str += \" \";\n }\n } else if(check > len) {\n str = str.slice(0, len)\n }\n return str;\n } else {\n str = String(str);\n var check = str.length;\n var temp = \"\";\n if (check < len) {\n for (var i = 0 ; i < (len - check) ; i++) {\n temp += \"0\";\n }\n str = temp + str;\n } else if(check > len) {\n str = str.slice(0, len)\n }\n return str;\n }\n}\n\nfunction nowDateFormat() {\n var nowTime = new Date();\n return nowTime.getFullYear() + checkZeroTime(nowTime.getMonth()+1) + checkZeroTime(nowTime.getDate()) + checkZeroTime(nowTime.getHours()) + checkZeroTime(nowTime.getMinutes()) + checkZeroTime(nowTime.getSeconds());\n}\n\nfunction checkZeroTime(value) {\n return (value>9 ? '' : '0') + value\n}\n\nfunction checkZeroTimeMillisec(value) {\n if (value < 10) {\n return '00' + value;\n } else if (value < 100) {\n return '0' + value;\n } else {\n return value;\n }\n}\n\nfunction createDataRefine(value) {\n var returnStr = \"\"\n var sendDatas = global.get(\"SendDataFormat\");\n var formatData = sendDatas.filter(function(obj){ return obj.tc === Number(msg.tag) })[0];\n console.log(formatData);\n if (formatData !== undefined) {\n var result;\n for (var i=0; i< formatData.title.length; i++) {\n if (formatData.title[i] === 'TC_CODE') {\n returnStr += msg.tag;\n continue;\n } else if (formatData.title[i] === 'Time') {\n returnStr += nowDateFormat();\n continue; \n } else if (formatData.title[i] === 'SEQUENCE_NO') {\n result = msg.fields.SEQUENCE_NO;\n } else if (formatData.title[i] === 'CHE_S') {\n result = msg.fields.CHE_S;\n } else if (formatData.title[i] === 'CHE_SI') {\n result = msg.fields.CHE_SI;\n } else if (formatData.title[i] === 'KR_TM') {\n result = msg.fields.KR_TM;\n } else if (formatData.title[i] === 'KR_WGT') {\n result = msg.fields.KR_WGT; \n } else if (formatData.title[i] === 'LADLE_NO') {\n result = msg.fields.LADLE_NO; \n } else {\n continue;\n }\n returnStr += checkLengthString(result, formatData.len[i], formatData.type[i]);\n }\n if (value === true) {\n returnStr += \"\\n\";\n }\n console.log(returnStr);\n console.log(returnStr.length);\n return returnStr;\n }\n return '';\n}\nmsg.payload = createDataRefine(false);\n\nreturn msg;","outputs":1,"noerr":0,"x":700,"y":660,"wires":[["d297757b.71ba28","25e7e754.0c10c8","66b150a3.388b7"]]},{"id":"3b33b50e.177a6a","type":"tcp in","z":"11c5be82.e35261","name":"","server":"server","host":"","port":"5001","datamode":"stream","datatype":"buffer","newline":"","topic":"","base64":false,"x":140,"y":220,"wires":[["2460762f.feccea","ba1f9162.d44a"]]},{"id":"2460762f.feccea","type":"debug","z":"11c5be82.e35261","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":340,"y":300,"wires":[]},{"id":"ba1f9162.d44a","type":"function","z":"11c5be82.e35261","name":"","func":"var orgData = msg.payload;\n\nvar tempBuff1 = new Buffer(12);\ntempBuff1 = orgData.slice(0,12);\nconsole.log(tempBuff1);\nfor (var i = 0; i < tempBuff1.length; i++) {\n console.log(tempBuff1.readInt8(i));\n}\nconsole.log(tempBuff1.toString('utf-8'));\n\nvar tempBuff2 = new Buffer(2);\ntempBuff2 = orgData.slice(12,14);\nconsole.log(tempBuff2);\nfor (var i = 0; i < tempBuff2.length; i++) {\n console.log(tempBuff2.readInt8(i));\n}\n// for (var i = 0; i < tempBuff2.length; i++) {\n console.log(tempBuff2.readUInt16BE(0));\n// }\n\n console.log((tempBuff2.readUInt8(1) << 8) + tempBuff2.readUInt8(0));\n\n\nvar tempBuff3 = new Buffer(4);\ntempBuff3.fill(0);\ntempBuff3 = orgData.slice(16,20);\nconsole.log(tempBuff3);\nfor (var i = 0; i < tempBuff3.length; i++) {\n console.log(tempBuff3.readInt8(i));\n}\n// for (var i = 0; i < tempBuff2.length; i++) {\n console.log(tempBuff3.readUInt32BE(0));\n// }\nconsole.log((tempBuff3.readUInt8(0)));\nconsole.log((tempBuff3.readUInt8(1) << 8));\nconsole.log((tempBuff3.readUInt8(2) << 16));\nconsole.log((tempBuff3.readUInt8(3) << 24));\n\nvar bufInt = (tempBuff3.readUInt8(3) << 24) + (tempBuff3.readUInt8(2) << 16) + (tempBuff3.readUInt8(1) << 8) + tempBuff3.readUInt8(0);\nconsole.log(bufInt);\n\n\nmsg.payload = strData;\nreturn msg;","outputs":1,"noerr":0,"x":320,"y":260,"wires":[["787d97d5.238c08"]]},{"id":"787d97d5.238c08","type":"debug","z":"11c5be82.e35261","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":490,"y":260,"wires":[]},{"id":"e082aab5.ba5168","type":"function","z":"11c5be82.e35261","name":"Data Process","func":"//Function Area -----------------------------------------------------------------------------------------\ncontext.global.dataType = new Map();\n\nString.prototype.trim = function() {\n return this.replace(/^\\s+|\\s+$/g,\"\");\n}\n\n/* \n Return Map Data (format.title, value)\n*/\nfunction translateData(str, format) {\n // var dataMap = new Map();\n if (context.global.dataMap === undefined || context.global.dataMap === null)\n context.global.dataMap = new Map();\n else \n context.global.dataMap.clear();\n var sumTotal = 0;\n for (var i=0;i< format.title.length;i++) {\n if (i == 0) {\n sumTotal += (format.len[i])\n context.global.dataMap.set(format.title[i], str.slice(i, sumTotal))\n context.global.dataType.set(format.title[i], format.type[i]);\n } else {\n context.global.dataMap.set(format.title[i], str.slice(sumTotal, sumTotal + format.len[i]));\n sumTotal += format.len[i];\n context.global.dataType.set(format.title[i], format.type[i]);\n }\n }\n // console.log(context.global.dataMap);\n}\n\nfunction confirmMsg(strData) {\n var size = context.global.FormatData.length;\n for (var i=0; i<size; i++) {\n var format = context.global.FormatData[i];\n if (strData.length === format.DataLength) {\n var defineData = context.global.FormatObjMap.get(format.TC_CODE);\n translateData(strData, defineData);\n } else {\n continue;\n }\n }\n}\n\n//Main Area -----------------------------------------------------------------------------------------\nvar strData = msg.payload.toString('utf-8');\nconsole.log(strData);\nconfirmMsg(strData);\n\n\n\n// var mapData = translateData(msg.payload, context.global.SlabFormat);\n// console.log(context.global.dataType);\n//JSON으로 변환시 이용\nvar object = {};\ncontext.global.dataMap.forEach((value, key) => {\n if (context.global.dataType.get(key) !== 'char') {\n // console.log(value)ds;\n object[key] = value.trim();\n object[key] = parseFloat(value);\n } else {\n if (key === 'TC_CODE')\n msg.tag = value;\n else if (key === 'Length') {\n object[key] = value.trim();\n object[key] = parseInt(value);\n } else\n object[key] = value;\n }\n});\n\nmsg.fields = object;\ncontext.global.dataType = null;\nreturn msg;","outputs":1,"noerr":0,"x":150,"y":100,"wires":[[]]},{"id":"298d24b3.08539c","type":"comment","z":"11c5be82.e35261","name":"Data Slice and Insert to DB","info":"","x":190,"y":60,"wires":[]},{"id":"66b150a3.388b7","type":"tcp out","z":"f41712ff.dd9de","host":"192.168.0.20","port":"52004","beserver":"client","base64":false,"end":false,"name":"Send To Media Server","x":1000,"y":700,"wires":[]},{"id":"d297757b.71ba28","type":"function","z":"f41712ff.dd9de","name":"Influx Data Process","func":"//Main Area -----------------------------------------------------------------------------------------\nlet YYYYMMDD = context.global.todaydate;\nif (!YYYYMMDD) {\n YYYYMMDD = \"20180101\";\n}\n\nvar logFormat = global.get(\"LogFormat\");\nvar sender_ip = logFormat.image_Server_IP;\nvar strData = msg.payload.toString('utf-8');\n\n// msg.measurement = `posco-slab-${YYYYMMDD}`;\n\nmsg.payload = [{\n measurement:`posco-send-media-${YYYYMMDD}`,\n fields:{\n Data:strData\n },\n tags: {\n TcNo:msg.tag,\n IP:sender_ip\n }\n}]\n\ndelete msg.fields;\nreturn msg;","outputs":1,"noerr":0,"x":1010,"y":760,"wires":[["fb2d770e.fb0e68","f1802a91.c59298"]]},{"id":"fb2d770e.fb0e68","type":"influxdb batch","z":"f41712ff.dd9de","influxdb":"85a94193.17dfb","precision":"ms","retentionPolicy":"","name":"","x":1230,"y":780,"wires":[]},{"id":"87f22f2c.cbbd5","type":"function","z":"f41712ff.dd9de","name":"Create MQTT Data ","func":"var fileName = msg.info.fileName;\nvar folder = msg.info.path;\nvar jsonData = \n{\n \"uuid\":msg._msgid,\n \"camera\":msg.metric.id\n}\n// context.global.set_uuid = msg._msgid;\n// context.global.set_camera = msg.metric.id;\n\nmsg.payload = jsonData;\n\n// msg.topic = \"THINGSPIN/EDGEAI/KR/IN/0\";\n// msg.qos = 0;\n\n// return msg;\nvar tccode = context.global.Ml_Time.get(\"camera\");\nmlProjectMap = context.global.mlProject.get(tccode);\nconsole.log(mlProjectMap);\nif (context.global.topicList === undefined || context.global.topicList === null) {\n context.global.topicList = new Map();\n}\nif (mlProjectMap !== undefined) {\n \n var arrKeys = Array.from(mlProjectMap.keys());\n \n for (var count=0; count < arrKeys.length; count++) {\n msg.topic = \"THINGSPIN/EDGEAI/\" + arrKeys[count] + \"/IN/0\";\n msg.qos = 0;\n context.global.topicList.set(\"THINGSPIN/EDGEAI/\" + arrKeys[count] + \"/OUT\", \"camera\");\n console.log(msg.topic);\n node.send(msg);\n }\n return null;\n\n}","outputs":1,"noerr":0,"x":1050,"y":180,"wires":[["db298103.50797","e88c4f0d.b37bc"]]},{"id":"e2ddd466.fe28a8","type":"mqtt out","z":"f41712ff.dd9de","name":"","topic":"","qos":"","retain":"","broker":"d6cadf0a.6e81","x":1410,"y":180,"wires":[]},{"id":"db298103.50797","type":"delay","z":"f41712ff.dd9de","name":"","pauseType":"delay","timeout":"200","timeoutUnits":"milliseconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":1250,"y":180,"wires":[["e2ddd466.fe28a8"]]},{"id":"14578807.8c7198","type":"mqtt in","z":"f41712ff.dd9de","name":"","topic":"THINGSPIN/EDGEAI/+/OUT","qos":"2","broker":"fa98ec3b.aa1b8","x":220,"y":1260,"wires":[["beee4be8.6f8a38"]]},{"id":"cde1cc64.f536c","type":"function","z":"f41712ff.dd9de","name":"Make Update DB Query","func":"function makeColumnString(dataType, valueData) {\n var title = dataType.title;\n var type = dataType.type;\n var columns = \"(\";\n var values = \"(\";\n console.log(title);\n for (var i=0; i<title.length;i++) {\n if (i+1 == title.length) {\n columns += title[i] + \")\";\n if (type[i] !== 'char') {\n if (valueData[title[i]] === undefined)\n values += \"0\" + \")\";\n else\n values += valueData[title[i]] + \")\";\n } else {\n if (valueData[title[i]] === undefined)\n values += \"'\\\"\\\"')\";\n else\n values += \"'\" + valueData[title[i]] + \"')\";\n }\n } else {\n columns += title[i] + \",\";\n if (type[i] !== 'char') {\n if (valueData[title[i]] === undefined)\n values += \"0\" + \",\";\n else\n values += valueData[title[i]] + \",\";\n } else {\n if (valueData[title[i]] === undefined)\n values += \"'\\\"\\\"')\";\n else\n values += \"'\" + valueData[title[i]] + \"',\";\n }\n }\n }\n var result = {\n columnStr : columns,\n valueStr : values\n };\n console.log(result);\n return result;\n}\n\ncontext.global.result = msg.payload.result;\n\nvar ml_db_info = global.get(\"ML_RESULT\");\nvar ml_value_db_info = global.get(\"ML_VALUE_RESULT\");\nvar inputData = msg.payload;\nif (inputData[\"uuid\"].length > 0) {\n var queryInputData = makeColumnString(ml_db_info, msg.payload);\n var dupligate = \" on duplicate key update uuid='\" + msg.payload[\"uuid\"] + \"', project='\" + msg.payload[\"project\"] + \"'\";\n\n if (inputData[\"camera\"] === undefined) {\n var queryStr = \"insert into \" + ml_value_db_info.db + queryInputData.columnStr + \" values \" + queryInputData.valueStr + dupligate;\n console.log(queryStr);\n msg.topic = queryStr;\n\n } else {\n var queryStr = \"insert into \" + ml_db_info.db + queryInputData.columnStr + \" values \" + queryInputData.valueStr + dupligate;\n console.log(queryStr);\n msg.topic = queryStr;\n }\n \n return msg; \n}","outputs":1,"noerr":0,"x":910,"y":1160,"wires":[["92db7c92.3a93f","a5653057.4bdd3"]]},{"id":"beee4be8.6f8a38","type":"json","z":"f41712ff.dd9de","name":"","property":"payload","action":"obj","pretty":false,"x":450,"y":1260,"wires":[["cbb986bd.a34e28","d0efbf95.df06d"]]},{"id":"92db7c92.3a93f","type":"mysql","z":"f41712ff.dd9de","mydb":"a28692d4.03579","name":"","x":1150,"y":1160,"wires":[[]]},{"id":"6e78ddd2.3951d4","type":"inject","z":"11c5be82.e35261","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":180,"y":440,"wires":[["3ada8fc1.d9a63"]]},{"id":"74cdfd84.3e3724","type":"function","z":"11c5be82.e35261","name":"Set KR Data","func":"function getUID(makeSize,size){\n var chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789',\n out = '';\n\n for(var i=0, clen=chars.length; i<makeSize; i++){\n out += chars.substr(0|Math.random() * clen, 1);\n }\n \n return checkLengthString(out, size);\n}\n\nfunction getRandomShort(size) {\n var bottomValue = Math.round(Math.random() *100);\n var topValue = Math.round(Math.random() *100);\n var resultData = topValue + \".\" + bottomValue;\n\n return checkLengthString(resultData, size);\n}\n\nfunction getRandomInt(multiple,size) {\n var value = Math.round(Math.random() * multiple);\n return checkLengthString(value, size);\n}\n\nfunction checkLengthString(str, len) {\n var check = str.length;\n if (check < len) {\n for (var i = 0 ; i < (len - check) ; i++) {\n str += \" \";\n }\n } else if(check > len) {\n str = str.slice(0, len)\n }\n return str;\n}\n\nfunction nowDateFormat() {\n var nowTime = new Date();\n return nowTime.getFullYear() + \"/\" + checkZeroTime(nowTime.getMonth()+1) + \"/\" + checkZeroTime(nowTime.getDate()) + \" \" + checkZeroTime(nowTime.getHours()) + \":\" + checkZeroTime(nowTime.getMinutes()) + \":\" + checkZeroTime(nowTime.getSeconds()) + \".\" + checkZeroTimeMillisec(nowTime.getMilliseconds());\n}\n\nfunction checkZeroTime(value) {\n return (value>9 ? '' : '0') + value\n}\n\nfunction checkZeroTimeMillisec(value) {\n if (value < 10) {\n return '00' + value;\n } else if (value < 100) {\n return '0' + value;\n } else {\n return value;\n }\n}\n\nfunction createDataRefine(value) {\n var returnStr = \"\"\n var formatData = context.global.SendDataFormat.filter(function(obj){ return obj.tc === msg.sendmsg })[0];\n console.log(formatData);\n for (var i=0; i< formatData.title.length; i++) {\n if (formatData.title[i] === 'TcNo') {\n returnStr += msg.sendmsg;\n continue;\n } else {\n if (formatData.type[i] === \"char\") {\n returnStr += getUID(8,formatData.len[i]); \n } else if (formatData.type[i] === \"int\") {\n returnStr += getRandomInt(100000, formatData.len[i]);\n } else if (formatData.type[i] === \"short\") {\n returnStr += getRandomShort(formatData.len[i]);\n } else if (formatData.type[i] === \"datetime\"){\n returnStr += nowDateFormat(); \n }\n continue;\n }\n }\n if (value === true) {\n returnStr += \"\\n\";\n }\n return returnStr;\n}\n\nmsg.payload = createDataRefine(false);\n\nconsole.log(msg)\n\nreturn msg;","outputs":1,"noerr":0,"x":710,"y":500,"wires":[[]]},{"id":"c85dec7e.28c0f","type":"tcp out","z":"11c5be82.e35261","host":"localhost","port":"52004","beserver":"client","base64":false,"end":false,"name":"","x":1010,"y":440,"wires":[]},{"id":"703e4dbb.e05114","type":"debug","z":"11c5be82.e35261","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":990,"y":560,"wires":[]},{"id":"8e7a8be8.4fb0b8","type":"comment","z":"11c5be82.e35261","name":"KR Send AI Server ","info":"","x":150,"y":380,"wires":[]},{"id":"3ada8fc1.d9a63","type":"function","z":"11c5be82.e35261","name":"Send Message 3181","func":"msg.sendmsg = 3181\nreturn msg;","outputs":1,"noerr":0,"x":400,"y":440,"wires":[["74cdfd84.3e3724"]]},{"id":"78cda3d.c96aa5c","type":"inject","z":"11c5be82.e35261","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":180,"y":500,"wires":[["d69b8217.cb87"]]},{"id":"d69b8217.cb87","type":"function","z":"11c5be82.e35261","name":"Send Message 3182","func":"msg.sendmsg = 3182\nreturn msg;","outputs":1,"noerr":0,"x":400,"y":500,"wires":[["74cdfd84.3e3724"]]},{"id":"77581f8e.166","type":"inject","z":"11c5be82.e35261","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":180,"y":560,"wires":[["4719a88a.2532a8"]]},{"id":"4719a88a.2532a8","type":"function","z":"11c5be82.e35261","name":"Send Message 3183","func":"msg.sendmsg = 3183\nreturn msg;","outputs":1,"noerr":0,"x":400,"y":560,"wires":[["74cdfd84.3e3724"]]},{"id":"9841788c.405018","type":"function","z":"11c5be82.e35261","name":"Influx Data Process","func":"//Main Area -----------------------------------------------------------------------------------------\nlet YYYYMMDD = context.global.todaydate;\nif (!YYYYMMDD) {\n YYYYMMDD = \"20180101\";\n}\n\nvar sender_ip = context.global.LogFormat.image_Server_IP;\nvar sender_port = context.global.LogFormat.send_Port;\nvar send_msg = msg.sendmsg;\nvar send_data = msg.payload;\nvar data_length = msg.payload.length;\n\nvar strData = msg.payload.toString('utf-8');\n\n// msg.measurement = `posco-slab-${YYYYMMDD}`;\n\nmsg.payload = [{\n measurement:`posco-simulator-${YYYYMMDD}`,\n fields:{\n Data:strData\n },\n tags: {\n TcNo:msg.tag,\n IP:sender_ip\n }\n}]\n\ndelete msg.fields;\nreturn msg;","outputs":1,"noerr":0,"x":1010,"y":500,"wires":[["949f2cc8.174f"]]},{"id":"949f2cc8.174f","type":"influxdb batch","z":"11c5be82.e35261","influxdb":"85a94193.17dfb","precision":"ms","retentionPolicy":"","name":"","x":1230,"y":500,"wires":[]},{"id":"3fa8b6f.f4c104a","type":"function","z":"f41712ff.dd9de","name":"Influx Data Process","func":"//Main Area -----------------------------------------------------------------------------------------\nlet YYYYMMDD = context.global.todaydate;\nif (!YYYYMMDD) {\n YYYYMMDD = \"20180101\";\n}\nvar inputData = msg.payload;\n\nmsg.payload = [{\n measurement:`posco-post-recv-${YYYYMMDD}`,\n fields:{\n Data:JSON.stringify(inputData)\n },\n tags: {\n Camera:inputData.id \n }\n}]\n\ndelete msg.fields;\nreturn msg;","outputs":1,"noerr":0,"x":570,"y":220,"wires":[["819dd9e6.56d998"]]},{"id":"182e3511.91448b","type":"inject","z":"54fead13.e0d974","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":340,"y":600,"wires":[["9dea94b3.b63518"]]},{"id":"8efb858d.069a48","type":"function","z":"f41712ff.dd9de","name":"History data insert","func":"var dataMap = context.global.dataMap;\nvar dataFormat = context.global.FormatObjMap.get(msg.tag);\n\nif(dataFormat.db !== \"t_msg_history\") {\n msg.topic = \"insert into t_msg_history (SEQUENCE_NO, TC_CODE) values ('\" + dataMap.get('SEQUENCE_NO') + \"', '\" + dataMap.get('TC_CODE') + \"')\";\n return msg;\n} else {\n msg.topic = '';\n msg.payload = '';\n}","outputs":1,"noerr":0,"x":1010,"y":480,"wires":[["da04699a.5710b8"]]},{"id":"f5a06f03.c6c18","type":"comment","z":"f41712ff.dd9de","name":"[ 관리자 내부 변수 초기화 ]","info":"","x":180,"y":1440,"wires":[]},{"id":"8f455093.fca95","type":"inject","z":"f41712ff.dd9de","name":"","topic":"","payload":"","payloadType":"date","repeat":"3600","crontab":"","once":false,"onceDelay":0.1,"x":210,"y":1540,"wires":[["595d4c7e.819464","12556e9b.905111"]]},{"id":"595d4c7e.819464","type":"function","z":"f41712ff.dd9de","name":"YYYYMMDD","func":"Date.prototype.yyyymmdd = function() {\n var mm = this.getMonth() + 1; // getMonth() is zero-based\n var dd = this.getDate();\n\n return [this.getFullYear(),\n (mm>9 ? '' : '0') + mm,\n (dd>9 ? '' : '0') + dd\n ].join('');\n};\n\nvar date = new Date();\ndate.yyyymmdd();\n\ncontext.global.todaydate = date.yyyymmdd();\n// context.global.set(\"YYYYMMDD\", \"20180101\");\n\nreturn;","outputs":1,"noerr":0,"x":410,"y":1540,"wires":[[]]},{"id":"12556e9b.905111","type":"function","z":"f41712ff.dd9de","name":"Init Format Map","func":"if (context.global.FormatObjMap === undefined || context.global.FormatObjMap === null)\n context.global.FormatObjMap = new Map();\nelse\n context.global.FormatObjMap.clear();\nvar formatDatas = global.get(\"FormatData\");\nvar size = formatDatas.length;\nconsole.log(size);\nfor (var i=0; i<size; i++) {\n var format = formatDatas[i];\n if (format.TC_CODE === \"3180\")\n context.global.FormatObjMap.set(format.TC_CODE, global.get(\"MSG_3180\"));\n else if (format.TC_CODE === \"3181\")\n context.global.FormatObjMap.set(format.TC_CODE, global.get(\"MSG_3181\"));\n else if (format.TC_CODE === \"3182\")\n context.global.FormatObjMap.set(format.TC_CODE, global.get(\"MSG_3182\"));\n else if (format.TC_CODE === \"3183\")\n context.global.FormatObjMap.set(format.TC_CODE, global.get(\"MSG_3183\"));\n else if (format.TC_CODE === \"3184\")\n context.global.FormatObjMap.set(format.TC_CODE, global.get(\"MSG_3184\"));\n}\n\nvar checkTC = global.get(\"SendTccode\");\nvar timeTC = global.get(\"PublishTime\");\n\nif (context.global.Ml_Time === undefined || context.global.Ml_Time === null)\n context.global.Ml_Time = new Map();\nelse\n context.global.Ml_Time.clear();\n\nfor (var i=0; i<checkTC.length; i++) {\n context.global.Ml_Time.set(timeTC[i], checkTC[i]);\n}\nconsole.log(context.global.Ml_Time);\n\ncontext.global.krcount = 1;\ncontext.global.ladlecount = 11;\n\nreturn;","outputs":1,"noerr":0,"x":420,"y":1580,"wires":[[]]},{"id":"7874fe8b.7fc27","type":"status","z":"f41712ff.dd9de","name":"","scope":["3a4db9c3.af6e76"],"x":200,"y":1580,"wires":[["595d4c7e.819464","12556e9b.905111"]]},{"id":"42ca21a7.a68d6","type":"debug","z":"f41712ff.dd9de","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":970,"y":420,"wires":[]},{"id":"f1802a91.c59298","type":"debug","z":"f41712ff.dd9de","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":1210,"y":740,"wires":[]},{"id":"25e7e754.0c10c8","type":"debug","z":"f41712ff.dd9de","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":970,"y":660,"wires":[]},{"id":"290317db.c3bf88","type":"function","z":"f41712ff.dd9de","name":"construct-by-MAC","func":"function checkZeroTime(value) {\n return (value>9 ? '' : '0') + value\n}\n\nfunction nowDateFormat() {\n var nowTime = new Date();\n return nowTime.getFullYear() + checkZeroTime(nowTime.getMonth()+1) + checkZeroTime(nowTime.getDate());\n}\n\nvar p = msg.payload;\nvar metric = {};\n\nvar path = global.get(\"basePath\");\nconsole.log(path);\n\nif (context.global.todaydate === undefined) {\n context.global.todaydate = nowDateFormat();\n}\n\nvar date = context.global.todaydate;\nvar img = [];\nvar cameraID = p.id;\n\nObject.keys(p).filter((value) => { return (value !== 'image') }).map( (k) => {\n metric[k] = p[k];\n});\n\nvar data = {\n path: path + date + \"/\" + cameraID + \"/\",\n image: p.image,\n directory: date,\n metric: metric\n};\n\ndelete msg.payload;\nmsg.statusCode = 200;\n\nreturn [msg, data];\n\n","outputs":2,"noerr":0,"x":570,"y":120,"wires":[["6441d114.b3bfa"],["c0c498dc.6d95e8"]]},{"id":"80cd13ce.94d74","type":"debug","z":"f41712ff.dd9de","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":550,"y":260,"wires":[]},{"id":"96d767b9.7c9d38","type":"function","z":"54fead13.e0d974","name":"Make Simulation Data","func":"function getRandomTemperator() {\n var bottomValue = Math.round(Math.random() *1000);\n var topValue = Math.round(Math.random() *1000);\n var resultData = topValue + \".\" + bottomValue;\n return parseFloat(resultData);\n \n}\n\nmsg.payload = {\n // \"uuid\" : context.global.set_uuid,\n // \"camera\": context.global.set_camera,\n \"uuid\":\"5146438f.78b98c\",\n \"project\": \"pro-1\",\n \"tc_code\": msg.sendType,\n \"spare\": \"spare\",\n \"camera\": \"CAM01\",\n \"result\": getRandomTemperator()\n}\nreturn msg;","outputs":1,"noerr":0,"x":560,"y":800,"wires":[["e949ba12.88c7b8","e058559.f00b6a8"]]},{"id":"e949ba12.88c7b8","type":"mqtt out","z":"54fead13.e0d974","name":"","topic":"THINGSPIN/EDGEAI/0/OUT","qos":"0","retain":"false","broker":"b48cad1a.c9913","x":880,"y":800,"wires":[]},{"id":"e058559.f00b6a8","type":"debug","z":"54fead13.e0d974","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":830,"y":880,"wires":[]},{"id":"5d26c367.7faf4c","type":"inject","z":"54fead13.e0d974","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":120,"y":780,"wires":[["eb92b50f.5a4b18"]]},{"id":"93326d70.01cc2","type":"inject","z":"54fead13.e0d974","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":120,"y":840,"wires":[["6a114417.185dfc"]]},{"id":"20ec31bd.f6a6ee","type":"inject","z":"54fead13.e0d974","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":120,"y":900,"wires":[["65b7cdd8.5977e4"]]},{"id":"39ca2b29.744604","type":"inject","z":"54fead13.e0d974","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":120,"y":720,"wires":[["1103e837.f1dc78"]]},{"id":"eb92b50f.5a4b18","type":"function","z":"54fead13.e0d974","name":"T/C Code 3021","func":"msg.sendType = \"3021\"\nreturn msg;","outputs":1,"noerr":0,"x":300,"y":780,"wires":[["96d767b9.7c9d38"]]},{"id":"6a114417.185dfc","type":"function","z":"54fead13.e0d974","name":"T/C Code 3022","func":"msg.sendType = \"3022\"\nreturn msg;","outputs":1,"noerr":0,"x":300,"y":840,"wires":[["96d767b9.7c9d38"]]},{"id":"65b7cdd8.5977e4","type":"function","z":"54fead13.e0d974","name":"T/C Code 3023","func":"msg.sendType = \"3023\"\nreturn msg;","outputs":1,"noerr":0,"x":300,"y":900,"wires":[["96d767b9.7c9d38"]]},{"id":"1103e837.f1dc78","type":"function","z":"54fead13.e0d974","name":"T/C Code 3020","func":"msg.sendType = \"3020\"\nreturn msg;","outputs":1,"noerr":0,"x":300,"y":720,"wires":[["96d767b9.7c9d38"]]},{"id":"a480ca93.764428","type":"function","z":"f41712ff.dd9de","name":"Make Data to L2 Server","func":"var dataFormat;\n\nfunction getRandomTemperator() {\n var bottomValue = Math.round(Math.random() *100);\n var topValue = Math.round(Math.random() *100);\n var resultData = topValue + \".\" + bottomValue;\n var parseData = parseFloat(resultData);\n var buff = new Buffer(4);\n \n return buff.writeFloatBE(parseData);\n}\n\n\nfunction nowDateFormat() {\n var nowTime = new Date();\n return nowTime.getFullYear() + checkZeroTime(nowTime.getMonth()+1) + checkZeroTime(nowTime.getDate()) + checkZeroTime(nowTime.getHours()) + checkZeroTime(nowTime.getMinutes()) + checkZeroTime(nowTime.getSeconds());\n}\n\nfunction checkZeroTime(value) {\n return (value>9 ? '' : '0') + value\n}\n\nfunction checkZeroTimeMillisec(value) {\n if (value < 10) {\n return '00' + value;\n } else if (value < 100) {\n return '0' + value;\n } else {\n return value;\n }\n}\n\nfunction initDataFormat(code) {\n console.log(code);\n switch(code) {\n case 3020:\n dataFormat = global.get(\"S_MSG_3020\");\n return true;\n case 3021:\n dataFormat = global.get(\"S_MSG_3021\");\n return true;\n case 3022:\n dataFormat = global.get(\"S_MSG_3022\");\n return true;\n case 3023:\n dataFormat = global.get(\"S_MSG_3023\");\n return true; \n default:\n return false;\n }\n}\n\nconsole.log(msg.payload[\"tc_code\"]);\n\nif(initDataFormat(msg.payload[\"tc_code\"])) {\n var sendBuff = new Buffer(dataFormat.Length);\n sendBuff.fill(0);\n var sumTotal = 0;\n for (var count=0;count < dataFormat.title.length;count++) {\n var title = dataFormat.title[count];\n\n if (dataFormat.type[count] === \"char\") {\n if (title === \"Process\" || title === \"TC_CODE\") {\n if (count === 0) {\n console.log(\"sumTotal : \" + 0 + \" END : \" + dataFormat.len[count]);\n console.log(dataFormat.values[count]);\n sendBuff.write(dataFormat.values[count], 0, dataFormat.len[count]); \n } else {\n console.log(\"sumTotal : \" + sumTotal + \" END : \" + ((sumTotal) + dataFormat.len[count]));\n console.log(dataFormat.values[count]);\n sendBuff.write(dataFormat.values[count], sumTotal, ((sumTotal) + dataFormat.len[count]));\n }\n } else if (title === \"Time\") {\n console.log(\"sumTotal : \" + sumTotal + \" END : \" + ((sumTotal) + dataFormat.len[count]));\n var date = nowDateFormat();\n console.log(date);\n sendBuff.write(date, sumTotal, (sumTotal) + dataFormat.len[count]);\n } else if (title === \"Length\") {\n console.log(\"sumTotal : \" + sumTotal + \" END : \" + ((sumTotal) + dataFormat.len[count]));\n console.log(dataFormat.Length + \" \");\n sendBuff.write(dataFormat.Length + \" \", sumTotal, ((sumTotal) + dataFormat.len[count]));\n } else if (title === \"Spare\") {\n console.log(\"sumTotal : \" + sumTotal + \" END : \" + ((sumTotal) + dataFormat.len[count]));\n console.log(\" \");\n sendBuff.write(\" \", sumTotal, (sumTotal) + dataFormat.len[count]);\n }\n sumTotal += (dataFormat.len[count]);\n } else if (dataFormat.type[count] === \"float\") {\n console.log(title);\n if (title === \"SEQUENCE_NO\") {\n console.log(\"sumTotal : \" + sumTotal + \" END : \" + ((sumTotal) - dataFormat.len[count]));\n console.log(parseFloat(context.global.sequence_no));\n sendBuff.writeFloatLE(parseFloat(context.global.sequence_no), sumTotal);\n console.log(sendBuff);\n sumTotal += (dataFormat.len[count]);\n } else {\n console.log(\"sumTotal : \" + sumTotal + \" END : \" + ((sumTotal) - dataFormat.len[count]));\n console.log(parseFloat(msg.payload[\"result\"]));\n sendBuff.writeFloatLE(parseFloat(msg.payload[\"result\"]), sumTotal);\n console.log(sendBuff);\n }\n }\n }\n}\n// var sendBuff = new Buffer(header);\n// console.log(sendBuff);\n// const buf = Buffer.allocUnsafe(4);\n// buf.writeFloatBE(0xcafebabe, 0);\n// console.log(buf) \n// console.log(sendBuff + buf);\n\nmsg.payload = sendBuff;\nreturn msg;","outputs":1,"noerr":0,"x":910,"y":1240,"wires":[["6cf9e42a.f7637c","9cb2e6f5.377858"]]},{"id":"6cf9e42a.f7637c","type":"tcp out","z":"f41712ff.dd9de","host":"","port":"","beserver":"reply","base64":false,"end":false,"name":"Reply To L2 Server","x":1190,"y":1260,"wires":[]},{"id":"ab4a7def.074df","type":"function","z":"f41712ff.dd9de","name":"Influx Data Process","func":"//Main Area -----------------------------------------------------------------------------------------\nlet YYYYMMDD = context.global.todaydate;\nif (!YYYYMMDD) {\n YYYYMMDD = \"20180101\";\n}\nvar inputData = msg.payload;\n\nif (inputData.camera === undefined) {\n console.log('camera is undefined');\n\n if (inputData.spare === undefined) {\n inputData.spare = \"\";\n }\n msg.payload = [{\n measurement:`posco-send-l2-${YYYYMMDD}`,\n fields:{\n uuid:inputData.uuid,\n result:inputData.result,\n spare:inputData.spare,\n CHE_S:context.global.che_s,\n CHE_SI:context.global.che_si,\n KR_TM:context.global.kr_tm,\n KR_WGT:context.global.kr_wgt,\n TcNo:inputData.tc_code\n },\n tags: {\n project:inputData.project\n }\n }]\n} else {\n if (inputData.spare === undefined) {\n inputData.spare = \"\";\n }\n msg.payload = [{\n measurement:`posco-send-l2-${YYYYMMDD}`,\n fields:{\n uuid:inputData.uuid,\n camera:inputData.camera,\n result:inputData.result,\n spare:inputData.spare,\n TcNo:inputData.tc_code\n },\n tags: {\n project:inputData.project\n }\n }]\n}\n\ndelete msg.fields;\nreturn msg;","outputs":1,"noerr":0,"x":890,"y":1420,"wires":[["7732197.1addae8"]]},{"id":"9cb2e6f5.377858","type":"debug","z":"f41712ff.dd9de","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":1150,"y":1220,"wires":[]},{"id":"908d036f.ee5c9","type":"function","z":"f41712ff.dd9de","name":"Make Data to Database","func":"var dataFormat;\n\nfunction initDataFormat(value) {\n switch(value) {\n case 3020:\n dataFormat = global.get(\"S_MSG_3020\");\n return true;\n case 3021:\n dataFormat = global.get(\"S_MSG_3021\");\n return true;\n case 3022:\n dataFormat = global.get(\"S_MSG_3022\");\n return true;\n case 3023:\n dataFormat = global.get(\"S_MSG_3023\");\n return true;\n default:\n return false;\n }\n}\n//insert into t_msg_history (CHARGE_NO, TC_CODE) values (\nif(initDataFormat(msg.payload.tc_code)) {\n var tableName = dataFormat.db;\n var dbschema = dataFormat.dbsechma;\n console.log(dbschema);\n msg.topic = \"insert into \" + tableName + \" (\" + dbschema + \") values (\" + msg.payload.result + \",'\" + msg.payload.uuid + \"');\"\n console.log(msg.topic);\n return msg;\n}","outputs":1,"noerr":0,"x":910,"y":1360,"wires":[["e608baf7.79a328","78e1dc5a.7b3864"]]},{"id":"4d9c0a11.3b89a4","type":"function","z":"11c5be82.e35261","name":"Make Data to L2 Server","func":"var dataType = msg.sendType;\nvar data = msg.value;\nvar dataFormat;\n\nfunction getRandomTemperator() {\n var bottomValue = Math.round(Math.random() *100);\n var topValue = Math.round(Math.random() *100);\n var resultData = topValue + \".\" + bottomValue;\n var parseData = parseFloat(resultData);\n var buff = new Buffer(4);\n \n return buff.writeFloatBE(parseData);\n}\n\n\nfunction nowDateFormat() {\n var nowTime = new Date();\n return nowTime.getFullYear() + checkZeroTime(nowTime.getMonth()+1) + checkZeroTime(nowTime.getDate()) + checkZeroTime(nowTime.getHours()) + checkZeroTime(nowTime.getMinutes()) + checkZeroTime(nowTime.getSeconds());\n}\n\nfunction checkZeroTime(value) {\n return (value>9 ? '' : '0') + value\n}\n\nfunction checkZeroTimeMillisec(value) {\n if (value < 10) {\n return '00' + value;\n } else if (value < 100) {\n return '0' + value;\n } else {\n return value;\n }\n}\n\nfunction initDataFormat(value) {\n console.log(value);\n switch(value) {\n case \"3020\":\n dataFormat = global.get(\"S_MSG_3020\");\n console.log(dataFormat);\n return true;\n case \"3021\":\n dataFormat = global.get(\"S_MSG_3021\");\n return true;\n case \"3022\":\n dataFormat = global.get(\"S_MSG_3022\");\n return true;\n case \"3023\":\n dataFormat = global.get(\"S_MSG_3023\");\n return true;\n default:\n return false;\n }\n}\n\nif(initDataFormat(msg.payload.tc_code)) {\n var sendBuff = new Buffer(dataFormat.Length);\n sendBuff.fill(0);\n var sumTotal = 0;\n for (var count=0;count < dataFormat.title.length;count++) {\n var title = dataFormat.title[count];\n\n if (dataFormat.type[count] === \"char\") {\n if (title === \"Process\" || title === \"TC_CODE\") {\n if (count === 0) {\n console.log(\"sumTotal : \" + 0 + \" END : \" + dataFormat.len[count]);\n console.log(dataFormat.values[count]);\n sendBuff.write(dataFormat.values[count], 0, dataFormat.len[count]); \n } else {\n console.log(\"sumTotal : \" + sumTotal + \" END : \" + ((sumTotal) + dataFormat.len[count]));\n console.log(dataFormat.values[count]);\n sendBuff.write(dataFormat.values[count], sumTotal, ((sumTotal) + dataFormat.len[count]));\n }\n } else if (title === \"Time\") {\n console.log(\"sumTotal : \" + sumTotal + \" END : \" + ((sumTotal) + dataFormat.len[count]));\n var date = nowDateFormat();\n console.log(date);\n sendBuff.write(date, sumTotal, (sumTotal) + dataFormat.len[count]);\n } else if (title === \"Length\") {\n console.log(\"sumTotal : \" + sumTotal + \" END : \" + ((sumTotal) + dataFormat.len[count]));\n console.log(dataFormat.Length + \" \");\n sendBuff.write(dataFormat.Length + \" \", sumTotal, ((sumTotal) + dataFormat.len[count]));\n } else if (title === \"Spare\") {\n console.log(\"sumTotal : \" + sumTotal + \" END : \" + ((sumTotal) + dataFormat.len[count]));\n console.log(\" \");\n sendBuff.write(\" \", sumTotal, (sumTotal) + dataFormat.len[count]);\n }\n sumTotal += (dataFormat.len[count]);\n } else if (dataFormat.type[count] === \"float\") {\n console.log(\"sumTotal : \" + sumTotal + \" END : \" + ((sumTotal) - dataFormat.len[count]));\n // sendBuff.writeFloatLE(15.357, sumTotal);\n sendBuff.writeFloatLE(parseFloat(msg.payload.result), sumTotal);\n console.log(sendBuff);\n // sendBuff += getRandomTemperator();\n }\n }\n}\n// var sendBuff = new Buffer(header);\n// console.log(sendBuff);\n// const buf = Buffer.allocUnsafe(4);\n// buf.writeFloatBE(0xcafebabe, 0);\n// console.log(buf) \n// console.log(sendBuff + buf);\n\nmsg.payload = sendBuff;\nreturn msg;","outputs":1,"noerr":0,"x":650,"y":100,"wires":[["4cd7101.7b7dbf"]]},{"id":"4cd7101.7b7dbf","type":"tcp out","z":"11c5be82.e35261","host":"","port":"","beserver":"reply","base64":false,"end":false,"name":"Reply To L2 Server","x":930,"y":100,"wires":[]},{"id":"89c6320d.27be9","type":"function","z":"f41712ff.dd9de","name":"Create CSV File","func":"msg.payload = msg.fields;\nmsg.payload.TC_CODE = Number(msg.tag);\nvar path = global.get(\"baseDataPath\");\n\nmsg.payload.CHE_S = 356;\nmsg.payload.CHE_SI = 566;\nmsg.payload.KR_TM = 1355;\nmsg.payload.KR_WGT = 1030;\n\n//38403,356,566,1355,1030\n//2018-11-26 15:43:45,38403,356,566,1355,1030,686.328\n\nmsg.payload.CHE_S = msg.payload.CHE_S/10000;\nmsg.payload.CHE_SI = msg.payload.CHE_SI/1000;\nmsg.payload.KR_WGT = msg.payload.KR_WGT/10;\n\nmsg.filename = path + \"L2_Data.csv\";\nreturn msg;","outputs":1,"noerr":0,"x":660,"y":840,"wires":[["2826815e.4bf4ee"]]},{"id":"f21cfc4.86f62","type":"csv","z":"f41712ff.dd9de","name":"Create 3184 CSV","sep":",","hdrin":"","hdrout":true,"multi":"one","ret":"\\r\\n","temp":"CHE_S,CHE_SI,KR_TM,KR_WGT","skip":"0","x":1050,"y":840,"wires":[["b6a5312b.0b33"]]},{"id":"2826815e.4bf4ee","type":"switch","z":"f41712ff.dd9de","name":"","property":"payload.TC_CODE","propertyType":"msg","rules":[{"t":"eq","v":"3184","vt":"num"},{"t":"eq","v":"3181","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":830,"y":840,"wires":[["f21cfc4.86f62","e4674299.92832"],["78c24.58e0c3dcc"]]},{"id":"b6a5312b.0b33","type":"file","z":"f41712ff.dd9de","name":"","filename":"","appendNewline":true,"createDir":false,"overwriteFile":"true","x":1230,"y":840,"wires":[]},{"id":"e4674299.92832","type":"function","z":"f41712ff.dd9de","name":"Publish MQTT","func":"var resultJson;\nvar tempVal = msg.payload;\n// resultJson.SEQUENCE_NO = tempVal['SEQUENCE_NO'];\ncontext.global.che_s = tempVal['CHE_S'];\ncontext.global.che_si = tempVal['CHE_SI'];\ncontext.global.kr_tm = tempVal['KR_TM'];\ncontext.global.kr_wgt = tempVal['KR_WGT'];\nvar resultJson =\n{\n \"uuid\":msg._msgid\n /*\n \"CHE_S\":tempVal['CHE_S'],\n \"CHE_SI\":tempVal['CHE_SI'],\n \"KR_TM\":tempVal['KR_TM'],\n \"KR_WGT\":tempVal['KR_WGT']\n */\n};\nmsg.payload = resultJson;\nvar tccode = context.global.Ml_Time.get(msg.tag);\nmlProjectMap = context.global.mlProject.get(tccode);\n\nif (context.global.topicList === undefined || context.global.topicList === null) {\n context.global.topicList = new Map();\n}\n\nvar arrKeys = Array.from(mlProjectMap.keys());\n\nfor (var count=0; count < arrKeys.length; count++) {\n msg.topic = \"THINGSPIN/EDGEAI/\" + arrKeys[count] + \"/IN/0\";\n msg.qos = 0;\n context.global.topicList.set(\"THINGSPIN/EDGEAI/\" + arrKeys[count] + \"/OUT\", \"false\");\n node.send(msg);\n}\nreturn null;","outputs":1,"noerr":0,"x":1040,"y":900,"wires":[["afde9a34.583ea8","7640c698.43f068"]]},{"id":"afde9a34.583ea8","type":"mqtt out","z":"f41712ff.dd9de","name":"","topic":"","qos":"","retain":"","broker":"d6cadf0a.6e81","x":1230,"y":900,"wires":[]},{"id":"bc244621.7f62d8","type":"debug","z":"f41712ff.dd9de","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":630,"y":480,"wires":[]},{"id":"e608baf7.79a328","type":"debug","z":"f41712ff.dd9de","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":1150,"y":1320,"wires":[]},{"id":"a5653057.4bdd3","type":"debug","z":"f41712ff.dd9de","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":1150,"y":1120,"wires":[]},{"id":"acb885d7.c3e198","type":"inject","z":"f41712ff.dd9de","name":"Result Create File","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"59 23 * * *","once":false,"onceDelay":0.1,"x":230,"y":1680,"wires":[["2fc586a7.df1cda"]]},{"id":"2fc586a7.df1cda","type":"function","z":"f41712ff.dd9de","name":"File Setting","func":"function checkZeroTime(value) {\n return (value>9 ? '' : '0') + value\n}\n\nfunction nowDateFormat() {\n var nowTime = new Date();\n return nowTime.getFullYear() + \"-\" + checkZeroTime(nowTime.getMonth()+1) + \"-\" + checkZeroTime(nowTime.getDate());\n}\n\nfunction nowDate() {\n var nowTime = new Date();\n return nowTime.getFullYear() + \"-\" + checkZeroTime(nowTime.getMonth()+1);\n}\n\nvar date = nowDateFormat();\nvar path = global.get(\"baseDataPath\");\npath += nowDate() + \"\\\\\";\nvar fs = global.get(\"mkdirp\");\n\nfs(path, function(e) {\n if (!e || (e && e.code === 'EEXIST')) {\n } else {\n console.log(e);\n }\n});\nmsg.filename = path + date + \"-KR-RESULT.csv\"\n\nmsg.topic = \"select msg1.time, msg2.SEQUENCE_NO, msg2.CHE_S, msg2.CHE_SI, msg2.KR_TM, msg2.KR_WGT, msg1.result as 'CaO' from t_kr_ml_value_result msg1 join t_msg_3184 msg2 on msg1.uuid = msg2.UUID where DATE(msg1.time) = '\" + date + \"' order by msg1.time asc\";\nreturn msg;","outputs":1,"noerr":0,"x":450,"y":1680,"wires":[["3600ae23.e95442"]]},{"id":"3600ae23.e95442","type":"mysql","z":"f41712ff.dd9de","mydb":"a28692d4.03579","name":"","x":650,"y":1680,"wires":[["1a30cd7b.01cad3"]]},{"id":"1a30cd7b.01cad3","type":"csv","z":"f41712ff.dd9de","name":"","sep":",","hdrin":"","hdrout":true,"multi":"one","ret":"\\r\\n","temp":"time, SEQUENCE_NO, CHE_S, CHE_SI, KR_TM, KR_WGT, CaO","skip":"0","x":810,"y":1680,"wires":[["8358b94.01ac948"]]},{"id":"8358b94.01ac948","type":"file","z":"f41712ff.dd9de","name":"","filename":"","appendNewline":true,"createDir":false,"overwriteFile":"true","x":970,"y":1680,"wires":[]},{"id":"4fa565b2.9384ac","type":"inject","z":"f41712ff.dd9de","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":240,"y":1640,"wires":[["2fc586a7.df1cda"]]},{"id":"a925cc7f.9a536","type":"file in","z":"f41712ff.dd9de","name":"","filename":"","format":"utf8","chunk":false,"sendError":false,"x":1050,"y":1480,"wires":[["566d3909.5739b8"]]},{"id":"bb0c533d.2a914","type":"function","z":"f41712ff.dd9de","name":"Create CSV File","func":"var path = global.get(\"baseDataPath\");\n\nmsg.filename = path + \"L2_Data.csv\";\nreturn msg;","outputs":1,"noerr":0,"x":880,"y":1480,"wires":[["a925cc7f.9a536"]]},{"id":"566d3909.5739b8","type":"csv","z":"f41712ff.dd9de","name":"","sep":",","hdrin":true,"hdrout":"","multi":"one","ret":"\\n","temp":"","skip":"0","x":1190,"y":1480,"wires":[["fa317a2c.b2eef8"]]},{"id":"fa317a2c.b2eef8","type":"function","z":"f41712ff.dd9de","name":"","func":"msg.payload.CaO = context.global.result\nreturn msg;","outputs":1,"noerr":0,"x":1340,"y":1480,"wires":[["a5015838.b68aa8"]]},{"id":"a5015838.b68aa8","type":"csv","z":"f41712ff.dd9de","name":"","sep":",","hdrin":"","hdrout":true,"multi":"one","ret":"\\r\\n","temp":"CHE_S, CHE_SI, KR_TM, KR_WGT, CaO","skip":"0","x":1490,"y":1480,"wires":[["de2806a0.a21318","97fc183e.39a658"]]},{"id":"de2806a0.a21318","type":"file","z":"f41712ff.dd9de","name":"","filename":"","appendNewline":true,"createDir":true,"overwriteFile":"true","x":1650,"y":1480,"wires":[]},{"id":"97fc183e.39a658","type":"debug","z":"f41712ff.dd9de","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":1640,"y":1440,"wires":[]},{"id":"849c79ac.b88c08","type":"json","z":"f41712ff.dd9de","name":"","property":"payload","action":"","pretty":false,"x":290,"y":1040,"wires":[["3654c771.b1a338"]]},{"id":"3654c771.b1a338","type":"function","z":"f41712ff.dd9de","name":"ML-Project-Setting","func":"if (msg.topic === \"config\") {\n var TS_ML_Project = msg.payload;\n \n var arrayProject = Object.values(TS_ML_Project);\n if (context.global.mlProject === undefined || context.global.mlProject === null) {\n context.global.mlProject = new Map();\n }\n var checkTC = global.get(\"SendTccode\");\n for (var count=0;count<checkTC.length;count++) {\n var tccode = checkTC[count];\n var arrayCID = new Map();\n for (var sub=0;sub<arrayProject.length;sub++) {\n var item = arrayProject[sub];\n if (item['cname'].indexOf(tccode) != -1) {\n arrayCID.set(item.cid, item.cname);\n console.log(item.cid);\n console.log(item.cname);\n } else\n continue;\n }\n context.global.mlProject.set(tccode, arrayCID);\n console.log(arrayCID);\n }\n}\nreturn null;","outputs":1,"noerr":0,"x":510,"y":1040,"wires":[[]]},{"id":"e1ef016e.2be2f","type":"function","z":"f41712ff.dd9de","name":"Create MQTT Data ","func":"var resultJson;\nmsg.tag = \"3184\";\nvar tempVal = msg.payload;\n// resultJson.SEQUENCE_NO = tempVal['SEQUENCE_NO']; 396,639,1040,1385\n\ncontext.global.che_s = 396;\ncontext.global.che_si = 639;\ncontext.global.kr_tm = 1040;\ncontext.global.kr_wgt = 1385;\nvar resultJson =\n{\n \"uuid\":\"73bcfb29.b18764\"\n /*\n \"CHE_S\":tempVal['CHE_S'],\n \"CHE_SI\":tempVal['CHE_SI'],\n \"KR_TM\":tempVal['KR_TM'],\n \"KR_WGT\":tempVal['KR_WGT']\n */\n};\nmsg.payload = resultJson;\nvar tccode = context.global.Ml_Time.get(msg.tag);\nmlProjectMap = context.global.mlProject.get(tccode);\nconsole.log(\"MQTT : \" + tccode + \" : \" + mlProjectMap);\n\nif (context.global.topicList === undefined || context.global.topicList === null) {\n context.global.topicList = new Map();\n}\n\nvar arrKeys = Array.from(mlProjectMap.keys());\n\nfor (var count=0; count < arrKeys.length; count++) {\n msg.topic = \"THINGSPIN/EDGEAI/\" + arrKeys[count] + \"/IN/0\";\n msg.qos = 0;\n context.global.topicList.set(\"THINGSPIN/EDGEAI/\" + arrKeys[count] + \"/OUT\", \"false\");\n node.send(msg);\n}\nreturn null;","outputs":1,"noerr":0,"x":1050,"y":940,"wires":[["afde9a34.583ea8","7640c698.43f068"]]},{"id":"cbb986bd.a34e28","type":"function","z":"f41712ff.dd9de","name":"","func":"var resultMsg = msg;\nvar result = context.global.topicList.get(msg.topic);\nconsole.log(msg.topic + \":\" + result);\nif (result === \"false\") {\n if (msg.payload.camera === undefined)\n context.global.topicList.set(msg.topic, \"true\");\n console.log(msg.topic);\n msg.payload.result = msg.payload.CaO;\n node.send(msg);\n // return resultMsg;\n} else if (result === \"camera\")\n node.send(msg);\n // return null;","outputs":1,"noerr":0,"x":590,"y":1260,"wires":[["cde1cc64.f536c","a480ca93.764428","908d036f.ee5c9","ab4a7def.074df","bb0c533d.2a914"]]},{"id":"e88c4f0d.b37bc","type":"debug","z":"f41712ff.dd9de","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":1390,"y":140,"wires":[]},{"id":"78e1dc5a.7b3864","type":"mysql","z":"f41712ff.dd9de","mydb":"a28692d4.03579","name":"","x":1150,"y":1360,"wires":[[]]},{"id":"da04699a.5710b8","type":"mysql","z":"f41712ff.dd9de","mydb":"a28692d4.03579","name":"","x":1210,"y":480,"wires":[[]]},{"id":"819dd9e6.56d998","type":"influxdb batch","z":"f41712ff.dd9de","influxdb":"85a94193.17dfb","precision":"ms","retentionPolicy":"","name":"","x":790,"y":220,"wires":[]},{"id":"7732197.1addae8","type":"influxdb batch","z":"f41712ff.dd9de","influxdb":"85a94193.17dfb","precision":"ms","retentionPolicy":"","name":"","x":1190,"y":1420,"wires":[]},{"id":"b9d1d45b.825b48","type":"debug","z":"f41712ff.dd9de","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":290,"y":1080,"wires":[]},{"id":"7640c698.43f068","type":"debug","z":"f41712ff.dd9de","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":1290,"y":940,"wires":[]},{"id":"e9e03ced.b3062","type":"inject","z":"f41712ff.dd9de","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":840,"y":940,"wires":[["e1ef016e.2be2f"]]},{"id":"d0efbf95.df06d","type":"debug","z":"f41712ff.dd9de","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":590,"y":1200,"wires":[]},{"id":"11907ba8.b5f8b4","type":"function","z":"f41712ff.dd9de","name":"Influx Data Process","func":"//Main Area -----------------------------------------------------------------------------------------\nlet YYYYMMDD = context.global.todaydate;\nif (!YYYYMMDD) {\n YYYYMMDD = \"20180101\";\n}\n\n// msg.measurement = `posco-slab-${YYYYMMDD}`;\n\nmsg.payload = [{\n measurement:`posco-send-l2-distance-${YYYYMMDD}`,\n fields:{\n Data:msg.payload.toString(),\n Distance:msg.metric.distance,\n SequenceNo:context.global.sequence_no_3024\n }\n}]\n\nreturn msg;","outputs":1,"noerr":0,"x":1350,"y":260,"wires":[["c779f9a1.ea6b18"]]},{"id":"c779f9a1.ea6b18","type":"influxdb batch","z":"f41712ff.dd9de","influxdb":"85a94193.17dfb","precision":"ms","retentionPolicy":"","name":"","x":1570,"y":260,"wires":[]},{"id":"d0474118.7b429","type":"http in","z":"c45e3888.e82a68","name":"KR","url":"/thingspin/api/kr","method":"post","upload":false,"swaggerDoc":"","x":150,"y":160,"wires":[["54320b81.0181e4"]]},{"id":"54320b81.0181e4","type":"json","z":"c45e3888.e82a68","name":"","property":"payload","action":"obj","pretty":false,"x":370,"y":160,"wires":[["3485e81a.38f188","285c54d7.bc2b8c","759b4a92.980d04"]]},{"id":"752bbdc7.4bb144","type":"config","z":"c45e3888.e82a68","name":"Config","properties":[{"p":"basePath","pt":"global","to":"D:\\\\thingspin\\\\server\\\\data\\\\thingspin\\\\images\\\\","tot":"str"},{"p":"filePrefix","pt":"global","to":"KR","tot":"str"},{"p":"fileLadlePrefix","pt":"global","to":"LADEL","tot":"str"},{"p":"mlPrefix","pt":"global","to":"mlexam","tot":"str"},{"p":"basePath-ORG","pt":"flow","to":"D:\\\\thingspin\\\\server\\\\data\\\\thingspin\\\\images\\\\","tot":"str"},{"p":"baseDataPath","pt":"global","to":"D:\\\\thingspin\\\\data\\\\","tot":"str"},{"p":"baseDataPath-ORG","pt":"global","to":"D:\\\\thingspin\\\\data\\\\","tot":"str"},{"p":"SendTccode","pt":"global","to":"[\"3020\",\"3021\",\"3022\",\"3023\"]","tot":"json"},{"p":"PublishTime","pt":"global","to":"[\"3184\",\"0\",\"0\",\"0\"]","tot":"json"}],"active":true,"x":90,"y":40,"wires":[]},{"id":"6e30110b.d8886","type":"tcp in","z":"c45e3888.e82a68","name":"TCP Server","server":"server","host":"","port":"50000","datamode":"stream","datatype":"buffer","newline":"\\n","topic":"","base64":false,"x":150,"y":440,"wires":[["f9964f53.8a655","551a7dd4.b14404"]]},{"id":"c8c98223.2e2fc","type":"comment","z":"c45e3888.e82a68","name":"Data Slice and Insert to DB","info":"","x":410,"y":500,"wires":[]},{"id":"da0b2d04.628d5","type":"comment","z":"c45e3888.e82a68","name":"Input Infomation Insert to DB","info":"","x":420,"y":400,"wires":[]},{"id":"b0b24e3d.e9938","type":"comment","z":"c45e3888.e82a68","name":"HTTP KR POST Process","info":"","x":150,"y":120,"wires":[]},{"id":"7d019b6b.5e7c74","type":"comment","z":"c45e3888.e82a68","name":"TCP Server Process","info":"","x":130,"y":380,"wires":[]},{"id":"d8072bf1.09f9a8","type":"comment","z":"c45e3888.e82a68","name":"MQTT Process","info":"","x":120,"y":1000,"wires":[]},{"id":"23ab6195.f3886e","type":"function","z":"c45e3888.e82a68","name":"Create insert mariadb query ","func":"//Function Area -----------------------------------------------------------------------------------------\nfunction makeColumnString(dataType, valueData) {\n var title = dataType.dbsechma;\n var type = dataType.type;\n var columns = \"(\";\n var values = \"(\";\n console.log(title);\n for (var i=0; i<title.length;i++) {\n if (i+1 == title.length) {\n columns += title[i] + \")\";\n if (title[i] === 'UUID') {\n values += \"'\" + msg._msgid + \"')\";\n } else {\n if (type[i] !== 'char')\n values += valueData.get(title[i]) + \")\";\n else\n values += \"'\" + valueData.get(title[i]) + \"')\";\n }\n } else {\n columns += title[i] + \",\";\n if (type[i] !== 'char')\n values += valueData.get(title[i]) + \",\";\n else \n values += \"'\" + valueData.get(title[i]) + \"',\";\n }\n }\n var result = {\n columnStr : columns,\n valueStr : values\n };\n console.log(result);\n return result;\n}\n\n//Main Area -----------------------------------------------------------------------------------------\nvar dataMap = context.global.dataMap;\nvar dataFormat = context.global.FormatObjMap.get(msg.tag);\n// console.log(dataMap);\n// console.log(msg.tag);\n// console.log(dataFormat);\nvar queryInputData = makeColumnString(dataFormat, dataMap);\nvar queryStr = \"insert into \" + dataFormat.db + queryInputData.columnStr + \" values \" + queryInputData.valueStr;\n\nmsg.topic = queryStr;\n\nreturn msg;","outputs":1,"noerr":0,"x":700,"y":540,"wires":[["7cc355af.382edc","e1edf3d5.4c9b7","1051c79e.7c6178"]]},{"id":"a9cc5bc4.05e7a8","type":"function","z":"c45e3888.e82a68","name":"Influx Data Process","func":"//Main Area -----------------------------------------------------------------------------------------\nlet YYYYMMDD = context.global.todaydate;\nif (!YYYYMMDD) {\n YYYYMMDD = \"20180101\";\n}\n\n// msg.measurement = `posco-slab-${YYYYMMDD}`;\n\nmsg.payload = [{\n measurement:`posco-msg-${YYYYMMDD}`,\n fields:msg.fields,\n tags: {TC_CODE:msg.tag}\n}]\n\ndelete msg.fields;\nreturn msg;","outputs":1,"noerr":0,"x":670,"y":600,"wires":[["fe9aa2f6.0c28f"]]},{"id":"fe9aa2f6.0c28f","type":"influxdb batch","z":"c45e3888.e82a68","influxdb":"85a94193.17dfb","precision":"ms","retentionPolicy":"","name":"","x":1010,"y":600,"wires":[]},{"id":"7cc355af.382edc","type":"mysql","z":"c45e3888.e82a68","mydb":"a28692d4.03579","name":"","x":970,"y":540,"wires":[[]]},{"id":"65b5fc32.4474e4","type":"http response","z":"c45e3888.e82a68","name":"","statusCode":"","headers":{},"x":970,"y":80,"wires":[]},{"id":"759b4a92.980d04","type":"function","z":"c45e3888.e82a68","name":"construct-by-WIN","func":"function checkZeroTime(value) {\n return (value>9 ? '' : '0') + value\n}\n\nfunction nowDateFormat() {\n var nowTime = new Date();\n return nowTime.getFullYear() + checkZeroTime(nowTime.getMonth()+1) + checkZeroTime(nowTime.getDate());\n}\n\nvar p = msg.payload;\nvar metric = {};\n\nvar path = global.get(\"basePath\");\nconsole.log(path);\n\nif (context.global.todaydate === undefined) {\n context.global.todaydate = nowDateFormat();\n}\n\nvar date = context.global.todaydate;\nvar img = [];\nvar cameraID = p.id;\n\nObject.keys(p).filter((value) => { return (value !== 'image') }).map( (k) => {\n metric[k] = p[k];\n});\n\nvar data = {\n // path: path + date + \"\\\\\\\\\",\n path: path + date + \"\\\\\\\\\" + cameraID + \"\\\\\\\\\",\n directory : date,\n image: p.image,\n metric: metric\n};\n\ndelete msg.payload;\nmsg.statusCode = 200;\n\nreturn [msg, data];\n\n","outputs":2,"noerr":0,"x":570,"y":160,"wires":[["2155d7ae.9a7ac8"],["ba8916d8.268f88"]]},{"id":"ba8916d8.268f88","type":"function","z":"c45e3888.e82a68","name":"img","func":"var fs = global.get(\"mkdirp\");\n\nfs(msg.path, function(e) {\n if (!e || (e && e.code === 'EEXIST')) {\n } else {\n console.log(e);\n }\n});\n\nvar b = global.get(\"base64-to-image\");\n// var b = global.get(\"base64-img\");\n// console.log(b);\n\nvar filePrefix = global.get(\"filePrefix\");\n\nvar image = msg.image;\nvar path = msg.path;\n\nvar t = Date.now();\nvar fileName = filePrefix + t;\n\nvar option = {\n fileName: fileName,\n type: 'jpg'\n};\n\nvar imageInfo = b(image, path, option);\n// console.log(msg);\nmsg.info = imageInfo;\nmsg.info.fullPath = path + fileName + \".\" + imageInfo.imageType;\ndelete msg.image;\ndelete msg.path;\n\nreturn msg;","outputs":1,"noerr":0,"x":770,"y":160,"wires":[["7739e26b.ecd85c","96f9e45c.304a18","c800e429.eeda58"]]},{"id":"6debf9b1.6092e8","type":"mysql","z":"c45e3888.e82a68","mydb":"a28692d4.03579","name":"posco-ai","x":1240,"y":140,"wires":[[]]},{"id":"7739e26b.ecd85c","type":"function","z":"c45e3888.e82a68","name":"SQL","func":"var sql = \"INSERT INTO t_kr_capture (sno, uuid, distance, fileName, absPath, directory) values \";\n\nvar r = {\n sno: msg.metric.id,\n uuid: msg._msgid,\n distance: msg.metric.distance,\n fileName: msg.info.fileName,\n absPath: msg.info.fullPath,\n directory: msg.directory\n};\nconsole.log(msg.directory);\nvar values = \"\\\"\" + r.sno + \"\\\"\" + \",\"\nvalues += \"\\\"\" + r.uuid + \"\\\"\" + \",\"\nvalues += r.distance + \",\"\nvalues += \"\\\"\" + r.fileName + \"\\\"\" + \",\"\nvalues += \"\\\"\" + r.absPath + \"\\\"\" + \",\"\nvalues += \"\\\"\" + r.directory + \"\\\"\"\n\nsql = sql + \"(\" + values + \");\"\n\nmsg.topic = sql;\n\nreturn msg;","outputs":1,"noerr":0,"x":1010,"y":140,"wires":[["6debf9b1.6092e8"]]},{"id":"2155d7ae.9a7ac8","type":"function","z":"c45e3888.e82a68","name":"response-kr","func":"delete msg.payload;\ndelete msg.topic;\n\nmsg.statusCode = 200;\nmsg.headers = {\n \"contents-Type\": \"application/json\"\n};\n\nmsg.payload = {\n Result:\"OK\"\n};\n\nreturn msg;","outputs":1,"noerr":0,"x":790,"y":120,"wires":[["65b5fc32.4474e4"]]},{"id":"a1d40214.acaae","type":"mqtt in","z":"c45e3888.e82a68","name":"","topic":"#","qos":"0","broker":"536d87d3.cb0088","x":150,"y":1040,"wires":[["5801676c.85c7c8","6709f67c.7f6cc8"]]},{"id":"551a7dd4.b14404","type":"function","z":"c45e3888.e82a68","name":"Influx Data Process","func":"//Main Area -----------------------------------------------------------------------------------------\nlet YYYYMMDD = context.global.todaydate;\nif (!YYYYMMDD) {\n YYYYMMDD = \"20180101\";\n}\n\nsender_ip = msg.ip.slice(7, msg.ip.length);\nvar strData = msg.payload.toString('utf-8');\n\nmsg.payload = [{\n measurement:`posco-recv-${YYYYMMDD}`,\n fields:{\n Data:strData\n },\n tags: {\n TcNo:msg.tag,\n IP:sender_ip\n }\n}]\n\ndelete msg.fields;\nreturn msg;","outputs":1,"noerr":0,"x":390,"y":440,"wires":[["a69ad5e1.23ea38"]]},{"id":"a69ad5e1.23ea38","type":"influxdb batch","z":"c45e3888.e82a68","influxdb":"85a94193.17dfb","precision":"ms","retentionPolicy":"","name":"","x":690,"y":440,"wires":[]},{"id":"f9964f53.8a655","type":"function","z":"c45e3888.e82a68","name":"Buffer Parsing Process","func":"/* \n Return Map Data (format.title, value)\n*/\nfunction translateData(str, format) {\n if (context.global.dataMap === undefined || context.global.dataMap === null)\n context.global.dataMap = new Map();\n else \n context.global.dataMap.clear();\n \n if (context.global.dataType === undefined || context.global.dataType === null)\n context.global.dataType = new Map();\n else\n context.global.dataType.clear();\n // console.log(format);\n var sumTotal = 0;\n for (var i=0;i< format.title.length;i++) {\n if (i === 0) {\n sumTotal += (format.len[i])\n if (format.type[i] === 'char') {\n context.global.dataMap.set(format.title[i],msg.payload.slice(i, sumTotal).toString('utf-8'));\n } else if (format.type[i] === 'short') {\n var buff = new Buffer(format.len[i]);\n buff = msg.payload.slice(i, sumTotal);\n var inputValue = (buff.readUInt8(1) << 8) + buff.readUInt8(0);\n context.global.dataMap.set(format.title[i], inputValue);\n delete buff;\n } else if (format.type[i] === 'int') {\n var buff = new Buffer(format.len[i]);\n buff = msg.payload.slice(i, sumTotal);\n var inputValue = (buff.readUInt8(3) << 24) + (buff.readUInt8(2) << 16) + (buff.readUInt8(1) << 8) + buff.readUInt8(0);\n context.global.dataMap.set(format.title[i], inputValue);\n delete buff;\n } \n context.global.dataType.set(format.title[i], format.type[i]);\n } else {\n // console.log(\"first :\" +sumTotal + \" cut :\" + ((sumTotal) + format.len[i]));\n var buff = new Buffer(format.len[i]);\n buff = msg.payload.slice(sumTotal, (sumTotal) + format.len[i]);\n\n if (format.type[i] === 'char') {\n context.global.dataMap.set(format.title[i], buff.toString('utf-8'));\n } else if (format.type[i] === 'short') {\n var inputValue = (buff.readUInt8(1) << 8) + buff.readUInt8(0);\n context.global.dataMap.set(format.title[i], inputValue);\n } else if (format.type[i] === 'int') {\n var inputValue = (buff.readUInt8(3) << 24) + (buff.readUInt8(2) << 16) + (buff.readUInt8(1) << 8) + buff.readUInt8(0);\n context.global.dataMap.set(format.title[i], inputValue); \n }\n sumTotal += format.len[i];\n context.global.dataType.set(format.title[i], format.type[i]);\n delete buff;\n }\n }\n}\n\nfunction confirmMsg(strData) {\n var formatDatas = global.get(\"FormatData\");\n var size = formatDatas.length;\n for (var i=0; i<size; i++) {\n var format = formatDatas[i];\n if (strData.length === format.DataLength) {\n var defineData = context.global.FormatObjMap.get(format.TC_CODE);\n translateData(strData, defineData);\n } else {\n continue;\n }\n }\n}\n\nconfirmMsg(msg.payload);\n\nString.prototype.trim = function() {\n return this.replace(/^\\s+|\\s+$/g,\"\");\n}\n\nvar object = {};\ncontext.global.dataMap.forEach((value, key) => {\n if (context.global.dataType.get(key) !== 'char') {\n // console.log(value);\n // object[key] = value.trim();\n object[key] = parseFloat(value);\n } else {\n if (key === 'TC_CODE')\n msg.tag = value;\n else if (key === 'Length') {\n // object[key] = value.trim();\n object[key] = parseInt(value);\n } else\n object[key] = value;\n }\n});\n\nmsg.fields = object;\ncontext.global.dataType = null;\n\nreturn msg;","outputs":1,"noerr":0,"x":400,"y":540,"wires":[["23ab6195.f3886e","a9cc5bc4.05e7a8","6e95d144.d4b91","d7e7cf91.9e369","5f67f654.137228"]]},{"id":"6e95d144.d4b91","type":"function","z":"c45e3888.e82a68","name":"Make Data to Media Server","func":"function checkLengthString(str, len, type) {\n if (type === \"char\") {\n var check = str.length;\n if (check === undefined) {\n str = String(str);\n check = str.length;\n }\n if (check < len) {\n for (var i = 0 ; i < (len - check) ; i++) {\n str += \" \";\n }\n } else if(check > len) {\n str = str.slice(0, len)\n }\n return str;\n } else {\n str = String(str);\n var check = str.length;\n var temp = \"\";\n if (check < len) {\n for (var i = 0 ; i < (len - check) ; i++) {\n temp += \"0\";\n }\n str = temp + str;\n } else if(check > len) {\n str = str.slice(0, len)\n }\n return str;\n }\n}\n\nfunction nowDateFormat() {\n var nowTime = new Date();\n return nowTime.getFullYear() + checkZeroTime(nowTime.getMonth()+1) + checkZeroTime(nowTime.getDate()) + checkZeroTime(nowTime.getHours()) + checkZeroTime(nowTime.getMinutes()) + checkZeroTime(nowTime.getSeconds());\n}\n\nfunction checkZeroTime(value) {\n return (value>9 ? '' : '0') + value\n}\n\nfunction checkZeroTimeMillisec(value) {\n if (value < 10) {\n return '00' + value;\n } else if (value < 100) {\n return '0' + value;\n } else {\n return value;\n }\n}\n\nfunction createDataRefine(value) {\n var returnStr = \"\"\n var sendDatas = global.get(\"SendDataFormat\");\n var formatData = sendDatas.filter(function(obj){ return obj.tc === Number(msg.tag) })[0];\n console.log(formatData);\n if (formatData !== undefined) {\n var result;\n for (var i=0; i< formatData.title.length; i++) {\n if (formatData.title[i] === 'TC_CODE') {\n returnStr += msg.tag;\n continue;\n } else if (formatData.title[i] === 'Time') {\n returnStr += nowDateFormat();\n continue; \n } else if (formatData.title[i] === 'SEQUENCE_NO') {\n result = msg.fields.SEQUENCE_NO;\n } else if (formatData.title[i] === 'CHE_S') {\n result = msg.fields.CHE_S;\n } else if (formatData.title[i] === 'CHE_SI') {\n result = msg.fields.CHE_SI;\n } else if (formatData.title[i] === 'KR_TM') {\n result = msg.fields.KR_TM;\n } else if (formatData.title[i] === 'KR_WGT') {\n result = msg.fields.KR_WGT; \n } else if (formatData.title[i] === 'LADLE_NO') {\n result = msg.fields.LADLE_NO; \n } else {\n continue;\n }\n returnStr += checkLengthString(result, formatData.len[i], formatData.type[i]);\n }\n if (value === true) {\n returnStr += \"\\n\";\n }\n console.log(returnStr);\n console.log(returnStr.length);\n return returnStr;\n }\n return '';\n}\nmsg.payload = createDataRefine(false);\n\nreturn msg;","outputs":1,"noerr":0,"x":700,"y":660,"wires":[["5e078f9f.01b8c","1aa6cfa4.0b3bf","d8d284bc.e6b948"]]},{"id":"d8d284bc.e6b948","type":"tcp out","z":"c45e3888.e82a68","host":"192.168.0.10","port":"52000","beserver":"client","base64":false,"end":false,"name":"Send To Media Server","x":1000,"y":700,"wires":[]},{"id":"5e078f9f.01b8c","type":"function","z":"c45e3888.e82a68","name":"Influx Data Process","func":"//Main Area -----------------------------------------------------------------------------------------\nlet YYYYMMDD = context.global.todaydate;\nif (!YYYYMMDD) {\n YYYYMMDD = \"20180101\";\n}\n\nvar logFormat = global.get(\"LogFormat\");\nvar sender_ip = logFormat.image_Server_IP;\nvar strData = msg.payload.toString('utf-8');\n\n// msg.measurement = `posco-slab-${YYYYMMDD}`;\n\nmsg.payload = [{\n measurement:`posco-send-media-${YYYYMMDD}`,\n fields:{\n Data:strData\n },\n tags: {\n TcNo:msg.tag,\n IP:sender_ip\n }\n}]\n\ndelete msg.fields;\nreturn msg;","outputs":1,"noerr":0,"x":1010,"y":760,"wires":[["5ff71bc2.027084","5b589e47.15e42"]]},{"id":"5ff71bc2.027084","type":"influxdb batch","z":"c45e3888.e82a68","influxdb":"85a94193.17dfb","precision":"ms","retentionPolicy":"","name":"","x":1230,"y":780,"wires":[]},{"id":"96f9e45c.304a18","type":"function","z":"c45e3888.e82a68","name":"Create MQTT Data ","func":"var fileName = msg.info.fileName;\nvar folder = msg.info.path;\nvar jsonData = \n{\n \"uuid\":msg._msgid,\n \"camera\":msg.metric.id\n}\n// context.global.set_uuid = msg._msgid;\n// context.global.set_camera = msg.metric.id;\n\nmsg.payload = jsonData;\n\n// msg.topic = \"THINGSPIN/EDGEAI/KR/IN/0\";\n// msg.qos = 0;\n\n// return msg;\nvar tccode = context.global.Ml_Time.get(\"camera\");\nmlProjectMap = context.global.mlProject.get(tccode);\nconsole.log(mlProjectMap);\nif (context.global.topicList === undefined || context.global.topicList === null) {\n context.global.topicList = new Map();\n}\nif (mlProjectMap !== undefined) {\n \n var arrKeys = Array.from(mlProjectMap.keys());\n \n for (var count=0; count < arrKeys.length; count++) {\n msg.topic = \"THINGSPIN/EDGEAI/\" + arrKeys[count] + \"/IN/0\";\n msg.qos = 0;\n context.global.topicList.set(\"THINGSPIN/EDGEAI/\" + arrKeys[count] + \"/OUT\", \"camera\");\n console.log(msg.topic);\n node.send(msg);\n }\n return null;\n\n}","outputs":1,"noerr":0,"x":1050,"y":180,"wires":[["4ef53ce2.3818f4","b14ba6fa.095558"]]},{"id":"76ca9065.4c8a6","type":"mqtt out","z":"c45e3888.e82a68","name":"","topic":"","qos":"","retain":"","broker":"d6cadf0a.6e81","x":1530,"y":180,"wires":[]},{"id":"4ef53ce2.3818f4","type":"delay","z":"c45e3888.e82a68","name":"","pauseType":"delay","timeout":"200","timeoutUnits":"milliseconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":1350,"y":180,"wires":[["76ca9065.4c8a6"]]},{"id":"59ed9f0e.3b114","type":"mqtt in","z":"c45e3888.e82a68","name":"","topic":"THINGSPIN/EDGEAI/+/OUT","qos":"2","broker":"fa98ec3b.aa1b8","x":220,"y":1260,"wires":[["552417ff.6242f8"]]},{"id":"b005e34c.3d316","type":"function","z":"c45e3888.e82a68","name":"Make Update DB Query","func":"function makeColumnString(dataType, valueData) {\n var title = dataType.title;\n var type = dataType.type;\n var columns = \"(\";\n var values = \"(\";\n console.log(title);\n for (var i=0; i<title.length;i++) {\n if (i+1 == title.length) {\n columns += title[i] + \")\";\n if (type[i] !== 'char') {\n if (valueData[title[i]] === undefined)\n values += \"0\" + \")\";\n else\n values += valueData[title[i]] + \")\";\n } else {\n if (valueData[title[i]] === undefined)\n values += \"'\\\"\\\"')\";\n else\n values += \"'\" + valueData[title[i]] + \"')\";\n }\n } else {\n columns += title[i] + \",\";\n if (type[i] !== 'char') {\n if (valueData[title[i]] === undefined)\n values += \"0\" + \",\";\n else\n values += valueData[title[i]] + \",\";\n } else {\n if (valueData[title[i]] === undefined)\n values += \"'\\\"\\\"')\";\n else\n values += \"'\" + valueData[title[i]] + \"',\";\n }\n }\n }\n var result = {\n columnStr : columns,\n valueStr : values\n };\n console.log(result);\n return result;\n}\n\ncontext.global.result = msg.payload.result;\n\nvar ml_db_info = global.get(\"ML_RESULT\");\nvar ml_value_db_info = global.get(\"ML_VALUE_RESULT\");\nvar inputData = msg.payload;\nif (inputData[\"uuid\"].length > 0) {\n var queryInputData = makeColumnString(ml_db_info, msg.payload);\n var dupligate = \" on duplicate key update uuid='\" + msg.payload[\"uuid\"] + \"', project='\" + msg.payload[\"project\"] + \"'\";\n\n if (inputData[\"camera\"] === undefined) {\n var queryStr = \"insert into \" + ml_value_db_info.db + queryInputData.columnStr + \" values \" + queryInputData.valueStr + dupligate;\n console.log(queryStr);\n msg.topic = queryStr;\n\n } else {\n var queryStr = \"insert into \" + ml_db_info.db + queryInputData.columnStr + \" values \" + queryInputData.valueStr + dupligate;\n console.log(queryStr);\n msg.topic = queryStr;\n }\n \n return msg; \n}","outputs":1,"noerr":0,"x":910,"y":1160,"wires":[["5b138969.ee1778","9973038a.856c5"]]},{"id":"552417ff.6242f8","type":"json","z":"c45e3888.e82a68","name":"","property":"payload","action":"obj","pretty":false,"x":450,"y":1260,"wires":[["30b8a76.dec1e58"]]},{"id":"5b138969.ee1778","type":"mysql","z":"c45e3888.e82a68","mydb":"a28692d4.03579","name":"","x":1150,"y":1160,"wires":[[]]},{"id":"3485e81a.38f188","type":"function","z":"c45e3888.e82a68","name":"Influx Data Process","func":"//Main Area -----------------------------------------------------------------------------------------\nlet YYYYMMDD = context.global.todaydate;\nif (!YYYYMMDD) {\n YYYYMMDD = \"20180101\";\n}\nvar inputData = msg.payload;\n\nmsg.payload = [{\n measurement:`posco-post-recv-${YYYYMMDD}`,\n fields:{\n Data:JSON.stringify(inputData)\n },\n tags: {\n Camera:inputData.id \n }\n}]\n\ndelete msg.fields;\nreturn msg;","outputs":1,"noerr":0,"x":570,"y":220,"wires":[["e41603d8.8fea8"]]},{"id":"e1edf3d5.4c9b7","type":"function","z":"c45e3888.e82a68","name":"History data insert","func":"var dataMap = context.global.dataMap;\nvar dataFormat = context.global.FormatObjMap.get(msg.tag);\n\nif(dataFormat.db !== \"t_msg_history\") {\n msg.topic = \"insert into t_msg_history (SEQUENCE_NO, TC_CODE) values ('\" + dataMap.get('SEQUENCE_NO') + \"', '\" + dataMap.get('TC_CODE') + \"')\";\n return msg;\n} else {\n msg.topic = '';\n msg.payload = '';\n}","outputs":1,"noerr":0,"x":1010,"y":480,"wires":[["b3ceb8f3.a1f5c8"]]},{"id":"10ed90c9.cfd88f","type":"config","z":"c45e3888.e82a68","name":"Global Init Data","properties":[{"p":"LogFormat","pt":"global","to":"{\"send\":\"t_data_send_log\",\"image_Server_IP\":\"192.168.0.107\",\"send_Port\":52004,\"recv\":\"t_data_receive_log\",\"column\":[\"uuid\",\"ip\",\"port\",\"message\",\"dataLength\",\"dataDetail\"]}","tot":"json"},{"p":"SendDataFormat","pt":"global","to":"[{\"tc\":3181,\"title\":[\"TC_CODE\",\"SEQUENCE_NO\",\"Time\"],\"type\":[\"char\",\"short\",\"datetime\"],\"len\":[4,5,14]},{\"tc\":3183,\"title\":[\"TC_CODE\",\"SEQUENCE_NO\",\"Time\"],\"type\":[\"char\",\"short\",\"datetime\"],\"len\":[4,5,14]},{\"tc\":3184,\"title\":[\"TC_CODE\",\"SEQUENCE_NO\",\"Time\",\"CHE_S\",\"CHE_SI\",\"KR_TM\",\"KR_WGT\",\"LADLE_NO\"],\"type\":[\"char\",\"short\",\"datetime\",\"short\",\"short\",\"short\",\"int\",\"short\"],\"len\":[4,5,14,5,5,5,10,5]}]","tot":"json"},{"p":"FormatData","pt":"global","to":"[{\"TC_CODE\":\"3180\",\"Process\":\"1KR\",\"DataLength\":44},{\"TC_CODE\":\"3181\",\"Process\":\"1KR\",\"DataLength\":44},{\"TC_CODE\":\"3182\",\"Process\":\"1KR\",\"DataLength\":44},{\"TC_CODE\":\"3183\",\"Process\":\"1KR\",\"DataLength\":44},{\"TC_CODE\":\"3184\",\"Process\":\"1KR\",\"DataLength\":56}]","tot":"json"},{"p":"MSG_3180","pt":"global","to":"{\"db\":\"t_msg_history\",\"length\":44,\"title\":[\"Process\",\"TC_CODE\",\"Time\",\"Length\",\"Spare\",\"SEQUENCE_NO\"],\"type\":[\"char\",\"char\",\"char\",\"char\",\"char\",\"int\"],\"len\":[3,4,14,5,14,4],\"dbsechma\":[\"SEQUENCE_NO\",\"TC_CODE\"]}","tot":"json"},{"p":"MSG_3181","pt":"global","to":"{\"db\":\"t_msg_history\",\"length\":44,\"title\":[\"Process\",\"TC_CODE\",\"Time\",\"Length\",\"Spare\",\"SEQUENCE_NO\"],\"type\":[\"char\",\"char\",\"char\",\"char\",\"char\",\"int\"],\"len\":[3,4,14,5,14,4],\"dbsechma\":[\"SEQUENCE_NO\",\"TC_CODE\"]}","tot":"json"},{"p":"MSG_3182","pt":"global","to":"{\"db\":\"t_msg_history\",\"length\":44,\"title\":[\"Process\",\"TC_CODE\",\"Time\",\"Length\",\"Spare\",\"SEQUENCE_NO\"],\"type\":[\"char\",\"char\",\"char\",\"char\",\"char\",\"char\"],\"len\":[3,4,14,5,14,4],\"dbsechma\":[\"SEQUENCE_NO\",\"TC_CODE\"]}","tot":"json"},{"p":"MSG_3183","pt":"global","to":"{\"db\":\"t_msg_history\",\"length\":44,\"title\":[\"Process\",\"TC_CODE\",\"Time\",\"Length\",\"Spare\",\"SEQUENCE_NO\"],\"type\":[\"char\",\"char\",\"char\",\"char\",\"char\",\"int\"],\"len\":[3,4,14,5,14,4],\"dbsechma\":[\"SEQUENCE_NO\",\"TC_CODE\"]}","tot":"json"},{"p":"MSG_3184","pt":"global","to":"{\"db\":\"t_msg_3184\",\"length\":56,\"title\":[\"Process\",\"TC_CODE\",\"Time\",\"Length\",\"Spare\",\"SEQUENCE_NO\",\"CHE_S\",\"CHE_SI\",\"KR_TM\",\"KR_WGT\",\"LADLE_NO\"],\"type\":[\"char\",\"char\",\"char\",\"char\",\"char\",\"int\",\"short\",\"short\",\"short\",\"int\",\"short\"],\"len\":[3,4,14,5,14,4,2,2,2,4,2],\"dbsechma\":[\"SEQUENCE_NO\",\"CHE_S\",\"CHE_SI\",\"KR_TM\",\"KR_WGT\",\"LADLE_NO\",\"UUID\"]}","tot":"json"},{"p":"S_MSG_3020","pt":"global","to":"{\"db\":\"t_msg_3020\",\"Length\":48,\"title\":[\"Process\",\"TC_CODE\",\"Time\",\"Length\",\"Spare\",\"SEQUENCE_NO\",\"DATA\"],\"type\":[\"char\",\"char\",\"char\",\"char\",\"char\",\"float\",\"float\"],\"len\":[3,4,14,5,14,4,4],\"dbsechma\":[\"DATA\",\"UUID\"],\"values\":[\"1KR\",\"3020\"]}","tot":"json"},{"p":"S_MSG_3021","pt":"global","to":"{\"db\":\"t_msg_3021\",\"Length\":48,\"title\":[\"Process\",\"TC_CODE\",\"Time\",\"Length\",\"Spare\",\"SEQUENCE_NO\",\"DATA\"],\"type\":[\"char\",\"char\",\"char\",\"char\",\"char\",\"float\",\"float\"],\"len\":[3,4,14,5,14,4,4],\"dbsechma\":[\"DATA\",\"UUID\"],\"values\":[\"1KR\",\"3021\"]}","tot":"json"},{"p":"S_MSG_3022","pt":"global","to":"{\"db\":\"t_msg_3022\",\"Length\":48,\"title\":[\"Process\",\"TC_CODE\",\"Time\",\"Length\",\"Spare\",\"SEQUENCE_NO\",\"DATA\"],\"type\":[\"char\",\"char\",\"char\",\"char\",\"char\",\"float\",\"float\"],\"len\":[3,4,14,5,14,4,4],\"dbsechma\":[\"DATA\",\"UUID\"],\"values\":[\"1KR\",\"3022\"]}","tot":"json"},{"p":"S_MSG_3023","pt":"global","to":"{\"db\":\"t_msg_3023\",\"Length\":48,\"title\":[\"Process\",\"TC_CODE\",\"Time\",\"Length\",\"Spare\",\"SEQUENCE_NO\",\"DATA\"],\"type\":[\"char\",\"char\",\"char\",\"char\",\"char\",\"float\",\"float\"],\"len\":[3,4,14,5,14,4,4],\"dbsechma\":[\"DATA\",\"UUID\"],\"values\":[\"1KR\",\"3023\"]}","tot":"json"},{"p":"ML_RESULT","pt":"global","to":"{\"db\":\"t_kr_ml_result\",\"title\":[\"uuid\",\"project\",\"result\",\"tc_code\",\"spare\"],\"type\":[\"char\",\"char\",\"float\",\"char\",\"char\"]}","tot":"json"},{"p":"ML_VALUE_RESULT","pt":"global","to":"{\"db\":\"t_kr_ml_value_result\",\"title\":[\"uuid\",\"project\",\"result\",\"tc_code\",\"spare\"],\"type\":[\"char\",\"char\",\"float\",\"char\",\"char\"]}","tot":"json"},{"p":"S_MSG_3024","pt":"global","to":"{\"db\":\"t_msg_3024\",\"Length\":48,\"title\":[\"Process\",\"TC_CODE\",\"Time\",\"Length\",\"Spare\",\"SEQUENCE_NO\",\"DATA\"],\"type\":[\"char\",\"char\",\"char\",\"char\",\"char\",\"float\",\"float\"],\"len\":[3,4,14,5,14,4,4],\"dbsechma\":[\"DATA\",\"UUID\"],\"values\":[\"1KR\",\"3024\"]}","tot":"json"}],"active":true,"x":220,"y":1480,"wires":[]},{"id":"7b6b1756.4696a8","type":"comment","z":"c45e3888.e82a68","name":"[ 관리자 내부 변수 초기화 ]","info":"","x":180,"y":1440,"wires":[]},{"id":"edcc52e9.0d7d5","type":"inject","z":"c45e3888.e82a68","name":"","topic":"","payload":"","payloadType":"date","repeat":"3600","crontab":"","once":false,"onceDelay":0.1,"x":210,"y":1540,"wires":[["ca7407d3.ddac68","7ce4a9c5.1ccd28"]]},{"id":"ca7407d3.ddac68","type":"function","z":"c45e3888.e82a68","name":"YYYYMMDD","func":"Date.prototype.yyyymmdd = function() {\n var mm = this.getMonth() + 1; // getMonth() is zero-based\n var dd = this.getDate();\n\n return [this.getFullYear(),\n (mm>9 ? '' : '0') + mm,\n (dd>9 ? '' : '0') + dd\n ].join('');\n};\n\nvar date = new Date();\ndate.yyyymmdd();\n\ncontext.global.todaydate = date.yyyymmdd();\n// context.global.set(\"YYYYMMDD\", \"20180101\");\n\nreturn;","outputs":1,"noerr":0,"x":410,"y":1540,"wires":[[]]},{"id":"7ce4a9c5.1ccd28","type":"function","z":"c45e3888.e82a68","name":"Init Format Map","func":"if (context.global.FormatObjMap === undefined || context.global.FormatObjMap === null)\n context.global.FormatObjMap = new Map();\nelse\n context.global.FormatObjMap.clear();\nvar formatDatas = global.get(\"FormatData\");\nvar size = formatDatas.length;\nconsole.log(size);\nfor (var i=0; i<size; i++) {\n var format = formatDatas[i];\n if (format.TC_CODE === \"3180\")\n context.global.FormatObjMap.set(format.TC_CODE, global.get(\"MSG_3180\"));\n else if (format.TC_CODE === \"3181\")\n context.global.FormatObjMap.set(format.TC_CODE, global.get(\"MSG_3181\"));\n else if (format.TC_CODE === \"3182\")\n context.global.FormatObjMap.set(format.TC_CODE, global.get(\"MSG_3182\"));\n else if (format.TC_CODE === \"3183\")\n context.global.FormatObjMap.set(format.TC_CODE, global.get(\"MSG_3183\"));\n else if (format.TC_CODE === \"3184\")\n context.global.FormatObjMap.set(format.TC_CODE, global.get(\"MSG_3184\"));\n}\n\nvar checkTC = global.get(\"SendTccode\");\nvar timeTC = global.get(\"PublishTime\");\n\nif (context.global.Ml_Time === undefined || context.global.Ml_Time === null)\n context.global.Ml_Time = new Map();\nelse\n context.global.Ml_Time.clear();\n\nfor (var i=0; i<checkTC.length; i++) {\n context.global.Ml_Time.set(timeTC[i], checkTC[i]);\n}\n\ncontext.global.krcount = 1;\ncontext.global.ladlecount = 11;\n\nreturn;","outputs":1,"noerr":0,"x":420,"y":1580,"wires":[[]]},{"id":"98f0cc0c.8ebb6","type":"status","z":"c45e3888.e82a68","name":"","scope":["6e30110b.d8886"],"x":200,"y":1580,"wires":[["ca7407d3.ddac68","7ce4a9c5.1ccd28"]]},{"id":"1051c79e.7c6178","type":"debug","z":"c45e3888.e82a68","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":970,"y":420,"wires":[]},{"id":"5b589e47.15e42","type":"debug","z":"c45e3888.e82a68","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":1210,"y":740,"wires":[]},{"id":"1aa6cfa4.0b3bf","type":"debug","z":"c45e3888.e82a68","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":970,"y":660,"wires":[]},{"id":"92a0d698.b0f168","type":"function","z":"c45e3888.e82a68","name":"construct-by-MAC","func":"function checkZeroTime(value) {\n return (value>9 ? '' : '0') + value\n}\n\nfunction nowDateFormat() {\n var nowTime = new Date();\n return nowTime.getFullYear() + checkZeroTime(nowTime.getMonth()+1) + checkZeroTime(nowTime.getDate());\n}\n\nvar p = msg.payload;\nvar metric = {};\n\nvar path = global.get(\"basePath\");\nconsole.log(path);\n\nif (context.global.todaydate === undefined) {\n context.global.todaydate = nowDateFormat();\n}\n\nvar date = context.global.todaydate;\nvar img = [];\nvar cameraID = p.id;\n\nObject.keys(p).filter((value) => { return (value !== 'image') }).map( (k) => {\n metric[k] = p[k];\n});\n\nvar data = {\n path: path + date + \"/\" + cameraID + \"/\",\n image: p.image,\n directory: date,\n metric: metric\n};\n\ndelete msg.payload;\nmsg.statusCode = 200;\n\nreturn [msg, data];\n\n","outputs":2,"noerr":0,"x":570,"y":120,"wires":[["2155d7ae.9a7ac8"],["ba8916d8.268f88"]]},{"id":"285c54d7.bc2b8c","type":"debug","z":"c45e3888.e82a68","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":550,"y":260,"wires":[]},{"id":"a8edce1d.12a8e","type":"function","z":"c45e3888.e82a68","name":"Make Data to L2 Server","func":"var dataFormat;\n\nfunction getRandomTemperator() {\n var bottomValue = Math.round(Math.random() *100);\n var topValue = Math.round(Math.random() *100);\n var resultData = topValue + \".\" + bottomValue;\n var parseData = parseFloat(resultData);\n var buff = new Buffer(4);\n \n return buff.writeFloatBE(parseData);\n}\n\n\nfunction nowDateFormat() {\n var nowTime = new Date();\n return nowTime.getFullYear() + checkZeroTime(nowTime.getMonth()+1) + checkZeroTime(nowTime.getDate()) + checkZeroTime(nowTime.getHours()) + checkZeroTime(nowTime.getMinutes()) + checkZeroTime(nowTime.getSeconds());\n}\n\nfunction checkZeroTime(value) {\n return (value>9 ? '' : '0') + value\n}\n\nfunction checkZeroTimeMillisec(value) {\n if (value < 10) {\n return '00' + value;\n } else if (value < 100) {\n return '0' + value;\n } else {\n return value;\n }\n}\n\nfunction initDataFormat(code) {\n console.log(code);\n switch(code) {\n case \"3020\":\n dataFormat = global.get(\"S_MSG_3020\");\n return true;\n case \"3021\":\n dataFormat = global.get(\"S_MSG_3021\");\n return true;\n case \"3022\":\n dataFormat = global.get(\"S_MSG_3022\");\n return true;\n case \"3023\":\n dataFormat = global.get(\"S_MSG_3023\");\n return true; \n default:\n return false;\n }\n}\n\nconsole.log(msg.payload[\"tc_code\"]);\n\nif(initDataFormat(msg.payload[\"tc_code\"])) {\n var sendBuff = new Buffer(dataFormat.Length);\n sendBuff.fill(0);\n var sumTotal = 0;\n for (var count=0;count < dataFormat.title.length;count++) {\n var title = dataFormat.title[count];\n\n if (dataFormat.type[count] === \"char\") {\n if (title === \"Process\" || title === \"TC_CODE\") {\n if (count === 0) {\n console.log(\"sumTotal : \" + 0 + \" END : \" + dataFormat.len[count]);\n console.log(dataFormat.values[count]);\n sendBuff.write(dataFormat.values[count], 0, dataFormat.len[count]); \n } else {\n console.log(\"sumTotal : \" + sumTotal + \" END : \" + ((sumTotal) + dataFormat.len[count]));\n console.log(dataFormat.values[count]);\n sendBuff.write(dataFormat.values[count], sumTotal, ((sumTotal) + dataFormat.len[count]));\n }\n } else if (title === \"Time\") {\n console.log(\"sumTotal : \" + sumTotal + \" END : \" + ((sumTotal) + dataFormat.len[count]));\n var date = nowDateFormat();\n console.log(date);\n sendBuff.write(date, sumTotal, (sumTotal) + dataFormat.len[count]);\n } else if (title === \"Length\") {\n console.log(\"sumTotal : \" + sumTotal + \" END : \" + ((sumTotal) + dataFormat.len[count]));\n console.log(dataFormat.Length + \" \");\n sendBuff.write(dataFormat.Length + \" \", sumTotal, ((sumTotal) + dataFormat.len[count]));\n } else if (title === \"Spare\") {\n console.log(\"sumTotal : \" + sumTotal + \" END : \" + ((sumTotal) + dataFormat.len[count]));\n console.log(\" \");\n sendBuff.write(\" \", sumTotal, (sumTotal) + dataFormat.len[count]);\n }\n sumTotal += (dataFormat.len[count]);\n } else if (dataFormat.type[count] === \"float\") {\n console.log(title);\n if (title === \"SEQUENCE_NO\") {\n console.log(\"sumTotal : \" + sumTotal + \" END : \" + ((sumTotal) - dataFormat.len[count]));\n console.log(parseFloat(context.global.sequence_no));\n sendBuff.writeFloatLE(parseFloat(context.global.sequence_no), sumTotal);\n console.log(sendBuff);\n sumTotal += (dataFormat.len[count]);\n } else {\n console.log(\"sumTotal : \" + sumTotal + \" END : \" + ((sumTotal) - dataFormat.len[count]));\n console.log(parseFloat(msg.payload[\"result\"]));\n sendBuff.writeFloatLE(parseFloat(msg.payload[\"result\"]), sumTotal);\n console.log(sendBuff);\n }\n }\n }\n}\n// var sendBuff = new Buffer(header);\n// console.log(sendBuff);\n// const buf = Buffer.allocUnsafe(4);\n// buf.writeFloatBE(0xcafebabe, 0);\n// console.log(buf) \n// console.log(sendBuff + buf);\n\nmsg.payload = sendBuff;\nreturn msg;","outputs":1,"noerr":0,"x":910,"y":1240,"wires":[["c5170080.099c7","5a1a8d1d.b5f2b4"]]},{"id":"c5170080.099c7","type":"tcp out","z":"c45e3888.e82a68","host":"","port":"","beserver":"reply","base64":false,"end":false,"name":"Reply To L2 Server","x":1190,"y":1260,"wires":[]},{"id":"6d800263.8f6cdc","type":"function","z":"c45e3888.e82a68","name":"Influx Data Process","func":"//Main Area -----------------------------------------------------------------------------------------\nlet YYYYMMDD = context.global.todaydate;\nif (!YYYYMMDD) {\n YYYYMMDD = \"20180101\";\n}\nvar inputData = msg.payload;\n\nif (inputData.camera === undefined) {\n console.log('camera is undefined');\n\n if (inputData.spare === undefined) {\n inputData.spare = \"\";\n }\n msg.payload = [{\n measurement:`posco-send-l2-${YYYYMMDD}`,\n fields:{\n uuid:inputData.uuid,\n result:inputData.result,\n spare:inputData.spare,\n CHE_S:context.global.che_s,\n CHE_SI:context.global.che_si,\n KR_TM:context.global.kr_tm,\n KR_WGT:context.global.kr_wgt,\n TcNo:inputData.tc_code\n },\n tags: {\n project:inputData.project\n }\n }]\n} else {\n if (inputData.spare === undefined) {\n inputData.spare = \"\";\n }\n msg.payload = [{\n measurement:`posco-send-l2-${YYYYMMDD}`,\n fields:{\n uuid:inputData.uuid,\n camera:inputData.camera,\n result:inputData.result,\n spare:inputData.spare,\n TcNo:inputData.tc_code\n },\n tags: {\n project:inputData.project\n }\n }]\n}\n\ndelete msg.fields;\nreturn msg;","outputs":1,"noerr":0,"x":890,"y":1420,"wires":[["8467d8ea.698fe8"]]},{"id":"5a1a8d1d.b5f2b4","type":"debug","z":"c45e3888.e82a68","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":1150,"y":1220,"wires":[]},{"id":"e8d5c7e9.32c2d8","type":"function","z":"c45e3888.e82a68","name":"Make Data to Database","func":"var dataFormat;\n\nfunction initDataFormat(value) {\n switch(value) {\n case \"3020\":\n dataFormat = global.get(\"S_MSG_3020\");\n return true;\n case \"3021\":\n dataFormat = global.get(\"S_MSG_3021\");\n return true;\n case \"3022\":\n dataFormat = global.get(\"S_MSG_3022\");\n return true;\n case \"3023\":\n dataFormat = global.get(\"S_MSG_3023\");\n return true;\n default:\n return false;\n }\n}\n//insert into t_msg_history (CHARGE_NO, TC_CODE) values (\nif(initDataFormat(msg.payload.tc_code)) {\n var tableName = dataFormat.db;\n var dbschema = dataFormat.dbsechma;\n console.log(dbschema);\n msg.topic = \"insert into \" + tableName + \" (\" + dbschema + \") values (\" + msg.payload.result + \",'\" + msg.payload.uuid + \"');\"\n console.log(msg.topic);\n return msg;\n}","outputs":1,"noerr":0,"x":910,"y":1360,"wires":[["3c790b16.ae82d4","eb8af688.1083b8"]]},{"id":"d7e7cf91.9e369","type":"function","z":"c45e3888.e82a68","name":"Create CSV File","func":"msg.payload = msg.fields;\nmsg.payload.TC_CODE = Number(msg.tag);\nvar path = global.get(\"baseDataPath\");\n\nmsg.payload.CHE_S = msg.payload.CHE_S/10000;\nmsg.payload.CHE_SI = msg.payload.CHE_SI/1000;\n\nmsg.filename = path + \"L2_Data.csv\";\nreturn msg;","outputs":1,"noerr":0,"x":660,"y":840,"wires":[["d5744174.6aa1"]]},{"id":"5f9d7ce8.22b034","type":"csv","z":"c45e3888.e82a68","name":"Create 3184 CSV","sep":",","hdrin":"","hdrout":true,"multi":"one","ret":"\\r\\n","temp":"CHE_S,CHE_SI,KR_TM,KR_WGT","skip":"0","x":1050,"y":840,"wires":[["8457c0a8.44e09"]]},{"id":"d5744174.6aa1","type":"switch","z":"c45e3888.e82a68","name":"","property":"payload.TC_CODE","propertyType":"msg","rules":[{"t":"eq","v":"3184","vt":"num"},{"t":"eq","v":"3181","vt":"num"}],"checkall":"true","repair":false,"outputs":2,"x":830,"y":840,"wires":[["5f9d7ce8.22b034","44fa20d1.5817f"],["5915a1a2.53cb9"]]},{"id":"8457c0a8.44e09","type":"file","z":"c45e3888.e82a68","name":"","filename":"","appendNewline":true,"createDir":false,"overwriteFile":"true","x":1230,"y":840,"wires":[]},{"id":"44fa20d1.5817f","type":"function","z":"c45e3888.e82a68","name":"Publish MQTT","func":"var resultJson;\nvar tempVal = msg.payload;\ncontext.global.sequence_no = tempVal['SEQUENCE_NO'];\ncontext.global.che_s = tempVal['CHE_S'];\ncontext.global.che_si = tempVal['CHE_SI'];\ncontext.global.kr_tm = tempVal['KR_TM'];\ncontext.global.kr_wgt = tempVal['KR_WGT'];\nvar resultJson =\n{\n \"uuid\":msg._msgid\n /*\n \"CHE_S\":tempVal['CHE_S'],\n \"CHE_SI\":tempVal['CHE_SI'],\n \"KR_TM\":tempVal['KR_TM'],\n \"KR_WGT\":tempVal['KR_WGT']\n */\n};\nmsg.payload = resultJson;\nvar tccode = context.global.Ml_Time.get(msg.tag);\nmlProjectMap = context.global.mlProject.get(tccode);\n\nif (context.global.topicList === undefined || context.global.topicList === null) {\n context.global.topicList = new Map();\n}\n\nvar arrKeys = Array.from(mlProjectMap.keys());\n\nfor (var count=0; count < arrKeys.length; count++) {\n msg.topic = \"THINGSPIN/EDGEAI/\" + arrKeys[count] + \"/IN/0\";\n msg.qos = 0;\n context.global.topicList.set(\"THINGSPIN/EDGEAI/\" + arrKeys[count] + \"/OUT\", \"false\");\n node.send(msg);\n}\nreturn null;","outputs":1,"noerr":0,"x":1040,"y":900,"wires":[["8e14a68f.5966f8"]]},{"id":"8e14a68f.5966f8","type":"mqtt out","z":"c45e3888.e82a68","name":"","topic":"","qos":"","retain":"","broker":"d6cadf0a.6e81","x":1230,"y":900,"wires":[]},{"id":"5f67f654.137228","type":"debug","z":"c45e3888.e82a68","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":630,"y":480,"wires":[]},{"id":"3c790b16.ae82d4","type":"debug","z":"c45e3888.e82a68","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":1150,"y":1320,"wires":[]},{"id":"9973038a.856c5","type":"debug","z":"c45e3888.e82a68","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":1150,"y":1120,"wires":[]},{"id":"5e412603.e9d7a8","type":"inject","z":"c45e3888.e82a68","name":"Result Create File","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"59 23 * * *","once":false,"onceDelay":0.1,"x":230,"y":1680,"wires":[["73c2475f.34eba8"]]},{"id":"73c2475f.34eba8","type":"function","z":"c45e3888.e82a68","name":"File Setting","func":"function checkZeroTime(value) {\n return (value>9 ? '' : '0') + value\n}\n\nfunction nowDateFormat() {\n var nowTime = new Date();\n return nowTime.getFullYear() + \"-\" + checkZeroTime(nowTime.getMonth()+1) + \"-\" + checkZeroTime(nowTime.getDate());\n}\nvar date = nowDateFormat();\nvar path = global.get(\"baseDataPath\");\nvar fs = global.get(\"mkdirp\");\n\nfs(path, function(e) {\n if (!e || (e && e.code === 'EEXIST')) {\n } else {\n console.log(e);\n }\n});\nmsg.filename = path + date + \"-KR-RESULT.csv\"\n\nmsg.topic = \"select msg1.time, msg2.SEQUENCE_NO, msg2.CHE_S, msg2.CHE_SI, msg2.KR_TM, msg2.KR_WGT, msg1.result from t_kr_ml_value_result msg1 join t_msg_3184 msg2 on msg1.uuid = msg2.UUID where DATE(msg1.time) = '\" + date + \"' order by msg1.time asc\";\nreturn msg;","outputs":1,"noerr":0,"x":450,"y":1680,"wires":[["ec2a0a0f.033708"]]},{"id":"ec2a0a0f.033708","type":"mysql","z":"c45e3888.e82a68","mydb":"a28692d4.03579","name":"","x":650,"y":1680,"wires":[["60196442.eca6cc"]]},{"id":"60196442.eca6cc","type":"csv","z":"c45e3888.e82a68","name":"","sep":",","hdrin":"","hdrout":true,"multi":"one","ret":"\\r\\n","temp":"time, SEQUENCE_NO, CHE_S, CHE_SI, KR_TM, KR_WGT, result","skip":"0","x":810,"y":1680,"wires":[["5b0b782a.52f888"]]},{"id":"5b0b782a.52f888","type":"file","z":"c45e3888.e82a68","name":"","filename":"","appendNewline":true,"createDir":false,"overwriteFile":"true","x":970,"y":1680,"wires":[]},{"id":"9ec2a149.0a438","type":"inject","z":"c45e3888.e82a68","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":240,"y":1640,"wires":[["73c2475f.34eba8"]]},{"id":"cfcba4ef.1fd288","type":"file in","z":"c45e3888.e82a68","name":"","filename":"","format":"utf8","chunk":false,"sendError":false,"x":1050,"y":1480,"wires":[["c2491067.2c682"]]},{"id":"4d2509ba.0c66d8","type":"function","z":"c45e3888.e82a68","name":"Create CSV File","func":"var path = global.get(\"baseDataPath\");\n\nmsg.filename = path + \"L2_Data.csv\";\nreturn msg;","outputs":1,"noerr":0,"x":880,"y":1480,"wires":[["cfcba4ef.1fd288"]]},{"id":"c2491067.2c682","type":"csv","z":"c45e3888.e82a68","name":"","sep":",","hdrin":true,"hdrout":"","multi":"one","ret":"\\n","temp":"","skip":"0","x":1190,"y":1480,"wires":[["2cdd4569.de584a"]]},{"id":"2cdd4569.de584a","type":"function","z":"c45e3888.e82a68","name":"","func":"msg.payload.RESULT = context.global.result\nreturn msg;","outputs":1,"noerr":0,"x":1340,"y":1480,"wires":[["9b1cb9dd.7b9498"]]},{"id":"9b1cb9dd.7b9498","type":"csv","z":"c45e3888.e82a68","name":"","sep":",","hdrin":"","hdrout":true,"multi":"one","ret":"\\r\\n","temp":"CHE_S, CHE_SI, KR_TM, KR_WGT, RESULT","skip":"0","x":1490,"y":1480,"wires":[["e4f3e335.745e8","8dead0ee.7374a"]]},{"id":"e4f3e335.745e8","type":"file","z":"c45e3888.e82a68","name":"","filename":"","appendNewline":true,"createDir":true,"overwriteFile":"true","x":1650,"y":1480,"wires":[]},{"id":"8dead0ee.7374a","type":"debug","z":"c45e3888.e82a68","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":1640,"y":1440,"wires":[]},{"id":"5801676c.85c7c8","type":"json","z":"c45e3888.e82a68","name":"","property":"payload","action":"","pretty":false,"x":290,"y":1040,"wires":[["1703088f.58df77"]]},{"id":"1703088f.58df77","type":"function","z":"c45e3888.e82a68","name":"ML-Project-Setting","func":"if (msg.topic === \"config\") {\n var TS_ML_Project = msg.payload;\n \n var arrayProject = Object.values(TS_ML_Project);\n if (context.global.mlProject === undefined || context.global.mlProject === null) {\n context.global.mlProject = new Map();\n }\n var checkTC = global.get(\"SendTccode\");\n for (var count=0;count<checkTC.length;count++) {\n var tccode = checkTC[count];\n var arrayCID = new Map();\n for (var sub=0;sub<arrayProject.length;sub++) {\n var item = arrayProject[sub];\n if (item['cname'].indexOf(tccode) != -1) {\n arrayCID.set(item.cid, item.cname);\n } else\n continue;\n }\n context.global.mlProject.set(tccode, arrayCID);\n }\n}\nreturn null;","outputs":1,"noerr":0,"x":470,"y":1040,"wires":[[]]},{"id":"30b8a76.dec1e58","type":"function","z":"c45e3888.e82a68","name":"","func":"var resultMsg = msg;\nvar result = context.global.topicList.get(msg.topic);\nconsole.log(msg.topic + \":\" + result);\nif (result === \"false\") {\n if (msg.payload.camera === undefined)\n context.global.topicList.set(msg.topic, \"true\");\n console.log(msg.topic);\n node.send(msg);\n // return resultMsg;\n} else if (result === \"camera\")\n node.send(msg);\n // return null;","outputs":1,"noerr":0,"x":590,"y":1260,"wires":[["b005e34c.3d316","a8edce1d.12a8e","e8d5c7e9.32c2d8","6d800263.8f6cdc","4d2509ba.0c66d8"]]},{"id":"b14ba6fa.095558","type":"debug","z":"c45e3888.e82a68","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":1430,"y":140,"wires":[]},{"id":"eb8af688.1083b8","type":"mysql","z":"c45e3888.e82a68","mydb":"a28692d4.03579","name":"","x":1150,"y":1360,"wires":[[]]},{"id":"b3ceb8f3.a1f5c8","type":"mysql","z":"c45e3888.e82a68","mydb":"a28692d4.03579","name":"","x":1210,"y":480,"wires":[[]]},{"id":"e41603d8.8fea8","type":"influxdb batch","z":"c45e3888.e82a68","influxdb":"85a94193.17dfb","precision":"ms","retentionPolicy":"","name":"","x":790,"y":220,"wires":[]},{"id":"8467d8ea.698fe8","type":"influxdb batch","z":"c45e3888.e82a68","influxdb":"85a94193.17dfb","precision":"ms","retentionPolicy":"","name":"","x":1190,"y":1420,"wires":[]},{"id":"6709f67c.7f6cc8","type":"debug","z":"c45e3888.e82a68","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":330,"y":1100,"wires":[]},{"id":"5915a1a2.53cb9","type":"function","z":"c45e3888.e82a68","name":"","func":"context.global.sequence_no_3024 = msg.payload.SEQUENCE_NO;\nconsole.log(context.global.sequence_no_3024);\nreturn null;","outputs":1,"noerr":0,"x":1020,"y":940,"wires":[[]]},{"id":"c800e429.eeda58","type":"function","z":"c45e3888.e82a68","name":"Make Data to L2 Server","func":"var dataFormat;\n\nfunction nowDateFormat() {\n var nowTime = new Date();\n return nowTime.getFullYear() + checkZeroTime(nowTime.getMonth()+1) + checkZeroTime(nowTime.getDate()) + checkZeroTime(nowTime.getHours()) + checkZeroTime(nowTime.getMinutes()) + checkZeroTime(nowTime.getSeconds());\n}\n\nfunction checkZeroTime(value) {\n return (value>9 ? '' : '0') + value\n}\n\nfunction initDataFormat() {\n dataFormat = global.get(\"S_MSG_3024\");\n if (dataFormat === undefined)\n return false;\n else\n return true;\n}\n\nif(initDataFormat()) {\n var sendBuff = new Buffer(dataFormat.Length);\n sendBuff.fill(0);\n var sumTotal = 0;\n for (var count=0;count < dataFormat.title.length;count++) {\n var title = dataFormat.title[count];\n\n if (dataFormat.type[count] === \"char\") {\n if (title === \"Process\" || title === \"TC_CODE\") {\n if (count === 0) {\n console.log(\"sumTotal : \" + 0 + \" END : \" + dataFormat.len[count]);\n console.log(dataFormat.values[count]);\n sendBuff.write(dataFormat.values[count], 0, dataFormat.len[count]); \n } else {\n console.log(\"sumTotal : \" + sumTotal + \" END : \" + ((sumTotal) + dataFormat.len[count]));\n console.log(dataFormat.values[count]);\n sendBuff.write(dataFormat.values[count], sumTotal, ((sumTotal) + dataFormat.len[count]));\n }\n } else if (title === \"Time\") {\n console.log(\"sumTotal : \" + sumTotal + \" END : \" + ((sumTotal) + dataFormat.len[count]));\n var date = nowDateFormat();\n console.log(date);\n sendBuff.write(date, sumTotal, (sumTotal) + dataFormat.len[count]);\n } else if (title === \"Length\") {\n console.log(\"sumTotal : \" + sumTotal + \" END : \" + ((sumTotal) + dataFormat.len[count]));\n console.log(dataFormat.Length + \" \");\n sendBuff.write(dataFormat.Length + \" \", sumTotal, ((sumTotal) + dataFormat.len[count]));\n } else if (title === \"Spare\") {\n console.log(\"sumTotal : \" + sumTotal + \" END : \" + ((sumTotal) + dataFormat.len[count]));\n console.log(\" \");\n sendBuff.write(\" \", sumTotal, (sumTotal) + dataFormat.len[count]);\n }\n sumTotal += (dataFormat.len[count]);\n } else if (dataFormat.type[count] === \"float\") {\n console.log(title);\n if (title === \"SEQUENCE_NO\") {\n console.log(\"sumTotal : \" + sumTotal + \" END : \" + ((sumTotal) - dataFormat.len[count]));\n console.log(parseFloat(context.global.sequence_no_3024));\n sendBuff.writeFloatLE(parseFloat(context.global.sequence_no_3024), sumTotal);\n console.log(sendBuff);\n sumTotal += (dataFormat.len[count]);\n } else {\n console.log(\"sumTotal : \" + sumTotal + \" END : \" + ((sumTotal) - dataFormat.len[count]));\n console.log(parseFloat(msg.metric.distance));\n sendBuff.writeFloatLE(parseFloat(msg.metric.distance), sumTotal);\n console.log(sendBuff);\n }\n }\n }\n}\n\nmsg.payload = sendBuff;\nreturn msg;","outputs":1,"noerr":0,"x":1070,"y":220,"wires":[["f3beac76.2e337","e327cb31.9af1d8","ba675c5b.098d2"]]},{"id":"e327cb31.9af1d8","type":"tcp out","z":"c45e3888.e82a68","host":"","port":"","beserver":"reply","base64":false,"end":false,"name":"Reply To L2 Server","x":1370,"y":220,"wires":[]},{"id":"f3beac76.2e337","type":"debug","z":"c45e3888.e82a68","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":1330,"y":260,"wires":[]},{"id":"ba675c5b.098d2","type":"function","z":"c45e3888.e82a68","name":"Influx Data Process","func":"//Main Area -----------------------------------------------------------------------------------------\nlet YYYYMMDD = context.global.todaydate;\nif (!YYYYMMDD) {\n YYYYMMDD = \"20180101\";\n}\n\n// msg.measurement = `posco-slab-${YYYYMMDD}`;\n\nmsg.payload = [{\n measurement:`posco-send-l2-distance-${YYYYMMDD}`,\n fields:{\n Data:msg.payload.toString(),\n Distance:msg.metric.distance,\n SequenceNo:context.global.sequence_no_3024\n }\n}]\n\nreturn msg;","outputs":1,"noerr":0,"x":1370,"y":300,"wires":[["c6f58ffa.f2742","aa88993e.fa8b08"]]},{"id":"c6f58ffa.f2742","type":"influxdb batch","z":"c45e3888.e82a68","influxdb":"85a94193.17dfb","precision":"ms","retentionPolicy":"","name":"","x":1610,"y":300,"wires":[]},{"id":"aa88993e.fa8b08","type":"debug","z":"c45e3888.e82a68","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":1570,"y":260,"wires":[]},{"id":"b369b9e7.58d428","type":"function","z":"f41712ff.dd9de","name":"Make Data to L2 Server","func":"var dataFormat;\n\nfunction nowDateFormat() {\n var nowTime = new Date();\n return nowTime.getFullYear() + checkZeroTime(nowTime.getMonth()+1) + checkZeroTime(nowTime.getDate()) + checkZeroTime(nowTime.getHours()) + checkZeroTime(nowTime.getMinutes()) + checkZeroTime(nowTime.getSeconds());\n}\n\nfunction checkZeroTime(value) {\n return (value>9 ? '' : '0') + value\n}\n\nfunction initDataFormat() {\n dataFormat = global.get(\"S_MSG_3024\");\n if (dataFormat === undefined)\n return false;\n else\n return true;\n}\n\nif(initDataFormat()) {\n var sendBuff = new Buffer(dataFormat.Length);\n sendBuff.fill(0);\n var sumTotal = 0;\n for (var count=0;count < dataFormat.title.length;count++) {\n var title = dataFormat.title[count];\n\n if (dataFormat.type[count] === \"char\") {\n if (title === \"Process\" || title === \"TC_CODE\") {\n if (count === 0) {\n console.log(\"sumTotal : \" + 0 + \" END : \" + dataFormat.len[count]);\n console.log(dataFormat.values[count]);\n sendBuff.write(dataFormat.values[count], 0, dataFormat.len[count]); \n } else {\n console.log(\"sumTotal : \" + sumTotal + \" END : \" + ((sumTotal) + dataFormat.len[count]));\n console.log(dataFormat.values[count]);\n sendBuff.write(dataFormat.values[count], sumTotal, ((sumTotal) + dataFormat.len[count]));\n }\n } else if (title === \"Time\") {\n console.log(\"sumTotal : \" + sumTotal + \" END : \" + ((sumTotal) + dataFormat.len[count]));\n var date = nowDateFormat();\n console.log(date);\n sendBuff.write(date, sumTotal, (sumTotal) + dataFormat.len[count]);\n } else if (title === \"Length\") {\n console.log(\"sumTotal : \" + sumTotal + \" END : \" + ((sumTotal) + dataFormat.len[count]));\n console.log(dataFormat.Length + \" \");\n sendBuff.write(dataFormat.Length + \" \", sumTotal, ((sumTotal) + dataFormat.len[count]));\n } else if (title === \"Spare\") {\n console.log(\"sumTotal : \" + sumTotal + \" END : \" + ((sumTotal) + dataFormat.len[count]));\n console.log(\" \");\n sendBuff.write(\" \", sumTotal, (sumTotal) + dataFormat.len[count]);\n }\n sumTotal += (dataFormat.len[count]);\n } else if (dataFormat.type[count] === \"float\") {\n console.log(title);\n if (title === \"SEQUENCE_NO\") {\n console.log(\"sumTotal : \" + sumTotal + \" END : \" + ((sumTotal) - dataFormat.len[count]));\n console.log(parseFloat(context.global.sequence_no_3024));\n sendBuff.writeFloatLE(parseFloat(context.global.sequence_no_3024), sumTotal);\n console.log(sendBuff);\n sumTotal += (dataFormat.len[count]);\n } else {\n console.log(\"sumTotal : \" + sumTotal + \" END : \" + ((sumTotal) - dataFormat.len[count]));\n console.log(parseFloat(msg.metric.distance));\n sendBuff.writeFloatLE(parseFloat(msg.metric.distance), sumTotal);\n console.log(sendBuff);\n }\n }\n }\n}\n\nmsg.payload = sendBuff;\nreturn msg;","outputs":1,"noerr":0,"x":1070,"y":220,"wires":[["7f4e3079.e6059","11907ba8.b5f8b4"]]},{"id":"7f4e3079.e6059","type":"tcp out","z":"f41712ff.dd9de","host":"","port":"","beserver":"reply","base64":false,"end":false,"name":"Reply To L2 Server","x":1350,"y":220,"wires":[]},{"id":"4c4e0da9.745984","type":"config","z":"f41712ff.dd9de","name":"Global Init Data","properties":[{"p":"LogFormat","pt":"global","to":"{\"send\":\"t_data_send_log\",\"image_Server_IP\":\"192.168.0.107\",\"send_Port\":52004,\"recv\":\"t_data_receive_log\",\"column\":[\"uuid\",\"ip\",\"port\",\"message\",\"dataLength\",\"dataDetail\"]}","tot":"json"},{"p":"SendDataFormat","pt":"global","to":"[{\"tc\":3181,\"title\":[\"TC_CODE\",\"SEQUENCE_NO\",\"Time\"],\"type\":[\"char\",\"short\",\"datetime\"],\"len\":[4,5,14]},{\"tc\":3183,\"title\":[\"TC_CODE\",\"SEQUENCE_NO\",\"Time\"],\"type\":[\"char\",\"short\",\"datetime\"],\"len\":[4,5,14]},{\"tc\":3184,\"title\":[\"TC_CODE\",\"SEQUENCE_NO\",\"Time\",\"CHE_S\",\"CHE_SI\",\"KR_TM\",\"KR_WGT\",\"LADLE_NO\"],\"type\":[\"char\",\"short\",\"datetime\",\"short\",\"short\",\"short\",\"int\",\"short\"],\"len\":[4,5,14,5,5,5,10,5]}]","tot":"json"},{"p":"FormatData","pt":"global","to":"[{\"TC_CODE\":\"3180\",\"Process\":\"1KR\",\"DataLength\":44},{\"TC_CODE\":\"3181\",\"Process\":\"1KR\",\"DataLength\":44},{\"TC_CODE\":\"3182\",\"Process\":\"1KR\",\"DataLength\":44},{\"TC_CODE\":\"3183\",\"Process\":\"1KR\",\"DataLength\":44},{\"TC_CODE\":\"3184\",\"Process\":\"1KR\",\"DataLength\":56}]","tot":"json"},{"p":"MSG_3180","pt":"global","to":"{\"db\":\"t_msg_history\",\"length\":44,\"title\":[\"Process\",\"TC_CODE\",\"Time\",\"Length\",\"Spare\",\"SEQUENCE_NO\"],\"type\":[\"char\",\"char\",\"char\",\"char\",\"char\",\"int\"],\"len\":[3,4,14,5,14,4],\"dbsechma\":[\"SEQUENCE_NO\",\"TC_CODE\"]}","tot":"json"},{"p":"MSG_3181","pt":"global","to":"{\"db\":\"t_msg_history\",\"length\":44,\"title\":[\"Process\",\"TC_CODE\",\"Time\",\"Length\",\"Spare\",\"SEQUENCE_NO\"],\"type\":[\"char\",\"char\",\"char\",\"char\",\"char\",\"int\"],\"len\":[3,4,14,5,14,4],\"dbsechma\":[\"SEQUENCE_NO\",\"TC_CODE\"]}","tot":"json"},{"p":"MSG_3182","pt":"global","to":"{\"db\":\"t_msg_history\",\"length\":44,\"title\":[\"Process\",\"TC_CODE\",\"Time\",\"Length\",\"Spare\",\"SEQUENCE_NO\"],\"type\":[\"char\",\"char\",\"char\",\"char\",\"char\",\"char\"],\"len\":[3,4,14,5,14,4],\"dbsechma\":[\"SEQUENCE_NO\",\"TC_CODE\"]}","tot":"json"},{"p":"MSG_3183","pt":"global","to":"{\"db\":\"t_msg_history\",\"length\":44,\"title\":[\"Process\",\"TC_CODE\",\"Time\",\"Length\",\"Spare\",\"SEQUENCE_NO\"],\"type\":[\"char\",\"char\",\"char\",\"char\",\"char\",\"int\"],\"len\":[3,4,14,5,14,4],\"dbsechma\":[\"SEQUENCE_NO\",\"TC_CODE\"]}","tot":"json"},{"p":"MSG_3184","pt":"global","to":"{\"db\":\"t_msg_3184\",\"length\":56,\"title\":[\"Process\",\"TC_CODE\",\"Time\",\"Length\",\"Spare\",\"SEQUENCE_NO\",\"CHE_S\",\"CHE_SI\",\"KR_TM\",\"KR_WGT\",\"LADLE_NO\"],\"type\":[\"char\",\"char\",\"char\",\"char\",\"char\",\"int\",\"short\",\"short\",\"short\",\"int\",\"short\"],\"len\":[3,4,14,5,14,4,2,2,2,4,2],\"dbsechma\":[\"SEQUENCE_NO\",\"CHE_S\",\"CHE_SI\",\"KR_TM\",\"KR_WGT\",\"LADLE_NO\",\"UUID\"]}","tot":"json"},{"p":"S_MSG_3020","pt":"global","to":"{\"db\":\"t_msg_3020\",\"Length\":48,\"title\":[\"Process\",\"TC_CODE\",\"Time\",\"Length\",\"Spare\",\"SEQUENCE_NO\",\"DATA\"],\"type\":[\"char\",\"char\",\"char\",\"char\",\"char\",\"float\",\"float\"],\"len\":[3,4,14,5,14,4,4],\"dbsechma\":[\"DATA\",\"UUID\"],\"values\":[\"1KR\",\"3020\"]}","tot":"json"},{"p":"S_MSG_3021","pt":"global","to":"{\"db\":\"t_msg_3021\",\"Length\":48,\"title\":[\"Process\",\"TC_CODE\",\"Time\",\"Length\",\"Spare\",\"SEQUENCE_NO\",\"DATA\"],\"type\":[\"char\",\"char\",\"char\",\"char\",\"char\",\"float\",\"float\"],\"len\":[3,4,14,5,14,4,4],\"dbsechma\":[\"DATA\",\"UUID\"],\"values\":[\"1KR\",\"3021\"]}","tot":"json"},{"p":"S_MSG_3022","pt":"global","to":"{\"db\":\"t_msg_3022\",\"Length\":48,\"title\":[\"Process\",\"TC_CODE\",\"Time\",\"Length\",\"Spare\",\"SEQUENCE_NO\",\"DATA\"],\"type\":[\"char\",\"char\",\"char\",\"char\",\"char\",\"float\",\"float\"],\"len\":[3,4,14,5,14,4,4],\"dbsechma\":[\"DATA\",\"UUID\"],\"values\":[\"1KR\",\"3022\"]}","tot":"json"},{"p":"S_MSG_3023","pt":"global","to":"{\"db\":\"t_msg_3023\",\"Length\":48,\"title\":[\"Process\",\"TC_CODE\",\"Time\",\"Length\",\"Spare\",\"SEQUENCE_NO\",\"DATA\"],\"type\":[\"char\",\"char\",\"char\",\"char\",\"char\",\"float\",\"float\"],\"len\":[3,4,14,5,14,4,4],\"dbsechma\":[\"DATA\",\"UUID\"],\"values\":[\"1KR\",\"3023\"]}","tot":"json"},{"p":"ML_RESULT","pt":"global","to":"{\"db\":\"t_kr_ml_result\",\"title\":[\"uuid\",\"project\",\"result\",\"tc_code\",\"spare\"],\"type\":[\"char\",\"char\",\"float\",\"char\",\"char\"]}","tot":"json"},{"p":"ML_VALUE_RESULT","pt":"global","to":"{\"db\":\"t_kr_ml_value_result\",\"title\":[\"uuid\",\"project\",\"result\",\"tc_code\",\"spare\"],\"type\":[\"char\",\"char\",\"float\",\"char\",\"char\"]}","tot":"json"},{"p":"S_MSG_3024","pt":"global","to":"{\"db\":\"t_msg_3024\",\"Length\":48,\"title\":[\"Process\",\"TC_CODE\",\"Time\",\"Length\",\"Spare\",\"SEQUENCE_NO\",\"DATA\"],\"type\":[\"char\",\"char\",\"char\",\"char\",\"char\",\"float\",\"float\"],\"len\":[3,4,14,5,14,4,4],\"dbsechma\":[\"DATA\",\"UUID\"],\"values\":[\"1KR\",\"3024\"]}","tot":"json"}],"active":true,"x":220,"y":1480,"wires":[]},{"id":"78c24.58e0c3dcc","type":"function","z":"f41712ff.dd9de","name":"","func":"context.global.sequence_no_3024 = msg.payload.SEQUENCE_NO;\nconsole.log(context.global.sequence_no_3024);\nreturn null;","outputs":1,"noerr":0,"x":1010,"y":980,"wires":[[]]}]