@@ -111,6 +111,8 @@ def enable_error_codes(self):
111111 def at_command (self , at_command : str , wait_for_result = False , suppress_errors = False ):
112112 """Write an AT command to the command interface. Optionally wait for OK"""
113113
114+ self .comms .reset_input_buffer ()
115+
114116 if self .shell :
115117 # Transform line endings to match shell expectations
116118 at_command = at_command .replace ("\r " , "" )
@@ -133,12 +135,14 @@ def delete_credential(self, sectag: int, cred_type: int):
133135
134136 def check_credential_exists (self , sectag : int , cred_type : int , get_hash = True ):
135137 self .at_command (f'AT%CMNG=1,{ sectag } ,{ cred_type } ' )
136- retval , res = self .comms .expect_response ("OK" , "ERROR" , "%CMNG" )
137- if retval and res :
138+ retval , output = self .comms .expect_response ("OK" , "ERROR" , "%CMNG: " )
139+ # get the last line of the response
140+ output = [x .strip () for x in output .split ("\n " ) if x .strip ()][- 1 ]
141+ if retval and output :
138142 if not get_hash :
139143 return True , None
140144 else :
141- return True , self ._parse_sha (res )
145+ return True , self ._parse_sha (output )
142146
143147 return False , None
144148
@@ -152,20 +156,26 @@ def go_offline(self):
152156 def get_imei (self ):
153157 self .at_command ('AT+CGSN' )
154158 retval , output = self .comms .expect_response ("OK" , "ERROR" , "" )
159+ # get the last line of the response
160+ output = [x .strip () for x in output .split ("\n " ) if x .strip ()][- 1 ]
155161 if not retval :
156162 return None
157163 return output [:IMEI_LEN ]
158164
159165 def get_model_id (self ):
160166 self .at_command ('AT+CGMM' )
161167 retval , output = self .comms .expect_response ("OK" , "ERROR" , "" )
168+ # get the last line of the response
169+ output = [x .strip () for x in output .split ("\n " ) if x .strip ()][- 1 ]
162170 if not retval :
163171 return None
164172 return output
165173
166174 def get_mfw_version (self ):
167175 self .at_command ('AT+CGMR' )
168176 retval , output = self .comms .expect_response ("OK" , "ERROR" , "" )
177+ # get the last line of the response
178+ output = [x .strip () for x in output .split ("\n " ) if x .strip ()][- 1 ]
169179 if not retval :
170180 return None
171181 return output
0 commit comments