Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
osie
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
Nikola Balog
osie
Commits
72421950
Commit
72421950
authored
May 23, 2024
by
Philipp
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
adding client fhi
parent
3ed480ed
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
187 additions
and
28 deletions
+187
-28
opcua-client-fhi/minimal-client.py
opcua-client-fhi/minimal-client.py
+55
-0
opcua-server-fhi/minimal-server.py
opcua-server-fhi/minimal-server.py
+27
-28
slapos/software/opcua-client-fhi/.gitkeep
slapos/software/opcua-client-fhi/.gitkeep
+0
-0
slapos/software/opcua-client-fhi/buildout.hash.cfg
slapos/software/opcua-client-fhi/buildout.hash.cfg
+3
-0
slapos/software/opcua-client-fhi/instance.cfg.in
slapos/software/opcua-client-fhi/instance.cfg.in
+50
-0
slapos/software/opcua-client-fhi/software.cfg
slapos/software/opcua-client-fhi/software.cfg
+52
-0
No files found.
opcua-client-fhi/minimal-client.py
0 → 100644
View file @
72421950
#!//usr/bin/python
"""
Basic client with minimal data
"""
import
logging
import
asyncio
from
asyncua
import
Client
,
ua
import
argparse
# command line handling
parser
=
argparse
.
ArgumentParser
(
description
=
'Run OPCUA Server.'
)
a
=
parser
.
add_argument
a
(
'--ipv6'
,
help
=
'The IPv6 address on which the OPCUA Server runs'
,
default
=
"::"
)
a
(
'--ipv6-enabled'
,
help
=
'The IPv6 address check whether it is enabled or disabled'
,
default
=
"1"
)
a
(
'--port'
,
help
=
'The port on which the OPCUA Server runs'
,
default
=
"4840"
)
a
(
'--xml'
,
help
=
'Path of XML to configure Server. See asyncua doc for more details.'
,
default
=
None
)
args
=
parser
.
parse_args
()
ipv6
=
args
.
ipv6
ipv6
=
"2001:67c:1254:108:404e::a"
ipv6_enabled
=
args
.
ipv6_enabled
port
=
args
.
port
xml
=
args
.
xml
# Server information
if
bool
(
int
(
ipv6_enabled
)):
url
=
"opc.tcp://[{ipv6}]:{port}/PwDC"
#url = "opc.tcp://0.0.0.0:4880/PwDC"
async
def
main
():
_logger
=
logging
.
getLogger
(
__name__
)
_logger
.
info
(
"Connecting to %s ..."
,
url
)
async
with
Client
(
url
=
url
,
timeout
=
2
)
as
client
:
while
True
:
await
asyncio
.
sleep
(
1
)
# Get the root node
#namespace_uri = "http://examples.freeopcua.github.io"
#nsidx = await client.get_namespace_index(namespace_uri)
nsidx
=
1
# Get the Powerfuse object
s
=
"Powerfuse_Maschinenstatus_Status_Rot"
var
=
await
client
.
nodes
.
root
.
get_child
(
f"0:Objects/
{
nsidx
}
:Powerfuse/
{
nsidx
}
:
{
s
}
"
)
value
=
await
var
.
read_value
()
name
=
await
var
.
read_browse_name
()
_logger
.
info
(
f"Value of
{
s
}
(
{
var
}
):
{
value
}
"
)
s
=
"Powerfuse_Maschinenstatus_Status_Gelb"
var
=
await
client
.
nodes
.
root
.
get_child
(
f"0:Objects/
{
nsidx
}
:Powerfuse/
{
nsidx
}
:
{
s
}
"
)
value
=
await
var
.
read_value
()
name
=
await
var
.
read_browse_name
()
_logger
.
info
(
f"Value of
{
s
}
(
{
var
}
):
{
value
}
"
)
if
__name__
==
"__main__"
:
logging
.
basicConfig
(
level
=
logging
.
INFO
)
asyncio
.
run
(
main
())
opcua-server-fhi/minimal-server.py
View file @
72421950
...
...
@@ -17,17 +17,13 @@ a('--ipv6', help='The IPv6 address on which the OPCUA Server runs', default="::"
a
(
'--ipv6-enabled'
,
help
=
'The IPv6 address check whether it is enabled or disabled'
,
default
=
"1"
)
a
(
'--port'
,
help
=
'The port on which the OPCUA Server runs'
,
default
=
"4840"
)
a
(
'--xml'
,
help
=
'Path of XML to configure Server. See asyncua doc for more details.'
,
default
=
None
)
args
=
parser
.
parse_args
()
ipv6
=
args
.
ipv6
ipv6_enabled
=
args
.
ipv6_enabled
port
=
args
.
port
xml
=
args
.
xml
@
uamethod
def
func
(
parent
,
value
):
return
value
*
2
async
def
main
():
_logger
=
logging
.
getLogger
(
__name__
)
# setup our server
...
...
@@ -35,38 +31,41 @@ async def main():
await
server
.
init
()
if
bool
(
int
(
ipv6_enabled
)):
server
.
set_endpoint
(
f"opc.tcp://[
{
ipv6
}
]:
{
port
}
/
freeopcua/server/
"
)
server
.
set_endpoint
(
f"opc.tcp://[
{
ipv6
}
]:
{
port
}
/
PwDC
"
)
if
xml
is
not
None
:
await
server
.
import_xml
(
xml
)
# set up 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
],
)
idx
=
1
# Create an object to hold the variables
objects
=
server
.
get_objects_node
()
powerfuse_obj
=
await
objects
.
add_object
(
idx
,
"Powerfuse"
)
# Create variables
machine_status_rot
=
await
powerfuse_obj
.
add_variable
(
idx
,
"Powerfuse_Maschinenstatus_Status_Rot"
,
False
)
machine_status_gelb
=
await
powerfuse_obj
.
add_variable
(
idx
,
"Powerfuse_Maschinenstatus_Status_Gelb"
,
False
)
# Set the variables as writable
await
machine_status_rot
.
set_writable
()
await
machine_status_gelb
.
set_writable
()
# Start the server
_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
)
# Randomly change the machine status
new_status_rot
=
random
.
choice
([
True
,
False
])
new_status_gelb
=
random
.
choice
([
True
,
False
])
await
machine_status_rot
.
write_value
(
new_status_rot
)
await
machine_status_gelb
.
write_value
(
new_status_gelb
)
val_machine_status_rot
=
await
machine_status_rot
.
get_value
()
val_machine_status_gelb
=
await
machine_status_gelb
.
get_value
()
_logger
.
info
(
"New machine status: Rot=%r, Gelb=%r"
,
val_machine_status_rot
,
val_machine_status_gelb
)
await
asyncio
.
sleep
(
1
)
if
__name__
==
"__main__"
:
logging
.
basicConfig
(
level
=
logging
.
DEBUG
)
asyncio
.
run
(
main
(),
debug
=
True
)
slapos/software/opcua-client-fhi/.gitkeep
0 → 100644
View file @
72421950
slapos/software/opcua-client-fhi/buildout.hash.cfg
0 → 100644
View file @
72421950
[instance-profile]
filename = instance.cfg.in
md5sum = e02dafa3ef034684052c6cdc5da9d09f
slapos/software/opcua-client-fhi/instance.cfg.in
0 → 100644
View file @
72421950
[buildout]
parts =
directory
opcua-xml-url
opcua-client-fhi-service
publish-connection-parameter
eggs-directory = {{ buildout["eggs-directory"] }}
develop-eggs-directory = {{ buildout["develop-eggs-directory"] }}
offline = true
[check-port-listening-promise]
recipe = slapos.cookbook:check_port_listening
path = ${directory:promise}/${:_buildout_section_name_}
[directory]
recipe = slapos.cookbook:mkdirectory
home = ${buildout:directory}
etc = ${:home}/etc
var = ${:home}/var
script = ${:etc}/run/
service = ${:etc}/service
promise = ${:etc}/promise/
log = ${:var}/log
bin = ${:home}/bin
[instance-parameter]
recipe = slapos.cookbook:slapconfiguration
computer = ${slap-connection:computer-id}
partition = ${slap-connection:partition-id}
url = ${slap-connection:server-url}
key = ${slap-connection:key-file}
cert = ${slap-connection:cert-file}
configuration.opcua-xml-url = "https://lab.nexedi.com/Demonkey/osie/raw/philipp_opcua/opcua-to-http-gw/opcua-server-config.xml"
[opcua-xml-url]
recipe = slapos.recipe.build:download
url = https://lab.nexedi.com/Demonkey/osie/raw/philipp_opcua/opcua-to-http-gw/opcua-server-config.xml
offline = false
destination = ${directory:etc}/schema.xml
[opcua-client-fhi-service]
recipe = slapos.cookbook:wrapper
command-line = {{ interpreter_location }}/py {{ osie_repository_location }}/opcua-client-fhi/minimal-client.py --xml ${opcua-xml-url:destination} --port '4840' --ipv6 ${instance-parameter:ipv6-random} --ipv6-enabled '1'
wrapper-path = ${directory:service}/opcua-client-fhi-service
output = $${:wrapper-path}
[publish-connection-parameter]
recipe = slapos.cookbook:publish
ipv6 = ${instance-parameter:ipv6-random}
slapos/software/opcua-client-fhi/software.cfg
0 → 100644
View file @
72421950
[buildout]
extends =
buildout.hash.cfg
https://lab.nexedi.com/nexedi/slapos/raw/master/stack/monitor/buildout.cfg
https://lab.nexedi.com/nexedi/slapos/raw/master/stack/slapos.cfg
https://lab.nexedi.com/nexedi/slapos/raw/master/component/python3/buildout.cfg
https://lab.nexedi.com/nexedi/slapos/raw/master/component/git/buildout.cfg
https://lab.nexedi.com/nexedi/slapos/raw/master/component/python-cryptography/buildout.cfg
https://lab.nexedi.com/nexedi/slapos/raw/master/component/lxml-python/buildout.cfg
parts =
slapos-cookbook
interpreter
osie-repository
instance-profile
[python]
part = python3
[interpreter]
recipe = zc.recipe.egg:script
interpreter = py
eggs =
${lxml-python:egg}
${python-cryptography:egg}
requests
asyncua
[osie-repository]
recipe = slapos.recipe.build:gitclone
git-executable = ${git:location}/bin/git
repository = https://lab.nexedi.com/Demonkey/osie.git
location = ${buildout:parts-directory}/osie
branch = philipp_opcua
[versions]
aiosqlite = 0.17.0
aiofiles = 23.1.0
cryptography = 3.3.2
asyncua = 0.9.2
lxml = 4.9.1
[instance-profile]
recipe = slapos.recipe.template:jinja2
template = ${:_profile_base_location_}/instance.cfg.in
rendered = ${buildout:directory}/instance.cfg
context =
section buildout buildout
key interpreter_location buildout:bin-directory
key osie_repository_location osie-repository:location
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