Modbus Application
This tutorial will show how to collect data from a Modbus device and publish it on a cloud platform using Wires. The Modbus device will be emulated using a software simulator, like ModbusPal.
Configure Modbus device
- Download ModbusPal on a computer that will act as a Modbus slave.
- Open ModbusPal application as root and click on the “Add” button under the “Modbus Slaves” tab to create a Modbus slave device. Select an address (i.e. 1) and put a name into the “Slave name” form.
- Click on the button with the eye to edit the slave device. Once the window is opened, add a coil with address 1 and set a value (0 or 1).
- Close the editor and on the main window, click on the “TCP/IP” button under the “Link Settings” tab. Set the “TCP port” to 502. Be sure that the selected TCP port is opened and reachable on the system.
- Click on “Run” button to start the device.
![ModbusPal.png 907](https://files.readme.io/a8bd1a7-ModbusPal.png)
Configure Wires Modbus application
- Install the Modbus driver from Eclipse Kura Marketplace
- In the ESF Administrative Web Interface, create a new driver instance:
- Under Drivers and Assets, click the New Driver button
- Select org.eclipse.kura.driver.modbus, type in a name, and click Apply: a new service will show up in the Drivers and Assets table.
- Configure the new service as follows:
- access.type: TCP
- modbus.tcp-udp.ip: IP address of the system where ModbusPal is running
- modbus.tcp-udp.port: 502
- Click on Wires in System
- Add a new Timer component and configure the interval at which the Modbus slave will be sampled
- Add a new Asset with the previously added Modbus driver
- Configure the new Modbus asset, adding a new Channel with the following configuration:
- name: a custom cool name
- type: READ_WRITE
- value type: BOOLEAN
- unit.id: the Modbus slave address configured in ModbusPal (i.e. 1)
- primary.table: COILS
- memory.address: the Modbus coil address configured in ModbusPal (i.e. 1)
- Add a new Publisher component and configure the chosen cloud platform stack in cloud.service.pid option
- Add a Logger component
- Connect the Timer to the Asset, and the Asset to the Publisher and Logger.
- Click on Apply and check the logs and cloud platform that the data is correctly published.
![ModbusWires.png 2364](https://files.readme.io/bfddce3-ModbusWires.png)
Interact with the Asset using REST APIs
Using an application like Postman, the user can interact with the Assets defined in the system.
![Screenshot 2018-11-09 at 15.59.31.png 1280](https://files.readme.io/4ed884e-Screenshot_2018-11-09_at_15.59.31.png)
Have a look to the Rest Service page to learn more about REST APIs in ESF and how to use them.
Assets REST APIs are available in the context path /services/assets
.
In Postman, the user needs to define a new GET request specifying <gatewayip>/services/assets
to get the list of assets available for the target gateway.
![Screenshot 2018-11-09 at 16.00.42.png 970](https://files.readme.io/aae040e-Screenshot_2018-11-09_at_16.00.42.png)
In order to correctly perform the REST call, the user may need to specify Basic Authentication
and a proper Username
and Password
![Screenshot 2018-11-09 at 16.01.09.png 968](https://files.readme.io/5c03e8a-Screenshot_2018-11-09_at_16.01.09.png)
Once specified the desired asset in the request URL, the user may be able to get the list of Channels configured in the Asset
![Screenshot 2018-11-09 at 16.04.03.png 964](https://files.readme.io/31223ae-Screenshot_2018-11-09_at_16.04.03.png)
And read all the data from those channels
![Screenshot 2018-11-09 at 16.04.43.png 969](https://files.readme.io/f57e063-Screenshot_2018-11-09_at_16.04.43.png)
Using a POST
, the user can also read specific channels that can be defined in the request Body.
![Screenshot 2018-11-09 at 16.05.40.png 967](https://files.readme.io/deaed80-Screenshot_2018-11-09_at_16.05.40.png)
The user can also use the REST APIs to perform writes to one or more channels.
![Screenshot 2018-11-09 at 16.06.27.png 966](https://files.readme.io/f5a9964-Screenshot_2018-11-09_at_16.06.27.png)
Updated 8 months ago