Gateway Example with EIP, S7Comm, PCCC and Modbus

Simple Example showing how to read variables from multiple PLCs, format into one global context and publish to Hive MQ MQTT Broker.

[{"id":"f6f2187d.f17ca8","type":"tab","label":"Mapping","disabled":false,"info":""},{"id":"25f42886.25999","type":"tab","label":"Cloud","disabled":false,"info":""},{"id":"c00f143c.653b38","type":"ui_group","name":"CPU Load","tab":"732bdc09.3de594","order":1,"disp":true,"width":"16","collapse":false},{"id":"a0baf0d8.e19db","type":"ui_base","theme":{"name":"theme-dark","lightTheme":{"default":"#0094CE","baseColor":"#0094CE","baseFont":"-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Oxygen-Sans,Ubuntu,Cantarell,Helvetica Neue,sans-serif","edited":true,"reset":false},"darkTheme":{"default":"#097479","baseColor":"#097479","baseFont":"-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Oxygen-Sans,Ubuntu,Cantarell,Helvetica Neue,sans-serif","edited":true,"reset":false},"customTheme":{"name":"Untitled Theme 1","default":"#4B7930","baseColor":"#4B7930","baseFont":"-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Oxygen-Sans,Ubuntu,Cantarell,Helvetica Neue,sans-serif","reset":false},"themeState":{"base-color":{"default":"#097479","value":"#097479","edited":false},"page-titlebar-backgroundColor":{"value":"#097479","edited":false},"page-backgroundColor":{"value":"#111111","edited":false},"page-sidebar-backgroundColor":{"value":"#333333","edited":false},"group-textColor":{"value":"#0eb8c0","edited":false},"group-borderColor":{"value":"#555555","edited":false},"group-backgroundColor":{"value":"#333333","edited":false},"widget-textColor":{"value":"#eeeeee","edited":false},"widget-backgroundColor":{"value":"#097479","edited":false},"widget-borderColor":{"value":"#333333","edited":false},"base-font":{"value":"-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Oxygen-Sans,Ubuntu,Cantarell,Helvetica Neue,sans-serif"}},"angularTheme":{"primary":"indigo","accents":"blue","warn":"red","background":"grey","palette":"light"}},"site":{"name":"Node-RED Dashboard","hideToolbar":"false","allowSwipe":"false","lockMenu":"true","allowTempTheme":"true","dateFormat":"DD/MM/YYYY","sizes":{"sx":48,"sy":48,"gx":6,"gy":6,"cx":6,"cy":6,"px":0,"py":0}}},{"id":"900215ec.584de8","type":"tls-config","name":"","cert":"","key":"","ca":"","certname":"a67d063aac-certificate.pem.crt","keyname":"a67d063aac-private.pem.key","caname":"ca-certificates.crt","servername":"","verifyservercert":true},{"id":"eed86b34.d85f98","type":"mqtt-broker","name":"","broker":"broker.hivemq.com","port":"1883","tls":"900215ec.584de8","clientid":"","usetls":false,"protocolVersion":"4","keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","birthMsg":{},"closeTopic":"","closeQos":"0","closePayload":"","closeMsg":{},"willTopic":"","willQos":"0","willPayload":"","willMsg":{},"sessionExpiry":""},{"id":"f15aa13e.6fda","type":"ui_group","name":"Group2","tab":"28d3d628.34976a","order":3,"disp":true,"width":6,"collapse":false},{"id":"2a99ab4e.7c5fb4","type":"ui_group","name":"Group Controls","tab":"28d3d628.34976a","order":2,"disp":true,"width":"6","collapse":false},{"id":"ca135223.d6582","type":"ui_group","name":"Menu Controls","tab":"28d3d628.34976a","order":1,"disp":true,"width":"6","collapse":false},{"id":"f16e2c23.d7dc4","type":"ui_tab","name":"Home","icon":"dashboard","disabled":false,"hidden":false},{"id":"28d3d628.34976a","type":"ui_tab","name":"WAGO","icon":"check","order":3,"disabled":false,"hidden":false},{"id":"732bdc09.3de594","type":"ui_tab","name":"Home","icon":"dashboard","disabled":false,"hidden":false},{"id":"51bf0475.ddfd2c","type":"ui_group","name":"Group 2","tab":"279d8078.dcf29","order":2,"disp":true,"width":"6"},{"id":"279d8078.dcf29","type":"ui_tab","z":"f6f2187d.f17ca8","name":"New Test","icon":"dashboard"},{"id":"a257a939.3e5d3","type":"s7 endpoint","transport":"iso-on-tcp","address":"192.168.4.37","port":"102","rack":"0","slot":"1","localtsaphi":"01","localtsaplo":"00","remotetsaphi":"01","remotetsaplo":"00","connmode":"rack-slot","adapter":"","busaddr":"2","cycletime":"500","timeout":"2000","name":"","vartable":[{"addr":"DB1,X26.0","name":"DigitalInput1"},{"addr":"DB1,X26.1","name":"DigitalInput2"}]},{"id":"e0fb3a5a.1afe9","type":"eth-ip endpoint","address":"192.168.4.86","slot":"0","cycletime":"500","name":"","vartable":{"":{"iCounter":{"type":"INT"},"rValue":{"type":"REAL"}}}},{"id":"5de0aded.a1b9dc","type":"pccc endpoint","address":"192.168.4.87","port":"44818","userouting":false,"routing":"0x01,0x00,0x01,0x00","cycletime":"500","timeout":"1500","name":"","vartable":[{"addr":"N7:0","name":"iValue"}]},{"id":"c5b302e0.364f08","type":"modbus-client","name":"","clienttype":"tcp","bufferCommands":true,"stateLogEnabled":false,"queueLogEnabled":false,"tcpHost":"192.168.4.20","tcpPort":"502","tcpType":"DEFAULT","serialPort":"/dev/ttyUSB","serialType":"RTU-BUFFERD","serialBaudrate":"9600","serialDatabits":"8","serialStopbits":"1","serialParity":"none","serialConnectionDelay":"100","unit_id":"1","commandDelay":"1","clientTimeout":"1000","reconnectOnTimeout":true,"reconnectTimeout":"2000","parallelUnitIdsAllowed":true},{"id":"9bc11572.a6f8e","type":"inject","z":"f6f2187d.f17ca8","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":true,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":130,"y":60,"wires":[["2168b677.493ed2"]]},{"id":"2168b677.493ed2","type":"function","z":"f6f2187d.f17ca8","name":"Make Object","func":"var myPLC = {};\nmyPLC = {\n    button1 : false,\n    button2 : false,    \n    iCounter : 0,\n    rValue  : 0.0,\n    iValue : 0,\n    wOutputs : 0\n}\nmsg.payload = myPLC;\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":330,"y":60,"wires":[["f2c9c6b.44f2438"]]},{"id":"f2c9c6b.44f2438","type":"change","z":"f6f2187d.f17ca8","name":"","rules":[{"t":"set","p":"myMachine","pt":"global","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":560,"y":60,"wires":[[]]},{"id":"98bfe811.684f08","type":"s7 in","z":"f6f2187d.f17ca8","endpoint":"a257a939.3e5d3","mode":"all","variable":"","diff":true,"name":"","x":150,"y":160,"wires":[["9904d63.6faf928","8e9ac88d.aa5a2","f188ec0e.8c06a"]]},{"id":"9904d63.6faf928","type":"function","z":"f6f2187d.f17ca8","name":"S7Comm","func":"msg.topic = \"s7comm\";\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":390,"y":180,"wires":[["a81acdff.4023a"]]},{"id":"a81acdff.4023a","type":"function","z":"f6f2187d.f17ca8","name":"Map Variables","func":"var myMachine = global.get('myMachine');\n\n// Map variables from S7-1200\nif(msg.topic === \"s7comm\"){\n    myMachine.button1 = msg.payload.DigitalInput1;\n    myMachine.button2 = msg.payload.DigitalInput2;   \n}   \n// Map variables from AB CLX\nif(msg.topic === \"cip\"){\n    myMachine.rValue =  msg.payload.rValue; \n    myMachine.iCounter =  msg.payload.iCounter;  \n}  \n// Map variables from AB MicroLogix\nif(msg.topic === \"pccc\"){\n    myMachine.iValue =  msg.payload; \n}  \n// Map variables from WAGO\nif(msg.topic === \"modbus\"){\n    myMachine.wOutputs =  msg.payload[0]; \n}  \nglobal.set('myMachine',myMachine);\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":710,"y":460,"wires":[[]]},{"id":"8e9ac88d.aa5a2","type":"function","z":"f6f2187d.f17ca8","name":"Button 1","func":"node.status({fill:\"green\",shape:\"dot\",text:\"Value: \"+msg.payload.DigitalInput1});\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":400,"y":240,"wires":[[]]},{"id":"f188ec0e.8c06a","type":"function","z":"f6f2187d.f17ca8","name":"Button 2","func":"node.status({fill:\"green\",shape:\"dot\",text:\"Value: \"+msg.payload.DigitalInput2});\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":400,"y":300,"wires":[[]]},{"id":"87d9b730.314bf","type":"comment","z":"f6f2187d.f17ca8","name":"Siemens S7Comm (RFC1006)","info":"","x":170,"y":120,"wires":[]},{"id":"9d17d4fc.a5a0b","type":"comment","z":"f6f2187d.f17ca8","name":"AB EIP/CIP","info":"","x":120,"y":340,"wires":[]},{"id":"c2b1ca75.052698","type":"eth-ip in","z":"f6f2187d.f17ca8","endpoint":"e0fb3a5a.1afe9","mode":"all","variable":"","program":"","name":"","x":150,"y":380,"wires":[["f9d66f09.caf98","809eb7c1.44d0c","584f269.97e60d8"]]},{"id":"f9d66f09.caf98","type":"function","z":"f6f2187d.f17ca8","name":"CIP","func":"msg.topic = \"cip\";\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":380,"y":380,"wires":[["a81acdff.4023a"]]},{"id":"809eb7c1.44d0c","type":"function","z":"f6f2187d.f17ca8","name":"rValue","func":"node.status({fill:\"green\",shape:\"dot\",text:\"Value: \"+msg.payload.rValue});\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":380,"y":440,"wires":[[]]},{"id":"584f269.97e60d8","type":"function","z":"f6f2187d.f17ca8","name":"iCounter","func":"node.status({fill:\"green\",shape:\"dot\",text:\"Value: \"+msg.payload.iCounter});\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":380,"y":500,"wires":[[]]},{"id":"d132639d.65778","type":"comment","z":"f6f2187d.f17ca8","name":"AB PCCC","info":"","x":110,"y":520,"wires":[]},{"id":"1163f3ed.32c9cc","type":"pccc in","z":"f6f2187d.f17ca8","endpoint":"5de0aded.a1b9dc","mode":"single","variable":"iValue","diff":true,"name":"","x":140,"y":580,"wires":[["94755902.fd7db8","4b895963.e6ee9"]]},{"id":"94755902.fd7db8","type":"function","z":"f6f2187d.f17ca8","name":"PCCC","func":"msg.topic = \"pccc\";\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":340,"y":580,"wires":[["a81acdff.4023a"]]},{"id":"4b895963.e6ee9","type":"function","z":"f6f2187d.f17ca8","name":"iValue","func":"node.status({fill:\"green\",shape:\"dot\",text:\"Value: \"+msg.payload});\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":360,"y":640,"wires":[[]]},{"id":"70dd8a5a.2ea35c","type":"comment","z":"f6f2187d.f17ca8","name":"WAGO ModbusTCP","info":"","x":140,"y":680,"wires":[]},{"id":"bb36feda.eaec48","type":"modbus-read","z":"f6f2187d.f17ca8","name":"","topic":"","showStatusActivities":false,"logIOActivities":false,"showErrors":false,"unitid":"0","dataType":"HoldingRegister","adr":"512","quantity":"1","rate":"500","rateUnit":"ms","delayOnStart":false,"startDelayTime":"","server":"c5b302e0.364f08","useIOFile":false,"ioFile":"","useIOForPayload":false,"emptyMsgOnFail":false,"x":140,"y":720,"wires":[["e0619dbe.1ba6c8","77521cf8.656a64"],[]]},{"id":"e0619dbe.1ba6c8","type":"function","z":"f6f2187d.f17ca8","name":"WAGO Modbus","func":"msg.topic = \"modbus\";\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":370,"y":720,"wires":[["a81acdff.4023a"]]},{"id":"77521cf8.656a64","type":"function","z":"f6f2187d.f17ca8","name":"wOutputs","func":"node.status({fill:\"green\",shape:\"dot\",text:\"Value: \"+msg.payload[0]});\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":370,"y":780,"wires":[[]]},{"id":"34fcad20.8b7002","type":"inject","z":"25f42886.25999","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":170,"y":100,"wires":[["75e62e1b.ac6bb8"]]},{"id":"75e62e1b.ac6bb8","type":"function","z":"25f42886.25999","name":"Build Namespace message","func":"var myMachine = global.get('myMachine');\nmsg.payload = myMachine;\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":470,"y":100,"wires":[["7048313a.c7bfc"]]},{"id":"7048313a.c7bfc","type":"mqtt out","z":"25f42886.25999","name":"","topic":"myMachineWAGOKurt","qos":"","retain":"","respTopic":"","contentType":"","userProps":"","correl":"","expiry":"","broker":"eed86b34.d85f98","x":800,"y":100,"wires":[]},{"id":"773a613d.fdd9d","type":"mqtt in","z":"25f42886.25999","name":"","topic":"myMachineWAGOKurt","qos":"2","datatype":"json","broker":"eed86b34.d85f98","nl":false,"rap":true,"rh":0,"x":250,"y":320,"wires":[["2c4be370.a40a74"]]},{"id":"2c4be370.a40a74","type":"debug","z":"25f42886.25999","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":460,"y":320,"wires":[]}]

Flow Info

Created 4 years, 3 months ago
Rating: 5 2

Owner

Actions

Rate:

Node Types

Core
  • change (x1)
  • comment (x4)
  • debug (x1)
  • function (x13)
  • inject (x2)
  • mqtt in (x1)
  • mqtt out (x1)
  • mqtt-broker (x1)
  • tls-config (x1)
Other
  • eth-ip endpoint (x1)
  • eth-ip in (x1)
  • modbus-client (x1)
  • modbus-read (x1)
  • pccc endpoint (x1)
  • pccc in (x1)
  • s7 endpoint (x1)
  • s7 in (x1)
  • tab (x2)
  • ui_base (x1)
  • ui_group (x5)
  • ui_tab (x4)

Tags

  • EthernetIP
  • CIP
  • PCCC
  • Modbus
  • ModbusTCP
  • WAGO
  • MQTT
  • Gateway
Copy this flow JSON to your clipboard and then import into Node-RED using the Import From > Clipboard (Ctrl-I) menu option