Values not updating in adafruit(MQTT+GSM)

as per the above link, i have modified the code according to my adafruit account, AT commands are working fine with sim800, but the values are not updating in IOadafruit,

here’s the code, please could you give me any suggestion?

int led = 13;
unsigned int Counter = 0;
unsigned long datalength,CheckSum,RLength;
unsigned short topiclength;
unsigned char topic[30];
char str[250];
unsigned char encodedByte;
int X;
unsigned short MQTTProtocolNameLength;
unsigned short MQTTClientIDLength;
unsigned short MQTTUsernameLength;
unsigned short MQTTPasswordLength;
const char MQTTHost[30] = “ioadafruitcom”;
const char MQTTPort[10] = “1883”;
const char MQTTClientID[20] = “Arun”;
const char MQTTTopic[30] = “username/feeds/temp”;
const char MQTTProtocolName[10] = “MQTT”;
const char MQTTLVL = 0x03;
const char MQTTFlags = 0xC2;
const unsigned int MQTTKeepAlive = 60;
const char MQTTUsername[30] = “username”;
const char MQTTPassword[35] = “aiokey”;
const char MQTTQOS = 0x00;
const char MQTTPacketID = 0x0001;
void setup()
{
pinMode(led, OUTPUT);
Serial.begin(9600);
Serial.println(“Arduino MQTT Tutorial, Xolcano”);
delay(5000);}
void SendConnectPacket(void)
{
Serial.print("\r\nAT+CIPSEND\r\n");
delay(5000);
Serial.write(0x10);
MQTTProtocolNameLength = strlen(MQTTProtocolName);
MQTTClientIDLength = strlen(MQTTClientID);
MQTTUsernameLength = strlen(MQTTUsername);
MQTTPasswordLength = strlen(MQTTPassword);
datalength = MQTTProtocolNameLength+2+4+MQTTClientIDLength+2+MQTTUsernameLength+2+MQTTPasswordLength+2;X=datalength;
do
{
encodedByte = X%128;
X = X/128;
if ( X > 0 )
{
encodedByte |= 128;
}
Serial.write(encodedByte);
}
while ( X > 0 );
Serial.write(MQTTProtocolNameLength >> 8);
Serial.write(MQTTProtocolNameLength & 0xFF);
Serial.print(MQTTProtocolName);
Serial.write(MQTTLVL);
// LVL
Serial.write(MQTTFlags); // Flags
Serial.write(MQTTKeepAlive >> 8);
Serial.write(MQTTKeepAlive & 0xFF);
Serial.write(MQTTClientIDLength >> 8);
Serial.write(MQTTClientIDLength & 0xFF);
Serial.print(MQTTClientID);
Serial.write(MQTTUsernameLength >> 8);
Serial.write(MQTTUsernameLength & 0xFF);
Serial.print(MQTTUsername);
Serial.write(MQTTPasswordLength >> 8);
Serial.write(MQTTPasswordLength & 0xFF);
Serial.print(MQTTPassword);
Serial.write(0x1A);
}
void SendPublishPacket(void)
{
Serial.print("\r\nAT+CIPSEND\r\n");
delay(3000);
memset(str,0,250);
topiclength = sprintf((char*)topic,MQTTTopic);
datalength = sprintf((char*)str,"%s%u",topic,Counter);
delay(1000);
Serial.write(0x30);
X=datalength+2;
do
{
encodedByte = X%128;
X = X/128;
if ( X > 0 )
{
encodedByte |= 128;
}
Serial.write(encodedByte);
}
while ( X > 0 );
Serial.write(topiclength >> 8);
Serial.write(topiclength & 0xFF);
Serial.print(str);
Serial.write(0x1A);
}
void SendSubscribePacket(void)
{
Serial.print("\r\nAT+CIPSEND\r\n");
delay(3000);
memset(str,0,250);
topiclength = strlen(MQTTTopic);
datalength = 2+2+topiclength+1;
delay(1000);
Serial.write(0x82);
X=datalength;
do
{
encodedByte = X%128;
X = X/128;
if ( X > 0 )
{
encodedByte |= 128;
}
Serial.write(encodedByte);
}
while ( X > 0 );
Serial.write(MQTTPacketID >> 8);
Serial.write(MQTTPacketID & 0xFF);
Serial.write(topiclength >> 8);
Serial.write(topiclength & 0xFF);
Serial.print(MQTTTopic);
Serial.write(MQTTQOS);
Serial.write(0x1A);
}
void loop()
{
Serial.print(“AT+CIPSHUT\r\n”);
delay(2000);
Serial.print(“AT+CSTT=“airtelgprscom”,”",""\r\n");
delay(1000);
Serial.print(“AT+CIPMODE=0\r\n”);
delay(1000);
Serial.print(“AT+CIICR\r\n”);
delay(9000);
Serial.print(“AT+CIPSTART=“TCP”,“ioadafruitcom”,“1883”\r\n”);
delay(6000);
SendConnectPacket();
delay(5000);
SendSubscribePacket();
delay(5000);
while(1)
{
/* if(Serial.available()>0)
{
str[0] = Serial.read();
Serial.write(str[0]);
if(str[0] == ‘N’)
digitalWrite(led, HIGH);
if(str[0] == ‘F’)
digitalWrite(led, LOW);
}*/
delay(1000);
SendPublishPacket();
Counter++;

}
}

Hello and welcome! You might have noticed that nobody has taken the time to answer you, in short it’s due to several problems in your question that make it difficult to help you:

What link do you speak of? Did you copy-pasted your question from other forum? Please take the time to revise your writing. If you don’t take the proper time to properly formulate the question, you can’t expect someone else to take her or his time to answer.

A more detailed description of the situation/problem always comes in handy.

Two problems with this. First, it would be nice to try and isolate the possible source of the problem instead of dumping the whole source code at once. Second, and failing to do the first thing, it would be nice to at least get the code somewhat formatted; this forum includes very nice formatting tools to create snippets, code blocks and lots of other elements that make your question easier to read. Without formatting, it just looks like a chunk of text with very little readability.


Having said that…

The problems with your code that I can see at a glance are:

  • You have to terminate each TCP connection before starting a new one. That means that you can’t use the AT+CIPSEND multiple times consecutively. You have to first finish the connection with AT+CIPSHUT and start a new connection.

  • You are waiting between 5 and 6 seconds after you initiate the connection before you send the message. In all that time the connection stays open. Most servers wouldn’t allow you to keep a connection open for so long, so they’ll close it long before you send the message. You should send the message as soon as the module responds to the previous command.

  • Your program does not include any ability to handle error responses from the module, so you wouldn’t be able to catch the previously mentioned problem. You should read each response from the module and interpret it to know how to proceed.