Please note that this page is the archive of content now maintained in the EdgeX Foundry GitHub. Find the current source of record for this information here: https://github.com/edgexfoundry/edgex-go/blob/master/docs/examples/Ch-ExamplesAddingModbusDevice.rst

You can see the documentation in presentation form at https://nexus.edgexfoundry.org/content/sites/docs/staging/master/docs/_build/html/

EdgeX - Barcelona Release

Ubuntu Desktop 16.04 with Docker/Docker-Compose

Adding a new Modbus RTU Device


Datanab Modbus Enabled Room Temperature & Humidity Sensor w/ LCD



Project Components Needed

Hardware needed

X86 computer with native RS485 communication device or RS485 adapter

Datanab Modbus Enabled Room Temp/Humidity Sensor w/ LCD

-- http://www.datanab.com/sensors/modbus_rth_lcd.php

Software needed


The following software was installed from 3rd parties

Postman (Linux 64bit)

-- https://www.getpostman.com/

EdgeX - barcelona-docker-compose.yaml

-- https://github.com/edgexfoundry/developer-scripts/blob/master/docker-compose.yml

Modbus - Device documentation

-- http://www.datanab.com/zc/docs/sensors/MBus_RTH_LCD.pdf

Modbus - Device communication settings

Modbus device Baud rate = 19200

Modbus device Parity = N (none)

Modbus device Data bits = 8

Modbus device Stop bits = 1
Modbus device address: 254 (device specific)
Modbus device register: 100, 101, 102 (device specific)
Modbus device register data type: Integer/Floating point (device specific)

Gateway RS485 Port Configuration

For the Dell Edge Gateway 5000:

Ensuring success

Verify the following, prior to following the instruction on the following pages

Is the COM port set to RS485?

Does the Modbus device power on?

With a separate utility, can you read(from)/write(to) the modbus device?

Creating the Modbus yaml file

An example Modbus device yaml file can be found here: <Click Here>

The Modbus device yaml file used in this example can be found here: <Click Here>

When you are creating your yaml file you will need to know what command options are available to use, they can be found here:

https://github.com/edgexfoundry/core-domain/blob/master/src/main/java/org/edgexfoundry/domain/meta/PropertyValue.java

With your favorite file editor, open the file

Modify the following fields


deviceResources

resources

commands

Bringing up EdgeX via Docker

Starting with following system configuration:

Verify your Docker installation

Verify that Docker is installed and working as expected.

>$ sudo docker run hello-world

Verify that the image is on the system

>$ sudo docker ps -a

Download docker-compose file

Verify the version of dockerized EdgeX that you will be running

Enable Modbus in the Docker Compose file

With your favorite file editor, open the docker-compose file

Find the section “device-modbus” section, which will be commented out with “#” symbols.

Uncomment the entire section

Save your changes and exit out of the editor

Starting EdgeX Docker components

Start Edgex by using the following commands

Docker Command

Description

Suggested Wait Time After Completing

sudo docker-compose pull

Pull down, but don't start, all the EdgeX Foundry microservices

Docker Compose will indicate when all the containers have been pulled successfully

sudo docker-compose up -d volume

Start the EdgeX Foundry file volume--must be done before the other services are started

A couple of seconds

sudo docker-compose up -d config seed

Start and populate the configuration/registry microservice which all services must register with and get their configuration from.

1 minute

sudo docker-compose up -d mongo

Start the NoSQL MongoDB container

1 minute

sudo docker-compose up -d logging

Start the logging microservice--used by all micro services that make log entries

1 minute

sudo docker-compose up -d notifications

Start the notifications and alerts microservice--used by many of the microservices

30 seconds

sudo docker-compose up -d metadata

Start the Core Metadata microservices.

1 minute

sudo docker-compose up -d data

Start the Core Data microservice.

1 minute

sudo docker-compose up -d command

Start the Core Command microservice

1 minute

sudo docker-compose up -d scheduler

Start the scheduling microservice--used by many of the microservices

1 minute

sudo docker-compose up -d export-client

Start the Export Client registration microservice.

1 minute

sudo docker-compose up -d export-distro

Start the Export Distribution microservice.

1 minute

sudo docker-compose up -d rulesengine

Start the Rules Engine microservice.

1 minute

sudo docker-compose up -d device-virtual

Start the virtual device service

1 minute

sudo docker-compose up -d device-modbus

Start the Modbus Device microservice

1 minute


Check the containers status

Run a "docker ps -a" command to confirm that all the containers have been downloaded and started

Show containers

To get a list of all the EdgeX containers, you can use “docker-compose config --services”

Stop Containers

To stop (but not remove) all containers, issue “docker-compose stop”.

To stop an individual container, you can use “docker-compose stop [compose-container-name]”.

Start Containers

To start all the containers (after a stop) issue "docker-compose start" to re-start

To start an individual container, you can use "docker-compose start [compose-container-name]" (after that container has been stopped).

Delete Containers *** DANGER ***

To stop all the containers running and DELETE them, you can use “docker-compose down”

EdgeX Foundry Container Logs

To view the log of any container, use the command:

"docker-compose logs -f compose-contatainer-name"

(ex. docker-compose logs -f edgex-device-snmp)

At this point the Dockerized version of EdgeX is running.

Adding the device to edgex

Importing APIs

In this section you will be using the program Postman to interact with EdgeX. You will also need to have the file “core-metadata.raml” available to load into the Postman application.  The file “core-metadata.raml” can be found here: “edgex/core-metadata…./src/test/resources/raml/core-metadata.raml”

Viewing available APIs

Create an addressable

Upload the profile

Post the device

What if a mistake is made

Verify device added

Check the edgex-device-modbus logs to see if the device was added without issue

“sudo docker logs -f --tail 100 edgex-device-snmp”

Creating a scheduled event

This is used to regularly get & push data to another service or for regularly viewing data.

Gathering information for the addressable

Got to http://localhost:48082/api/v1/device

Look for the id or the device that you want to schedule an event for

[

   {

       "name": "mbus-rth-lcd-device",

       "id": "5a1dd585e4b0c3936013123d",  <--- This

       "description": "living room HVAC thermostat",

       "labels": [

           "temperature",

           "modbus",

           "industrial"

       ],

       "adminState": "unlocked",


In this example the id is “5a1dd585e4b0c3936013123d”

Next you want to get the “name” of the command you want to schedule an event for

"commands": [
           {
               "id": "5a1dcdfce4b0c39360131239",
               "name": "TemperatureDegF", <--- This
               "get": {
                   "url": "http://localhost:48082/api/v1/device/5a1dd585e4b0c3936013123d/command/5a1dcdfce4b0c39360131239",
                   "responses": [
                       {
                           "code": "200",
                           "description": "Get the temperature in degrees F",
                           "expectedValues": [
                               "TemperatureDegF"
                           ]


In this example the name is "TemperatureDegF".

Create addressable

In this section you will need to supply a path the the item you want to schedule.

The path outline is:

/api/v1/device/{device id}/{command name}

In this case, the address would be

/api/v1/device/5a1dd585e4b0c3936013123d/TemperatureDegF

/POST addressable

Create a schedule

/POST schedule

Create an event that will use the schedule

/POST scheduleevent