Practical example for transmitting switching states
Box-2-Box via MQTT with Web-IO 4.0
with CloudMQTT as broker
This step-by-step manual explains the setup of Box-2-Box operation of the Web-IO 4.0 Digital via the Internet of Things.
In Box-2-Box mode you connect two Web-IOs together so that switching signals present on the inputs of the one device are transmitted via MQTT to the outputs on the other device. The broker is CloudMQTT, a commercial, free provider for smaller applications.
To familiarize yourself with MQTT we recommend the page "Communication in the Internet of Things."
Structure of the MQTT system
To synchronize the in- and outputs, both Web-IOs exchange messages via MQTT. Each Web-IO publishes the states of its own inputs as a publisher to the broker.
At the same time the input states of the other device are received as a subscription. When a device receives a state change on an input of the opposite device, it changes the state of its corresponding output.
Part 1: Setting up the MQTT broker
To set up an MQTT communication system, you first need a broker. This serves as a messaging center and coordinates the communication flow between the participants.
In this manual a free, public broker for smaller applications called CloudMQTT is used. For larger scale use there are a large number of other providers available. With commercial and free software solutions you can also run your own MQTT brokers in the Internet or Intranet. Ready--to-use hardware appliances are available, from IBM for example. A detailed overview can be found on the page "MQTT Resources".
Broker authentication requires each Web-IO to have a user name and password. To ensure that no other device connected to the broker sends messages for the device topics, access authorization via ACLs is set up.
Summary of the broker configuration | ||
---|---|---|
Web-IO 1 | Web-IO 2 | |
User name | webio1 | webio1 |
Password | Super$afe123 | Super$afe123 |
Write access to | webio1/in/# | webio2/in/# |
Read access to | webio2/in/# | webio1/in/# |
[info] Use of the wildcards + and # eliminates the need for explicitly list the rights for each individual topic. The + stands for all elements in a level of hierarchy, whereas # represents the entire subtree below a level. |
Creating a broker account
CloudMQTT offers the "CuteCat" package, a free online broker for up to 10 devices.
1 Open the site www.cloudmqtt.com and select the ’Plans’ menu item.
2 Select the free plan CuteCat and follow the instructions on the screen.
Creating a broker instance
After logging on in the control panel you can create a new broker.
1 Select the Amazon data center in Ireland as well as
2 the free plan CuteCat.
Configuring the broker for Box-to-Box use
On the details page you can make the necessary settings of your broker for the Web-IO Box-2-Box application.
1 Next to your broker instance click on Details
1 Create the users webio1 and webio2, each with the 2 password Super$afe123.
Assigning access rightsNow create the Access Control List (ACL). Here you will specify for each user 1 the rights 2 he has for writing 3 on a topic.
Recording connection dataIn the last step scroll down to the very bottom of the details page and write down the connection data for your broker.
You need the server address 1 and the port 2 .
Part 2: Setting up the Web-IOs
MQTT basic settings
Open the Web interface of the first Web-IO as described in the user’s manual. Then log on with the administration user.
1 In the configuration area select the menu item Communication paths >> MQTT.
Now provide the connection data for the MQTT broker.
1 Activate MQTT.
2 Enter the user name for the first Web-IO.
3 Enter the corresponding password.
4 Finally, enter the host name and the
5 port of the MQTT broker.
6 For the Box-2-Box application to function, you must enable the outputs for MQTT.
After clicking on the Apply button the device shows a green checkmark to indicate that the changes have been applied.
Configuring actions for the inputs
An action determines how the Web-IO responds to a trigger. In addition to the general specifications ’Designation’ and ’Activation status’, an action consists of a trigger and an action which is performed when the trigger is applied.
When there is a state change on a device input, the other device needs to be informed of this via MQTT. This means an action is created for each input which performs an MQTT Publish when there is a state change.
1 In the configuration area select the menu item Actions.
2 Now click on the Add button.
General information
1 Activate the action and assign a logical name. This allows you to more easily identify the action on the overview page and in the menu.
Instructions for the trigger
2 As the trigger select Input.
3 Select the first input, i.e. Input0.
4 Select for when changing to the value ON.
Instructions for the performed action
5 As action select MQTT Publish.
6 The messages for the first output of the first device are published under the Topic "webio1/in/0".
7 For topic text select "ON" as the message contents which should be published when the trigger is applied.
8 For Topic Clear Text enter the message contents to be sent when the trigger is no longer present. This is the case when the output is switched to OFF.
9 The message should be sent only once when the event occurs. Therefore select here "Perform action only once".
Then specify an action with the corresponding values for Input 1 (Topic: webio/in/1).
Setting up actions for the outputs
General information
1 Activate the action and assign a logical name.
Instructions for the trigger
2 Here you select MQTT Subscribe
3 The Topic is "webio2/in/0" for the first input on the second device
4 Topic text stands for the received message contents, in this case "ON".
Instructions for the performed action
5 As the action "Switch output" is selected
6 A local output should be switched
7 The output which is switched is Output 0
8 The status which is set is ON
Now specify the three missing actions for "Output0 off", "Output1 on" and "Output1 off":
Title | Topic | Topic text | Action | Status |
---|---|---|---|---|
Output0 off | webio2/in0 | OFF | Switch Output0 | OFF |
Output1 on | webio2/in1 | ON | Switch Output1 | ON |
Output1 off | webio2/in1 | OFF | Switch Output1 | OFF |
If you want to save two actions, it may occur to you to send the message "TOGGLE" when there is a status change and select "TOGGLE" as the action instead of explicitly indicating the status change.
We do not advise this: The MQTT service quality for the Web-IO is set to QoS1. This means messages are repeated until the target has confirmed receipt.
If a confirmation gets lost due to a transmission error, the toggle message is sent again and the target switched once more. In this case both devices are no longer in synch.
Configuring second Web-IO
In the last step send the configuration to the second Web-IO. Don’t forget to alter users and topics!
Actions for the outputs
Title | Topic | Topic text | Action | Status |
---|---|---|---|---|
Output0 on | webio2/in0 | ON | Switch Output0 | ON |
Output0 off | webio2/in0 | OFF | Switch Output0 | OFF |
Output1 on | webio2/in1 | ON | Switch Output1 | ON |
Output1 off | webio2/in1 | OFF | Switch Output1 | OFF |
Actions for the inputs
Title | Topic | Topic text | Clear Topic Text | when changing to |
---|---|---|---|---|
switch Input0 | webio2/in0 | ON | OFF | ON |
Switch Input1 | webio2/in0 | OFF | OFF | OFF |
Try it yourself
Would you like to try out MQTT? Our Web-IO Digital is the ideal entry into the IoT universe. Simply request the Web-IO Digital as a sample. If the sample is returned within 30 days, you pay only the return shipping costs. To keep the test unit, simply pay the accompanying invoice.
Questions about the Web-IO Digital with MQTT?
Mr. Thiel is ready to help you with any questions.
Phone: +49 202/2680-110 (Mon.-Fri. 8 a.m. to 5 p.m.)
E-mail: f.thiel@wut.de