Hello,
Here is an exemple with other code. I should have shown this one. But there more code 
Thank for your reading
In powerOnSim908() look at sendAtCommand() then go to sendAtcomand for detail of my problem (my code works in spite of this
(@Paul, I take care to put the { in a line, as you told me)
(I put my comments in CAPITAL)
boolean powerOnSim908(void)
{
if(debug)
{
Serial.println(F("Powering up SIM908"));
}
boolean turnedON = false;
//uint8_t answer=0;
int cont;
for (cont=0; cont<3; cont++)
{
digitalWrite(pin_power,HIGH);
delay(1500);
digitalWrite(pin_power,LOW);
// PAY ATTENTION AT THIS LINE REGARDING MY WORRY
Serial.println(F("Testing if modeule is up"));
if(sendATcommand("AT", "OK", 5000)) // GO TO HAVE A LOOK AT sendAtCommand() NOW
{
cont = 4; // Leave the loop
turnedON = true;
}
else
{
turnedON = false;
if(debug)
{
Serial.println(F("\nTrying agin to turn on SIM908"));
}
};
}
if(turnedON)
{
if(debug)
{
Serial.println(F("Module is tunrned on\n"));
}
}
else
{
if(debug)
{
Serial.println(F("Module is NOT tunrned ON\n"));
}
}
return turnedON;
}
The sendAtCommande wait 5sec for an OK. This work.
Now look at my sendAtCommand(). I change it a little bit to store a buffer the return value. Look...
boolean sendATcommand(char* ATcommand, char* expected_answer, unsigned int timeout)
{
uint8_t x=0;
bool answer=false;
//buffer[0]='\0';
unsigned long previous;
//memset(buffer, '\0', 100); // Initialice the string
delay(100);
// I DO NOT UNDERTSAND THAT LINE, BECAUSE APPERENTLY IS NOT CLEENING THE INPUT BUFFER, SEE BELOW
while( Serial.available() > 0) Serial.read(); // Clean the input buffer
if (ATcommand[0] != '\0')
{
// HERE IS SEND THE AT COMMAND
Serial.println(ATcommand); // Send the AT command
}
x = 0;
previous = millis();
index=0;
do
{
// FROM THAT POINT THE BUFFER SHOULD BE CLEAN AND PRINT THE RESULT OF THE "AT" COMMAND
if(Serial.available() > 0)
{
if(index < 199) // One less than the size of the array // Same as buffer size
{
// HERE, IT STORE THE SERIAL DATAS GENERATE BY THE AT COMMAND INTO buffer
inChar = Serial.read(); // Read a character
buffer[index] = inChar; // Store it
index++; // Increment where to write next
//Serial.println(index);
buffer[index] = '\0'; // Null terminate the string
}
}
}while(((millis() - previous) < timeout));
if(strstr(buffer,"NORMAL POWER DOWN") != NULL)
{
answer = false;
}
else if (strstr(buffer, expected_answer) != NULL) // check if the desired answer (OK) is in the response of the module
{
// HERE I PRINT THE BUFFER CONTENT.
Serial.println(F("### BUFFER"));
Serial.println(buffer);
Serial.println(F("### END BUFFER"));
answer = true;
}
else
{
answer = false;
}
if(debug)
{
if(answer)
{
//Serial.println(F("Expected answer : OK!\n"));
}
else
{
//Serial.println(F("Expected answer : KO!\n"));
};
}
// IT RETUR TRUE OF IT GET "OK" OR FALSE IF NOT
return answer;
}
While the powerOnSim908 is lunched,
This is printed : 'Testing if modeule is up'
the AT is sent.
BUT In my terminal, Serila.println(buffer) print me that:
BUFFER
Testing if modeule is up
AT
OK
Call Ready
GPS Ready
END BUFFER
It includes 'Testing if modeule is up' and it should not. It why I am asking if that part of code
while( Serial.available() > 0) Serial.read(); // Clean the input buffer
it really cleaning the buffer
Serial.println(buffer) should print
AT
OK
Call Ready
GPS Ready
and not
Testing if modeule is up
AT
OK
Call Ready
GPS Ready
Do you see my worries?
Thank a lot