10

I have been working on an MQTT protocol using the SIM5320. I am familiar with the AT command documentation, and have a working implementation with an Arduino.

  1. I open a network socket with AT+NETOPEN
  2. Then I open a TCP connection with AT+CIPOPEN=0,"TCP","ip address",port.
  3. I then transmit data for the MQTT protocol using AT+CIPSEND, which executes successfully.

If I send data to the SIM module through MQTT, it is also received and the message is detected.

With MQTT, there is a Keep-Alive interval which specifies how long the server will keep a connection open between communication, basically how long the client can idle before being forcibly disconnected from the server. However, I have set this value to the maximum of 18 hours, which is far longer than the ~15 minute disconnections.

My issue arises after ~15 minutes, when I try sending a command to the server, and no response is given. The SIM has not issued a "+IPCLOSE: 0,4", which usually occurs when the server forcibly disconnects the client, or any other sort of indicator.

Additionally, I am still able to send data and it appears that the CIP connection is still open, as indicated by AT+CIPOPEN?. When I try and close the connection with AT+CIPCLOSE=0, I receive +CIPCLOSE: 0,4 and "ERROR". There is no mention of what +CIPCLOSE: 0,4 means in the documentation, however it does not seem to close the connection, as it cannot be opened or used.

I would really love to know what is happening in this 15 minutes, between establishing a connection and sending data, to attempting to send data again. There is no alert or any indication of anything going wrong, so I am seriously confused.

I initially asked this question on Electrical Engineering stack exchange, but was advised to ask it here as well.

I've attached the code I wrote here for anyone who would like to take a look, and there aren't any libraries you need to run it.

Rohit Gupta
  • 507
  • 2
  • 3
  • 18
Boris Deletic
  • 203
  • 1
  • 6

2 Answers2

7

Default TCP/IP timeout is 15mins, you must send something inside this interval to keep the underlying TCP connection alive, even if it's just a sync/ack pair.

The MQTT keepalive is to do with when to trigger the Last Will and Testement messages.

hardillb
  • 12,813
  • 1
  • 21
  • 34
2

Try enabling TCP keep alive with a shorter period than 15 minutes, you should be able to enable TCP keep alive from your server and/or from your device (SIM5320), enabling either one should solve your problem.

In the SIM5320 you can use AT+CTCPKA to enable TCP keep alive.

In your server, enable socket.SO_KEEPALIVE

This is transparent to the TCP user (you), so it should not interfere with your application, as opposed to the accepted answer.