Beispiel #1
0
void GM862::init() {
  delay(1000);
  getStatus();                    // identify if modem is turned on or not
  Serial.println("GM862 MC Control");
  // test to see if modem is on
  if(!isOn()){
    Serial.println("Turning on Modem ...");
    switchOn();                   // switch the modem on
    delay(4000);                        // wait for the modem to boot
  }
  Serial.println("initializing modem ...");
  char buf[BUF_LENGTH];
  requestModem("AT", 1000, true, buf);
  requestModem("AT+IPR=19200", 1000, true, buf);
  requestModem("AT+CMEE=2", 1000, true, buf);
  requestModem("AT+CNMI=2,1,2,1,0", 1000, true, buf);
  requestModem("AT+CMGF=1", 1000, true, buf);             // send text sms
  state |= STATE_INITIALIZED;
  checkNetwork();             // check the network availability
//  modem.version();                    // request modem version info
/*  while (!modem.isRegistered()) {
    delay(1000);
    modem.checkNetwork();             // check the network availability
  }*/
  Serial.println("Modem is ready");
}
Beispiel #2
0
/*
 * eplus
 *   internet.eplus.de, eplus, eplus
 * o2
 *   internet, <>, <>
 */
void GM862::initGPRS() {
  char buf[BUF_LENGTH];
  Serial.println("initializing GPRS ...");
  requestModem("AT+CGDCONT=1,\"IP\",\"internet\",\"0.0.0.0\",0,0", 1000, false, buf);
  requestModem("AT#USERID=\"\"", 1000, false, buf);
  requestModem("AT#PASSW=\"\"", 1000, false, buf);
  Serial.println("done");
}    
Beispiel #3
0
void GM862::version() {
  char buf[BUF_LENGTH];
  Serial.println("version info ...");
  requestModem("AT+GMI", 1000, false, buf);
  requestModem("AT+GMM", 1000, false, buf);
  requestModem("AT+GMR", 1000, false, buf);
  requestModem("AT+CSQ", 1000, false, buf);
  Serial.println("done");
}
Beispiel #4
0
void	GPRS::setup()
	{
		if(waiting==OFF)
		{
			char buf[BUF_LENGTH];requestModem(ATcommand[ATindex], 1000, true, buf);
			timestart = millis();
			waiting = ON;
			timeout = 5000;
			Serial.println("Started GM865");
			ATindex++;
			
		}
		else
		{
			if(Serial3.available())
			{
				if(readterminal())
					waiting = OFF;
				else if(!checktimeout(timeout) || !readterminal())
				{
					gprsstate = setupstate;
					ATindex=0;
					waiting=OFF;
					timeout = 5000;
					timestart=0;
				}
			}
			
		}
	}
Beispiel #5
0
boolean GM862::getStatus(){
  char buf[BUF_LENGTH];
  byte r = 0;
  if(state == STATE_NONE){
  r = requestModem("AT",1000,true,buf);
//  Serial.println("r: " + r);
    if(r){
        state |= STATE_ON;
    }
  }
  return state;
}
Beispiel #6
0
void GM862::checkNetwork() {
  char buf[BUF_LENGTH];
  char result;
  Serial.println("checking network ...");
  requestModem("AT+CREG?", 1000, false, buf);
  result = buf[20];
  if (result == '1') {
    state |= STATE_REGISTERED;
  }
  else {
    state &= ~STATE_REGISTERED;
  }
  Serial.println("done");
}
Beispiel #7
0
void GM862::deleteMessage(String index){
    char buf[BUF_LENGTH];
    char cmdBuf[BUF_LENGTH];
    char delflag;
    String cmd = "AT+CMGD=";
    if(index.equalsIgnoreCase("0")){
        cmd.concat("1,3");  // delete all read messages from <memr> storage, sent and unsent mobile originated messages, leaving unread messages untouched
    } else {
        index.concat(",0");
        cmd.concat(index);
    }
    cmd.toCharArray(cmdBuf,BUF_LENGTH);
    requestModem(cmdBuf, 2000,true,buf);
}
Beispiel #8
0
void GM862::sendSMS(String number, String message) {
  char buf[BUF_LENGTH];
  char cmdbuf[30];
  String Scmdbuf = "AT+CMGS=\"";
  Serial.println("sending SMS ...");
  Serial.println("number: "+number+" and message: "+message);
  Scmdbuf.concat(number + "\"");
  Scmdbuf.toCharArray(cmdbuf,30);
  requestModem(cmdbuf, 1000, false, buf);
  modem->print(message);
  modem->print(0x1a, BYTE);
  getsTimeout(buf, 2000);
//  Serial.println(buf);
//  Serial.println("done");
}
Beispiel #9
0
Position GM862::requestGPS(void) {
  char buf[150];
  Serial.println("requesting GPS position ...");
  requestModem("AT$GPSACP", 2000, false, buf);
  if (strlen(buf) > 29) {
    actPosition.fix = 0;	// invalidate actual position			
    parseGPS(buf, &actPosition);
    if (actPosition.fix > 0) {
      Serial.println(actPosition.fix);
      state |= STATE_POSFIX;
    }
  }
  else {
    actPosition.fix = 0;
    Serial.println("no fix");
    state &= ~STATE_POSFIX;
  }
  return actPosition;
}
Beispiel #10
0
boolean GM862::openHTTP(char *domain) {
  char buf[BUF_LENGTH];
  char cmdbuf[50] = "AT#SKTD=0,80,\"";
  byte i = 0;
  boolean connect = false;
  Serial.println("opening socket ...");
  strcat(cmdbuf, domain);
  strcat(cmdbuf, "\",0,0\r");
  requestModem(cmdbuf, 1000, false, buf);
  do {
    getsTimeout(buf, 1000);
    Serial.print("buf:");
    Serial.println(buf);
    if (strstr(buf, "CONNECT")) {
      connect = true;
      break;
    }
  } while (i++ < 10);
  if (!connect) {
    Serial.println("failed");
  }
  return (connect);
}
Beispiel #11
0
int GM862::parseMessage(char *buf){
    char buf2[BUF_LENGTH];
    int state;
    String loc;
//    Serial.print("pm -->");
//    Serial.println(buf);
    if(strstr(buf,"CMTI")){ // incoming txt message
        Serial.println("getting message ... ");
        loc = strstr(buf,",")+1;
        loc = loc.trim();
//        Serial.println("mem loc: " + loc);
        requestModem("AT+CMGL=\"REC UNREAD\"",1000,false,buf2); // list message
	   while(!strstr(buf2,"+CMGL:")){	// wait until the txt message response is sent.
	       getsTimeout(buf2,100);
	   }
//      Serial.print(buf2);
    state = extractData(buf2);
    Serial.print("State Parse: ");
    Serial.println(state);
//    delay(4500);
    deleteMessage(loc);
    }
  return state;
}
Beispiel #12
0
void GM862::warmStartGPS() {
  char buf[BUF_LENGTH];
  Serial.println("warm start GPS ...");
  requestModem("AT$GPSR=2", 1000, false, buf);
  Serial.println("done");
}
Beispiel #13
0
void GM862::disableGPRS() {
  char buf[BUF_LENGTH];
  Serial.println("switching GPRS off ...");
  requestModem("AT#GPRS=0", 1000, false, buf);
  Serial.println("done");
}