[{"id":"35c1e4d6.7bc984","type":"function","z":"934594b.367d3e8","name":"Request Headers","func":"msg.headers = {};\nmsg.headers['Content-Type'] = 'application/json';\nmsg.headers['Authorization'] = 'SharedAccessSignature sr=cnm-ih-na.azure-devices.net%2Furn%3Adev%3Aops%3A000000-EMA-prod-13ad67be49e1c6996c84da63&sig=q80q315qBbMkbvpfIPRumeMPPGJO9RGeptYB8%2FkfleQ%3D&se=1584715001195' ;\n\nreturn msg;\n","outputs":1,"noerr":0,"x":1098,"y":213,"wires":[["57458267.4b8b84","7b49c9d9.9e81d"]]},{"id":"57458267.4b8b84","type":"http request","z":"934594b.367d3e8","name":"HTTP Request","method":"POST","ret":"txt","url":"https://cnm-ih-na.azure-devices.net/devices/urn%3Adev%3Aops%3A000000-EMA-prod-13ad67be49e1c6996c84da63/messages/events?api-version=2016-11-14","tls":"","x":1295,"y":211,"wires":[["bfc7ff2c.70084"]]},{"id":"d5bd677a.f580f","type":"debug","z":"934594b.367d3e8","name":"Request Body","active":false,"console":false,"complete":"payload","x":1088,"y":143,"wires":[]},{"id":"bfc7ff2c.70084","type":"debug","z":"934594b.367d3e8","name":"HTTP Response","active":false,"console":false,"complete":"true","x":1572,"y":209,"wires":[]},{"id":"7b9d3015.a7a898","type":"function","z":"934594b.367d3e8","name":"Charlie formatter","func":"// var epoch_time = (new Date()).getTime();\nvar epoch_time = (new Date()).getTime();\n\nvar metrics = {\n        \"assetName\": \"VSP_PLC\"\n    };\n    \nvar key =\"\";\nfor (key in msg.payload){\n    metrics[key] = msg.payload[key]\n    metrics[key+'_timestamp']= epoch_time\n}\n\nmsg.payload={metrics};\n\nreturn msg;","outputs":1,"noerr":0,"x":876,"y":213,"wires":[["d5bd677a.f580f","35c1e4d6.7bc984"]]},{"id":"362e377a.2e2048","type":"debug","z":"934594b.367d3e8","name":"","active":false,"console":false,"complete":"payload","x":596,"y":138,"wires":[]},{"id":"b8461422.b07ce8","type":"modbustcp-read","z":"934594b.367d3e8","name":"Read modbus TCP","topic":"Data_PLC","dataType":"HoldingRegister","adr":"10","quantity":"4","rate":"10","rateUnit":"s","server":"216820c1.396828","ieeeType":"off","ieeeBE":"true","x":386,"y":137,"wires":[["362e377a.2e2048","992fe8b6.d8459"]]},{"id":"7b49c9d9.9e81d","type":"debug","z":"934594b.367d3e8","name":"Entire message","active":false,"console":false,"complete":"true","x":1318,"y":139,"wires":[]},{"id":"c812ea72.b204a8","type":"function","z":"934594b.367d3e8","name":"Request Headers","func":"msg.headers = {};\nmsg.headers['Content-Type'] = 'application/json';\nmsg.headers['Authorization'] = 'SharedAccessSignature sr=cnm-ih-na.azure-devices.net%2Furn%3Adev%3Aops%3A000000-EMA-prod-13ad67be49e1c6996c84da63&sig=q80q315qBbMkbvpfIPRumeMPPGJO9RGeptYB8%2FkfleQ%3D&se=1584715001195' ;\n\nreturn msg;\n","outputs":1,"noerr":0,"x":1051,"y":390,"wires":[["5782648f.0d26fc","ef3860cc.55cc88"]]},{"id":"5782648f.0d26fc","type":"http request","z":"934594b.367d3e8","name":"HTTP Request","method":"POST","ret":"txt","url":"https://cnm-ih-na.azure-devices.net/devices/urn%3Adev%3Aops%3A000000-EMA-prod-13ad67be49e1c6996c84da63/messages/events?api-version=2016-11-14","tls":"","x":1261,"y":390,"wires":[["fcd28bcf.884098"]]},{"id":"482777ae.f68308","type":"debug","z":"934594b.367d3e8","name":"Request Body","active":false,"console":false,"complete":"payload","x":1040,"y":309,"wires":[]},{"id":"fcd28bcf.884098","type":"debug","z":"934594b.367d3e8","name":"HTTP Response","active":false,"console":false,"complete":"true","x":1452,"y":389,"wires":[]},{"id":"c82b4b90.8a923","type":"function","z":"934594b.367d3e8","name":"Charlie formatter 2","func":"//var epoch_time = msg.routertimestamp;\nvar epoch_time = {}; //(new Date()).getTime();\nvar sendpayload = {};\nvar key =\"\";\n\nif (msg.payload[0] == 1) {\n    var metrics = {\n        \"assetName\": \"VSP_motor\"\n    };\n    epoch_time =   (msg.payload[2] << 16) | msg.payload[1];\n    sendpayload[\"m1-test\"]=msg.payload[3];\n\n\n    for (key in sendpayload){\n        metrics[key] = sendpayload[key]\n        metrics[key+'_timestamp']= epoch_time\n    }\n\n    msg.payload={metrics};\n} else {\n    msg = null;\n}\nreturn msg;\n\n\n\n","outputs":1,"noerr":0,"x":736,"y":390,"wires":[["482777ae.f68308","c812ea72.b204a8"]]},{"id":"3310db67.891604","type":"debug","z":"934594b.367d3e8","name":"","active":false,"console":false,"complete":"payload","x":587,"y":311,"wires":[]},{"id":"1476fa9a.fa943d","type":"modbustcp-read","z":"934594b.367d3e8","name":"Read modbus TCP","topic":"Data_motor","dataType":"HoldingRegister","adr":"20","quantity":"6","rate":"4","rateUnit":"s","server":"216820c1.396828","ieeeType":"off","ieeeBE":"true","x":377,"y":310,"wires":[["3310db67.891604","c82b4b90.8a923","bd8ff17c.26e44"]]},{"id":"ef3860cc.55cc88","type":"debug","z":"934594b.367d3e8","name":"Entire message","active":true,"console":false,"complete":"true","x":1253,"y":304,"wires":[]},{"id":"8eea5631.df2bc","type":"comment","z":"934594b.367d3e8","name":"Always send info","info":"","x":371,"y":75,"wires":[]},{"id":"30b31ba.a08d9e4","type":"comment","z":"934594b.367d3e8","name":"Conditioned send info","info":"","x":385,"y":270,"wires":[]},{"id":"bd8ff17c.26e44","type":"function","z":"934594b.367d3e8","name":"Choose if send + rename","func":"sendpayload = {};\nvar key = \"\";\n\n\nif(msg.payload[0] == 1) {\n   msg.routertimestamp = (new Date()).getTime();\n    msg.plctimestamp = (msg.payload[2] << 16) | msg.payload[1];\n    sendpayload[\"m1 test\"]=msg.payload[3];\n    msg.payload = sendpayload;    \n} else {\n    msg = null;\n}\n\nreturn msg;\n\n    \n\n","outputs":"1","noerr":0,"x":644,"y":475.0000305175781,"wires":[["1f93b0de.577fef"]]},{"id":"992fe8b6.d8459","type":"function","z":"934594b.367d3e8","name":"Rename","func":"sendpayload = {};\n\n    sendpayload[\"x1\"]=msg.payload[0];\n    sendpayload[\"x2\"]=msg.payload[1];\n    sendpayload[\"x3\"]=msg.payload[2];\n    sendpayload[\"x4\"]=msg.payload[3];\n    msg.payload = sendpayload;    \n\nreturn msg;\n\n    \n\n","outputs":"1","noerr":0,"x":627,"y":213,"wires":[["7b9d3015.a7a898"]]},{"id":"1f93b0de.577fef","type":"debug","z":"934594b.367d3e8","name":"","active":false,"console":false,"complete":"plctimestamp","x":883,"y":530,"wires":[]},{"id":"c86998ec.b13848","type":"function","z":"934594b.367d3e8","name":"Rename","func":"sendpayload = {};\n\n    sendpayload[\"i00\"]=msg.payload[0];\n    sendpayload[\"i01\"]=msg.payload[1];\n    sendpayload[\"i02\"]=msg.payload[2];\n    sendpayload[\"i03\"]=msg.payload[3];\n    sendpayload[\"i04\"]=msg.payload[4];\n    sendpayload[\"i05\"]=msg.payload[5];\n    sendpayload[\"i06\"]=msg.payload[6];\n    sendpayload[\"i07\"]=msg.payload[7];\n    sendpayload[\"i08\"]=msg.payload[8];\n    sendpayload[\"i09\"]=msg.payload[9];\n\n    sendpayload[\"i10\"]=msg.payload[10];\n    sendpayload[\"i11\"]=msg.payload[11];\n    sendpayload[\"i12\"]=msg.payload[12];\n    sendpayload[\"i13\"]=msg.payload[13];\n    sendpayload[\"i14\"]=msg.payload[14];\n    sendpayload[\"i15\"]=msg.payload[15];\n    sendpayload[\"i16\"]=msg.payload[16];\n    sendpayload[\"i17\"]=msg.payload[17];\n    sendpayload[\"i18\"]=msg.payload[18];\n    sendpayload[\"i19\"]=msg.payload[19];\n\n    sendpayload[\"i20\"]=msg.payload[20];\n    sendpayload[\"i21\"]=msg.payload[21];\n    sendpayload[\"i22\"]=msg.payload[22];\n    sendpayload[\"i23\"]=msg.payload[23];\n    sendpayload[\"i24\"]=msg.payload[24];\n    sendpayload[\"i25\"]=msg.payload[25];\n    sendpayload[\"i26\"]=msg.payload[26];\n    sendpayload[\"i27\"]=msg.payload[27];\n    sendpayload[\"i28\"]=msg.payload[28];    \n    sendpayload[\"i29\"]=msg.payload[29];\n\n    sendpayload[\"i30\"]=msg.payload[30];\n    sendpayload[\"i31\"]=msg.payload[31];\n    sendpayload[\"i32\"]=msg.payload[32];\n    sendpayload[\"i33\"]=msg.payload[33];\n    sendpayload[\"i34\"]=msg.payload[34];\n    sendpayload[\"i35\"]=msg.payload[35];\n    sendpayload[\"i36\"]=msg.payload[36];\n    sendpayload[\"i37\"]=msg.payload[37];\n    sendpayload[\"i38\"]=msg.payload[38];    \n    sendpayload[\"i39\"]=msg.payload[39];\n\n    msg.payload = sendpayload;    \n\nreturn msg;\n\n    \n\n","outputs":"1","noerr":0,"x":583.2833251953125,"y":641.88330078125,"wires":[["a4adfbfa.6579e"]]},{"id":"b71f74cb.b35a3","type":"modbustcp-read","z":"934594b.367d3e8","name":"Read modbus TCP","topic":"Data_PLC","dataType":"HoldingRegister","adr":"30","quantity":"40","rate":"1","rateUnit":"s","server":"216820c1.396828","ieeeType":"off","ieeeBE":"true","x":438.2832946777344,"y":565.88330078125,"wires":[["5662afdb.0edad8","c86998ec.b13848"]]},{"id":"a4adfbfa.6579e","type":"function","z":"934594b.367d3e8","name":"Charlie formatter","func":"// var epoch_time = (new Date()).getTime();\nvar epoch_time = (new Date()).getTime();\n\nvar metrics = {\n        \"assetName\": \"VSP_PLC\"\n    };\n    \nvar key =\"\";\nfor (key in msg.payload){\n    metrics[key] = msg.payload[key]\n    metrics[key+'_timestamp']= epoch_time\n}\n\nmsg.payload={metrics};\n\nreturn msg;","outputs":1,"noerr":0,"x":683.2832946777344,"y":728.88330078125,"wires":[["b2917ad0.4d1c78","459417cc.388318"]]},{"id":"5662afdb.0edad8","type":"debug","z":"934594b.367d3e8","name":"","active":false,"console":false,"complete":"payload","x":648.2832946777344,"y":566.88330078125,"wires":[]},{"id":"b2917ad0.4d1c78","type":"debug","z":"934594b.367d3e8","name":"Request Body","active":false,"console":false,"complete":"payload","x":890.2832946777344,"y":667.88330078125,"wires":[]},{"id":"459417cc.388318","type":"function","z":"934594b.367d3e8","name":"Request Headers","func":"msg.headers = {};\nmsg.headers['Content-Type'] = 'application/json';\nmsg.headers['Authorization'] = 'SharedAccessSignature sr=cnm-ih-na.azure-devices.net%2Furn%3Adev%3Aops%3A000000-EMA-prod-13ad67be49e1c6996c84da63&sig=q80q315qBbMkbvpfIPRumeMPPGJO9RGeptYB8%2FkfleQ%3D&se=1584715001195' ;\n\nreturn msg;\n","outputs":1,"noerr":0,"x":897.2832946777344,"y":807.88330078125,"wires":[["bbaa6aae.6f9798","19a8f309.cbda9d"]]},{"id":"bbaa6aae.6f9798","type":"http request","z":"934594b.367d3e8","name":"HTTP Request","method":"POST","ret":"txt","url":"https://cnm-ih-na.azure-devices.net/devices/urn%3Adev%3Aops%3A000000-EMA-prod-13ad67be49e1c6996c84da63/messages/events?api-version=2016-11-14","tls":"","x":1105.2832946777344,"y":866.88330078125,"wires":[["b648a2d5.b6e24"]]},{"id":"19a8f309.cbda9d","type":"debug","z":"934594b.367d3e8","name":"Entire message","active":false,"console":false,"complete":"true","x":1105.2832946777344,"y":726.88330078125,"wires":[]},{"id":"b648a2d5.b6e24","type":"debug","z":"934594b.367d3e8","name":"HTTP Response","active":false,"console":false,"complete":"true","x":1303.2832946777344,"y":798.8833312988281,"wires":[]},{"id":"216820c1.396828","type":"modbustcp-server","z":"","name":"PLC","host":"192.168.1.4","port":"502","unit_id":"1","reconnecttimeout":"5"}]