CellularLib : Modem returns ERROR: line AT+USOCR=6,0

Hello,

I’m running OTA on top of the cellularlib. I’ve been making an endurance test and ran into several probably unrelated cellularlib problems. For each of these I will create a new topic.

Details
-Using the SARA-R410M with software 02B-01
-Running on a STM32L4S5
-Using the Cellular comm interface of the STM32L4S5 Discovery

For this particular problem the program fails to make a TLS connection due to a socket error. I observed this once in a 24 hour run of my code. The relevant error section in the log is:

[INFO] [OTADemo] [OtaOverMqttDemoExample.c:1273] Attempting to open TLS socket to broker...


[INFO] [OTADemo] [OtaOverMqttDemoExample.c:1284] Creating a TLS connection to a32g9qwxlmbo20-ats.iot.eu-central-1.amazonaws.com:8883.
[ERROR] [TlsTransport] [using_mbedtls.c:550] Failed to perform TLS handshake: mbedTLSError= SSL - The connection indicated an EOF : <No-Low-Level-Code>.
[WARN] [OTADemo] [OtaOverMqttDemoExample.c:1302] Connection to the broker failed. Retrying connection in 0 ms.
[INFO] [OTADemo] [OtaOverMqttDemoExample.c:1284] Creating a TLS connection to a32g9qwxlmbo20-ats.iot.eu-central-1.amazonaws.com:8883.
[ERROR] [TlsTransport] [using_mbedtls.c:550] Failed to perform TLS handshake: mbedTLSError= SSL - The connection indicated an EOF : <No-Low-Level-Code>.
[WARN] [OTADemo] [OtaOverMqttDemoExample.c:1302] Connection to the broker failed. Retrying connection in 346 ms.
[INFO] [OTADemo] [OtaOverMqttDemoExample.c:1284] Creating a TLS connection to a32g9qwxlmbo20-ats.iot.eu-central-1.amazonaws.com:8883.
[ERROR] [TlsTransport] [using_mbedtls.c:550] Failed to perform TLS handshake: mbedTLSError= SSL - The connection indicated an EOF : <No-Low-Level-Code>.
[WARN] [OTADemo] [OtaOverMqttDemoExample.c:1302] Connection to the broker failed. Retrying connection in 130 ms.
[INFO] [OTADemo] [OtaOverMqttDemoExample.c:1284] Creating a TLS connection to a32g9qwxlmbo20-ats.iot.eu-central-1.amazonaws.com:8883.
[ERROR] [TlsTransport] [using_mbedtls.c:550] Failed to perform TLS handshake: mbedTLSError= SSL - The connection indicated an EOF : <No-Low-Level-Code>.
[WARN] [OTADemo] [OtaOverMqttDemoExample.c:1302] Connection to the broker failed. Retrying connection in 2980 ms.
[INFO] [OTADemo] [OtaOverMqttDemoExample.c:1284] Creating a TLS connection to a32g9qwxlmbo20-ats.iot.eu-central-1.amazonaws.com:8883.
[ERROR] [TlsTransport] [using_mbedtls.c:550] Failed to perform TLS handshake: mbedTLSError= SSL - The connection indicated an EOF : <No-Low-Level-Code>.
[WARN] [OTADemo] [OtaOverMqttDemoExample.c:1302] Connection to the broker failed. Retrying connection in 1090 ms.
[INFO] [OTADemo] [OtaOverMqttDemoExample.c:1284] Creating a TLS connection to a32g9qwxlmbo20-ats.iot.eu-central-1.amazonaws.com:8883.
[ERROR] [TlsTransport] [using_mbedtls.c:550] Failed to perform TLS handshake: mbedTLSError= SSL - The connection indicated an EOF : <No-Low-Level-Code>.
[WARN] [OTADemo] [OtaOverMqttDemoExample.c:1302] Connection to the broker failed. Retrying connection in 1654 ms.
[INFO] [OTADemo] [OtaOverMqttDemoExample.c:1284] Creating a TLS connection to a32g9qwxlmbo20-ats.iot.eu-central-1.amazonaws.com:8883.
[ERROR] [TlsTransport] [using_mbedtls.c:550] Failed to perform TLS handshake: mbedTLSError= SSL - The connection indicated an EOF : <No-Low-Level-Code>.
[WARN] [OTADemo] [OtaOverMqttDemoExample.c:1302] Connection to the broker failed. Retrying connection in 2116 ms.
[INFO] [OTADemo] [OtaOverMqttDemoExample.c:1284] Creating a TLS connection to a32g9qwxlmbo20-ats.iot.eu-central-1.amazonaws.com:8883.
[WARN] [CellularLib] [cellular_pktio.c:367] Modem return ERROR: line AT+USOCR=6,0, cmd : +CME ERROR: Operation not allowed, respPrefix +USOCR, status: 0
[WARN] [CellularLib] [cellular_pkthandler.c:247] Modem returns error in sending AT command AT+USOCR=6,0, pktStatus 2.
[ERROR] [CellularLib] [cellular_r4_api.c:499] _Cellular_GetSocketNumber: get socekt number failed PktRet: 2
[ERROR] [CellularLib] [cellular_common.c:487] _Cellular_TranslatePktStatus: Status 2
[ERROR] [Sockets] [sockets_wrapper.c:700] Failed to establish new connection. Socket status 10.
[ERROR] [CellularLib] [cellular_r4_api.c:804] Cellular_SocketClose : invalid session ID for socket index 7
[ERROR] [TlsTransport] [using_mbedtls.c:670] Failed to connect to a32g9qwxlmbo20-ats.iot.eu-central-1.amazonaws.com with error -1.
[WARN] [OTADemo] [OtaOverMqttDemoExample.c:1302] Connection to the broker failed. Retrying connection in 2592 ms.

It then tries to reconnect a whole bunch of times before it eventally hangs in configASSERT( xNetworkStatus == pdPASS ); inside of prvConnectToMQTTBroker();

How to handle such a situation?

Here’s a complete log for reference:
AT+USOCR error.zip (6.5 KB)

-edit- I’m now re-running the code to reproduce while also logging the serial lines of the modem. I will add that later.

Hi Mike,

There are two problems I saw from your log.

  • Possible socket state overwritten :
    This PR may related to your problem. SOCKETSTATE_CONNECTED may be overwritten by SOCKETSTATE_CONNECTING. If the socket state is overwritten, the following socket send command will return error. This may be the reason of the following log.
[INFO] [OTADemo] [OtaOverMqttDemoExample.c:1284] Creating a TLS connection to a32g9qwxlmbo20-ats.iot.eu-central-1.amazonaws.com:8883.
Bike state transition: [LOWPOWERSLEEP] --> [LOWPOWERAWAKE]
[ERROR] [TlsTransport] [using_mbedtls.c:550] Failed to perform TLS handshake: mbedTLSError= SSL - The connection indicated an EOF : <No-Low-Level-Code>.
  • Socket is not properly closed :
    At this line, Sockets_Disconnect should be used. The maximum socket number supported by SARA-R4 is 7.
    This problem results in socket exhausted and the following error returned by cellular modem. From your log, we can see that at the eighth attempt the command fails and error is returned.
AT+USOCR=6,0
+CME ERROR: Operation not allowed

Please help to check these two problems. We will also update our demo. Thank you for your feedback.

Hi Lee,

Thank you for your help. I have updated my code concerning your first noted problem.
For the second problem, should I replace the existing

FreeRTOS_closesocket( pTlsTransportParams->tcpSocket );
with
Sockets_Disconnect( pTlsTransportParams->tcpSocket );

or should I keep the existing line and add Sockets_Disconnect( pTlsTransportParams->tcpSocket ); thereafter?

You can replace the line FreeRTOS_closesocket with Sockets_Disconnect. FreeRTOS_closesocket is not required for cellular interface.

Thank you, I think this resolved this particular problem. I’m running long duration tests, If I encounter this problem again I will report it here.