--- a/connectors/WAMP/__init__.py Fri Feb 21 14:20:04 2025 +0100
+++ b/connectors/WAMP/__init__.py Wed Mar 12 13:19:11 2025 +0100
@@ -185,9 +185,12 @@
_WampConnection = threads.blockingCallFromThread(
reactor, RegisterWampClient)
if not _WampConnectEvent.wait(4):
- threads.blockingCallFromThread(
- reactor, _WampConnection.stopConnecting)
confnodesroot.logger.write_error("WAMP connection timeout\n")
+ threads.blockingCallFromThread( + reactor, _WampConnection.stopConnecting) --- a/runtime/WampClient.py Fri Feb 21 14:20:04 2025 +0100
+++ b/runtime/WampClient.py Wed Mar 12 13:19:11 2025 +0100
@@ -33,7 +33,7 @@
from autobahn.wamp.serializer import MsgPackSerializer
from twisted.internet.protocol import ReconnectingClientFactory
from twisted.python.components import registerAdapter
-from twisted.internet.ssl import optionsForClientTLS
+from twisted.internet.ssl import optionsForClientTLS, VerificationError from twisted.internet._sslverify import OpenSSLCertificateAuthorities
from OpenSSL import crypto
@@ -42,6 +42,7 @@
from nevow import tags, url, static
from runtime import GetPLCObjectSingleton
from runtime.Stunnel import getPSKID
+from runtime.loglevels import LogLevelsDict mandatoryConfigItems = ["ID", "active", "realm", "url"]
@@ -136,6 +137,8 @@
def onJoin(self, details):
+ GetPLCObjectSingleton().LogMessage(LogLevelsDict["INFO"], + 'WAMP session joined for: '+self.config.extra["ID"]) ID = self.config.extra["ID"]
@@ -154,10 +157,10 @@
- print('WAMP session joined (%s) by: %s' % (time.ctime(), ID))
def onLeave(self, details):
global _WampSession, _transportFactory
+ GetPLCObjectSingleton().LogMessage(LogLevelsDict["INFO"], + 'WAMP session left for: {} reason: "{}" message: "{}"'.format(self.config.extra["ID"], details.reason, details.message)) @@ -198,17 +201,31 @@
return ReconnectingClientFactory.buildProtocol(self, addr)
+ def _clientConnectionLostOrFailed(self, connector, reason): + """ report connection lost """ + if not reason.check(VerificationError): + GetPLCObjectSingleton().LogMessage(LogLevelsDict["WARNING"], + "WAMP TLS certificate verification failed: "+\ + reason.getErrorMessage()+ + "\nProvide a certicate on web interface or as wampTrustStore.crt in project files.") + GetPLCObjectSingleton().LogMessage(LogLevelsDict["WARNING"], + "WAMP connection lost: "+reason.getErrorMessage()) def clientConnectionFailed(self, connector, reason):
print("WAMP Client connection failed (%s) .. retrying .." %
super(ReconnectingWampWebSocketClientFactory,
self).clientConnectionFailed(connector, reason)
+ self._clientConnectionLostOrFailed(connector, reason) def clientConnectionLost(self, connector, reason):
print("WAMP Client connection lost (%s) .. retrying .." %
super(ReconnectingWampWebSocketClientFactory,
self).clientConnectionFailed(connector, reason)
+ self._clientConnectionLostOrFailed(connector, reason) def CheckConfiguration(WampClientConf):
@@ -328,7 +345,7 @@
reactor.callInThread(_RegisterWampClient)
def _RegisterWampClient():
+ global _WampSecret, _transportFactory WampClientConf = GetConfiguration()
WampClientConf["secret"] = _WampSecret
@@ -357,9 +374,11 @@
connectWS(_transportFactory, contextFactory)
print("WAMP client connecting to :", WampClientConf["url"])
- print("WAMP client can not connect to :", WampClientConf["url"])
+ GetPLCObjectSingleton().LogMessage(LogLevelsDict["WARNING"], + "WAMP configuration invalid:", WampClientConf["url"]) def MakeSecureContextFactory(verifyHostname):
+ global _transportFactory