@@ -31,8 +31,9 @@ def __init__(self, value, type_, cb=None):
3131
3232
3333class Connection :
34- def __init__ (self , board , deviceID , port , apiKey , debug = True ):
35- self .mode = board .get_lang_id ()
34+ def __init__ (self , debug = True ):
35+ self .__board = LiveObjects .BoardsFactory (net_type = LiveObjects .BoardsInterface .DEFAULT_CARRIER )
36+ self .mode = self .__board .get_lang_id ()
3637
3738 try :
3839 if self .mode == LiveObjects .BoardsInterface .PYTHON :
@@ -44,8 +45,9 @@ def __init__(self, board, deviceID, port, apiKey, debug=True):
4445 print ("[ERROR] U have missing libraries Paho-mqtt(for Python) or umqttrobust(for uPython)" )
4546 sys .exit ()
4647
47- self .__port = port
48- self .__apiKey = apiKey
48+ self .__port = self .__board .get_security_level ()
49+ self .__apiKey = self .__board .get_apikey ()
50+ self .__device_id = self .__board .get_client_id ()
4951 self .__parameters = {}
5052 self .__server = "mqtt.liveobjects.orange-business.com"
5153 self .__topic = "dev/data"
@@ -56,7 +58,7 @@ def __init__(self, board, deviceID, port, apiKey, debug=True):
5658 self .quit = False
5759
5860 if self .mode == LiveObjects .BoardsInterface .PYTHON :
59- self .__mqtt = paho .Client (deviceID )
61+ self .__mqtt = paho .Client (self . __device_id )
6062 elif self .mode == LiveObjects .BoardsInterface .MICROPYTHON :
6163
6264 class MQTTClient2 (MQTTClient ):
@@ -99,8 +101,8 @@ def wait_msg(self): # overriding original method wait_msg due to avoid infin
99101 elif op & 6 == 4 :
100102 assert 0
101103
102- self .ssl = port == SSL
103- self .__mqtt = MQTTClient2 (deviceID , self .__server , self .__port , "json+device" ,
104+ self .ssl = self . __port == SSL
105+ self .__mqtt = MQTTClient2 (self . __device_id , self .__server , self .__port , "json+device" ,
104106 self .__apiKey , 0 , self .ssl , {'server_hostname' : self .__server })
105107
106108 def loop (self ):
@@ -148,6 +150,7 @@ def __onConnect(self, client="", userdata="", flags="", rc=""):
148150 self .__sendConfig ()
149151
150152 def connect (self ):
153+ self .__board .connect ()
151154 if self .mode == LiveObjects .BoardsInterface .PYTHON :
152155 self .__mqtt .username_pw_set ("json+device" , self .__apiKey )
153156 self .__mqtt .on_connect = self .__onConnect
0 commit comments