Hi
I have a function, which i use to run all my AT COMMANDS.
But it currently just waits for a response, and not for the modem to connect, get ip or some other function that might require time.
I need the function to wait for the right response (somehow?).
So instead of just shooting ERROR when I run a command, I want it to check the response, and if its not "OK" or "CONNECTED" or whatever the command is supposed to return, I want it to wait for the right response.
Ive tried jugling around with a function for it, but I cant get it working.
The function I use currently, looks like this:
void ModemCommand(String command)
{
//Send command to modem
mySerial.println(command);
Serial.println(command);
delay(100);
while (!mySerial.available())
{
Serial.println(F("No response yet"));
delay(1000);
}
while (mySerial.available())
{
Serial.write(mySerial.read());
}
Serial.println("");
delay(10);
}
But that will just return ERROR instead of waiting for the right response if I dont use any delays.
I currently have guesses as to how much delay is needed, but I'd like to make it more effecient and save battery ![]()
Parts of what I currently run:
ModemCommand(F("ATE0")); //Turn on echo
ModemCommand(F("AT+CFUN=1")); //Turn modem functions on
waitSec(8,F("turning on Modem functions"));
ModemCommand(F("AT+CGREG?")); //GSM attached?
ModemCommand(F("AT+CSQ")); //Signal Quality
ModemCommand(F("AT+CSTT=\"internet\"")); //Set APN
ModemCommand(F("AT+CIICR")); //Connect to APN GPRS
waitSec(8,F("connecting to APN GPRS"));
ModemCommand(F("AT+CIFSR")); //Get IP
The waitSec is a function that calls a delay*1000 on the number with a description after. Its merely for debugging.
Is there a way to wait for the command to return OK?