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);