--- a/Beremiz_service.py Wed Apr 18 10:42:33 2018 +0200
+++ b/Beremiz_service.py Thu Apr 19 13:40:56 2018 +0200
@@ -620,11 +620,11 @@
_wampconf = WC.LoadWampClientConf(wampconf)
- WC.SetServer(pyroserver)
- if _wampconf.get("url", None): # TODO : test more ?
- WC.RegisterWampClient(wampconf, wampsecret)
+ WC.SetServer(pyroserver, wampconf, wampsecret) + if _wampconf.get("url", False) and _wampconf.get("active", False): # TODO : test more ? + WC.RegisterWampClient() - raise Exception(_("WAMP config is incomplete."))
+ raise Exception(_("WAMP config is incomplete or active is false.")) raise Exception(_("WAMP config is missing."))
--- a/runtime/WampClient.py Wed Apr 18 10:42:33 2018 +0200
+++ b/runtime/WampClient.py Thu Apr 19 13:40:56 2018 +0200
@@ -39,6 +39,8 @@
@@ -184,6 +186,31 @@
+def SaveWampClientConf(wampconf, url, active): + WSClientConf = LoadWampClientConf(wampconf) + oldUrl = WSClientConf.get('url', None) + WSClientConf['url'] = url + oldActive = WSClientConf.get('active', False) + if oldActive != active: + WSClientConf['active'] = active + with open(os.path.realpath(wampconf), 'w') as f: + json.dump(WSClientConf, f) + print(_("WAMP load error: "), ve) def LoadWampSecret(secretfname):
@@ -203,8 +230,11 @@
-def RegisterWampClient(wampconf, secretfname):
- WSClientConf = LoadWampClientConf(wampconf)
+def RegisterWampClient(wampconf = None, secretfname = None): + WSClientConf = LoadWampClientConf(wampconf) + WSClientConf = LoadWampClientConf(_WampConf) print(_("WAMP client connection not established!"))
@@ -214,7 +244,10 @@
print(_("WAMP url {} is not correct!".format(WSClientConf["url"])))
- WampSecret = LoadWampSecret(secretfname)
+ WampSecret = LoadWampSecret(secretfname) + WampSecret = LoadWampSecret(_WampSecret) if WampSecret is not None:
WSClientConf["secret"] = WampSecret
@@ -240,16 +273,32 @@
-def GetTransportFactory():
- global _transportFactory
- return _transportFactory
+def ReconnectWampClient(active, url): + SaveWampClientConf(_WampConf, url, active) + if not active and _WampSession: + # crossbar connection active is off, retry connection off + _transportFactory.stopTrying() + return _WampSession.leave() + elif _WampSession and active: + _WampSession.disconnect() + elif not _WampSession and active: + # crossbar connection active is on, do connect
+ return _WampSession and _WampSession.is_attached()
+def SetServer(pysrv, wampconf = None, wampsecret = None): + global _PySrv, _WampConf, _WampSecret + _WampSecret = wampsecret