Beckhoff TwinCAT ADS to MQTT
PLCGateway reads TwinCAT 2 and TwinCAT 3 controllers over ADS, browses their symbols and publishes the selected variables to your MQTT broker – without MQTT code in the PLC project.
TwinCAT can publish MQTT from the PLC with an IoT function and function blocks in the project. PLCGateway is the way without PLC code: it connects over ADS, lists the symbols of the running project and publishes the variables you select.
The gateway finds TwinCAT systems in the network, adds the ADS route on the controller for you and takes the data types from the PLC. It runs on Windows or Linux, on a PC or a small device in the same network.
- Source
- Beckhoff TwinCAT ADS
ads - Connection
- ADS / AMS · TCP 48898 · UDP 48899
- Target
- MQTT
- Writing
- yes
Set it up in five steps
Add a device with the protocol Beckhoff TwinCAT (ADS) and click Find TwinCAT systems; selecting the PLC fills in its IP address and AMS NetId.
Click Add route on the PLC and enter the user of the PLC (older Beckhoff images: Administrator / 1). This is needed once.
Open the symbol browser, select program and global variables and add them in one step – the data types come from the PLC.
Open Gateway → MQTT, enter the broker address, port and login, switch on TLS if the broker requires it, and choose the base topic.
Choose publishing on change or at an interval and the JSON or plain-value format, then check the topics with mosquitto_sub or in your platform.
Example: topics and payloads
A device with the id cx1 and these tags is published as shown below; the lines are what mosquitto_sub -v prints. Names and values are examples.
| Tag | Address | Example value |
|---|---|---|
LineSpeed | MAIN.Speed | 12.5 m/min |
PumpRunning | GVL.Line1.Pump.Running | true |
Setpoint | MAIN.Recipe[3] | 75.5 °C |
MQTT topics and payloads
plcgateway/status online
plcgateway/cx1/LineSpeed {"q":"GOOD","t":1794465246839,"u":"m/min","v":12.5}
plcgateway/cx1/PumpRunning {"q":"GOOD","t":1794465246839,"v":true}
plcgateway/cx1/Setpoint {"q":"GOOD","t":1794465246839,"u":"°C","v":75.5}
Topic: base topic / device id / tag name. The JSON payload carries the value (v), the quality (q), the timestamp in milliseconds (t) and the unit (u).
The MQTT publisher in PLCGateway
PLCGateway publishes every tag to your MQTT broker – Mosquitto, EMQX, HiveMQ, AWS IoT Core or a cloud platform behind a bridge – so IT systems subscribe to topics instead of polling the controller. It speaks MQTT 3.1.1 over TCP or TLS, with user name and password.
Values are sent when they change or at a fixed interval, as JSON with quality and timestamp or as the bare value. A retained status topic with a last will tells subscribers whether the gateway is online.
- One topic per tag: base topic / device / tag, with a base topic of your choice
- QoS 0 or 1, retained messages, birth message and last will
- Optional writing: a value published to the tag's /set topic is written to the controller
- Messages are queued while the broker is unreachable and sent after the reconnect
Controllers and devices
Equipment that is typically connected with this driver.
Questions and answers
Do I need TwinCAT or an ADS router on the gateway computer?
No. PLCGateway implements ADS itself and needs no TwinCAT installation or router. It adds its own route on the controller with the user you enter once.
Does it work with TwinCAT 2?
Yes. TwinCAT 2 and TwinCAT 3 on CX Embedded PCs, Industrial PCs and Bus Terminal Controllers are supported, by symbol name or by memory and process-image address.
What happens after a download or an online change?
PLCGateway notices that the symbol table has changed, reconnects and resolves the variables again, so the topics keep their names and continue with the new values.
Connect your machines
Tell us which controllers you run; we show you PLCGateway with your own addresses.
Product and model names are trademarks of their owners. They are named only to show which equipment the drivers communicate with; PLCGateway is not affiliated with these companies.
