Usage of SimaticAlarmsAndConditions #1471
-
Hello, I'm currently monitoring alarms from a Siemens S7-1500 PLC, but I'm encountering unusual errors in the TIA Portal. Has anyone experienced similar issues? If you've found a more effective solution for monitoring alarms/events from a Siemens PLC, I'd appreciate your insights. The program works and i get all the alarms, but after a few days i get these strange errors. Here is what the python terminal says: WARNING:asyncua.client.client:Revised values returned differ from subscription values: CreateSubscriptionResult(SubscriptionId=3845216731, RevisedPublishingInterval=2000.0, RevisedLifetimeCount=150, RevisedMaxKeepAliveCount=15) Below, I've attached my code and screenshots from both the TIA Portal and UA Expert, where I'm also subscribed. async def subscribe_to_server(adresses: str, username: str, password: str):
"""
Parameters
----------
adresses - The address of the OPC UA server
username - The username to use when connecting to the OPC UA server
password - The password to use when connecting to the OPC UA server
"""
subscribing_params = ua.CreateSubscriptionParameters()
subscribing_params.RequestedPublishingInterval = 2000
subscribing_params.RequestedLifetimeCount = 6000
subscribing_params.RequestedMaxKeepAliveCount = 20
subscribing_params.MaxNotificationsPerPublish = 100
subscribing_params.PublishingEnabled = True
subscribing_params.Priority = 0
client:Client = None
while True:
try:
if client is None:
client = await connect_opcua(adresses, username, password)
await client.check_connection()
handler = SubHandler(adresses)
sub = await client.create_subscription(subscribing_params, handler)
logger_programming.info("Made a new subscription")
alarmConditionType = client.get_node("ns=0;i=2915")
server_node = client.get_node(ua.NodeId(Identifier=2253,
NodeIdType=ua.NodeIdType.Numeric, NamespaceIndex=0))
await sub.subscribe_alarms_and_conditions(server_node,alarmConditionType)
while True:
await asyncio.sleep(0.1)
await client.check_connection()
except (ConnectionError, ua.UaError) as e:
logger_programming.warning(f"{e} Reconnecting in 30 seconds")
if client is not None:
await client.delete_subscriptions(sub)
await client.disconnect()
client = None
await asyncio.sleep(30)
except Exception as e:
logger_programming.error(f"Error connecting or subscribing to server {adresses}: {e}")
if client is not None:
await client.delete_subscriptions(sub)
await client.disconnect()
client = None
await asyncio.sleep(30)
class SubHandler:
"""
Handles the events received from the OPC UA server, and what to do with them.
"""
def __init__(self, address: str):
self.address = address
def status_change_notification(self, status: ua.StatusChangeNotification):
"""
Called when a status change notification is received from the server.
"""
# Handle the status change event. This could be logging the change, raising an alert, etc.
print(f"Status change received from subscription with status: {status}")
logger_opcua_alarm.info(status)
async def event_notification(self, event):
"""
This function is called when an event is received from the OPC UA server.
and saves it to a log file.
returns: the event message
"""
opcua_alarm_message = {
"New event received from": self.address
}
attributes_to_check = [
"Message", "Time", "Severity", "SuppressedOrShelved",
"AckedState", "ConditionClassId", "NodeId", "Quality", "Retain",
"ActiveState", "EnabledState"
]

 |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
Hey Pyroarti, analysis I tend to think that the event subscription is not the problem, since it's using the Publish service from Subscription Service Set. The client is polling the Server Status Node. This task is created when on session creation, in asyncua.client.client.Client.create_session() you can find: suggestion Disclaimer: I am not an expert :) BR, Kevin |
Beta Was this translation helpful? Give feedback.
-
Set Client
|
Beta Was this translation helpful? Give feedback.
Set Client
watchdog_intervall
parameter to a high value. The intervall ofcheck_connection
is not a factor here. Because it only pulls checks if the watchdog task has a error.Client('opc.tcp://127.0.0.1', watchdog_intervall=10.0)