Send data with At-Command in OpenCPU

Hi
How can i send input the data After the response > in OpenCPU with Ql_RIL_SendATCmd() ?
for example i need to use (AT+QMTPUB) with Ql_RIL_SendATCmd() and send a data(e.g. time or temp) after response > sign with Ctrl+Z.
Thank you

Ql_sprintf(atComm, “AT+QMTPUB=0,0,0,0,”%s"", MQTT_TOPIC);
ret = Ql_RIL_SendATCmd(atComm, Ql_strlen(atComm), NULL, NULL, 0);

Dear bsalmani69

Do you need to use ‘Ql_RIL_SendATCmd’ to use AT command in OPEN mode or send and receive data through serial port?

Please give detailed feedback on the module model and SDK version you use.

Dear Grey Thanks your response

I’m using MC60 module and programming in SDK version 1.7
I need use AT-Command in Open-mode to use MQTT protocol for send data to MQTT-server. After Config/Open GPRS and PDP context, I can Connect to Broker with Ql_RIL_SendATCmd(AT+QMTCONN) but when i use AT+QMTPUB with Ql_RIL_SendATCmd, i can’t send data to server after response > and return (-1).

How can i detect (response >) and send data with Ctrl+Z (0x1A) in this Ql-Command?
How can i send data to MQTT-Server with Ql_RIL_SendATCmd(AT+QMTPUB)?
Please help me to solve this problem.

static void MQTT_Program()
{
s32 ret;
ret = RIL_NW_SetGPRSContext(Ql_GPRS_GetPDPContextId());
APP_DEBUG(“START SEND TO SERVER\r\n”);
ret = RIL_NW_SetAPN(1, APN_NAME, APN_USERID, APN_PASSWD);
APP_DEBUG("<-- Set GPRS APN, ret=%d -->\r\n", ret);
ret = RIL_NW_OpenPDPContext();
APP_DEBUG("<-- Open PDP context, ret=%d -->\r\n", ret);

// Packaging At-Command for Open a network for MQTT client
Ql_sprintf(atComm, “AT+QMTOPEN=0,”%s","%s"", MQTT_SRV_ADD, MQTT_SRV_PORT);
ret = Ql_RIL_SendATCmd(atComm, Ql_strlen(atComm), NULL, NULL, 0);
if(ret == 0)
{
APP_DEBUG("<-- Opened a Network for MQTT Client, ret=%d -->\r\n", ret);
}
else
{
APP_DEBUG("<-- Opennig a Network for MQTT Client Failed, ret=%d -->\r\n", ret);
}

// Packaging At-Command for Connect a client to MQTT server
Ql_sprintf(atComm, “AT+QMTCONN=0,”%s","%s","%s"", MQTT_CLIENT_ID, MQTT_CLIENT_USER, MQTT_CLIENT_PASS);
ret = Ql_RIL_SendATCmd(atComm, Ql_strlen(atComm), NULL, NULL, 0);
if(ret == 0)
{
APP_DEBUG("<-- Connected Client to MQTT Server, ret=%d -->\r\n", ret);
}
else
{
APP_DEBUG("<-- Connecting Client to MQTT Server Failed, ret=%d -->\r\n", ret);
}

// Packaging At-Command for Publish messages in MQTT
Ql_memset(atComm, 0, sizeof(atComm));
Ql_sprintf(atComm, "AT+QMTPUB=0,0,0,0,\"%s\"", MQTT_TOPIC);
ret = Ql_RIL_SendATCmd(atComm, Ql_strlen(atComm), NULL, NULL, 0);
if(ret == 0)
{
APP_DEBUG("<-- Publishing a Message in MQTT..., ret=%d -->\r\n", ret);
 }
else
{
APP_DEBUG("<-- Publishing a Message in MQTT Failed, ret=%d -->\r\n", ret);
}

// Packaging At-Command for Disconnect a client from MQTT server
Ql_memset(atComm, 0, sizeof(atComm));
Ql_sprintf(atComm, "AT+QMTDISC=0");
ret = Ql_RIL_SendATCmd(atComm, Ql_strlen(atComm), NULL, NULL, 0);
if(ret == 0)
{
APP_DEBUG("<-- Disconnect Client from MQTT Server, ret=%d -->\r\n", ret);
 }

else
{
APP_DEBUG("<-- Disconnecting Client from MQTT Server Failed, ret=%d -->\r\n", ret);
}

ret = RIL_NW_ClosePDPContext();
APP_DEBUG("<-- Close PDP context, ret=%d -->\r\n", ret);

Dear Grey Thanks your response

I’m using MC60 module and programming in SDK version 1.7
I need use AT-Command in Open-mode to use MQTT protocol for send data to MQTT-server. After Config/Open GPRS and PDP context, I can Connect to Broker with Ql_RIL_SendATCmd(AT+QMTCONN) but when i use AT+QMTPUB with Ql_RIL_SendATCmd, i can’t send data to server after response > and return (-1).

How can i detect (response >) and send data with Ctrl+Z (0x1A) in this Ql-Command?
How can i send data to MQTT-Server with Ql_RIL_SendATCmd(AT+QMTPUB)?
Please help me to solve this problem.

Hi Babak
You can use Ql_RIL_WriteDataToCore function in AT commands callback

Why reinvent the wheel? There is MQTT RIL library written by Quectel guys.
Here you are my compatriot

ril_mqtt.zip (4.2 KB)

Dear bsalmani69

Not all AT instructions are supported in OPEN mode. For details about how to use MQTT, see example_MQtt in the SDK.Thank you.

Thank you Dear Ahmadreza

It was great and my problem with this library solved.