Need Help:Return to void gprs() function if SIM800L is failing

hi…my project is about tracking system with SIM800L and NEO6M gps.i have encountered some problems that i couldnt solve…i hope the community will lend some help…below is the snippet of the code for my project…

void waitUntilResponse(String response)
{
beltTime = millis();
responseString="";
String totalResponse = “”;
while(responseString.indexOf(response) < 0 && millis() - beltTime < maxResponseTime)
{
readResponse();
totalResponse = totalResponse + responseString;
Serial.println(responseString);
}

if(totalResponse.length() <= 0)
{
Serial.println(“No response from the module. Check wiring, SIM-card and power!”);
return;
}
else if (responseString.indexOf(response) < 0)
{
Serial.println(“Unexpected response from the module”);
Serial.println(totalResponse);
digitalWrite(rstpin = 4,LOW );
delay(2000);
digitalWrite(rstpin = 4, HIGH);
gprs();
}
}

As you can see,if my arduino read “unexpected response from module”, it will trigger the SIM800L reset pin and try to reconnect to the GPRS,but it keep repeating the void gprs() many times and make the reconnecting process much longer…i have attached the code and hope someone willing to help me.

gps.ino (5.56 KB)

abe_long:
it will trigger the SIM800L reset pin and try to reconnect to the GPRS,but it keep repeating the void gprs() many times and make the reconnecting process much longer.

I can't say I understand.

And the function names in your program are not very helpful, for example tryToRead() and waitUntilResponse() "tryToRead" what? or waitUntilResponse from what or what type of response?

You have a lot of very long delay()s in your program. I reckon it would be much better to replace them all with non-blocking timing using millis() as illustrated in Several Things at a Time

In the piece I have quoted above you seem to be saying that it calls gprs() more often than you want. If so, why not implement a counter and put the number of calls under control.

However I don't understand the link that you seem to have between resetting the SIM800L and calling gprs(). Why would you want to call gprs() after you have reset the SIM800L ? They seem to me to be two separate things.

...R

my project is to make a real time vehicle tracking...what im trying to do is if the sim800l unresponsive,it will go to the function "Unexpected response from the module" and reset the sim800l and reconnect to the gprs...the coordinates obtain from the neo6m gps will be transmitted by using http get...this is why i want it to reconnect if there is a problem occur...

the trytoread() is to read the sim800l response...if the response received other than 'ok',it will be time out and reset the sim800l...hope you understand and thank you sir...

abe_long:
..hope you understand and thank you sir...

You have only responded to one part of my Reply #1 - arguably the least important part. And in that context what I was trying to suggest is that your function names would be more informative if they were tryToReadSIM800() and checkForSIM800ok()

...R

it will go to the function "Unexpected response from the module"

That is NOT a function. That may be something that a function prints, or may be a summary of a function that you need to develop.