Getting Error while sending connect packet to cloudmqtt using Arduino with SIM808

Hii,
I am just checking responses of AT command using following Arduino code for implementing MQTT protocol over TCP but getting error while sending connectivity packet.

#include <SoftwareSerial.h>
SoftwareSerial SIM808Serial(7,8);
void setup()
{
 SIM808Serial.begin(9600);                  
 Serial.begin(9600);

/*while(Serial.available())
Serial.read();
while(SIM808Serial.available())
SIM808Serial.read();*/                  
}

void loop()
{
if(Serial.available())
{
  SIM808Serial.write(Serial.read());
}

if(SIM808Serial.available())
{
  Serial.write(SIM808Serial.read());
}
}

TCP establishes

yesbc.ino (415 Bytes)
successfully but when I am sending connectivity packet getting this error

You should to check you connect packet. Broker wrote, that client don’t identified

Can you please elaborate what exactly the problem I didn’t get it.

Broker can.t see, that you send to him connect packet. Broker see only, that you connect to server. After it you must send connect packet. But in your code has error. And broker can’t see your step and disconnecting.

There is an impression, that you didn’t send your message, because module not response. " Send OK" or something like this.

Here I have written code to send simply message on cloudmqtt but I can’t find out whether message getting or not on Cloudmqtt server.

  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;
  unsigned short MQTTMsgLength;
  unsigned short MQTTtopicLength;
       
 
  const char MQTTHost[30] = "m14.cloudmqtt.com";
  const char MQTTPort[10] = "19262";
  const char MQTTClientID[20] = "ABCDEF";
  const char MQTTTopic[30] = "MSG_SENT";
  const char MQTTProtocolName[10] = "MQIsdp";
  const char MQTTMSG[10]="HII";
  const char MQTTLVL = 0x03;
  const char MQTTFlags = 0xC2;
  const unsigned int MQTTKeepAlive = 60;
  const char MQTTUsername[30] = "dxxkgkpp";
  const char MQTTPassword[35] = "qAUZBdaSIULx";
  const char MQTTQOS = 0x00;
  const char MQTTPacketID = 0x0001;
  void setup()
  {
    pinMode(led, OUTPUT); 
    Serial.begin(9600);    
    delay(3000); 

  }
  
  void SendConnectPacket(void)
  {
    Serial.print("\r\nAT+CIPSEND\r\n");
    delay(3000);
    
    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 there are more data to encode, set the top bit of this byte
        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);

    delay(10000);
    
}
void SendPublishPacket(void)
{
      Serial.print("\r\nAT+CIPSEND\r\n");
      delay(3000);
      
      MQTTtopicLength = strlen(MQTTTopic);
      MQTTMsgLength = strlen(MQTTMSG);
      datalength = MQTTtopicLength+ MQTTMsgLength;
      delay(1000);
      Serial.write(0x30);
      X=datalength+2;
      do
      {
          encodedByte = X%128;
          X = X/128;
          // if there are more data to encode, set the top bit of this byte
          if ( X > 0 ) { encodedByte |= 128; }          
           Serial.write(encodedByte);
      }
      while ( X > 0 );
      
      Serial.write(MQTTtopicLength >> 8);
      Serial.write(MQTTtopicLength & 0xFF);
      Serial.print(MQTTTopic);

       Serial.write(MQTTMsgLength >> 8);
      Serial.write(MQTTMsgLength & 0xFF);
      Serial.print(MQTTMSG);
      
      Serial.write(0x1A);

      delay(15000);
}
void loop()
{
    Serial.print("AT+CIPSHUT");
    delay(1000);
    Serial.print("AT+CSTT=\"www\",\"\",\"\"\r\n");
    delay(1000);
    Serial.print("AT+CIPMODE=0\r\n");    
    delay(1000);
    Serial.print("AT+CIICR\r\n"); 
    delay(5000);
    //Serial.print("AT+CIFSR\r\n");
    //delay(2000);
    Serial.print("AT+CIPSTART=\"TCP\",\"m14.cloudmqtt.com\",\"19262\"\r\n");
    delay(4000); 
    SendConnectPacket();
    delay(5000);
    Serial.println("msg_send...........");
    SendPublishPacket();  
    Serial.println("msg_publish...........");
}

You should create account in cloudmqtt.com and use your own username and password. I guess you are using my account credentials

Oops sorry actually I have written same code with my own account credential but it was sent by mistakenly different.

@Shivani_Umredkar start here https://bitbucket.org/mbari_peter/sim800-mqtt-ravi this one I wrote from the video Ravi did and it works. Mostly the errors occur bacause of malformed packets