1 How to build IO sample for Embedded OPC UA Server {#opcuaserver-io}
3 @brief Tutorial to add IO nodes for Embedded OPC UA Server that represents ioThinx-4533 device IO modules status.
16 If you are a total beginner to this, start here!
18 1. make sure your firmware version is above or equal to V1.1
22 2. download embeddedopcuaserver-plugin-dev_<version>_armhf.deb to 4533
23 * [embeddedopcuaserver-plugin-dev_1.1.0_armhf.deb](embeddedopcuaserver-plugin-dev_1.1.0_armhf.deb)
25 3. install embeddedopcuaserver-plugin-dev_<version>_armhf.deb
27 dpkg -i embeddedopcuaserver-plugin-dev_<version>_armhf.deb
30 4. Check io.conf under `/usr/local/bin/embeddedopcuaserver/Config` fits your ioThinx-4533 IO modules layout
31 5. Execute `systemctl start embedded-opcua-server` to run up server
32 6. Start using OPC UA client to browse IO data
33 7. Other general usage of OPC UA Server, please reference `How to build node sample for Embedded OPC UA Server` tutorial
38 ### User Scenario 1: Add an diStatus node(config only)
40 Add Slot 1/Channel 4 diStatus to OPC UA Server, just modify io.conf under `/usr/local/bin/embeddedopcuaserver/Config` to
47 {"ch": 0, "access": 1, "variant_type": 3, "func_type": 10, "name": "diMode", "description": "di mode"},
48 {"ch": 0, "access": 1, "variant_type": 3, "func_type": 11, "name": "diStatus", "description": "di status"},
49 {"ch": 1, "access": 1, "variant_type": 3, "func_type": 11, "name": "diStatus", "description": "di status"},
50 {"ch": 2, "access": 1, "variant_type": 3, "func_type": 11, "name": "diStatus", "description": "di status"},
51 {"ch": 3, "access": 3, "variant_type": 3, "func_type": 12, "name": "diCounterStatus", "description": "di counter status"},
52 {"ch": 3, "access": 3, "variant_type": 7, "func_type": 13, "name": "diCounterValue", "description": "di counter value"},
53 {"ch": 4, "access": 1, "variant_type": 3, "func_type": 11, "name": "diStatus", "description": "di status"}
60 - slot 1 must be 45MR-1600/45MR-1601/45MR-2606
61 - follow json format to add your own node
64 ### User Scenario 2: Change module slot order(config only)
66 Adjust io.config to follow ioThinx-4533 real hardware modules order.
67 Now slot 1 is 45MR-1600 and slot 2 is 45MR-2600 which the io.conf may looks like below.
74 {"ch": 0, "access": 1, "variant_type": 3, "func_type": 10, "name": "diMode", "description": "di mode"},
75 {"ch": 0, "access": 1, "variant_type": 3, "func_type": 11, "name": "diStatus", "description": "di status"},
76 {"ch": 1, "access": 1, "variant_type": 3, "func_type": 11, "name": "diStatus", "description": "di status"},
77 {"ch": 2, "access": 1, "variant_type": 3, "func_type": 11, "name": "diStatus", "description": "di status"},
78 {"ch": 3, "access": 3, "variant_type": 3, "func_type": 12, "name": "diCounterStatus", "description": "di counter status"},
79 {"ch": 3, "access": 3, "variant_type": 7, "func_type": 13, "name": "diCounterValue", "description": "di counter value"},
80 {"ch": 4, "access": 1, "variant_type": 3, "func_type": 11, "name": "diStatus", "description": "di status"}
83 {"ch": 0, "access": 1, "variant_type": 3, "func_type": 20, "name": "doMode", "description": "do mode"},
84 {"ch": 0, "access": 3, "variant_type": 3, "func_type": 21, "name": "doStatus", "description": "do status"},
85 {"ch": 1, "access": 3, "variant_type": 3, "func_type": 21, "name": "doStatus", "description": "do status"},
86 {"ch": 2, "access": 3, "variant_type": 3, "func_type": 22, "name": "doPulseStatus", "description": "do pluse status"},
87 {"ch": 2, "access": 3, "variant_type": 7, "func_type": 23, "name": "doPulseCount", "description": "do pluse count"},
88 {"ch": 3, "access": 3, "variant_type": 3, "func_type": 22, "name": "doPulseStatus", "description": "do pluse status"},
89 {"ch": 3, "access": 3, "variant_type": 7, "func_type": 23, "name": "doPulseCount", "description": "do pluse count"}
95 Now switch slot 1 and slot 2 and insert an 45MR-2404 in between which make ioThinx-4533 hardware modules order into
96 slot 1: 45MR-2600, slot 2: 45MR-2404, slot 3: 45MR-1600 and if we don't want to monitor 45MR-2404, the io.conf may replace like below.
103 {"ch": 0, "access": 1, "variant_type": 3, "func_type": 20, "name": "doMode", "description": "do mode"},
104 {"ch": 0, "access": 3, "variant_type": 3, "func_type": 21, "name": "doStatus", "description": "do status"},
105 {"ch": 1, "access": 3, "variant_type": 3, "func_type": 21, "name": "doStatus", "description": "do status"},
106 {"ch": 2, "access": 3, "variant_type": 3, "func_type": 22, "name": "doPulseStatus", "description": "do pluse status"},
107 {"ch": 2, "access": 3, "variant_type": 7, "func_type": 23, "name": "doPulseCount", "description": "do pluse count"},
108 {"ch": 3, "access": 3, "variant_type": 3, "func_type": 22, "name": "doPulseStatus", "description": "do pluse status"},
109 {"ch": 3, "access": 3, "variant_type": 7, "func_type": 23, "name": "doPulseCount", "description": "do pluse count"}
113 {"ch": 0, "access": 1, "variant_type": 3, "func_type": 10, "name": "diMode", "description": "di mode"},
114 {"ch": 0, "access": 1, "variant_type": 3, "func_type": 11, "name": "diStatus", "description": "di status"},
115 {"ch": 1, "access": 1, "variant_type": 3, "func_type": 11, "name": "diStatus", "description": "di status"},
116 {"ch": 2, "access": 1, "variant_type": 3, "func_type": 11, "name": "diStatus", "description": "di status"},
117 {"ch": 3, "access": 3, "variant_type": 3, "func_type": 12, "name": "diCounterStatus", "description": "di counter status"},
118 {"ch": 3, "access": 3, "variant_type": 7, "func_type": 13, "name": "diCounterValue", "description": "di counter value"},
119 {"ch": 4, "access": 1, "variant_type": 3, "func_type": 11, "name": "diStatus", "description": "di status"}
126 - slot order is start from 0 and slot 0 means the node from CPU head
127 - if this io module is no need to be monitor by OPC UA Server, then give an null in the io.conf
129 ### User Scenario 3: Add new IO func_type (coding & config)
131 Define new FUNC_TYPE in `DataSet.h` and add read/write function case in `io_control_read()` and `io_control_write()` of `io_node_operator.c`.
132 If this io data need to be configured first during the initialization, then configure function should be add in `add_io_nodes()`.
134 Modify `io.conf` to load __hello do__ info and add new func_type 99 as below.
141 {"ch": 0, "access": 1, "variant_type": 3, "func_type": 20, "name": "doMode", "description": "do mode"},
142 {"ch": 3, "access": 1, "variant_type": 3, "func_type": 99, "name": "helloDO", "description": "hello do"}
150 ### Using native toolchain
152 1. Copy sample.tar.gz contained in the programing guide from your PC to ioThinx:\n
153 For example, if the IP address of the ioThinx is "192.168.127.254", use the following command:
155 user@Linux:~$ scp sample.tar.gz moxa@192.168.127.254:~
157 2. Extract the sample code
159 moxa@Moxa:~$ tar zxvf sample.tar.gz
161 3. Build IO sample code
163 moxa@Moxa:~$ cd sample/mx_node_sdk/c/io
165 Build via cmake & make
167 moxa@Moxa:~/sample/mx_node_sdk/c/io$ cmake .
168 moxa@Moxa:~/sample/mx_node_sdk/c/io$ make
170 4. Move `liboperator.so` to `OperatorLib`
172 moxa@Moxa:~/sample/mx_node_sdk/c/io$ cp liboperator.so /usr/local/bin/embeddedopcuaserver/OperatorLib/io/
174 5. Restart server via systemd
176 moxa@Moxa:~/sample/mx_node_sdk/c/io$ sudo systemctl restart embedded-opcua-server
179 ### Using cross toolchain
181 1. Copy sample.tar.gz contained in the programing guide to your PC
182 2. Extract the sample code
184 user@Linux:~$ tar zxvf sample.tar.gz
186 3. Build IO sample code
188 user@Linux:~$ cd sample/mx_node_sdk/c/io
190 Build via cmake & make
192 user@Linux:~/sample/mx_node_sdk/c/io$ cmake . -DCMAKE_TOOLCHAIN_FILE=toolchain-cross.cmake
193 user@Linux:~/sample/mx_node_sdk/c/io$ make
195 4. Copy the sample program to ioThinx:\n
196 For example, if the IP address of the ioThinx is "192.168.127.254", use the following command:
198 user@Linux:~/sample/mx_node_sdk/c/io$ scp liboperator.so moxa@192.168.127.254:~
200 5. Move `liboperator.so` to `OperatorLib`
202 moxa@Moxa:~$ cp liboperator.so /usr/local/bin/embeddedopcuaserver/OperatorLib/io/
204 6. Restart server via systemd
206 moxa@Moxa:~$ sudo systemctl restart embedded-opcua-server
211 ### Programming Source Code
214 - quick example to show 2 data nodes onto OPC UA Server
216 - demo sample shows all data types nodes onto OPC UA Server
218 - io sample shows io data nodes onto OPC UA Server
225 │ ├── demo_node_operator.c
226 │ ├── toolchain-cross.cmake
227 │ └── toolchain-native.cmake
230 │ ├── sample_node_operator.c
231 │ ├── toolchain-cross.cmake
232 │ └── toolchain-native.cmake
238 ├── io_node_operator.c
239 ├── toolchain-cross.cmake
240 └── toolchain-native.cmake
244 Explain how to use io.conf to fit your usage
247 - follow array index to represent which slot
249 - Node's access right. Please reference MX_NODE_ACCESS_RIGHT
251 - MX_Variant's data type. please reference MX_NODE_VALUE_TYPE
253 - function type which is define in DataSet.h
255 ### Execute OPC UA server
258 moxa@Moxa:~$ sudo systemctl start embedded-opcua-server
259 moxa@Moxa:~$ sudo systemctl stop embedded-opcua-server
260 moxa@Moxa:~$ sudo systemctl restart embedded-opcua-server
261 moxa@Moxa:~$ sudo systemctl status embedded-opcua-server
262 moxa@Moxa:~$ sudo systemctl disable embedded-opcua-server
263 moxa@Moxa:~$ sudo systemctl enable embedded-opcua-server
266 ### Add/Delete OPC UA server account
269 moxa@Moxa:~$ sudo opcuauser --add moxa
270 moxa@Moxa:~$ sudo opcuauser --del moxa
272 moxa@Moxa:~$ sudo opcuauser --help
273 Usage: opcuauser [options] username
276 -a, --add Add user account
277 -d, --del Delete user account
278 -c, --change Change user password
279 -v, --verion Show version
283 opcuauser Add user account
284 opcuauser username Change user password
285 opcuauser --help Show help
288 Please notice that embedded-opcua-server should be reboot to take effect of user account list.
289 Current user account list can be verify by checking ```/etc/opcuauser_passwd```.
291 ### Anonymous user account setting
293 Default Anonymous user account is enable, use `opcuauser` command to add or delete anonymous user will not change anything.
294 If OPC UA Server want to delete anonymous user account, please move to file `/usr/local/bin/embeddedopcuaserver/OPCUAServerData/Config/OPCUA.json`
298 "SupportAnonymous":1,
301 Modify setting to disable,
304 "SupportAnonymous":0,
310 log: Systemd service syslog must be active(running)
312 - check `systemctl status embedded-opcua-server`.
314 - check `/var/log/syslog` to see all debug info during server enable.
318 1. This OPC UA Server can only be executed on ioThinx-4533-LX.
319 2. Please backup `/usr/local/bin/embeddedopcuaserver/OPCUAServerData/Config` before FWR upgrade.
320 3. Use Lan1 internet setting as default connection setting.