ThingsPro MQTT / Modbus

ThingsPro MQTT / Modbus

This flow cloud let you send Modbus write command via publish MQTT messages.

Prerequisite

  1. ThingsPro on Moxa device
  2. Node-Red running on Moxa device
  3. Create modbus template and attached to an interface

Topics & Message Format

You can modify the topics as you want in Node-Red editor. There are two mqtt node in this flow.

Here are the default topics and message format:

modbus-module/input

Publishing message for sending write command to equipment E1242, tag do1_w in ThingsPro.

{"equipment": "E1242", "tag": "do1_w", "value": 1}

modbus-module/output

Response messages

{"code": 0}

Step by Step

  1. ThingsPro Modbus settings

  2. Import Node-Red Flow and Modify Topic

  3. Subscribe output topic for response messages

  4. Publish message to input topic

  5. Check the response

{"code": 0}

[{"id":"50c307d1.8b1638","type":"exec","z":"473cc561.67a87c","command":"python","addpay":true,"append":"","useSpawn":"false","timer":"10","oldrc":false,"name":"","x":330,"y":420,"wires":[["5a5e69bb.5beec8"],["5a5e69bb.5beec8"],["2321c049.b899d"]]},{"id":"fd58f525.acdcb8","type":"mqtt in","z":"473cc561.67a87c","name":"iot.eclipse.org","topic":"modbus-module/input","qos":"0","broker":"dbe00a6a.0e77a8","x":130,"y":180,"wires":[["e3391b86.f0a0e8"]]},{"id":"e3391b86.f0a0e8","type":"json","z":"473cc561.67a87c","name":"","property":"payload","action":"obj","pretty":false,"x":330,"y":260,"wires":[["5e9492ed.849aac"]]},{"id":"5e9492ed.849aac","type":"function","z":"473cc561.67a87c","name":"","func":"var command = \"(lambda __print, __g: [(lambda __mod: [[(lambda __after: (main(), __after())[1] if (__name__ == '__main__') else __after())(lambda: None) for __g['main'], main.__name__ in [(lambda : (lambda __l: (__print(sys.argv), [[(sys.exit(__l['modbus'].write(sys.argv[1], sys.argv[2], __l['tag'])), None)[1] for __l['tag'] in [(Tag(Value(long(sys.argv[3])), Time.now(), ''))]][0] for __l['modbus'] in [(Modbus.instance())]][0])[1])({}), 'main')]][0] for __g['Modbus'], __g['Tag'], __g['Time'], __g['Value'] in [(__mod.Modbus, __mod.Tag, __mod.Time, __mod.Value)]][0])(__import__('libmxidaf_py', __g, __g, ('Modbus', 'Tag', 'Time', 'Value'), 0)) for __g['sys'] in [(__import__('sys', __g, __g))]][0])(__import__('__builtin__').__dict__['print'], globals())\";\n\nreturn {\n    payload: '-c \"' + command + '\" ' + \n        msg.payload.equipment + \" \" + \n        msg.payload.tag + \" \" +\n        msg.payload.value\n}","outputs":1,"noerr":0,"x":330,"y":340,"wires":[["50c307d1.8b1638"]]},{"id":"5a5e69bb.5beec8","type":"debug","z":"473cc561.67a87c","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":530,"y":420,"wires":[]},{"id":"2321c049.b899d","type":"mqtt out","z":"473cc561.67a87c","name":"","topic":"modbus-module/output","qos":"0","retain":"","broker":"dbe00a6a.0e77a8","x":590,"y":540,"wires":[]},{"id":"dbe00a6a.0e77a8","type":"mqtt-broker","z":"","name":"iot.eclipse.org","broker":"iot.eclipse.org","port":"1883","clientid":"","usetls":false,"compatmode":true,"keepalive":"30","cleansession":true,"willTopic":"","willQos":"0","willPayload":"","birthTopic":"","birthQos":"0","birthPayload":""}]

Flow Info

Created 7 years, 6 months ago
Updated 4 years, 10 months ago
Rating: not yet rated

Owner

Actions

Rate:

Node Types

Core
  • debug (x1)
  • exec (x1)
  • function (x1)
  • json (x1)
  • mqtt in (x1)
  • mqtt out (x1)
  • mqtt-broker (x1)

Tags

  • ThingsPro
  • MQTT
  • Modbus
  • IoT
  • Moxa
Copy this flow JSON to your clipboard and then import into Node-RED using the Import From > Clipboard (Ctrl-I) menu option