TCP socket fails to read after a short while

Hi everyone, I’m having some troubles with MQTT over a TCP socket. I am essentially using the same code as the one provided in the library, socket creation, connection, mqtt subscribe/publish/ping are working fine.

After connecting to a MQTT broker and subscribing to a topic, I poll “AT+USORD=0,0” to watch for new data coming. If data is published (using mosquitto_pub) to the topic every 2 o 3 seconds or so, then the socket reads everything and no data is lost. On the contrary if data publication (still using mosqutito_pub) is done every 5+ seconds, then the socket read seems to silently go idle (I keep on reading “+USORD: 0,0”). In this case sending data to the broker (for example through a ping) seems to re establish the communication and I can again receive data for a few seconds.

I tried this with a private broker and test.mosquitto.org and I got the same result.

I tried to enable the “keep alive” TCP socket option but with no result.

I run out of ideas, any input would be greatly appreciated!

Thanks,

Fred

1 Like

Hi Fred,

The R4 MQTT builtin is indeed not stable.
I recommend you use the extra libraries to build an MQTT on top of the TCP connection with our MQTT libraries.

Best regards,
Jan

Hi Jan thanks for your reply, maybe my message was not very clear, I am not using the built in mqtt, I implemented the protocol using a tcp socket (at+usocr), everything works perfectly except that after ~5 of inactivity (meaning 5s without getting any data from the broker) the socket seems to “lock” and cannot get any new data from the broker. Outgoing data keeps on working and sending data actually fully “awakes” the socket for 5 new seconds… I investigated the power management stuff and used:
AT+CPSMS=0
AT+CEDRXS=0
but no luck so far.
I studied your library closely and cannot find any meaningful difference, did you experience any similar issue?

1 Like

I ran some tests using your library and arduino test sketch, I have the same issue, if the broker (test.mosquitto.org) issues a message every 2 seconds or so, the device reads every single one of them, if the broker stops for 10 seconds and starts again then the device stops receiving anything.
I updated the ublox firmware. No change.

Can you make sure that the +UPSV setting is disabled. This is the ‘idle’ mode which disables the UART after 6s of inactivity, new activity over the UART wakes the modem. This puts the modem in a lower power state, but interferes with the commands sent, as usually the first command is discarded as it triggers the wake.

Hi thanks for your answer, I tried “AT+UPSV?” and I got “’+UPSV: 0”, so according to the manual, power saving should be disabled if I am not mistaken.

Hi @fabry-dev, @GabrielNotman
I am also facing the same issue. After sometime subscribe is not working, publish message runs smooth. Have you got any luck resolving this? “AT+UPSV?” gives “’+UPSV: 0”.
I am stuck with this issue at the final stages of my product delivery. Kindly provide help asap.
Thanks

Hi! I’m using SARA R412M and using the built-in MQTT and facing the same issue. After subscribing to a topic, I can receive msgs for just a feel seconds (4 seconds maybe) and then I receive from Sara the +CSCON: 0 which means the Sara connection went to idle state. After that I cannot receive msgs again from the broker unless I send msg or reconnect to the broker.
But a new information I have realizes is that this only happens while connected to LTE network. If I connect on the GSM network, everything works fine.