Communication flow

To enable data exchange and Device Discovery via ADS-over-MQTT, all ADS devices use a uniform topic structure on the message broker. The topic structure depends on the name of the configured virtual network and the AMS Net ID of the respective device.

Type

Topic

Discovery

<NetworkName>/<AmsNetId>/info

Communication

<NetworkName>/<AmsNetId>/ams

<NetworkName>/<AmsNetId>/ams/res

Each ADS device therefore has its own "topic area" on the message broker. The following figure illustrates this relationship.

Communication flow 1:

Discovery

A connecting TwinCAT ADS router sends a retain message with device information to its discovery topic, at the same time it subscribes to the topic <NetworkName>/+/info, so that it is informed about all other connected routers.

Communication flow 2:

The messages to the discovery topic contain an XML structure with device information, for example the host name and the TwinCAT version used:

<info>
  <online name="EC2AMAZ-2RRSQS6" osVersion="10.0.20348" osPlatform="2" tcVersion="3.1.4026.10">true</online>
</info>

If the message broker does not support retain messages, this can be taken into account in the ADS-over-MQTT configuration file. In this case, a communication handshake would take place instead of a retain message: a newly connecting device logs on to its discovery topic and all other connected devices respond with another message on their discovery topic. This ensures that devices can find each other even with message brokers that do not support retain messages. The disadvantage is an increased volume of messages in larger operating environments with frequent reconnects.

Communication

A TwinCAT ADS router subscribes to its communication topic (<NetworkName>/<AmsNetId>/ams/#) immediately after the connection is established. The ADS commands to this router are then sent to <NetworkName>/<AmsNetId>/ams, while the responses are received via the <NetworkName>/<AmsNetId>/ams/res topic.