Skip to content

kovorotnii/edgex-modbus-ric-tutorial

Repository files navigation

edgex-modbus-ric-tutorial

This tutorial will allow you to establish interaction between Rightech IoT Cloud platform sandbox https://sandbox.rightech.io/auth and EdgeX Foundry Modbus device service.

Prerequisites

Launch emulator. Then add a slave.

Adding slave

Add registers to slave device.

Add a holding register

  • We will add a holding register with address 12

Adding holding register

Add two coils.

  • We will add two coils with addresses: 1 and 15. In field "Name" you can add names for variables. It doesn't affect on work, generally it will help you to understand which variable stands for current address.

Adding cois 1 and 15

Run slave

  • The modbus emulator can be available at pc-ip-address:502

Running slave

Create model

Creating model

Create commands for controlling Switches.

  • SwitchA is a coil register with address: 1. SwitchB is a coil register with address: 15. Values can be 0 or 1.
  • For setting 1, in the field "Payload", set {"SwitchA": "true"}. For setting 0, set {"SwitchA": "false"}.Similarly change commands for SwitchB.
  • As you see, the general topic for commands is "Name" from "DeviceList".
[[DeviceList]]
# Device name, will be used as a base MQTT topic
Name = "Modbus-TCP-test-device-11"
# Profile name, see another.modbus.profile.yml
Profile = "Another.Device.Modbus.Profile"
Description = "This device is a product for monitoring and controlling digital inputs and outputs over a LAN."
labels = [ "Air conditioner","modbus TCP" ]
[DeviceList.Protocols]
  [DeviceList.Protocols.modbus-tcp]
     # Modbusl slave ip addres
     Address = "192.168.1.1"
     Port = "502"
     UnitID = "1"
[[DeviceList.AutoEvents]]
  # After establishing registration, service will send every 20 seconds values of both switches to the platform 
  Frequency = "20s"
  OnChange = false
  Resource = "Switch"

Creating command for SwitchA

Create command for getting state of both switches.

Creating command for getting switches states

Create command for setting operation mode.

  • Operation Mode is the holding register with address: 12.
  • Current operation modes are described in another.modbus.profile.yml
  • To set Operation Mode, paste in "Payload" {"OperationMode": "8"}. This is "VAM Auto" mode.

Creating command for setting operation mode

Create command for getting operation mode.

Creating command for gettting operation mode

Create an object in the platform.

create-object-gif

Establish interaction between platform and modbus device.

  • By default locate all necessary files: docker-compose.yml, configuration.toml, another.modbus.profile.yml in the same folder.
  • Pull necessary images. Execute docker-compose pull.
  • Run Edgex services. Execute docker-compose up -d.
  • Check whether services are running by docker-compose ps.
  • Edgex services UI will be available at your-ip:4000.
  • Add registration for establishing communication to the platform.
curl -X POST -d '{                                       
"name":"modbus-tutorial-example-thenew11",
"addressable":{
   "name":"Broker",
   "protocol":"tcp",
   "address":"192.168.2.199",
   "port":1883,
   "publisher":"modbus-edgex-11",
   "topic":"mb-topic"
},
"format":"JSON",
"filter":{
   "deviceIdentifiers":["Modbus-TCP-test-device-11"]
},
"enable":true,
"destination":"IOTCORE_TOPIC"
}' http://localhost:48071/api/v1/registration
  • "address" is address of mqtt broker
  • "publisher" is an ID of object in the platform
  • "deviceIdentifiers" are names of devices from configuration.toml establish-interaction

How it should work.

Testing switches.
  • Check whether modbus emulator works.

  • For controlling registers values press "Eye" icon in modbus slave section slave-registers

  • How emulator works. testing swtiches

Testing operation mode

operation-mode

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published