The OPC UA server is configured via a JSON file (tags_config.json) that defines all tags, their data types, and simulation behavior.
{
"TagName": {
"type": "float|int|string|bool",
"initial_value": <value>,
"simulate": true|false,
"simulation_type": "random|increment|sine|static",
"description": "Tag description",
... additional parameters...
}
}| Parameter | Type | Description |
|---|---|---|
type |
string | Data type: float, int, string, or bool |
initial_value |
varies | Starting value for the tag |
| Parameter | Type | Default | Description |
|---|---|---|---|
simulate |
boolean | false |
Enable value simulation |
simulation_type |
string | "random" |
Simulation mode |
description |
string | "" |
Tag description |
Generates random values within a specified range.
Parameters:
min(number): Minimum valuemax(number): Maximum value
Example:
{
"Temperature": {
"type": "float",
"initial_value": 20.0,
"simulate": true,
"simulation_type": "random",
"min": 15.0,
"max": 25.0
}
}Increments value by a fixed amount each update.
Parameters:
increment(number): Amount to add each updatemax(number, optional): Maximum value before rolloverreset_on_max(boolean, optional): Reset to min when max reached
Example:
{
"Counter": {
"type": "int",
"initial_value": 0,
"simulate": true,
"simulation_type": "increment",
"increment": 1,
"max": 1000,
"reset_on_max": true
}
}Generates values following a sine wave pattern.
Parameters:
amplitude(number): Wave amplitudeoffset(number): Center point of waveperiod(number): Period in seconds
Example:
{
"Level": {
"type": "float",
"initial_value": 50.0,
"simulate": true,
"simulation_type": "sine",
"amplitude": 30.0,
"offset": 50.0,
"period": 60
}
}Tag value remains constant unless written to.
Example:
{
"Status": {
"type": "string",
"initial_value": "Running",
"simulate": false
}
}Floating-point numbers with decimal precision.
{
"Pressure": {
"type": "float",
"initial_value": 101.325
}
}Whole numbers only.
{
"Count": {
"type": "int",
"initial_value": 0
}
}Text values.
{
"Message": {
"type": "string",
"initial_value": "System OK"
}
}True/False values.
{
"AlarmActive": {
"type": "bool",
"initial_value": false
}
}The server can be configured via environment variables:
| Variable | Default | Description |
|---|---|---|
UPDATE_INTERVAL |
2 |
Tag update interval in seconds |
OPC_ENDPOINT |
opc.tcp://0.0.0.0:4840/freeopcua/server/ |
OPC UA endpoint |
OPC_SERVER_NAME |
Python OPC UA Server |
Server name |
OPC_DEVICE_NAME |
EdgeDevice |
Device/folder name |
OPC_NAMESPACE |
http://opcua.edge.server |
OPC UA namespace |
In systemd service:
[Service]
Environment="UPDATE_INTERVAL=5"
Environment="OPC_DEVICE_NAME=Tank1"In command line:
UPDATE_INTERVAL=5 python3 opcua_server.pyIn LXC container:
lxc exec opcua-server -- systemctl edit opcua-server
# Add Environment variablespython3 opcua_server.py --help
Options:
-c, --config CONFIG Path to config file (default: tags_config. json)
-l, --log-level LEVEL Logging level: DEBUG, INFO, WARNING, ERROR
-i, --interval SECONDS Update interval in secondsExamples:
# Use custom config file
python3 opcua_server.py -c my_tags.json
# Enable debug logging
python3 opcua_server.py -l DEBUG
# Set 5 second update interval
python3 opcua_server.py -i 5
# Combine options
python3 opcua_server.py -c custom. json -l INFO -i 1See config/example_tags_manufacturing.json
See config/example_tags_process_control.json
See config/example_tags_simple.json
- Use descriptive tag names: Makes debugging easier
- Add descriptions: Document what each tag represents
- Set realistic ranges: Match real-world sensor ranges
- Use appropriate data types: Don't use float for counters
- Test configuration: Use
--log-level DEBUGto verify tags load correctly
- Check
"simulate": trueis set - Verify
simulation_typeis valid - Check logs:
journalctl -u opcua-server -f
- Validate JSON syntax (use jsonlint. com)
- Check for trailing commas
- Ensure all brackets/braces are closed
- Ensure
initial_valuematchestype - Check min/max values are correct type
- Review logs for specific error messages