Exemplo n.º 1
0
int QuectelM10::sendSMS(const char* to, const char* msg)
{

  //Status = READY or ATTACHED.
  if((getStatus() != READY)&&(getStatus() != ATTACHED))
    return 0;
      
  _tf.setTimeout(_GSM_DATA_TOUT_);	//Timeout for expecting modem responses.

  _cell.flush();

  //AT command to send a SMS. Destination telephone number 
  _cell << "AT+CMGS=\"" << to << "\"" <<  _BYTE(cr) << endl; // Establecemos el destinatario

  //Expect for ">" character.
  if(!_tf.find(">")) return 0;

  //SMS text.
  _cell << msg << _BYTE(ctrlz) << _BYTE(cr) << endl; 

  //Expect "OK".
  if(!_tf.find("OK"))
    return 0;
  else  
    return 1;
}
Exemplo n.º 2
0
int QuectelM10::configandwait(char* pin)
{
  _tf.setTimeout(_GSM_CONNECTION_TOUT_);

  if(pin) setPIN(pin); //syv

  // Try 5 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.
    _cell << "AT+CGREG?" <<  _BYTE(cr) << endl; 

    //Se espera la unsolicited response de registered to network.
    if (_tf.find("+CGREG: 0,1")) 
    {
      setStatus(READY);
      
 	_cell << "AT+CMGF=1" <<  _BYTE(cr) << endl; //SMS text mode.
  	delay(200);
      // Buah, we should take this to readCall()
	_cell << "AT+CLIP=1" <<  _BYTE(cr) << endl; //SMS text mode.
  	delay(200);
  	//_cell << "AT+QIDEACT" <<  _BYTE(cr) << endl; //To make sure not pending connection.
  	//delay(1000);
  
      return 1;
    }
    //Attach GPRS service.
    //_cell << "AT+CGATT=1" <<  _BYTE(cr) << endl; 
    //delay(500);
  }
  return 0;
}
Exemplo n.º 3
0
int QuectelM10::dettachGPRS()
{
  if (getStatus()==IDLE) return 0;
   
  _tf.setTimeout(_GSM_CONNECTION_TOUT_);

  _cell.flush();

  //GPRS dettachment.
  _cell << "AT+CGATT=0" <<  _BYTE(cr) << endl;
  
  if(!_tf.find("OK")) 
  {
    setStatus(ERROR);
    return 0;
  }
  delay(500);
  
  // Commented in initial trial code!!
  //Stop IP stack.
  //_cell << "AT+WIPCFG=0" <<  _BYTE(cr) << endl;
  //	if(!_tf.find("OK")) return 0;
  //Close GPRS bearer.
  //_cell << "AT+WIPBR=0,6" <<  _BYTE(cr) << endl;

  setStatus(READY);
  return 1;
}
Exemplo n.º 4
0
void
CBitReassemblerN::cachelast (CVector < _BYTE > &vecDataIn, size_t iSegSize)
{
	size_t iSize = size_t(iSegSize) * (bPack?1:8);
    vecLastSegment.resize (iSize);
    for (size_t i = 0; i < iSize; i++)
		vecLastSegment[i] = _BYTE(vecDataIn.Separate (bPack?8:1));
}
Exemplo n.º 5
0
void
CBitReassemblerN::copyin (CVector < _BYTE > &vecDataIn, size_t iSegNum)
{
	size_t iSize = size_t(iSegmentSize) * (bPack?1:8);
    size_t offset = iSegNum * iSize;
    size_t iNewSize = offset + iSize;
    if (vecData.size() < iNewSize)
		vecData.resize (iNewSize);
    for (size_t i = 0; i < iSize; i++)
		vecData[offset + i] = _BYTE(vecDataIn.Separate (bPack?8:1));
}
Exemplo n.º 6
0
void setup()
{
  Serial.begin(9600);
  int lettera = 'A';
  int month = 4, day = 17, year = 2009;
  
  Serial << "This is an example of the new streaming" << endl;
  Serial << "library.  This allows you to print variables" << endl;
  Serial << "and strings without having to type line after" << endl;
  Serial << "line of Serial.print() calls.  Examples: " << endl;
  
  Serial << "A is " << lettera << "." << endl;
  Serial << "The current date is " << day << "-" << month << "-" << year << "." << endl;
  
  Serial << "You can use modifiers too, for example:" << endl;
  Serial << _BYTE(lettera) << " is " << _HEX(lettera) << " in hex. " << endl;
}
Exemplo n.º 7
0
int QuectelM10::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.
  _cell << "AT+CPIN=" << pin <<  _BYTE(cr) << endl; // Establecemos el pin
  //_cell << "AT+CPIN=6104" << _BYTE(cr) << endl; // Establecemos el pin

  //Expect "OK".
  if(!_tf.find("OK"))
    return 0;
  else  
    return 1;
}
Exemplo n.º 8
0
int QuectelM10::shutdown()
{
  pinMode(RESETPIN, OUTPUT);
  digitalWrite(RESETPIN, HIGH);
  delay(800);
  digitalWrite(RESETPIN, LOW);
  delay(1000);

  _tf.setTimeout(_TCP_CONNECTION_TOUT_);
  _cell.flush();
  _cell << "AT+CFUN=4" <<  _BYTE(cr) << endl; //Comprobar
   if (_tf.find("OK")) 
   {
     setStatus(IDLE);
     return 1;
   }
   // After shutdown the modem may accept commands giving no answer.
   // We'll play safe
   delay(1000);
   return 0;
}     
Exemplo n.º 9
0
int QuectelM10::write(const uint8_t* buffer, size_t sz)
{
   if((getStatus() != TCPCONNECTEDSERVER)&&(getStatus() != TCPCONNECTEDCLIENT))
    return 0;
    
   if(sz>1460)
     return 0;
  
  _tf.setTimeout(_GSM_DATA_TOUT_);

  _cell.flush();
    
  for(int i=0;i<sz;i++)
    _cell << _BYTE(buffer[i]);
  
  //Not response for a write.
  /*if(_tf.find("OK"))
    return sz;
  else
    return 0;*/
    
  return sz;  
}
Exemplo n.º 10
0
int QuectelM10::connectTCP(const char* server, int port)
{
  _tf.setTimeout(_TCP_CONNECTION_TOUT_);

  //Status = ATTACHED.
  if (getStatus()!=ATTACHED)
    return 0;

  _cell.flush();
  
  //Visit the remote TCP server.
  _cell << "AT+QIOPEN=\"TCP\",\"" << server << "\"," << port <<  _BYTE(cr) << endl;
  
   //Expect "CONNECT". 
  if(_tf.find("CONNECT"))
  {
    setStatus(TCPCONNECTEDCLIENT); 
    delay(200);
    return 1;
  }
  else 
    return 0;
}
Exemplo n.º 11
0
//GroveStreams state machine
ethernetStatus_t GroveStreams::run(void)
{
    ethernetStatus_t ret = NO_STATUS;
    const char httpOKText[] = "HTTP/1.1 200 OK";
    static char statusBuf[sizeof(httpOKText)];

    if ( nError >= MAX_ERROR )
    {
        Serial << millis() << F(" too many network errors\n");
        mcuReset();
    }

    switch (GS_STATE)
    {
    case GS_WAIT:    //wait for next send
        break;

    case GS_SEND:
        if ( _xmit() == PUT_COMPLETE )
        {
            _msLastPacket = millis();    //initialize receive timeout
            GS_STATE = GS_RECV;
            ret = PUT_COMPLETE;
        }
        else
        {
            GS_STATE = GS_WAIT;
            ++connFail;
            ++nError;
            ret = CONNECT_FAILED;
        }
        break;

    case GS_RECV:
        {
            boolean haveStatus = false;

            if(client.connected())
            {
                uint16_t nChar = client.available();
                if (nChar > 0)
                {
                    _msLastPacket = millis();
                    Serial << _msLastPacket << F(" received packet, len=") << nChar << endl;
                    char* b = statusBuf;
                    for (uint16_t i = 0; i < nChar; i++)
                    {
                        char ch = client.read();
                        Serial << _BYTE(ch);
                        if ( !haveStatus && i < sizeof(statusBuf) )
                        {
                            if ( ch == '\r' || i == sizeof(statusBuf) - 1 )
                            {
                                haveStatus = true;
                                *b++ = 0;
                                if (strncmp(statusBuf, httpOKText, sizeof(httpOKText)) == 0)
                                {
                                    ++httpOK;
                                    nError = 0;
                                    ret = HTTP_OK;
                                }
                                else
                                {
                                    ++httpOther;
                                    ++nError;
                                    ret = HTTP_OTHER;
                                    Serial << endl << endl << millis() << F(" HTTP STATUS: ") << statusBuf << endl;
                                }
                            }
                            else
                            {
                                *b++ = ch;
                            }
                        }
                    }
                }
                //if too much time has elapsed since the last packet, time out and close the connection from this end
                else if (millis() - _msLastPacket >= RECEIVE_TIMEOUT)
                {
                    _msLastPacket = millis();
                    Serial << endl << _msLastPacket << F(" Recv timeout\n");
                    client.stop();
                    if (_ledPin >= 0) digitalWrite(_ledPin, LOW);
                    GS_STATE = GS_DISCONNECT;
                    ++recvTimeout;
                    ++nError;
                    ret = TIMEOUT;
                }
            }
            else
            {
                GS_STATE = GS_DISCONNECT;
                ret = DISCONNECTING;
            }
            break;
        }

    case GS_DISCONNECT:
        // close client end
        _msDisconnecting = millis();
        Serial << _msDisconnecting << F(" disconnecting\n");
        client.stop();
        if (_ledPin >= 0) digitalWrite(_ledPin, LOW);
        _msDisconnected = millis();
        respTime = _msLastPacket - _msPutComplete;
        discTime = _msDisconnected - _msDisconnecting;
        Serial << _msDisconnected << F(" disconnected\n\n");
        GS_STATE = GS_WAIT;
        ret = DISCONNECTED;
        break;
    }
    if (ret != NO_STATUS) lastStatus = ret;
    return ret;
}
Exemplo n.º 12
0
int QuectelM10::attachGPRS(char* domain, char* dom1, char* dom2)
{
	
   //Status = READY.
   if (getStatus()!=READY) 
     return 0;
   
  _tf.setTimeout(_GSM_DATA_TOUT_);	//Timeout for expecting modem responses.
 
  _cell.flush();
  
  //Attach to GPRS service.
  _cell << "AT+CGATT=1" <<  _BYTE(cr) << endl;
  
  //Expect "OK".
  if(!_tf.find("OK")) return 0;

  delay(500);
  
  //Set the context 0 as FGCNT.
  _cell << "AT+QIFGCNT=0" <<  _BYTE(cr) << endl;
  
  //Expect "OK".
  if(!_tf.find("OK")) return 0;

  delay(200);

  //Set bearer type as GPRS, APN, user name and pasword. 
  _cell << "AT+QICSGP=1,\""<< domain << "\",\""<< dom1 << "\",\"" << dom2 << "\"" << _BYTE(cr) << endl;	

  //Expect "OK".
  if(!_tf.find("OK")) return 0;

  delay(200);
  
  //Disable the function of MUXIP.
  _cell << "AT+QIMUX=0" <<  _BYTE(cr) << endl;
  
  //Expect "OK". ATTENTION, RETURNS ERROR BUT IT DOES NOT MATTER!!!!
  if(!_tf.find("OK")) ;//return 0;

  delay(200);

  //Set the session mode as transparent.
  _cell << "AT+QIMODE=1" <<  _BYTE(cr) << endl;
  
  //Expect "OK". ATTENTION, RETURNS ERROR BUT IT DOES NOT MATTER!!!!
  if(!_tf.find("OK")) ;//return 0;

  delay(200);	

  //Use domain name as the address to stablish a TCP session.
  //  _cell << "AT+QIDNSIP=1" <<  _BYTE(cr) << endl;
  _cell << "AT+QIDNSIP=0" <<  _BYTE(cr) << endl;
  
  //Expect "OK". ATTENTION, RETURNS ERROR BUT IT DOES NOT MATTER!!!!
  if(!_tf.find("OK")) ;//return 0;

  delay(200);	
  
  //Register the TCP/IP stack.
  _cell << "AT+QIREGAPP" <<  _BYTE(cr) << endl;
  
  //Expect "OK". ATTENTION, RETURNS ERROR BUT IT DOES NOT MATTER!!!!
  if(!_tf.find("OK")) ;//return 0;
  
  delay(200);	
  
  //Activate FGCNT.
  _cell << "AT+QIACT" <<  _BYTE(cr) << endl;

  //Expect "OK". 
  if(_tf.find("OK"))
  {
    setStatus(ATTACHED); 
    delay(1000);
    return 1;
  }
  else
  {
    setStatus(ATTACHED); 
    delay(1000);
    return 1;

    // In this case we dont know the modem mental position
    //setStatus(ERROR);
    //return 0;   
  }
}