Hi Everyone,
I have problems with combining data retrieved from OPC-UA server and INSERT it to a MySQL DB.
I collect data correctly and I can visualize it, and also I can connect to the Database, the problems come when I try to create the QUERY string:
- I Visualize "object object" instead of the actual value in the string,
- I get the "can't send string as a message" or something like that.
Thanks in advance!
Here the Flow:
[{"id":"41b92d74.6a1f7c","type":"tab","label":"Flow 1","disabled":false,"info":""},{"id":"8184b2af.3265e8","type":"inject","z":"41b92d74.6a1f7c","name":"ID_LAV_STR","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"5","crontab":"","once":false,"onceDelay":"0.1","topic":"ns=2;s=GVL_OPCUA.W_ID_Lavoro;datatype=String;","payload":"","payloadType":"date","x":140,"y":100,"wires":[["32fbdd98.14c1da"]]},{"id":"df364e24.699148","type":"inject","z":"41b92d74.6a1f7c","name":"NR_ALL_INT16","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"5","crontab":"","once":false,"onceDelay":"0.1","topic":"ns=2;s=GVL_OPCUA.W_NrAllarme;datatype=Int16;","payload":"","payloadType":"date","x":150,"y":140,"wires":[["32fbdd98.14c1da"]]},{"id":"6a4767d.a9d2f18","type":"function","z":"41b92d74.6a1f7c","name":"","func":"var id=flow.get('id') || 0;\nvar nAll=flow.get('nAll') || 0;\nvar Passo=flow.get('Passo') || 0;\nvar PzToProd=flow.get('PzToProd') || 0;\nvar PzProd=flow.get('PzProd') || 0;\nvar Vel=flow.get('Vel') || 0;\nvar BattOk=flow.get('BattOk') || 0;\n\n\nif (msg.topic == \"ns=2;s=GVL_OPCUA.W_ID_Lavoro\" && msg.payload !== null) {\n Id = {payload : (msg.topic === \"ns=2;s=GVL_OPCUA.W_ID_Lavoro\" ? msg.payload : null)}\n} \nif (msg.topic == \"ns=2;s=GVL_OPCUA.W_NrAllarme\" && msg.payload !== null) {\n nAll = {payload : (msg.topic ===\"ns=2;s=GVL_OPCUA.W_NrAllarme\"? msg.payload : null)}\n}\nif (msg.topic == \"ns=2;s=GVL_OPCUA.W_Passo\" && msg.payload !== null) {\n Passo = {payload : (msg.topic ===\"ns=2;s=GVL_OPCUA.W_Passo\"? msg.payload : null)}\n}\nif (msg.topic == \"ns=2;s=GVL_OPCUA.W_PezziDaFare\" && msg.payload !== null) {\n PzToProd = {payload : (msg.topic ===\"ns=2;s=GVL_OPCUA.W_PezziDaFare\"? msg.payload : null)}\n}\nif (msg.topic == \"ns=2;s=GVL_OPCUA.W_PezziFatti\" && msg.payload !== null) {\n PzProd = {payload : (msg.topic ===\"ns=2;s=GVL_OPCUA.W_PezziFatti\"? msg.payload : null)}\n}\nif (msg.topic == \"ns=2;s=GVL_OPCUA.W_Vel\" && msg.payload !== null) {\n Vel = {payload : (msg.topic ===\"ns=2;s=GVL_OPCUA.W_Vel\"? msg.payload : null)}\n}\nif (msg.topic == \"ns=2;s=GVL_OPCUA.W_BattuteBuone\" && msg.payload !== null) {\n BattOk = {payload : (msg.topic ===\"ns=2;s=GVL_OPCUA.W_BattuteBuone\"? msg.payload : null)}\n}\n\nreturn msg;\n","outputs":1,"noerr":0,"initialize":"\n\n","finalize":"// Code added here will be run when the\n// node is being stopped or re-deployed.\n/*if (msg.topic === \"ns=2;i=3885451109\")\n\nvar CntPayload = {payload : (msg.topic === \"ns=2;i=3885451109\" ? msg.payload : null)};\nvar TempPayload = {payload : (msg.topic ===\"ns=2;i=1976473973\"? msg.payload : null)};\nvar Cnt;\nvar Temp;\n\nif (TempPayload !== null) {\n Temp = TempPayload;\n} else if (TempPayload === null) {\n Temp = Temp; \n}\n\nif (CntPayload !== null) {\n Cnt = CntPayload;\n} else if (CntPayload === null) {\n Cnt = Cnt; \n}\n\n\nreturn [Cnt, Temp];*/","x":460,"y":100,"wires":[["ea6ac01b.73a6b8"]]},{"id":"32fbdd98.14c1da","type":"OpcUa-Client","z":"41b92d74.6a1f7c","endpoint":"89a8e5ca.e2cab","action":"read","deadbandtype":"a","deadbandvalue":1,"time":"1","timeUnit":"s","certificate":"n","localfile":"","localkeyfile":"","securitymode":"None","securitypolicy":"None","name":"OPC UA READ","x":420,"y":200,"wires":[["6a4767d.a9d2f18","40160be7.4f06f4"]]},{"id":"602d9b1.3537ce4","type":"comment","z":"41b92d74.6a1f7c","name":"READING_VARS","info":"","x":140,"y":60,"wires":[]},{"id":"531d484c.c9122","type":"inject","z":"41b92d74.6a1f7c","name":"PASSO_INT16","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":"0.1","topic":"ns=2;s=GVL_OPCUA.W_Passo;datatype=Int16;","payload":"","payloadType":"date","x":140,"y":180,"wires":[["32fbdd98.14c1da"]]},{"id":"9ae894b2.b6f928","type":"inject","z":"41b92d74.6a1f7c","name":"PZ_TOPROD_UINT32","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":"0.1","topic":"ns=2;s=GVL_OPCUA.W_PezziDaFare;datatype=UInt32;","payload":"","payloadType":"date","x":160,"y":220,"wires":[["32fbdd98.14c1da"]]},{"id":"317964b7.b7ca4c","type":"inject","z":"41b92d74.6a1f7c","name":"PZ_FATTI_UINT32","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":"0.1","topic":"ns=2;s=GVL_OPCUA.W_PezziFatti;datatype=UInt32;","payload":"","payloadType":"date","x":150,"y":260,"wires":[["32fbdd98.14c1da"]]},{"id":"94296fb2.ecfff8","type":"inject","z":"41b92d74.6a1f7c","name":"VEL_UINT32","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":"0.1","topic":"ns=2;s=GVL_OPCUA.W_Vel;datatype=UInt32;","payload":"","payloadType":"date","x":130,"y":300,"wires":[["32fbdd98.14c1da"]]},{"id":"ae9f4079.aa5ca8","type":"inject","z":"41b92d74.6a1f7c","name":"BATTOK_UINT32","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":"0.1","topic":"ns=2;s=GVL_OPCUA.W_BattuteBuone;datatype=UInt32;","payload":"","payloadType":"date","x":150,"y":340,"wires":[["32fbdd98.14c1da"]]},{"id":"80562dfa.b34768","type":"ui_switch","z":"41b92d74.6a1f7c","d":true,"name":"ABILITA_BOOL","label":"Contapezzi ON-OFF BOOLEANO","tooltip":"","group":"16898618.3223da","order":21,"width":0,"height":0,"passthru":true,"decouple":"false","topic":"","style":"","onvalue":"true","onvalueType":"bool","onicon":"","oncolor":"","offvalue":"false","offvalueType":"bool","officon":"","offcolor":"","x":140,"y":440,"wires":[["1245b5dd.477122"]]},{"id":"1245b5dd.477122","type":"OpcUa-Item","z":"41b92d74.6a1f7c","d":true,"item":"ns=2;s=GVL.Contapezzi_Attivo","datatype":"Boolean","value":"","name":"OPCUA Cnt On-Off","x":366,"y":440,"wires":[["6dfea63b.47b1d8"]]},{"id":"6dfea63b.47b1d8","type":"OpcUa-Client","z":"41b92d74.6a1f7c","d":true,"endpoint":"41824483.a5abac","action":"write","deadbandtype":"a","deadbandvalue":1,"time":"1","timeUnit":"s","certificate":"n","localfile":"","securitymode":"None","securitypolicy":"None","name":"OPC UA WRITE","x":608,"y":584,"wires":[["6fc9de43.ffb3d"]]},{"id":"6fc9de43.ffb3d","type":"debug","z":"41b92d74.6a1f7c","d":true,"name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":904,"y":584,"wires":[]},{"id":"c3cf5ac9.ca9a2","type":"comment","z":"41b92d74.6a1f7c","d":true,"name":"WRITING","info":"","x":620,"y":440,"wires":[]},{"id":"716dace0.5381cc","type":"ui_switch","z":"41b92d74.6a1f7c","d":true,"name":"ABILITA_INT","label":"Contapezzi ON-OFF INT","tooltip":"","group":"16898618.3223da","order":22,"width":0,"height":0,"passthru":true,"decouple":"false","topic":"","style":"","onvalue":"1","onvalueType":"num","onicon":"","oncolor":"","offvalue":"0","offvalueType":"num","officon":"","offcolor":"","x":130,"y":494,"wires":[["33043306.9159ec"]]},{"id":"33043306.9159ec","type":"OpcUa-Item","z":"41b92d74.6a1f7c","d":true,"item":"ns=2;s=GVL.Contapezzi_Attivo","datatype":"Int16","value":"","name":"OPCUA Cnt On-Off","x":366,"y":494,"wires":[["6dfea63b.47b1d8"]]},{"id":"4fefa162.1cfa68","type":"ui_slider","z":"41b92d74.6a1f7c","d":true,"name":"SET_DINT","label":"slider","tooltip":"","group":"16898618.3223da","order":7,"width":0,"height":0,"passthru":true,"outs":"all","topic":"","min":0,"max":"100000","step":"1000","x":130,"y":548,"wires":[["979d4960.fe24c8"]]},{"id":"979d4960.fe24c8","type":"OpcUa-Item","z":"41b92d74.6a1f7c","d":true,"item":"ns=2;s=GVL.PROVA_DINT","datatype":"Int32","value":"","name":"OPCUA PROVA_DINT","x":358,"y":548,"wires":[["6dfea63b.47b1d8"]]},{"id":"c29ed2c6.6c836","type":"ui_text","z":"41b92d74.6a1f7c","group":"16898618.3223da","order":6,"width":0,"height":0,"name":"ID","label":"ID","format":"{{msg.payload}}","layout":"row-spread","x":630,"y":280,"wires":[]},{"id":"3526519f.b6b516","type":"ui_text","z":"41b92d74.6a1f7c","group":"16898618.3223da","order":5,"width":0,"height":0,"name":"","label":"n Allarme","format":"{{msg.payload}}","layout":"row-spread","x":640,"y":314,"wires":[]},{"id":"202138e8.b3527","type":"ui_text","z":"41b92d74.6a1f7c","group":"16898618.3223da","order":4,"width":0,"height":0,"name":"passo","label":"Passo","format":"{{msg.payload}}","layout":"row-spread","x":630,"y":348,"wires":[]},{"id":"1c9ed1bb.d2a90e","type":"ui_text","z":"41b92d74.6a1f7c","group":"16898618.3223da","order":3,"width":0,"height":0,"name":"pcstoprod","label":"Pezzi da Fare","format":"{{msg.payload}}","layout":"row-spread","x":640,"y":383,"wires":[]},{"id":"72e880c2.a3312","type":"ui_text","z":"41b92d74.6a1f7c","group":"16898618.3223da","order":2,"width":0,"height":0,"name":"pcsOK","label":"Pezzi Fatti","format":"{{msg.payload}}","layout":"row-spread","x":770,"y":294,"wires":[]},{"id":"781e33ef.6055a4","type":"ui_text","z":"41b92d74.6a1f7c","group":"16898618.3223da","order":1,"width":0,"height":0,"name":"Vel","label":"Velocità","format":"{{msg.payload}}","layout":"row-spread","x":770,"y":328,"wires":[]},{"id":"a6619e25.ea41f","type":"ui_text","z":"41b92d74.6a1f7c","group":"16898618.3223da","order":0,"width":0,"height":0,"name":"BattOK","label":"Battute BUone","format":"{{msg.payload}}","layout":"row-spread","x":780,"y":364,"wires":[]},{"id":"39f954a0.59cbc4","type":"mysql","z":"41b92d74.6a1f7c","mydb":"c51a387f.56d07","name":"OpcUaFromPLC","x":920,"y":80,"wires":[[]]},{"id":"ea6ac01b.73a6b8","type":"debug","z":"41b92d74.6a1f7c","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":630,"y":140,"wires":[]},{"id":"40160be7.4f06f4","type":"function","z":"41b92d74.6a1f7c","d":true,"name":"","func":"var Id,nAll,Passo,PzToProd,PzProd,Vel,BattOk;\n\nif (msg.topic == \"ns=2;s=GVL_OPCUA.W_ID_Lavoro\" && msg.payload !== null) {\n Id = {payload : (msg.topic === \"ns=2;s=GVL_OPCUA.W_ID_Lavoro\" ? msg.payload : null)}\n} \nif (msg.topic == \"ns=2;s=GVL_OPCUA.W_NrAllarme\" && msg.payload !== null) {\n nAll = {payload : (msg.topic ===\"ns=2;s=GVL_OPCUA.W_NrAllarme\"? msg.payload : null)}\n}\nif (msg.topic == \"ns=2;s=GVL_OPCUA.W_Passo\" && msg.payload !== null) {\n Passo = {payload : (msg.topic ===\"ns=2;s=GVL_OPCUA.W_Passo\"? msg.payload : null)}\n}\nif (msg.topic == \"ns=2;s=GVL_OPCUA.W_PezziDaFare\" && msg.payload !== null) {\n PzToProd = {payload : (msg.topic ===\"ns=2;s=GVL_OPCUA.W_PezziDaFare\"? msg.payload : null)}\n}\nif (msg.topic == \"ns=2;s=GVL_OPCUA.W_PezziFatti\" && msg.payload !== null) {\n PzProd = {payload : (msg.topic ===\"ns=2;s=GVL_OPCUA.W_PezziFatti\"? msg.payload : null)}\n}\nif (msg.topic == \"ns=2;s=GVL_OPCUA.W_Vel\" && msg.payload !== null) {\n Vel = {payload : (msg.topic ===\"ns=2;s=GVL_OPCUA.W_Vel\"? msg.payload : null)}\n}\nif (msg.topic == \"ns=2;s=GVL_OPCUA.W_BattuteBuone\" && msg.payload !== null) {\n BattOk = {payload : (msg.topic ===\"ns=2;s=GVL_OPCUA.W_BattuteBuone\"? msg.payload : null)}\n}\n\nflow.set('R_Id',Id);\nflow.set('R_nAll',nAll);\nflow.set('R_Passo',Passo);\nflow.set('R_PzToProd',PzToProd);\nflow.set('R_PzProd',PzProd);\nflow.set('R_Vel',Vel);\nflow.set('R_BattOk',BattOk);\n\nreturn [Id,nAll,Passo,PzToProd,PzProd,Vel,BattOk];","outputs":7,"noerr":0,"initialize":"\n\n","finalize":"// Code added here will be run when the\n// node is being stopped or re-deployed.\n/*if (msg.topic === \"ns=2;i=3885451109\")\n\nvar CntPayload = {payload : (msg.topic === \"ns=2;i=3885451109\" ? msg.payload : null)};\nvar TempPayload = {payload : (msg.topic ===\"ns=2;i=1976473973\"? msg.payload : null)};\nvar Cnt;\nvar Temp;\n\nif (TempPayload !== null) {\n Temp = TempPayload;\n} else if (TempPayload === null) {\n Temp = Temp; \n}\n\nif (CntPayload !== null) {\n Cnt = CntPayload;\n} else if (CntPayload === null) {\n Cnt = Cnt; \n}\n\n\nreturn [Cnt, Temp];*/","x":460,"y":340,"wires":[["c29ed2c6.6c836"],["3526519f.b6b516"],["202138e8.b3527"],["1c9ed1bb.d2a90e"],["72e880c2.a3312"],["781e33ef.6055a4"],["a6619e25.ea41f"]]},{"id":"89a8e5ca.e2cab","type":"OpcUa-Endpoint","endpoint":"opc.tcp://10.247.77.15:4840/","secpol":"None","secmode":"None","login":false},{"id":"16898618.3223da","type":"ui_group","name":"OPC-UA","tab":"ef2cdaa.661b728","order":1,"disp":true,"width":"6","collapse":false},{"id":"41824483.a5abac","type":"OpcUa-Endpoint","endpoint":"opc.tcp://192.168.1.14:4840/","secpol":"None","secmode":"None","login":false},{"id":"c51a387f.56d07","type":"MySQLdatabase","name":"OpcUaFromPLC","host":"localhost","port":"3306","db":"OpcUa","tz":"","charset":"UTF8"},{"id":"ef2cdaa.661b728","type":"ui_tab","name":"OPC-UA Browse","icon":"OPC-UA","disabled":false,"hidden":false}]