@@ -76,7 +76,7 @@ def get_security_level(self):
7676 return LiveObjects .SSL if self ._wifi_tls_capability else LiveObjects .NONE
7777
7878 def get_client_id (self ):
79- return self .get_lang_str () + 'MQTT'
79+ return self .get_lang_str () + 'MQTT_' + get_pycom_mac ()
8080
8181
8282class GPy (BoardsInterface ):
@@ -104,7 +104,11 @@ def get_security_level(self):
104104 return LiveObjects .SSL if self ._lte_tls_capability else LiveObjects .NONE
105105
106106 def get_client_id (self ):
107- return self .get_lang_str () + 'MQTT'
107+ if self ._net_type == BoardsInterface .WIFI :
108+ return self .get_lang_str () + 'MQTT_' + get_pycom_mac ()
109+ elif self ._net_type == BoardsInterface .LTE :
110+ return self .get_lang_str () + 'MQTT_' + get_pycom_imei ()
111+
108112
109113class Esp8266 (BoardsInterface ):
110114 def __init__ (self , net_type ):
@@ -122,7 +126,7 @@ def get_security_level(self):
122126 return LiveObjects .SSL if self ._wifi_tls_capability else LiveObjects .NONE
123127
124128 def get_client_id (self ):
125- return self .get_lang_str () + 'MQTT'
129+ return self .get_lang_str () + 'MQTT_' + get_esp_mac ()
126130
127131
128132class Win32 (BoardsInterface ):
@@ -149,8 +153,7 @@ def get_store_cert_filename(self):
149153 sys .exit ()
150154
151155 def get_client_id (self ):
152- import uuid
153- return self .get_lang_str () + 'MQTT_' + ('' .join (['{:02x}' .format ((uuid .getnode () >> ele ) & 0xff ) for ele in range (0 ,8 * 6 ,8 )][::- 1 ]))
156+ return self .get_lang_str () + 'MQTT_' + get_mac ()
154157
155158
156159class Esp32 (BoardsInterface ):
@@ -169,7 +172,7 @@ def get_security_level(self):
169172 return LiveObjects .SSL if self ._wifi_tls_capability else LiveObjects .NONE
170173
171174 def get_client_id (self ):
172- return self .get_lang_str () + 'MQTT'
175+ return self .get_lang_str () + 'MQTT_' + get_esp_mac ()
173176
174177
175178class Linux (BoardsInterface ):
@@ -192,8 +195,7 @@ def get_store_cert_filename(self):
192195 return self ._cert_store_filename
193196
194197 def get_client_id (self ):
195- import uuid
196- return self .get_lang_str () + 'MQTT_' + ('' .join (['{:02x}' .format ((uuid .getnode () >> ele ) & 0xff ) for ele in range (0 ,8 * 6 ,8 )][::- 1 ]))
198+ return self .get_lang_str () + 'MQTT_' + get_mac ()
197199
198200
199201class BoardsFactory :
@@ -209,10 +211,15 @@ def use_existing_network_connection():
209211 print ('Using existing network connection' )
210212
211213
214+ def get_mac ():
215+ import uuid
216+ return '' .join (['{:02x}' .format ((uuid .getnode () >> ele ) & 0xff ) for ele in range (0 , 8 * 6 , 8 )][::- 1 ]).upper ()
217+
218+
212219def wifi_connect (ssid , password ):
213- import network
220+ from network import WLAN , STA_IF
214221
215- sta_if = network . WLAN (network . STA_IF )
222+ sta_if = WLAN (STA_IF )
216223 sta_if .active (True )
217224 while not sta_if .isconnected ():
218225 print ('Connecting to network...' )
@@ -223,6 +230,12 @@ def wifi_connect(ssid, password):
223230 print ('Network config:' , sta_if .ifconfig ())
224231
225232
233+ def get_esp_mac ():
234+ from network import WLAN
235+ import binascii
236+ return binascii .hexlify (WLAN ().config ('mac' )).decode ('ascii' ).upper ()
237+
238+
226239CONN_TIMEOUT = 20
227240
228241
@@ -245,8 +258,13 @@ def pycom_wifi_connect(ssid, password, hostname):
245258 break
246259
247260
248- def lte_connect (pin ):
261+ def get_pycom_mac ():
262+ from network import WLAN
263+ import binascii
264+ return binascii .hexlify (WLAN ().mac ()[0 ]).decode ('ascii' ).upper ()
249265
266+
267+ def lte_connect (pin ):
250268 from network import LTE
251269
252270 def is_sim_waiting_for_pin ():
@@ -274,3 +292,8 @@ def is_sim_waiting_for_pin():
274292 while not lte .isconnected ():
275293 time .sleep (1 )
276294 print ("connected!" )
295+
296+
297+ def get_pycom_imei ():
298+ from network import LTE
299+ return LTE ().imei ()
0 commit comments