Hi there,
I have an Adafruit Fona 800 and want to trigger the callerid, if the callerid is valid then hangup en start some function.
But the indexOf() won't work at all, what's wrong with this code?
String validPhoneNumbers[] = {"+45000000", "+45000001"};
String inputString = "";
String phonenumber;
int f;
void loop() {
while (! Serial.available() ) {
if (fona.available()) {
f = fona.read();
Serial.write(f);
if (f == 10) { // newline
if (inputString.indexOf("CLIP:") >= 0) {
Serial.print("incoming call...");
// here with substring() first the first ", and filter the phonenumber.
if (checkPhoneNumber(phonenumber)) {
Serial.println("all ok my friend");
// call some function
}
}
inputString = ""; //reset string
}
else {
char inChar = Serial.read();
inputString += inChar;
}
}
}
}
boolean checkPhoneNumber(String number) {
int i = sizeof( validPhoneNumbers )/sizeof( String );
while(i--) {
if (validPhoneNumbers[i] == number)
return true;
}
return false;
}