Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
slapos
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Levin Zimmermann
slapos
Commits
664bbd62
Commit
664bbd62
authored
Mar 09, 2023
by
Levin Zimmermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
component/opcua-server: make configurable
parent
753d06ad
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
26 additions
and
31 deletions
+26
-31
component/opcua-server/buildout.cfg
component/opcua-server/buildout.cfg
+21
-29
stack/erp5/buildout.hash.cfg
stack/erp5/buildout.hash.cfg
+1
-1
stack/erp5/instance-opcua-server.cfg.in
stack/erp5/instance-opcua-server.cfg.in
+4
-1
No files found.
component/opcua-server/buildout.cfg
View file @
664bbd62
...
...
@@ -12,46 +12,38 @@ egg-versions =
python-dateutil = 2.8.2:whl
entry-points = ${:_buildout_section_name_}=__main__:main
initialization =
import sys
ip = sys.argv[1]
port = 2262 # hard coded here + in stack/erp5/haproxy.cfg.in
# Adjusted minimal server example from opcua-asyncio documentation
# https://opcua-asyncio.readthedocs.io/en/latest/usage/get-started/minimal-server.html
# ######################
# Configure
import argparse
parser = argparse.ArgumentParser(description='Run OPCUA Server.')
parser.add_argument(
'--ip', help='The IP address on which the OPCUA Server runs', default="127.0.0.1"
)
parser.add_argument(
'--port', help='The port on which the OPCUA Server runs', default="2262"
)
parser.add_argument(
'--xml',
help='Path of XML to configure Server. See asyncua doc for more details.',
default=None
)
args = parser.parse_args()
ip, port, xml = args.ip, args.port, args.xml
# ######################
import asyncio
import logging
from asyncua import Server, ua
from asyncua.common.methods import uamethod
@uamethod
def func(parent, value):
return value * 2
from asyncua import Server
async def main():
_logger = logging.getLogger(__name__)
# setup our server
server = Server()
await server.init()
server.set_endpoint(f"tcp://{ip}:{port}")
# setup our own namespace, not really necessary but should as spec
uri = "http://examples.freeopcua.github.io"
idx = await server.register_namespace(uri)
# populating our address space
# server.nodes, contains links to very common nodes like objects and root
myobj = await server.nodes.objects.add_object(idx, "MyObject")
myvar = await myobj.add_variable(idx, "MyVariable", 6.7)
# Set MyVariable to be writable by clients
await myvar.set_writable()
await server.nodes.objects.add_method(
ua.NodeId("ServerMethod", idx),
ua.QualifiedName("ServerMethod", idx),
func,
[ua.VariantType.Int64],
[ua.VariantType.Int64],
)
if xml is not None:
await server.import_xml(xml)
_logger.info("Starting server!")
async with server:
while True:
await asyncio.sleep(1)
new_val = await myvar.get_value() + 0.1
_logger.info("Set value of %s to %.1f", myvar, new_val)
await myvar.write_value(new_val)
logging.basicConfig(level=logging.DEBUG)
asyncio.run(main(), debug=True)
stack/erp5/buildout.hash.cfg
View file @
664bbd62
...
...
@@ -106,4 +106,4 @@ md5sum = eb4be2669a9a56187cc4366272e11d18
[instance-opcua-server.cfg.in]
filename = instance-opcua-server.cfg.in
md5sum =
aeb48d87bac998402aba6ca829d62466
md5sum =
207b458e52de1a038af807274345b5ff
stack/erp5/instance-opcua-server.cfg.in
View file @
664bbd62
{% set ipv4 = (ipv4_set | list)[0] -%}
{# port is hard coded here + in stack/erp5/haproxy.cfg.in #}
{% set port = 2262 %}
[buildout]
extends = {{ template_monitor }}
...
...
@@ -18,5 +20,6 @@ var = ${buildout:directory}/var
[opcua-server]
recipe = slapos.cookbook:wrapper
command-line = {{ bin_directory }}/opcua-server {{ ipv4 }}
command-line =
{{ bin_directory }}/opcua-server --ip {{ ipv4 }} --port {{ port }}
wrapper-path = ${directory:service-on-watch}/opcua-server
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment