MQTT Client
Virtual Device MQTT Client
The input and output values of a Revolution Pi system (I/O values) can be exchanged with an MQTT broker. The web application PiCtory can configure a virtual component as an OPC Client. No programming is necessary.
The I/O values are sent cyclically or event-based to a MQTT broker. In cyclical mode, transmission takes place at a configured interval. In event-based mode, values are sent as soon as they change.
The sent values are stored within a defined MQTT topic in the MQTT broker.
Prerequisites
- RevPi base module with RevPi Bullseye Image or higher
- PiCtory version 2.3.0 or higher
- MQTT broker with MQTT protocol version 3.1
- Your RevPi base module is located in your network
The Virtual Device MQTT Client does not currently support brokers with MQTT protocol version 5.0.
Configure MQTT Client
▷ Start PiCtory.
▷ Select your RevPi base module from the Device Catalog and drag and drop it onto the empty slot with position number 0.
▷ Drag and drop the Virtual Device MQTT Client from the Device Catalog onto the Configuration Board.
▷ Click on the Virtual Device MQTT Client in the Configuration Board to highlight it.
❯ Under the Configuration Board, the Device Data and the Value Editor areas appear.
▷ If the MQTT broker requires authentication, enter the corresponding authentication data for MEM User_name and MEM Password.
▷ If the data transfer is to be encrypted, activate TLS encryption under MEM Use_TLS_encryption. The MQTT broker accepts all certificates.
▷ If several systems exchange their I/O values via MQTT, you can rename the MQTT topic under MEM Base_topic.
▷ Select the transmission mode under MEM Sending_behavior: cyclical (Send every X seconds) or event-based(Send on change).
Now define which I/O values are to be exported for the individual RevPi devices in your Revolution Pi system:
▷ Select for MEM Shared_IOs either All existing or only Marked as exported I/O values.
▷ To mark individual I/O values for export, click on the corresponding RevPi device in the Configuration Board.
▷ Activate the desired I/O values for this RevPi device in the Value Editor in the Export column.
▷ Click File > Save as Start Configto save the configuration.
▷ Click Tools > Reset Driverto restart the driver.
Query client_status
Test the configuration to ensure that the data transfer works without errors. You can use the free MQTT Explorer, for example.
To test the connection status, you can use the client_status
command in piTest.
Value | Function |
---|---|
client_status 0 | Connection successfully established |
client_status 1 | Connection refused - incorrect protocol version |
client_status 2 | Connection refused - invalid client identifier |
client_status 3 | Connection refused - server unavailable |
client_status 4 | Connection refused - bad username or password |
client_status 5 | Connection refused - not authorized |
client_status 255 | No connection attempt / service not running |
Further links
→ Tutorial: Use MQTT Explorer
→ Tutorial: RevPiModIO replace_io_file
→ mqtt.org