Reputation: 301
I'm having troubles getting the correct response from a SIM900 module, if I use the code as it is in the example it works just fine.
for this command:
void GetContacts(){
mySerial.print("AT+CPBF=\"Mailbox\"");
delay(100);
mySerial.println();
}
and with this print code:
if (mySerial.available()){
Serial.write(mySerial.read());
}
I get:
AT+CPBF="Mailbox"
+CPBF: 1,"+584125089112",145,"Mailbox3"
+CPBF: 2,"+584264273127",145,"Mailbox1"
+CPBF: 3,"+584147373665",145,"Mailbox2"
OK
which is perfect, but if I try to read the output and then print it like this:
if (mySerial.available()){
int intValue = mySerial.read();
String stringOne;
stringOne = String(intValue, HEX); //int to HEX
char charConversion;
charConversion = hexNibbleToChar(stringOne[0]) * 16 + hexNibbleToChar(stringOne[1]); //HEX to Char
contactString += charConversion;
Serial.println(contactString);
}
char hexNibbleToChar(char nibble){
if (nibble >= '0' && nibble <= '9')
return nibble - '0';
else if (nibble >= 'a' && nibble <= 'f')
return 10 + nibble - 'a';
else
return 10 + nibble - 'A';
}
I get:
AT+CPBF="Mailbox"
+CPBF: 1,"+584125089112",145,"Mailbox3"
+CPBF: 2,"+58426
Suddenly stops there and I have no idea why, I've tried just reading and printing right after the int intValue = mySerial.read(); line, and when I convert the decimal string that I got there to char with any online converter the result it's the same.
Does any of you see what I'm doing wrong?
Thanks, Juan Docal
Upvotes: 0
Views: 1690
Reputation: 301
Well, for those of you with the same problem or something related, my solution was to save all the response in a String variable and then proccess it when the "mySerial" variable wasn't available anymore
String contactString = "";
if(mySerial.available()){
contactString += (char) mySerial.read();
}
else{
if(contactString != ""){
//Process response
}
contactString = "";
}
I was proccessing all the data within mySerial.available() and somehow I was truncating the response...
Upvotes: 1