1restmbmaster(8) Rest API Modbus master restmbmaster(8)
2
3
4
6 restmbmaster — Rest API gateway to Modbus slaves
7
9 restmbmaster -c CONNECT_URI -p PORT
10 restmbmaster -f FILE
11 restmbmaster -h|-v
12
14 restmbmaster is a simple daemon that allows user to access Modbus
15 slaves over Rest API. The slaves could be either connected over serial
16 line (Modbus RTU protocol), or over TCP (Modbus TCP protocol).
17
19 -h, --help
20 Print help text to console and exit.
21
22 -v, --version
23 Print version information to console and exit.
24
25 -g, --debug
26 Turns on debugging messages. Repeating the option increases ver‐
27 bosity.
28
29 -c CONNECT_URI, --connect CONNECT_URI
30 Specifies the target Modbus bus to connect to. Supported for‐
31 mats:
32
33 tcp://HOSTNAME[:PORT]
34
35 Example: tcp://test.abc:1000
36
37 Default PORT: 502
38
39 rtu:DEVICEPATH[?baud=BAUDRATE]
40
41 Example: rtu:/dev/ttyS0?baud=9600
42
43 Default BAUDRATE: 115200
44
45 -p PORT, --port PORT
46 Specifies TCP port on which the webserver is listening and where
47 the Rest API is exposed.
48
49 -f FILE, --config FILE
50 Load the specified configuration file.
51
53 The API is quite simple. Only "GET" (read) and "PUT" (write) methods
54 are supported. The "Content-Type" is always "text/plain" for both "GET"
55 and "PUT". The path in the URL has following format:
56
57 http://HOSTNAME:PORT/slaves/SLAVE_ADDRESS/OBJECT_FAM‐
58 ILY/OBJECT_ADDRESS[?count=OBJECT_COUNT]
59
60 SLAVE_ADDRESS — Address of the slave to communitate with, number
61 in range from 0 to 255.
62
63 OBJECT_FAMILY — Is a string to identify the family of the
64 objects. It is one of:
65
66 coils — To access coils (RW).
67
68 discrete-inputs — To access discrete inputs (RO).
69
70 input-registers — To access input registers (RO).
71
72 holding-registers — To access holding registers (RW).
73
74 OBJECT_ADDRESS — Address of the object according to the family.
75 It is an integer number, starting from 0.
76
77 OBJECT_COUNT — Number of objects to read or write, starting at
78 OBJECT_ADDRESS. It is an integer number, starting from 0. If not
79 specified, defaults to 1.
80
81 The content being returned by "GET" method is a value of the object as
82 a plain integer number in the text. If values of multiple objects are
83 requested, they are separated by a single space. Same format applies
84 for the "PUT" method.
85
87 To run connecting to Modbus TCP:
88
89 $ restmbmaster -c tcp://test.abc:1000 -p 8080
90
91 To run connecting to Modbus RTU:
92
93 $ restmbmaster -c rtu:/dev/ttyS0?baud=9600 -p 8080
94
95 To run according to the configuration from file:
96
97 $ restmbmaster -f myconfig.conf
98
99 When restmbmaster is running, one can use for example curl to communicate with Modbus slaves.
100 In the following example, slave with address 55 is queried for the value of input register with address 10:
101
102 $ curl http://127.0.0.1:8080/slaves/55/input-registers/10
103 34
104
105 It is possible to query multiple registers (in sequence) at once:
106
107 $ curl http://127.0.0.1:8080/slaves/55/input-registers/10?count=4
108 34 78 234 2
109
110 To write new value (434) to holding register 20 the "PUT" method has to
111 be used:
112
113 $ curl http://127.0.0.1:8080/slaves/55/holding-registers/20 -d "434" -H "Content-Type: text/plain" -X PUT
114
115 It is also possible to write to a sequence of registers (20-26):
116
117 $ 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
118
120 restmbmaster.conf(5),
121
123 Jiri Pirko is the original author and current maintainer of restmbmas‐
124 ter.
125
126
127
128restmbmaster 26 December 2019 restmbmaster(8)