int SIMCOM900::readCellData(int &mcc, int &mnc, long &lac, long &cellid) { if (getStatus()==IDLE) return 0; //_tf.setTimeout(_GSM_DATA_TOUT_); //_cell.flush(); SimpleWriteln(F("AT+QENG=1,0")); SimpleWriteln(F("AT+QENG?")); if(gsm.WaitResp(5000, 50, "+QENG")!=RX_FINISHED_STR_NOT_RECV) return 0; //mcc=_tf.getValue(); // The first one is 0 mcc=_cell.read(); //mcc=_tf.getValue(); mcc=_cell.read(); //mnc=_tf.getValue(); mnc=_cell.read(); //lac=_tf.getValue(); lac=_cell.read(); //cellid=_tf.getValue(); cellid=_cell.read(); gsm.WaitResp(5000, 50, "+OK"); SimpleWriteln(F("AT+QENG=1,0")); gsm.WaitResp(5000, 50, "+OK"); return 1; }
int SIMCOM900::getCCI(char *cci) { //Status must be READY if((getStatus() != READY)) return 2; //_tf.setTimeout(_GSM_DATA_TOUT_); //Timeout for expecting modem responses. //_cell.flush(); //AT command to get CCID. SimpleWriteln(F("AT+QCCID")); //Read response from modem #ifdef UNO _tf.getString("AT+QCCID\r\r\r\n","\r\n",cci, 21); #endif #ifdef MEGA _cell.getString("AT+QCCID\r\r\r\n","\r\n",cci, 21); #endif //Expect "OK". if(gsm.WaitResp(5000, 50, "OK")!=RX_FINISHED_STR_NOT_RECV) return 0; else return 1; }
int SIMCOM900::configandwait(char* pin) { int connCode; //_tf.setTimeout(_GSM_CONNECTION_TOUT_); if(pin) setPIN(pin); //syv // Try 10 times to register in the network. Note this can take some time! for(int i=0; i<10; i++) { //Ask for register status to GPRS network. SimpleWriteln(F("AT+CGREG?")); //Se espera la unsolicited response de registered to network. while(gsm.WaitResp(5000, 50, "+CGREG: 0,")!=RX_FINISHED_STR_RECV) //while (_tf.find("+CGREG: 0,")) // CHANGE!!!! { //connCode=_tf.getValue(); connCode=_cell.read(); if((connCode==1)||(connCode==5)) { setStatus(READY); SimpleWriteln(F("AT+CMGF=1")); //SMS text mode. delay(200); // Buah, we should take this to readCall() SimpleWriteln(F("AT+CLIP=1")); //SMS text mode. delay(200); //_cell << "AT+QIDEACT" << _DEC(cr) << endl; //To make sure not pending connection. //delay(1000); return 1; } } } return 0; }
int SIMCOM900::read(char* result, int resultlength) { char temp; int i=0; for(i=0; i<resultlength;i++){ temp=gsm.read(); if(temp>0){ Serial.print(temp); result[i]=temp; } } return i; }
/** * SIMCOM900::read(char* buffer, int buffersize) * * Waits for data to be readable from the gsm module, reads data until * no more is available or the buffer has been filled * * returns number of bytes read * */ int SIMCOM900::read(char* result, int resultlength) { char temp; int i=0; #ifdef DEBUG_ON Serial.print(F("Starting read..\nWaiting for Data..")); #endif // Wait until we start receiving data while(gsm.available()<1) { delay(100); #ifdef DEBUG_ON Serial.print(F(".")); #endif } while(gsm.available()>0 && i<(resultlength-1)) { temp=_cell.read(); if(temp>0) { #ifdef DEBUG_ON Serial.print(temp); #endif result[i]=temp; i++; } delay(1); } // Terminate the string result[resultlength-1]='\0'; #ifdef DEBUG_ON Serial.println(F("\nDone..")); #endif return i; }
int SIMCOM900::changeNSIPmode(char mode) { //_tf.setTimeout(_TCP_CONNECTION_TOUT_); //if (getStatus()!=ATTACHED) // return 0; //_cell.flush(); SimpleWrite(F("AT+QIDNSIP=")); SimpleWriteln(mode); if(gsm.WaitResp(5000, 50, "OK")!=RX_FINISHED_STR_NOT_RECV) return 0; //if(!_tf.find("OK")) return 0; return 1; }
int SIMCOM900::setPIN(char *pin) { //Status = READY or ATTACHED. if((getStatus() != IDLE)) return 2; //_tf.setTimeout(_GSM_DATA_TOUT_); //Timeout for expecting modem responses. //_cell.flush(); //AT command to set PIN. SimpleWrite(F("AT+CPIN=")); SimpleWriteln(pin); //Expect "OK". if(gsm.WaitResp(5000, 50, "OK")!=RX_FINISHED_STR_NOT_RECV) return 0; else return 1; }
int SIMCOM900::getIMEI(char *imei) { //_tf.setTimeout(_GSM_DATA_TOUT_); //Timeout for expecting modem responses. //_cell.flush(); //AT command to get IMEI. SimpleWriteln(F("AT+GSN")); //Read response from modem #ifdef UNO _tf.getString("\r\n","\r\n",imei, 16); #endif #ifdef MEGA _cell.getString("\r\n","\r\n",imei, 16); #endif //Expect "OK". if(gsm.WaitResp(5000, 50, "OK")!=RX_FINISHED_STR_NOT_RECV) return 0; else return 1; }
boolean SIMCOM900::readCall(char* number, int nlength) { int index; if (getStatus()==IDLE) return false; //_tf.setTimeout(_GSM_DATA_TOUT_); if(gsm.WaitResp(5000, 50, "+CLIP: \"")!=RX_FINISHED_STR_RECV) //if(_tf.find("+CLIP: \"")) { #ifdef UNO _tf.getString("", "\"", number, nlength); #endif #ifdef MEGA _cell.getString("", "\"", number, nlength); #endif SimpleWriteln("ATH"); delay(1000); //_cell.flush(); return true; }; return false; };
boolean SIMCOM900::readSMS(char* msg, int msglength, char* number, int nlength) { long index; char *p_char; char *p_char1; /* if (getStatus()==IDLE) return false; */ #ifdef UNO _tf.setTimeout(_GSM_DATA_TOUT_); #endif //_cell.flush(); SimpleWriteln(F("AT+CMGL=\"REC UNREAD\",1")); if(gsm.WaitResp(5000, 50, "+CMGL")!=RX_FINISHED_STR_RECV) //if(_tf.find("+CMGL: ")) { /* //index p_char = strchr((char *)(gsm.comm_buf),':'); p_char1 = p_char+2; //we are on the first char of string p_char = strchr((char *)(p_char1), ','); if (p_char != NULL) { *p_char = 0; } //strcpy(msg, (char *)(p_char1)); // rec unread p_char++; p_char1 = strchr((char *)(p_char), ','); if (p_char1 != NULL) { *p_char1 = 0; } // number p_char1++; p_char1++; p_char = strchr((char *)(p_char1), '\"'); if (p_char != NULL) { *p_char = 0; } strcpy(number, (char *)(p_char1)); // UTC time p_char = strchr((char *)(p_char), '\n'); p_char1 = strchr((char *)(p_char), '\n'); if (p_char1 != NULL) { *p_char1 = 0; } strcpy(msg, (char *)(p_char)); */ #ifdef UNO index=_tf.getValue(); #endif #ifdef MEGA //index=_cell.read(); #endif #ifdef UNO _tf.getString("\",\"", "\"", number, nlength); #endif #ifdef MEGA _cell.getString("\",\"", "\"", number, nlength); #endif #ifdef UNO _tf.getString("\n", "\nOK", msg, msglength); #endif #ifdef MEGA _cell.getString("\n", "\nOK", msg, msglength); #endif SimpleWrite(F("AT+CMGD=")); SimpleWriteln(index); // Serial.print("VAL= "); // Serial.println(index); gsm.WaitResp(5000, 50, "OK"); return true; }; return false; };
boolean SIMCOM900::readSMS(char* msg, int msglength, char* number, int nlength) { Serial.println(F("This method is deprecated! Please use GetSMS in the SMS class.")); long index; char *p_char; char *p_char1; /* if (getStatus()==IDLE) return false; */ #ifdef UNO _tf.setTimeout(_GSM_DATA_TOUT_); #endif //_cell.flush(); WaitResp(500, 500); SimpleWriteln(F("AT+CMGL=\"REC UNREAD\",1")); WaitResp(5000, 500); if(gsm.IsStringReceived("+CMGL")) { //index p_char = strchr((char *)(gsm.comm_buf),'+CMGL'); p_char1 = p_char+3; //we are on the first char of string p_char = p_char1+1; *p_char = 0; index=atoi(p_char1); p_char1 = p_char+1; p_char = strstr((char *)(p_char1), "\",\""); p_char1 = p_char+3; p_char = strstr((char *)(p_char1), "\",\""); if (p_char != NULL) { *p_char = 0; } strcpy(number, (char *)(p_char1)); ////// p_char1 = p_char+3; p_char = strstr((char *)(p_char1), "\",\""); p_char1 = p_char+3; p_char = strstr((char *)(p_char1), "\n"); p_char1 = p_char+1; p_char = strstr((char *)(p_char1), "\n"); if (p_char != NULL) { *p_char = 0; } strcpy(msg, (char *)(p_char1)); // #ifdef UNO // index=_tf.getValue(); // #endif // #ifdef MEGA //index=_cell.read(); // #endif // Serial.println("DEBUG"); // #ifdef UNO // _tf.getString("\",\"", "\"", number, nlength); // #endif // Serial.println("PRIMA"); // #ifdef MEGA // _cell.getString("\",\"", "\"", number, nlength); // #endif // Serial.println("DEBUG"); // #ifdef UNO // _tf.getString("\n", "\nOK", msg, msglength); // #endif // #ifdef MEGA // _cell.getString("\n", "\nOK", msg, msglength); // #endif SimpleWrite(F("AT+CMGD=")); SimpleWriteln(index); // Serial.print("VAL= "); // Serial.println(index); gsm.WaitResp(5000, 50, "OK"); return true; }; return false; };