@@ -22,7 +22,23 @@ Follow these scripts in order:
2222If you don't have a real OPC UA server, start the included test server:
2323
2424``` bash
25- uv run python examples/opcua/server.py
25+ uv run python -m examples.opcua.server
26+ ```
27+
28+ To start a TLS-encrypted server (Basic256Sha256, port 4842):
29+
30+ ``` bash
31+ uv run python -m examples.opcua.server --tls
32+ ```
33+
34+ To start a TLS-encrypted server with username/password authentication (port 4843):
35+
36+ ``` python
37+ from examples.opcua import OPCUATLSAuthSim
38+ import synnax as sy
39+
40+ sim = OPCUATLSAuthSim(rate = 50 * sy.Rate.HZ )
41+ sim.start()
2642```
2743
2844This server simulates:
@@ -33,8 +49,8 @@ This server simulates:
3349- ** Boolean variables** (my_bool_0, my_bool_1): Square wave patterns
3450- ** Command variables** (command_0, command_1, command_2): Writable float values
3551
36- The server runs on ` opc.tcp://127.0.0.1:4841/ ` by default and prints node IDs on
37- startup.
52+ The server runs on ` opc.tcp://127.0.0.1:4841/ ` by default (port 4842 with ` --tls ` , port
53+ 4843 for TLS with username/password) and prints node IDs on startup.
3854
3955### 2. Connect Your OPC UA Server
4056
@@ -44,24 +60,40 @@ Register your OPC UA server with Synnax:
4460uv run python examples/opcua/connect_server.py
4561```
4662
63+ To connect a TLS-encrypted server (Basic256Sha256, port 4842):
64+
65+ ``` bash
66+ uv run python examples/opcua/connect_server.py --tls
67+ ```
68+
69+ To connect a TLS-encrypted server with username/password auth (port 4843):
70+
71+ ``` bash
72+ uv run python examples/opcua/connect_server.py --tls-auth
73+ ```
74+
4775This script will:
4876
4977- Check if the server is already registered
5078- Register the server with the embedded Synnax rack
51- - Set up the server configuration
79+ - Set up the server configuration (including security settings and credentials)
5280
5381** Configuration** : Edit the constants at the top of ` connect_server.py ` to match your
5482server:
5583
56- - ` DEVICE_NAME ` : A friendly name for your OPC UA server
57- - ` ENDPOINT ` : OPC UA endpoint URL (e.g., ` opc.tcp://127.0.0.1:4841/ ` )
84+ - ` PLAIN_DEVICE_NAME ` / ` TLS_DEVICE_NAME ` / ` TLS_AUTH_DEVICE_NAME ` : Friendly names for
85+ your OPC UA servers
86+ - ` PLAIN_ENDPOINT ` / ` TLS_ENDPOINT ` / ` TLS_AUTH_ENDPOINT ` : OPC UA endpoint URLs
87+ - ` TLS_AUTH_USERNAME ` / ` TLS_AUTH_PASSWORD ` : Credentials for username/password auth
5888
5989### 3. Read Float Data from OPC UA Nodes
6090
6191Read scalar float values from the server:
6292
6393``` bash
6494uv run python examples/opcua/read_task.py
95+ uv run python examples/opcua/read_task.py --tls
96+ uv run python examples/opcua/read_task.py --tls-auth
6597```
6698
6799This example:
@@ -74,14 +106,16 @@ This example:
74106** What you'll see** : Real-time sine wave values from my_float_0 and my_float_1.
75107
76108** Node IDs** : The example uses node IDs like ` NS=2;I=8 ` to identify OPC UA variables.
77- These IDs are printed by ` server_extended .py` on startup.
109+ These IDs are printed by ` server .py` on startup.
78110
79111### 4. Read Array Data from OPC UA Nodes
80112
81113Read array data in high-performance array mode:
82114
83115``` bash
84116uv run python examples/opcua/read_task_array.py
117+ uv run python examples/opcua/read_task_array.py --tls
118+ uv run python examples/opcua/read_task_array.py --tls-auth
85119```
86120
87121This example:
@@ -103,6 +137,8 @@ Read boolean (digital) values from the server:
103137
104138``` bash
105139uv run python examples/opcua/read_task_boolean.py
140+ uv run python examples/opcua/read_task_boolean.py --tls
141+ uv run python examples/opcua/read_task_boolean.py --tls-auth
106142```
107143
108144This example:
@@ -122,6 +158,8 @@ Send commands to writable OPC UA nodes:
122158
123159``` bash
124160uv run python examples/opcua/write_task.py
161+ uv run python examples/opcua/write_task.py --tls
162+ uv run python examples/opcua/write_task.py --tls-auth
125163```
126164
127165This example:
@@ -142,6 +180,8 @@ When finished, remove the server registration:
142180
143181``` bash
144182uv run python examples/opcua/delete_server.py
183+ uv run python examples/opcua/delete_server.py --tls
184+ uv run python examples/opcua/delete_server.py --tls-auth
145185```
146186
147187This will remove the server and all associated tasks from Synnax.
@@ -232,8 +272,40 @@ OPC UA supports various security policies:
232272- ** Aes128-Sha256-RsaOaep** : High security
233273- ** Aes256-Sha256-RsaPss** : Highest security
234274
235- ** Note** : The current examples use ` SecurityPolicy.None ` for simplicity. For production
236- deployments, configure security in ` device_props() ` .
275+ ### TLS Test Server
276+
277+ The included test server supports TLS encryption via the ` OPCUATLSSim ` class, which runs
278+ on port 4842 with ` Basic256Sha256_SignAndEncrypt ` . Self-signed certificates for both
279+ server and client are generated automatically under ` examples/opcua/certificates/ ` .
280+
281+ ``` python
282+ from examples.opcua import OPCUATLSSim
283+
284+ sim = OPCUATLSSim()
285+ sim.start() # Starts TLS server on opc.tcp://127.0.0.1:4842/
286+ sim.stop()
287+ ```
288+
289+ ### TLS Test Server with Username/Password
290+
291+ The ` OPCUATLSAuthSim ` class adds username/password authentication on top of TLS
292+ encryption. It runs on port 4843 with ` Basic256Sha256_SignAndEncrypt ` and requires
293+ credentials (` testuser ` / ` testpass ` ).
294+
295+ ``` python
296+ from examples.opcua import OPCUATLSAuthSim
297+
298+ sim = OPCUATLSAuthSim()
299+ sim.start() # Starts on opc.tcp://127.0.0.1:4843/
300+ sim.stop()
301+ ```
302+
303+ All three server variants expose the same full set of variables (floats, bools, arrays,
304+ commands, timestamps).
305+
306+ ** Note** : The default ` OPCUASim ` uses no encryption for simplicity. For production
307+ deployments, configure security mode, policy, and credentials when registering the
308+ device.
237309
238310## Sample Rates
239311
0 commit comments