@@ -257,7 +257,9 @@ def open_connection(self, host=None, port=None, cid=0):
257257 ]
258258
259259 if result ["status" ] == Status .SUCCESS :
260- result = self .atcom .get_urc_response (desired_response , fault_responses , timeout = 60 )
260+ result = self .atcom .get_urc_response (
261+ desired_response , fault_responses , timeout = 60
262+ )
261263 return result
262264 return {"status" : Status .ERROR , "response" : "Missing parameters : host" }
263265
@@ -301,15 +303,17 @@ def close_connection(self, cid=0):
301303 result = self .atcom .get_urc_response (desired_response , timeout = 60 )
302304 return result
303305
304- def connect_broker (self , client_id_string = "PicoLTE" , username = None , password = None , cid = 0 ):
306+ def connect_broker (
307+ self , client_id_string = None , username = None , password = None , cid = 0
308+ ):
305309 """
306310 Function for connecting to MQTT broker. This function is used when a client requests a
307311 connection to the MQTT server. When a TCP/IP socket connection is established between
308312 a client and a server, a protocol level session must be created using a CONNECT flow.
309313
310314 Parameters
311315 ----------
312- client_id_string : str, default: "PicoLTE"
316+ client_id_string : str, default: None
313317 Client ID string. Maximum length: 23 bytes.
314318 username : str, default: None
315319 Username. Maximum length: 23 bytes.
@@ -327,6 +331,9 @@ def connect_broker(self, client_id_string="PicoLTE", username=None, password=Non
327331 username = get_parameter (["mqtts" , "username" ])
328332 password = get_parameter (["mqtts" , "password" ])
329333
334+ if client_id_string is None :
335+ client_id_string = get_parameter (["mqtts" , "client_id" ], "PicoLTE" )
336+
330337 if username and password :
331338 command = f'AT+QMTCONN={ cid } ,"{ client_id_string } ","{ username } ","{ password } "'
332339 else :
@@ -337,7 +344,9 @@ def connect_broker(self, client_id_string="PicoLTE", username=None, password=Non
337344 if result ["status" ] == Status .SUCCESS :
338345 desired_response = f"+QMTCONN: { cid } ,0,0"
339346 fault_responses = [f"QMTSTAT: 0,{ err_code } " for err_code in range (1 , 8 )]
340- result = self .atcom .get_urc_response (desired_response , fault_responses , timeout = 60 )
347+ result = self .atcom .get_urc_response (
348+ desired_response , fault_responses , timeout = 60
349+ )
341350 return result
342351
343352 def is_connected_to_broker (self , cid = 0 ):
@@ -436,7 +445,9 @@ def unsubscribe_topic(self, topic, cid=0, message_id=1):
436445 command = f'AT+QMTUNS={ cid } ,{ message_id } ,"{ topic } "'
437446 return self .atcom .send_at_comm (command )
438447
439- def publish_message (self , payload , topic = None , qos = 1 , retain = 0 , message_id = 1 , cid = 0 ):
448+ def publish_message (
449+ self , payload , topic = None , qos = None , retain = 0 , message_id = 1 , cid = 0
450+ ):
440451 """
441452 Function for publishing MQTT message. This function is used when a client requests
442453 a message to be published. This method uses data mode of the modem to send the message.
@@ -473,13 +484,18 @@ def publish_message(self, payload, topic=None, qos=1, retain=0, message_id=1, ci
473484 if topic is None :
474485 topic = get_parameter (["mqtts" , "pub_topic" ])
475486
487+ if qos is None :
488+ qos = get_parameter (["mqtts" , "pub_qos" ], 1 )
489+
476490 if payload and topic :
477491 command = f'AT+QMTPUB={ cid } ,{ message_id } ,{ qos } ,{ retain } ,"{ topic } "'
478492 result = self .atcom .send_at_comm (command , ">" , urc = True )
479493
480494 if result ["status" ] == Status .SUCCESS :
481495 self .atcom .send_at_comm_once (payload , line_end = False ) # Send message
482- result = self .atcom .send_at_comm (self .CTRL_Z ) # Send end char --> CTRL+Z
496+ result = self .atcom .send_at_comm (
497+ self .CTRL_Z
498+ ) # Send end char --> CTRL+Z
483499 return result
484500 return {"response" : "Missing parameter" , "status" : Status .ERROR }
485501
0 commit comments