restmbmaster - Man Page

Rest API gateway to Modbus slaves

Synopsis

restmbmaster -c CONNECT_URI -p PORT
restmbmaster -f FILE
restmbmaster -h|-v

Description

restmbmaster is a simple daemon that allows user to access Modbus slaves over Rest API. The slaves could be either connected over serial line (Modbus RTU protocol), or over TCP (Modbus TCP protocol).

Options

-h,  --help

Print help text to console and exit.

-v,  --version

Print version information to console and exit.

-g,  --debug

Turns on debugging messages. Repeating the option increases verbosity.

-c CONNECT_URI, --connect CONNECT_URI

Specifies the target Modbus bus to connect to. Supported formats:

tcp://HOSTNAME[:PORT]

Example: tcp://test.abc:1000

Default PORT: 502

rtu:DEVICEPATH[?baud=BAUDRATE]

Example: rtu:/dev/ttyS0?baud=9600

Default BAUDRATE: 115200

-p PORT, --port PORT

Specifies TCP port on which the webserver is listening and where the Rest API is exposed.

-f FILE, --config FILE

Load the specified configuration file.

Rest API

The API is quite simple. Only "GET" (read) and "PUT" (write) methods are supported. The "Content-Type" is always "text/plain" for both "GET" and "PUT". The path in the URL has following format:

http://HOSTNAME:PORT/slaves/SLAVE_ADDRESS/OBJECT_FAMILY/OBJECT_ADDRESS[?count=OBJECT_COUNT]

SLAVE_ADDRESS — Address of the slave to communitate with, number in range from 0 to 255.

OBJECT_FAMILY — Is a string to identify the family of the objects. It is one of:

coils — To access coils (RW).

discrete-inputs — To access discrete inputs (RO).

input-registers — To access input registers (RO).

holding-registers — To access holding registers (RW).

OBJECT_ADDRESS — Address of the object according to the family. It is an integer number, starting from 0.

OBJECT_COUNT — Number of objects to read or write, starting at OBJECT_ADDRESS. It is an integer number, starting from 0. If not specified, defaults to 1.

The content being returned by "GET" method is a value of the object as a plain integer number in the text. If values of multiple objects are requested, they are separated by a single space. Same format applies for the "PUT" method.

Examples

To run connecting to Modbus TCP:

$ restmbmaster -c tcp://test.abc:1000 -p 8080

To run connecting to Modbus RTU:

$ restmbmaster -c rtu:/dev/ttyS0?baud=9600 -p 8080

To run according to the configuration from file:

$ restmbmaster -f myconfig.conf

When restmbmaster is running, one can use for example curl to communicate with Modbus slaves.
In the following example, slave with address 55 is queried for the value of input register with address 10:

$ curl http://127.0.0.1:8080/slaves/55/input-registers/10
34

It is possible to query multiple registers (in sequence) at once:

$ curl http://127.0.0.1:8080/slaves/55/input-registers/10?count=4
34 78 234 2

To write new value (434) to holding register 20 the "PUT" method has to be used:

$ curl http://127.0.0.1:8080/slaves/55/holding-registers/20 -d "434" -H "Content-Type: text/plain" -X PUT

It is also possible to write to a sequence of registers (20-26):

$ curl http://127.0.0.1:8080/slaves/55/holding-registers/20 -d "434 48 32 92 1 0 3" -H "Content-Type: text/plain" -X PUT

See Also

restmbmaster.conf(5),

Author

Jiri Pirko is the original author and current maintainer of restmbmaster.

Referenced By

restmbmaster.conf(5).

26 December 2019 Rest API Modbus master