I have Arduino UNO and a Sim800L module and I know the way to read the serial, it is something like this question, but when I perform this function :
String GetRegData()
{
Serial.println("Get nearby antenna info ...");
SIM800L.print("AT+CNETSCAN=1\r");
delay(1000);
SIM800L.print("AT+CNETSCAN\r");
delay(1000);
String buffer2;
while (SIM800L.available())
{
char c = SIM800L.read();
Serial.print(c);
buffer2.concat(c);
delay(10);
}
//Serial.println();
return buffer2;
}
The output is :
AT+CMGF=1
OK
AT+CNMI=2,2,0,0,0
OK
AT+CNETSCAN=1
OK
AT+CNETSCAN
Operator:"XXXX",MCC:XXX,MNC:XX,Rxlev:XX,Cellid:XX,Arfcn:XX,Lac:q5er32xlAair32xlAacrseifcca,Nvdc00
This AT command (AT+CNETSCAN) should scan all nearby antenna and print some information in multiple lines(according to datasheet), when I execute this command manually on this devices(SIM800L) ,I get multiple line such :
Operator:"XXXX",MCC:XXX,MNC:XX,Rxlev:XX,Cellid:XX,Arfcn:XX,Lac:XX,Bsic:XX
Operator:"XXXX",MCC:XXX,MNC:XX,Rxlev:XX,Cellid:XX,Arfcn:XX,Lac:XX,Bsic:XX
Operator:"XXXX",MCC:XXX,MNC:XX,Rxlev:XX,Cellid:XX,Arfcn:XX,Lac:XX,Bsic:XX
OK
But I don't know what happen when I do it programmatically, It is messed up, I tried to change baud rate and change receiving method and read char by char and I did put delaying between receives and I tried to do if
or for
instead of while
but no luck.
I guess there is a delay between receiving each line and it breaks the serial availability but I don't know what to do ! any help would be appreciated.
By the way, my setup function:
void setup() {
SIM800L.begin(9600);
Serial.begin(9600);
delay(3000);
SIM800L.print("AT+CMGF=1\r");
delay(100);
SIM800L.print("AT+CNMI=2,2,0,0,0\r");
delay(100);
GetRegData();
delay(1000);
}
Ps: The whole thing(Arduino+Sim800L) works perfectly fine with no error and the Simcard is unlocked and it can send an receive SMS and Calls ,etc.
Operator:"XXXX",MCC:XXX,MNC:XX,Rxlev:XX,Cellid:XX,Arfcn:XX,Lac:...
substitute 1vs1 the actual chars? What is the first unexpected character in the response? Is that message printed by theSerial.print(c);
or by another external call printing buffer2? – Roberto Caboni