Periodic Connect and Disconnect MQTT

Hi.

I need to publish and subscribe with MQTT protocol in MC60. I have periodic connect and disconnect to mqtt broker. for example, after 10 times trying, once i can connect and publish. I test it in AT-Command mode and OpenCPU mode. after open a network for mqtt client with AT+QMTOPEN, periodic i can’t connect to mqtt broker with AT+QMTCONN and returns ERROR.
Please help to solve this problem.

hi,bsalmani69:
Did you successfully connect to the MQTT server during the test?
If not, I recommend using MQtt.fx for server state testing.
Or you upload a log of your test failures

Hi.
Thanks for the Reply.

Both Yes and No. for more details, i can connect to the MQTT server with MQtt.fx and publish a data. but in AT-command test with a terminal like QCOM, i can sometimes open and connect to mqtt.

I realized that there is a delay to replying (AT+QMTOPEN) command for Opening MQTT-network and replying (AT+QMTCONN) command for connecting to MQTT-server and this delay to replying from Core cause Closing MQTT-network. because other AT-command run without delay and reply. I attached my test log in blow.

QCOM_LOG.zip (811 Bytes)

Logs with failure problems are displayed as follows

AT+CGREG?
+CGREG: 0,2

Logs with failure problems are displayed as follows.
In addition, the execution time between AT+QMTOPEN and AT+QMTCONN is about 10 seconds. Perform AT+QMTCONN as soon as possible after AT+QMTOPEN is executed

After sending (AT+QMTOPEN), it reply OK and as I understand it, if i send (AT+QMTCONN) before receiving (+QMTOPEN: 0,0) , it return (+CME ERROR: 3518) to me and i can’t run (AT+QMTCONN) command and then it return (+QMTOPEN: 0,4) that means is MQTT closed.

The problem is exactly that If i run fast (AT+QMTCONN) after (AT+QMTOPEN) and receiving OK, it return (+CME ERROR: 3518) because MQTT-network not opened yet ((+QMTOPEN: 0,0) not arrived yet) and if i don’t run (AT+QMTCONN) before 10 seconds the MQTT-network closes.
What do you recommend?

AT+QMTOPEN=0,“tb-srv.abreman.ir”,1883
OK
AT+QMTCONN=0,“gpsbabak”,"",""
+CME ERROR: 3518
+QMTOPEN: 0,4
AT+QMTOPEN=0,“tb-srv.abreman.ir”,1883
OK
AT+QMTCONN=0,“gpsbabak”,"",""
+CME ERROR: 3518
+QMTOPEN: 0,0
AT+QMTCONN=0,“gpsbabak”,"",""
OK
+QMTCONN: 0,0,0

yes,You are right to understand
But why is ERROR3518 so strange

However, what is your suggestion to solve this problem?

hi,bsalmani69:
I suggest you to find this error on the MQTT server platform. At present, your connection is normal, and you can also ignore this error

Thanks for the Reply herbert.pan

I have another question about MQTT in OpenCPU. How can i receive coming response(return data) after sending Ql_RIL_SendATCmd(AT+QMTSUB) in RIL_MQTT_QMTSUB?
after receive OK, how can i get coming data (like a key status) from MQTT-server? should i handle it(receiving data) in ATResponse_Handler? do you have any example or recommended solution?

Like this data:

AT+QMTSUB=0,1,“v1/devices/me/rpc/request/+”,0

OK

+QMTSUB: 0,1,0,0

+QMTRECV: 0,0,v1/devices/me/rpc/request/58,{“method”:“checkStatus”}

+QMTRECV: 0,0,v1/devices/me/rpc/request/59,{“method”:“setValue”,“params”:true}

sorry;
I am not familiar with openCPU, but I think there must be RIL about MQTT subscriptions

1 Like