Forums - MQTT Connection Status

4 posts / 0 new
Last post
MQTT Connection Status
jagan
Join Date: 2 Jan 20
Posts: 15
Posted: Sat, 2020-01-25 20:13

Hi,

I need a way to know the MQTT connection status at any time, so that I can reconnect to the MQTT broker again.

I observe that the  call back function registered via "qapi_Net_MQTTc_Register_Connect_Callback()" does not get called for every disconnect to the MQTT broker. 

Also the function qapi_Net_MQTTc_Publish() returns success, even after the MQTT disconnects.  Also qapi_Status_t returned by function qapi_Net_MQTTc_Publish()  is "QAPI_NET_STATUS_MQTTC_CONNECT_SUCCEEDED" after the MQTT disconnects.  

After MQTT disconnect may be 10-20 minutes later, the API qapi_Net_MQTTc_Publish() returns error "QAPI_NET_STATUS_MQTTC_SOCKET_WRITE_ERROR". 

I will require MQTT connection status immediately not after 10 -15 minutes. Is there any way I can get the MQTT connection status immediatley. 

Thanks in advance. 

Regards,
Jagan

 

  • Up0
  • Down0
jagan
Join Date: 2 Jan 20
Posts: 15
Posted: Sun, 2020-01-26 05:00

Hi,

I think, I will require to implement PINGREQ and PINGRESP to check if the connection is alive. More details are below.

http://docs.oasis-open.org/mqtt/mqtt/v3.1.1/errata01/os/mqtt-v3.1.1-errata01-os-complete.html#_Toc442180894

Please let me know how to implement with the given set of QAPIs. 

Regards,
Jagan

  • Up0
  • Down0
raja_pedada
Profile picture
Join Date: 18 Jun 18
Location: San Jose
Posts: 300
Posted: Mon, 2020-01-27 11:32

mqtt_connect() internally uses PINGREQ and PINGRESP.

However, for you test case, kindly configure the keepalive_sec and ConAck_wait_time intervals to valid value to verify the connection status at regular intervals.

  • Up0
  • Down0
jagan
Join Date: 2 Jan 20
Posts: 15
Posted: Tue, 2020-01-28 10:42

Thanks raja. 

After configuring keepalive_sec and ConAck_wait_time, I am able to see PINGREQ in the server logs.  Also MQTT connection seems to be stable. I am testing more, I will let you know if  I face any issues.   

  • Up0
  • Down0
or Register

Opinions expressed in the content posted here are the personal opinions of the original authors, and do not necessarily reflect those of Qualcomm Incorporated or its subsidiaries (“Qualcomm”). The content is provided for informational purposes only and is not meant to be an endorsement or representation by Qualcomm or any other party. This site may also provide links or references to non-Qualcomm sites and resources. Qualcomm makes no representations, warranties, or other commitments whatsoever about any non-Qualcomm sites or third-party resources that may be referenced, accessible from, or linked to this site.