I am trying to work with the sim900, what I am trying to do, is: 1- read the serial port, 2- input everything into a string, 3- search a parameter in that string, 4- clean the string. The code is really simple, but i cant understand what i am doing wrong. If anyone make something similar, or knows how to do it I will be graceful. Thank you very much Jose Luis
String leido = " ";
void setup(){ // the Serial1 baud rate
Serial.begin(9600);
Serial1.begin(9600);
}
String leido = " ";
void setup(){
// the Serial1 baud rate
Serial.begin(9600);
Serial1.begin(9600);
}
void loop()
{
//if (Serial1.available()) { Serial.write(Serial1.read()); } // Sim900
if (Serial.available()) { Serial1.write(Serial.read()); } // pc
leido = LeerSerial();
Serial.println(leido);
if (find_text("READY",leido)==1){leido = " ";}
}
String LeerSerial(){
char character;
while(Serial1.available()) {
character = Serial1.read();
leido.concat(character);
delay (10); }
if (leido != "") { Serial1.println(leido);return leido; }
}
int find_text(String needle, String haystack) {
int foundpos = -1;
for (int i = 0; (i < haystack.length() - needle.length()); i++) {
if (haystack.substring(i,needle.length()+i) == needle) {
foundpos = 1;
}
}
return foundpos;
}