MQTT protocol - GSM Module stops responding on packet arrival

Ravi, thank you for your advice, I recived the new broblem… When the module send request packet, and in this moment broker send message on my module. When I recived ‘>’ and broker send message from client in field intended for SendReqPacket get data from the broker. Module stops receiving data.

Hi Alexis,

Do you mean your module stops responding after you get a packet from broker?
Does it no reply to AT commands?

P.S: When we start new discussion, please create a new topic with appropriate heading. Now i have split the post to a new topic.

Hello Ravi! I am undestand, next time I’ll take this into account.
Yes sim 800 response on AT command. Just data from broker can’t reach my module. As if I hmm … unsubscribed. I send data from my mobile client, broker recive it, but module not receive. It continues to the moment when module send RequestPacket. After sending, I can again send data from mobile client to the module.
as I understood the problem due to the fact that the buffer for receiving data and sending one. And at one point when I got the ‘>’ character and should send a ping request, sim 800 takes the data and puts it together with the data to send the ping request. In the screenshot I selected it.

Hi Alexis,
Sorry for replying late,
What i understood is,
The module is responding properly.
And you meant that the publish is working and the subscribe is not working?
You are unable to receive messages on SIM800 for the subscribed topic?
Is that correct?

My module send message to the broker (PingReq). Module working I send message - module recived it and answer me. But in the moment when module sending data (PingReq), and I in this moment sent from mobile client command to arduino. Arduino stops responding and receiving data. Until the moment when the Arduino module sends a ping request, then the module responds and receives the data again. I connect external usb -tll converter and see, after occurred which I described above I didn’t receiving data from the broker, until that moment when arduino again send PingReq.

Ok, you mean Arduino stops responding when its sending the PingReqPacket. Is that correct?
Its normal as it is busy waiting for the prompt in a loop.
I think, it will be better if you describe the problem with a video about whats happening with a screen record. Post it on youtube and share a link. May be we can figure something out.


Sorry for my english

I guess, Your question is why it got struck in between. Correct?

My guess is, The code must be hung up somewhere in a loop waiting for something.

For debugging such problems what i do is i put debug prints everywhere, like

void SendPacket(void)
{
    while(waitforflag)
    {
        Serial.Print("Inside wait for flag while loop now");
    }
}
loop()
{
    Serial.Print("Inside loop, Before SendPacket");
    SendPacket();
    Serial.Print("Inside loop After SendPacket");    
}

These prints will help in identifying where is the code struck exactly. This is sample and you can put such prints in different places to know how is the execution flowing.

P.S : Why did you press ON button so many times. It might cause problems if too much data is sent at a time. Arduino has limited buffer space or RAM.

Yes after that module send ‘>’ Module wait data from arduino(SendReq), but in this moment broker send me data from my mobile, and past in serial buffer. Ok I try it))) I press button so many times because I want to send data in moment when module arduino send AT+CIPSEND. In real time I don’t make so often, but sometimes, I send data and have this problem. Thank you)))

Hi!
ReqPacket send data fine. There is broker didn’t send data. Work again after my module send ReqPacket…

Listen, I write code for process data from broker. But I can’t compare if(qq == “123”), is work only if I past ':'after “123”

#include <string.h>
int led = 13;
char *p, *i;
String tt, qq;
char buff[50]; 

void setup() {

  Serial.begin(9600);
  pinMode(led, OUTPUT); 
  Serial.println("Starting..");
}
 //digitalWrite(LED_BUILTIN, LOW);
// digitalWrite(LED_BUILTIN, HIGH);
void loop () {
       if( Serial.available() > 0 )
    Serial.readBytes(buff, 50);

  //  First strtok iteration
   p = strtok_r(buff,":",&i);
   tt=p;
   Serial.print(tt);
   
   //  Second strtok iteration
   p = strtok_r(NULL,":",&i);
    tt=p;
     Serial.print(tt);
    if(tt == "home")
    {digitalWrite(LED_BUILTIN, HIGH);
    Serial.print('\n');
    
    p = strtok_r(NULL,":",&i);
    qq=p;
  Serial.print(qq);
    if(qq == "123"){Serial.print("Value=123");}
    }
     memset(buff,0,50);
}

When I write Serial.print(qq);, The serial monitor deduces data “123”, but why I can’t compare if(qq == “123”). How I can to decide this problem. Also I can’t use another symbol after 123. There is variable from 50- 1000, non constants. Thank you!

P.S. Sorry, that I did not begin to create a new topic, so as not to litter the forum.

For searching for a string inside strings use strtok. It looks for a matching string and gives a pointer
to the location of the found string, that is not NULL.

I recived the data 123, if i use only print Serial.print(qq); but
if(qq == “123”){Serial.print(“Value=123”);} - not working. I try to use strtok it also work so.

#include <string.h>
int led = 13;
//char *record ;//= "<0>:home:123";
char *p, *i;
String tt, qq;
char buff[50]; 

void setup() {

  Serial.begin(9600);
  pinMode(led, OUTPUT); 
  Serial.println("Starting..");
}
void loop () {
       if( Serial.available() > 0 ){
    Serial.readBytes(buff, 50);
    // Serial.print 
  //  Start & First
   p = strtok(buff,":");
   tt=p;
   Serial.print(tt);
///////////////////////////////////////////////
   //  Second strtok iteration
   p = strtok(NULL, ":");
   tt=p;
   Serial.print(tt);
    if(tt == "home")
    {digitalWrite(LED_BUILTIN, HIGH);
    Serial.print('\n');
   // Third  strtok iteration
   p = strtok(NULL, ":");   
   qq=p;
 Serial.print(qq);
   if(qq == "123"){Serial.print("Value=123");}
        }
  }
}

I think qq=p might not work.
Better use sprintf to copy qq contents to p.
Or strcpy.

@ALEXIS looks like you are using the transparent mode for data sending. It is a bit more complex in processing the data than non transparent mode where you choose when to read the commands buffered in the module.

Hello MBARI!
Do you can explain me what the transparent mod, and how to find another way to read data. I finded how to cobvert dec to ASCII, across String. I added some code to my program, and after it I can see Topic and metric on my Serial monitor. But String more hard, I even say I can’t to operate with it. So please can help me with transparent mode. I put in code with String…

 while(1)
    {
       if( Serial.available() > 0 )
    {
   {
   hh = Serial.read();   //  unsigned char hh;
 Serial. print(hh);
     if(hh=='0'){
     tt = Serial.readString();  // String tt;
     Serial.print(tt);
   } 

      }}

}
In end I recived data: @home:745. There is, that I wanted recived.
But I can’t operate with this data.

try this

 if ( Serial.available() > 0 )while (1) {

       hh = Serial.read();   //  unsigned char hh;
       Serial. print(hh);
       if (hh == ‘0’) {
         tt = Serial.readString();  // String tt;
         Serial.print(tt);
         break;
       }
     }

Hmmm, I want escape from String, because I can’t use data for further processing. Or how String “tt” convert to massive (char buff[50]; ).

Ravi please show me how it do, i can’t find information how String convert to char*.

@ALEXIS I havent worked with direct String type in Arduino. But according to my experience String is just a char array terminated in ‘\0’ or null character.
I didnt understand the question exactly, what you are trying to implement?