Data is not displaying in Cloudmqtt websocket UI


#1

Hello Sir,
I am new to GSM hardware. I am using Sim900A GSM module along with Arduino Uno. I am using your code to connect to cloudmqtt. I am using idea sim in GSM module and I changed apn to “imis/internet”. And and similarly I changed username and password and host and port. But When I run code some junk values are displaying and In websocket UI I am not seeing any data. I am getting where am I doing wrong.
and connection:
gsm rx<->arduino tx
gsm tx<->arduino rx
Code
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] = “”;
const char MQTTPort[10] = “19016”;
const char MQTTClientID[20] = “ABCDEF”;
const char MQTTTopic[30] = “valetron”;
const char MQTTProtocolName[10] = “MQIsdp”;
const char MQTTLVL = 0x03;
const char MQTTFlags = 0xC2;
const unsigned int MQTTKeepAlive = 60;
const char MQTTUsername[30] = “clxqseyg”;
const char MQTTPassword[35] = “Cgabj7fVX3I4”;
const char MQTTQOS = 0x00;
const char MQTTPacketID = 0x0001;
void setup()
{
pinMode(led, OUTPUT);
Serial.begin(9600);

Serial.println(“Arduino MQTT Tutorial”);
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 ( 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+CSTT=“imis/internet”,”",""\r\n");
delay(1000);
Serial.print(“AT+CIPMODE=0\r\n”);
delay(1000);
Serial.print(“AT+CIICR\r\n”);
delay(5000);
Serial.print(“AT+CIPSTART=“TCP”,“m16.cloudmqtt.com”,“19016”\r\n”);
delay(4000);
SendConnectPacket();
delay(5000);
SendSubscribePacket();
while(1)
{
SendPublishPacket();

}
}

output in Serial monitor:
Arduino MQTT Tutorial, Valetron Systems @imis/internet.raviyp.com
AT+CSTT=“imis/internet”,"",""
AT+CIPMODE=0
AT+CIICR
AT+CIPSTART=“TCP”,“m16.cloudmqtt.com”,“19016”

AT+CIPSEND
,MQIsdp▒<ABCDEclxqseyg
Cgabj7fVX3I4
AT+CIPSEND
valetron
AT+CIPSEND
0
valetron0
AT+CIPSEND
0
valetron0
AT+CIPSEND
0
valetron0
AT+CIPSEND
0
valetron0
AT+CIPSEND
0
valetron0
AT+CIPSEND


#3

You need to capture the module output also. The OK and ERROR responses to find where exactly is the problem. The Adafruit also provides FONA libraries , you can use them to connect to other MQTT brokers also.


#4

I captured outputs and everywhere it is OK only. But In websocket UI it is not showing data.


#5

Check for connect packet acknowledgement in HEX mode of any terminal software. It must be two byte value in binary. If you get that proceed to publish packet acknowledgement.


#6

Thank you Sir,
I solved using arduino Uno. Now I am trying to connect cloudmqtt using GSM and STM32 module. I had watched your video Arduino MQTT Tutorial - Coding Live Demo using SIM900 and convert the same code for STM32. I am getting response SEND OK for At+CIPSEND. But data is not visible in cloudmqtt. Can you please help me solve this problem?