MQTT ADS Interface - RWTH-EBC/AixOCAT GitHub Wiki

The MQTT ADS interface is designed to allow a communication between a Beckhoff PLC system and an MQTT broker. Hence, it is responsible for reading data from the PLC system, converting it to the required MQTT endpoint format and transferring the converted data. On the other hand, it converts incoming messages to write data to the PLC system.

The interface is located in the interfaces folder and implemented in Python code. The main script is the mqtt_ads_interface.py, which contains the main class inlcuding individual classes for both communication interfaces, namely ads and mqtt. An additional function should support in fetching the readable and writable variables from the PLC and processing the data conversions.

For installation use pip. Run pip install -e "Path/to/this/repository/AixOCAT/Interfaces/Python/MQTT-ADS-interface"

The main class features following attributes and methods

Attributes

  • mqtt : mqtt class object - an instance of the mqtt class which covers generating an mqtt client object, establishing the connection to a broker and handling publishing and receiving messages from and to a broker.
  • ads : ads class object - an instance of the ads class which covers generating a plc object, opening the port connection to the plc and handling reading and writing of variables from and to the plc application.

Methods

  • connect_mqtt(mqtt_host='localhost', mqtt_port=1883, mqtt_keepalive=60, mqtt_user=None, mqtt_pass=None, credentials_env=None, aedifion=False) - Invokes the connect function of the mqtt instance; the on_message function of the mqtt instance is overwritten to define handling received messages by a method in this class.
  • disconnect_mqtt() - Releases the mqtt connection to the broker.
  • connect_ads(ams_netID, host, create_route=False) - Invokes the connect function of the ads instance.
  • disconnect_ads() - Releases the ads connection to the plc.
  • start_mqtt() - Invokes the mqtt instance start function. This creates the mqtt threading enabling listening for received messages. Afterwards the public method of this class is called.
  • listen(client=None, userdata=None, msg=None, sub_format='simple_json') - Overrides the on_message function for received mnessages from the broker and handles parsing and transferring the relevant data to the ads end point
  • publish(pub_format='simple_json') - Loops through a list of observations to be published and handles parsing and transferring the relevant data to the mqtt end point