Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
O
opcua-asyncio
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
1
Merge Requests
1
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
opcua-asyncio
Commits
08da848c
Commit
08da848c
authored
Nov 07, 2022
by
oroulet
Committed by
oroulet
Nov 08, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add example to reconnecto to server automicatically from client
parent
bc7338f6
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
62 additions
and
0 deletions
+62
-0
examples/client-reconnect.py
examples/client-reconnect.py
+62
-0
No files found.
examples/client-reconnect.py
0 → 100644
View file @
08da848c
import
logging
import
asyncio
from
asyncua
import
Client
,
ua
,
Node
_logger
=
logging
.
getLogger
(
"asyncua"
)
url
=
"opc.tcp://localhost:4840/freeopcua/server/"
namespace
=
"http://examples.freeopcua.github.io"
class
SubHandler
:
"""
Subscription Handler. To receive events from server for a subscription
This class is just a sample class. Whatever class having these methods can be used
"""
def
datachange_notification
(
self
,
node
:
Node
,
val
,
data
):
"""
called for every datachange notification from server
"""
_logger
.
info
(
"datachange_notification %r %s"
,
node
,
val
)
pass
def
event_notification
(
self
,
event
:
ua
.
EventNotificationList
):
"""
called for every event notification from server
"""
pass
def
status_change_notification
(
self
,
status
:
ua
.
StatusChangeNotification
):
"""
called for every status change notification from server
"""
pass
async
def
main
():
handler
=
SubHandler
()
while
True
:
client
=
Client
(
url
=
"opc.tcp://localhost:4840/freeopcua/server/"
)
client
=
Client
(
url
=
"opc.tcp://localhost:53530/OPCUA/SimulationServer/"
)
try
:
async
with
client
:
_logger
.
warning
(
"Connected"
)
...
subscription
=
await
client
.
create_subscription
(
500
,
handler
)
node
=
(
client
.
get_node
(
ua
.
ObjectIds
.
Server_ServerStatus_CurrentTime
),)
await
subscription
.
subscribe_data_change
(
node
)
while
1
:
await
asyncio
.
sleep
(
1
)
await
client
.
check_connection
()
# Throws a exception if connection is lost
except
(
ConnectionError
,
ua
.
UaError
):
_logger
.
warning
(
"Reconnecting in 2 seconds"
)
await
asyncio
.
sleep
(
2
)
if
__name__
==
"__main__"
:
logging
.
basicConfig
(
level
=
logging
.
INFO
)
asyncio
.
run
(
main
())
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