@@ -566,18 +566,44 @@ int QuectelCellular::available()
566566 char * recvToken = strstr (_buffer, " +QSSLRECV: " );
567567 recvToken += 11 ;
568568
569+ /* Get length of data */
569570 char * lfToken = strstr (recvToken, " \n " );
570571 uint32_t llen = lfToken - recvToken;
571572
572573 char numberStr[llen];
573574 strncpy (numberStr, recvToken, llen);
574575 numberStr[llen] = ' \0 ' ;
575576
576- sslLength = atoi (numberStr);
577+ sslLength = atoi (numberStr);
578+
577579 if (sslLength > 0 )
578580 {
579- lfToken++; // put the pointer in front of the linebreak
580- memcpy (_readBuffer, lfToken, sslLength);
581+ // set start of data to after the last new line
582+ char * data = lfToken + 1 ;
583+
584+ // The check below is because sometimes a URC-message gets through and ruins everything because it includes 2 more lines that we don't expect
585+ // First cut off the message so we only check the first 30 characters
586+
587+ // get first 30 characters
588+ char subbuff[30 ];
589+ memcpy ( subbuff, _buffer, 30 );
590+ subbuff[30 ] = ' \0 ' ;
591+
592+ // A bad message can at a maximum look like this: +QSSLURC: "recv",1<LF><LF>+QSSLRECV: [number]<LF>
593+ // but sometimes only part of it is included, example: v",1<LF><LF>+ QSSLRECV:[number]<LF>
594+ // i check for 2 new lines before +QSSLRECV because if there only is 1 then the data will still be read
595+ if (strstr (subbuff, " \n\n +QSSLRE" ) != nullptr ) {
596+ if (readReply (1000 , 2 )) {
597+ data = _buffer;
598+ }
599+ else {
600+ QT_ERROR (" Could not get data after URC-interrupt" );
601+
602+ sslLength = 0 ;
603+ }
604+ }
605+
606+ memcpy (_readBuffer, data, sslLength);
581607 }
582608 QT_TRACE (" available sslLength: %i" , sslLength);
583609 return sslLength;
0 commit comments