Software apps and online services
Hand tools and fabrication machines
This time, the focus is on a Modbus TCP/IP slave (server) device that communicates with WolkGatewayModule-Modbus acting as a master (client) using Ethernet as its physical layer. The parameters of the connection, the slave’s IP address and port, are configurable through a.json file.
Finally, the data from the slave’s registers are exchanged with WolkGateway through WolkGatewayModule-Modbus and then with WolkAbout IoT Platform.
The Modbus TCP/IP slave used in this project is actually a simulation of an offset printing machine described in the related Hackster project. A list of Modbus registers present on the slave is defined in a .json file. Finally, a visualisation dashboard is created on the Platform, providing insight and control over the simulated offset printing machine.
Here is an overview of the architecture of this project.
Connecting multiple Modbus TCP/IP slaves (servers) is possible by deploying additional WolkGatewayModule-Modbus and editing their register mapping and connectivity details files.
This project can be easily modified to work with a different Modbus TCP/IP slave instead.
Make a hardware connection following the diagram below. Do note that both the hardware connection of the offset printing machine simulator and WolkGateway device which can run on a generic Linux device (specifically Raspberry Pi Model B+ is used in this demo) are presented here.
WolkGateway bridges communication between WolkAbout IoT Platform and multiple non-IP-enabled devices connected to it through modules. The modules enable communication with subordinate devices by implementing the device’s network communication protocol on one end (Modbus TCP/IP in this project) and parse data between the Local Mosquitto MQTT broker on the other end.
Start with connecting to the Raspberry Pi and cloning the WolkGateway repository:
git clone --recurse-submodules https://github.com/Wolkabout/WolkGateway.git
After that, install WolkGateway’s dependencies by running:
sudo apt-get install mosquitto cmake python python-pip && sudo python -m pip install conan
Now that the dependencies are installed change directory into WolkGateway and run the configure.sh script. This script prepares the build system and compiles OpenSSL. This step takes some time (up to 10 minutes), so while waiting for this step to finish, create a gateway on WolkAbout IoT Platform.
Head over to demo.wolkabout.com and register/log in with your account. Next, switch to the Devices tab in the navigational menu.
Press + and from the dropdown menu select “Create Gateway”.
Enter a name for the gateway and the key and press “Create Gateway”.
A pop-up appears with the gateway name and the key, as well as its password. Save this information by using one of the options from the bottom on the left as you need to enter them into WolkGateway/out/gatewayConfiguration.json.
After the configure.sh script finishes, change directory to WolkGateway/out/ and run
make. To run the application correctly, you need to enter the device credentials into gatewayConfiguration.json:
Before running the gateway application, make sure that Mosquitto is running by invoking
systemctl start mosquitto
Then start the application with
After a couple of seconds, the gateway connects to the Platform and performs its initial configuration. Now, it is possible to register devices through the gateway.
For easier use, create a service that runs the gateway by creating a new file wolk_gateway.service and copy the content from the project’s attachments. Make changes to the username and the path if necessary. Then move it and enable it with the following commands:
sudo mv wolk_gateway.service /lib/systemd/system/wolk_gateway.service
sudo chmod 644 /lib/systemd/system/wolk_gateway.service
sudo systemctl daemon-reload
sudo systemctl enable wolk_gateway.service
sudo systemctl start wolk_gateway.service
To check the state of the service use
sudo systemctl status wolk_gateway.service
, and also use
disable commands if needed.
All of this completes the setup for WolkGateway repository, resulting in a service that routes the data from the Modbus module to WolkAbout IoT Platform.
After that, install WolkGatewayModule-Modbus’s dependencies by running:
sudo apt-get install automake autotools-dev autoconf m4 zlib1g-dev cmake libtool python python-pip && python -m pip install conan
Then change the directory to WolkGatewayModule-Modbus and run the configure.sh script. This time the configure.sh script takes considerably less time to finish as OpenSSL is already compiled and cached. Next, change the directory to WolkGatewayModule-Modbus/out/ and run
Now that you have built the project, the next step is to edit the configuration files needed to run this module correctly: deviceConfiguration.json, modbusConfiguration.json and modbusRegisterMapping.json
Enter a device name and a key into deviceConfiguration.json that is in the device registration process and later displayed on WolkAbout IoT Platform.
"name": "DEVICE_NAME", // Device name
"key": "DEVICE_KEY", // Device key
"protocol": "JsonProtocol", // Protocol used on WolkGateway
"localMqttUri": "tcp://localhost:1883" // WolkGateway Bus
The modbusConfiguration.json file is used to set the connectivity details of the Modbus connection, such as the IP address and the port. The Serial/RTU configuration is omitted.
// TCP/IP Configuration
// Modbus connection type configuration
"connectionType": "TCP/IP", // Connection type - "SERIAL/RTU" or "TCP/IP"
// Modbus register read parameters
"responseTimeoutMs": 200, // Register read/write timeout
"registerReadPeriodMs": 500 // Register pool period
Edit the last file, modbusRegisterMapping.json in such a way that it contains the list of all Modbus registers that is polled. There is a modbusRegisterMapping.json file in the project’s attachments that matches the register mapping of our offset printing machine simulator. For more information about mapping registers, see the README on WolkGatewayModule-Modbus.
"name":"mappingName", // Register name
"reference": "mappingReference", // Unique reference
"minimum": -32768, // Minimum value that can be held in register.
"maximum": 32767, // Maximum value that can be held in register.
"address": 0, // Register address
// Register type - "INPUT_REGISTER" or "HOLDING_REGISTER_ACTUATOR" or "HOLDING_REGISTER_SENSOR" or "INPUT_CONTACT" or "COIL"
// Data type stored in register - "INT16" or "UINT16" or "REAL32" for "INPUT_REGISTER"/"HOLDING_REGISTER_ACTUATOR"/"HOLDING_REGISTER_SENSOR" register type, and "BOOL" for "COIL"/"INPUT_CONTACT"
"slaveAddress": 1 // Slave address where the register is located
After configuring these files and running the WolkGateway application, you can start the Modbus module with:
./modbusModule deviceConfiguration.json modbusConfiguration.json modbusRegisterMapping.json
Starting the Modbus module tries to poll the registers of the slave devices and sends a device registration request based on deviceConfiguration.json through WolkGateway to WolkAbout IoT Platform.
By following the same steps as for wolk_gateway.service, create a service for the Modbus module using the modbus_module.service file from the project’s attachments.
Now that the Modbus module has been registered on the Platform and the register data is being sent to the Platform, you need a way to display it and send new values and have them written into the Modbus registers of your slave devices. To achieve this, first, create a Dashboard.
Then start adding widgets that fit your slave device: Actuator widgets for coils and holding registers (read/write) and Card widgets for input contacts and input registers (read-only). The Semantic Groups widget allows you to choose up to four feeds, regardless of the register type.
By connecting a Modbus TCP/IP slave (server) to WolkAbout IoT Platform, you can have an in-depth insight into the overall operation, including alarm notifications, productivity, as well as control over your device. Most importantly, you can do all of this remotely instead of on-premise, which has been the case so far.
Do you have an IoT project in mind? Share it with the WolkAbout Community through Hackster.io. We'd love to see what you can do using WolkAbout IoT Platform!
If you need help developing it, we've got you covered! Read our team’s projects and stay tuned for the new ones.