Sending SMS hangs thing.handle Arduino


#1

Hey all,

So my code is written such that if a SMS is recieved by the SIM900 module, it will send a reply back to me as an SMS as well as update the thinger page about the state of each sensor.

But, when it sends an SMS the handle hangs and refuses to reconnect to the thinger platform.

Is it a problem with the Module, or does the thing.handle not allow to use any other SIM900 commands?

I have enabled debug and got confirmation that it refuses to reconnect.

Thanks in advanced


#2

Hi @VarunNelakanti, can you share your code? Not sure if such kind of device is able to send SMS and use GRPS connection simultaneously, without breaking connection.


#3

Hey @alvarolb, yeah sure I have pasted the code down below, I have not included the setup of the APN and the other steps(Hoping that is okay as I doubt it will make a difference)

void loop()
{

thing.handle();
delay(100);
loopControl();

}

String readSIM900A() //Function ot read SMS recieved
{
String buffer;

while (Serial1.available())
{
    char c = Serial1.read();
    buffer.concat(c);
    delay(10);
}

  return buffer;

}
void loopControl() //Perform actions based on SMS recieved
{

String inchar = readSIM900A();
inchar.remove(0, 51);
int len = inchar.length();
Serial.print(inchar);
inchar.remove(len - 2, 2);
if (inchar == "Stats")
  stats();   // These are different functions
if (inchar == "Temperature")
  temp();	//Functions
if (inchar == "RelayON")
  RelayON();	//Functions
if (inchar == "RelayOFF")
  RelayOFF();	//Functions
else
  bright(inchar);//Functions
return;

}
String stats()
{
msg= “Hello, Is SIM900 working?”;
SendMessage(msg);
}

void SendMessage(String M)
{

delay(1000);
Serial1.print(“AT+CMGS=”+919620984969"\r");
delay(1000);
Serial.print(M);
Serial1.println(M);
Serial1.print("\r");
delay(1000);
Serial1.println((char)26);
Serial1.println();
return;
}

Thank You in advanced


#4

Hey @alvarolb, Also I created a function just to call thing.handle for a few seconds and then call thing.stop to close the connection so that the SIM900 can recieve SMS again.

But by doing so , i have noticed that the SIM900 later refuses to connect to its GPRS and also sometimes to its network.

Thanks in advanced.

PS- the functions is just

void thingstuff() // This is called from loop every 30 seconds using the BlinkwithoutDelay logic
{
thing.handle();
delay(5000);
thing.stop();
}


#5

Hi @VarunNelakanti, I am not sure if you can read from the serial connection as you are doing. I mean, the current thinger.io implementation (or any other working with sockets) will be working with the Serial connection also for handling the socket connection. If you are “interfering” with the Serial, there will be packets in the socket that will be missing, and the connection will be interrupted. It should recover eventually, but as long as you keep reading from it, the problem will persist.

Regarding the stop connection, it should just disconnect the socket, and not the network. But not sure what will happen when you are also working with the serial by your side… Maybe this is the problem?


#6

Hey @alvarolb, yeah i guess that is the problem. Thank you so much for helping me. Guess i have to use another method to get a message from the project. Possibly an email?

Thanks again. :smiley: