GSM-GPRS-GPS-Shield icon indicating copy to clipboard operation
GSM-GPRS-GPS-Shield copied to clipboard

getIMEI return OK - not IMEI

Open antoniosap opened this issue 9 years ago • 2 comments

function:

int getIMEI(char* imei);

lost the imei received displyed in debug mode and return OK string

antoniosap avatar Mar 06 '15 15:03 antoniosap

above fix didn't work for me, so i wrote my own funtion.

replace these two function in SIM900.cpp

int SIMCOM900::getIMEI(char *imei) int SIMCOM900::SimpleRead()

with

int SIMCOM900::getIMEI(char *imei){
  //AT command to get IMEI.
  int i =0,a;
  unsigned long startTime = millis();
  char c;
  SimpleWriteln(F("AT+GSN"));
  while(true){
    a = SimpleRead();
    c = a;
    if(a!=-1){
      if(a == 13 && i==15){
        imei[15] = '\0';
        return 1;
      }
      if(a != 13 && a!= 10 && c!= 'O' && c!= 'K'){
        startTime = millis();
        imei[i] = c;
        i++;
      }
    }else if((millis() - startTime)>5000){
      return 0;
    }
  }
  return 0;
}   

int SIMCOM900::SimpleRead(){
  char datain;
  if(_cell.available()>0){
    datain=_cell.read();
    if(datain>0){
      return datain;
    }else
      return -1;
  }else
    return -1;
}

nishantpardamwar avatar Mar 31 '16 07:03 nishantpardamwar

Hi, Although I have faced with the same problem, I can not solve with this solution, Can you help me please realted with getting IMEI with using Marco's library?

michaelproino avatar Jun 16 '16 12:06 michaelproino