@@ -4143,21 +4143,37 @@ SARA_R5_error_t SARA_R5::readMQTT(int* pQos, String* pTopic, uint8_t *readDest,
4143
4143
free (response);
4144
4144
return SARA_R5_ERROR_UNEXPECTED_RESPONSE;
4145
4145
}
4146
+
4147
+ err = SARA_R5_ERROR_SUCCESS;
4146
4148
searchPtr = strstr (searchPtr, " \" " );
4147
- if (pTopic) {
4148
- searchPtr[topic_length+1 ] = ' \0 ' ; // zero terminate
4149
- *pTopic = searchPtr+1 ;
4150
- searchPtr[topic_length+1 ] = ' \" ' ; // restore
4151
- }
4152
- searchPtr = strstr (searchPtr + topic_length + 2 , " \" " );
4153
- if (readDest) {
4154
- *bytesRead = (data_length > readLength) ? readLength : data_length;
4155
- memcpy (readDest, searchPtr+1 , *bytesRead);
4149
+ if (searchPtr!= NULL ) {
4150
+ if (pTopic) {
4151
+ searchPtr[topic_length + 1 ] = ' \0 ' ; // zero terminate
4152
+ *pTopic = searchPtr + 1 ;
4153
+ searchPtr[topic_length + 1 ] = ' \" ' ; // restore
4154
+ }
4155
+ searchPtr = strstr (searchPtr + topic_length + 2 , " \" " );
4156
+ if (readDest && (searchPtr != NULL ) && (response + responseLength >= searchPtr + data_length + 1 ) && (searchPtr[data_length + 1 ] == ' "' )) {
4157
+ if (data_length > readLength) {
4158
+ data_length = readLength;
4159
+ if (_printDebug == true ) {
4160
+ _debugPort->print (F (" readMQTT: error: trucate message" ));
4161
+ }
4162
+ err = SARA_R5_ERROR_OUT_OF_MEMORY;
4163
+ }
4164
+ memcpy (readDest, searchPtr+1 , data_length);
4165
+ *bytesRead = data_length;
4166
+ } else {
4167
+ if (_printDebug == true ) {
4168
+ _debugPort->print (F (" readMQTT: error: message end " ));
4169
+ }
4170
+ err = SARA_R5_ERROR_UNEXPECTED_RESPONSE;
4171
+ }
4156
4172
}
4157
4173
free (command);
4158
4174
free (response);
4159
4175
4160
- return (data_length > readLength) ? SARA_R5_ERROR_OUT_OF_MEMORY : SARA_R5_ERROR_SUCCESS ;
4176
+ return err ;
4161
4177
}
4162
4178
4163
4179
SARA_R5_error_t SARA_R5::getMQTTprotocolError (int *error_code, int *error_code2)
@@ -4832,7 +4848,7 @@ SARA_R5_error_t SARA_R5::getFileContents(String filename, String *contents)
4832
4848
// A large file will completely fill the backlog buffer - but it will be pruned afterwards
4833
4849
// Note to self: if the file contents contain "OK\r\n" sendCommandWithResponse will return true too early...
4834
4850
// To try and avoid this, look for \"\r\nOK\r\n
4835
- const char fileReadTerm[] = " \"\r\n OK\r\n " ;
4851
+ const char fileReadTerm[] = " \r\n OK \r\n " ; // LARA-R6 returns "\"\r\n\r\nOK\r\n" while SARA-R5 return "\ "\r\nOK\r\n";
4836
4852
err = sendCommandWithResponse (command, fileReadTerm,
4837
4853
response, (5 * SARA_R5_STANDARD_RESPONSE_TIMEOUT),
4838
4854
(fileSize + minimumResponseAllocation));
@@ -5958,6 +5974,7 @@ void SARA_R5::beginSerial(unsigned long baud)
5958
5974
delay (100 );
5959
5975
if (_hardSerial != NULL )
5960
5976
{
5977
+ _hardSerial->end ();
5961
5978
_hardSerial->begin (baud);
5962
5979
}
5963
5980
#ifdef SARA_R5_SOFTWARE_SERIAL_ENABLED
0 commit comments