--- a/Beremiz_service.py Wed May 09 09:59:53 2018 +0200
+++ b/Beremiz_service.py Mon May 14 08:45:44 2018 +0200
@@ -618,9 +618,9 @@
- _wampconf = WC.LoadWampClientConf(wampconf)
+ WC.SetServer(pyroserver, wampconf, wampsecret) + _wampconf = WC.LoadWampClientConf() - WC.SetServer(pyroserver, wampconf, wampsecret)
if _wampconf.get("url", False) and _wampconf.get("active", False): # TODO : test more ?
--- a/runtime/WampClient.py Wed May 09 09:59:53 2018 +0200
+++ b/runtime/WampClient.py Mon May 14 08:45:44 2018 +0200
@@ -177,34 +177,43 @@
-def LoadWampClientConf(wampconf):
+def LoadWampClientConf(items=None): - WSClientConf = json.load(open(wampconf))
+ WSClientConf = json.load(open(_WampConf)) + if items and isinstance(items, list): + wampconf_value = WSClientConf.get(item, None) + if wampconf_value is not None: + WSClientConfItems[item] = wampconf_value + return WSClientConfItems print(_("WAMP load error: "), ve)
+ print(_("WAMP load error: "), e) -def SaveWampClientConf(wampconf, url, active):
+def SaveWampClientConf(items): - WSClientConf = LoadWampClientConf(wampconf)
- oldUrl = WSClientConf.get('url', None)
- WSClientConf['url'] = url
+ WSClientConf = LoadWampClientConf() + for itemKey in items.keys(): + wampconf_value = WSClientConf.get(itemKey, None) + if (wampconf_value is not None) and (items[itemKey] is not None) and (wampconf_value != items[itemKey]): + WSClientConf[itemKey] = items[itemKey] - oldActive = WSClientConf.get('active', False)
- if oldActive != active:
- WSClientConf['active'] = active
- with open(os.path.realpath(wampconf), 'w') as f:
- json.dump(WSClientConf, f)
+ with open(os.path.realpath(_WampConf), 'w') as f: + json.dump(WSClientConf, f, sort_keys=True, indent=4) + if 'active' in WSClientConf and WSClientConf['active']: + StartReconnectWampClient() + StopReconnectWampClient() @@ -232,11 +241,13 @@
-def RegisterWampClient(wampconf = None, secretfname = None):
+def RegisterWampClient(wampconf=None, secretfname=None): - WSClientConf = LoadWampClientConf(wampconf)
+ WSClientConf = LoadWampClientConf() - WSClientConf = LoadWampClientConf(_WampConf)
+ WSClientConf = LoadWampClientConf() print(_("WAMP client connection not established!"))
@@ -272,43 +283,34 @@
# start the client from a Twisted endpoint
conn = connectWS(transport_factory)
print(_("WAMP client connecting to :"), WSClientConf["url"])
def StopReconnectWampClient():
_transportFactory.stopTrying()
return _WampSession.leave()
def StartReconnectWampClient():
_WampSession.disconnect()
-def ReconnectionWampClient(active, url):
- """ReconnectionWampClient function used for reconnecting to Crossbar router.
- active (bool): Value in wampconf.json file. True: using Wamp connection. False: not using Wamp connection.
- url (str): Value in wampconf.json file. Url of Crossbar router.
- SaveWampClientConf(_WampConf, url, active)
- StartReconnectWampClient()
- elif not active and _WampSession:
- StopReconnectWampClient()
return _WampSession and _WampSession.is_attached()
-def SetServer(pysrv, wampconf = None, wampsecret = None):
+def SetServer(pysrv, wampconf=None, wampsecret=None): global _PySrv, _WampConf, _WampSecret
--- a/tests/wamp/project_files/wampconf.json Wed May 09 09:59:53 2018 +0200
+++ b/tests/wamp/project_files/wampconf.json Mon May 14 08:45:44 2018 +0200
@@ -1,10 +1,17 @@
- "url":"ws://127.0.0.1:8888",
- "password":"1234567890",
- "protocolOptions":{"autoPingTimeout":20, "autoPingInterval":60},
- "registerOptions":{"match":"exact", "invoke":"last", "concurrency": 2}
+ "password": "1234567890", + "autoPingInterval": 60, + "url": "ws://127.0.0.1:8888"