Skip to content

A client that performs protocol translation from 'Modbus' to 'LWM2M' and back.

License

Notifications You must be signed in to change notification settings

zeelos/leshan-client-modbus

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

leshan-client-modbus

An example client that does a protocol translation between Modbus and Lightweight M2M. The client is drived by a configuration file that describes the Modbus/LWM2M Mapping and it can be made to suite specific requirements. Underlying it uses the active jlibmodbus open source library for the Modbus communication.

NOTE: Currently the state of the project is "in-preview" mode, don't expect to be production grade. We have only tested the Modbus TCP mode and it seems it works correctly. Much more testing is needed and feedback from the community will be greatly appreciated.

Setup

  1. Download a Modbus simulator and start it. We used the open source ModbusPal simulator but it should work with your favourite one.

    ModbusPal

  2. Create a modbus.json configuration that describes the LWM2M object id to Modbus translation (start from example configuration): Here is a snapshot for Modbus TCP mapping:

    {
      "connection": "tcp",
      "slave": 1,
      "tcpSettings": {
        "node": "localhost",
        "port": 5002,
        "keepalive": true
      },
      "objects": {
        "26241": [
          {
            "26251": {
              "type": "holding-register",
              "startAddress": 0,
              "pollMillis": 1000
            },
            "26253": {
              "type": "coil",
              "startAddress": 0
            },
            "26255": {
              "type": "holding-register",
              "startAddress": 0,
              "quantity": 10
            }
          },
          {
            "26251": {
              "type": "holding-register",
              "startAddress": 1
            },
            "26253": {
              "type": "coil",
              "startAddress": 1
            }
          }
        ],
        "3303": [
          {
            "5700": {
              "type": "holding-register",
              "startAddress": 0
            }
          }
        ]
      }
    }

    Here we used both a custom developed ObjectID;26241 to map the whole Modbus spectrum functionality, as well as an existing ObjectID;3303 where we map a specific resource (5700) to a Modbus holding register. More information on LWM2M Object id's can be found on OMA page.

  3. Start the client passing both the configuration and the remote LWM2M server hostname:

    Note that we bind the configuration file inside docker and pass the appropriate parameter.

     docker run -it --name leshan-client-modbus --mount type=bind,source="$(pwd)"/modbus.json,target=/modbus.json --rm -e JAVA_OPTS="-Xmx32M -Xms32M" zeelos/leshan-client-modbus:0.1-SNAPSHOT -t /modbus.json -u <leshan-server-hostname>
    
  4. Visit the Leshan web interface and notice the sensor been registered and the exposed object id's available to use. Execute Read/Write operations on resources and notice any changes being reflected back to the Modbus simulator:

    leshan_server_modbus

About

A client that performs protocol translation from 'Modbus' to 'LWM2M' and back.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages