GSM/GPRS 

Example

: Complete Example

This example shows how to use the different functions developed to manage the Waspmote GPRS module


File:
"WaspGPRS_6_completeExample.pde"


Code



/*
 *  ------Waspmote GPRS Complete Example--------
 *
 *  Explanation: This example shows how to use the different functions
 *  developed to manage the Waspmote GPRS module
 *
 *  Copyright (C) 2009 Libelium Comunicaciones Distribuidas S.L.
 *  http://www.libelium.com
 *
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 2 of the License, or
 *  (at your option) any later version.
 * 
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 * 
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 *  Version:                0.1
 *  Design:                 David Gascón
 *  Implementation:         Alberto Bielsa
 */

void setup(){
  
  // setup for Serial port over USB
  USB.begin();
  USB.println("USB port started...");

  // setup for GPRS serial port
  GPRS.ON();
  USB.println("GPRS module ready...");
  
  // set PIN if enabled
  while(!GPRS.setPIN("****")); // * should be replaced by the desired PIN
    
  // waiting while GPRS connects to the network
  while(!GPRS.check());
  USB.println("GPRS connected to the network");
  
  // configure SMS and Incoming Calls
  if(GPRS.setInfoIncomingCall()) USB.println("Info Incoming Call OK");
  if(GPRS.setInfoIncomingSMS()) USB.println("Info Incoming SMS OK");
  if(GPRS.setTextModeSMS()) USB.println("Text Mode SMS OK");
}

char* test="0000000000111111111122222222223333333333444444444455555555556666666666777777777788888888889999999999";
char command[30];
uint8_t n=0;

void loop(){
  
  //Making Calls
  if(GPRS.makeLostCall("*********",15)) USB.println("Lost Call Made"); // * should be replaced by the desired tlfn number
  else USB.println("Error calling");
  
  if(GPRS.makeCall("*********")) USB.println("Lost Call Made"); // * should be replaced by the desired tlfn number
  else USB.println("Error calling");
  
  delay(5000);
  
  if(GPRS.hangUp()) USB.println("Call finished");
  else USB.println("Error hanging up");
  
  delay(5000);
  
  // Sending SMS
  if(GPRS.sendSMS("Test Message!","*********")) USB.println("SMS Sent OK"); // * should be replaced by the desired tlfn number
  else USB.println("Error sending sms");
  
  delay(5000);
  
  // Receiving Calls and SMS
  if(GPRS.manageIncomingGSMData())
  {
    USB.println(GPRS.tlfIN);
    USB.println(GPRS.sms);
  }
  
  delay(5000);
  
  // Configure GPRS Connection
  if(GPRS.configureGPRS()) USB.println("Configured OK");
  if(GPRS.createSocket("www.libelium.com","80",GPRS_CLIENT)){
    USB.println("Socket Opened OK");
    USB.print("Session Number: ");
    USB.println(GPRS.socket_ID-'0',DEC);
  }
  delay(2000);
    
  // Send data via socket
  while(n<10){
    if(GPRS.sendData(test,GPRS.socket_ID)) USB.println("Datos enviados");
    n++;
  }
  
  // Get data from socket
  sprintf(command,"%s%c%c","GET / HTTP/1.0",'\r','\n');
  if(GPRS.sendData(command,GPRS.socket_ID)) USB.println("Datos enviados");  
  delay(2000);
  n=0;
  while(!n){
    n=GPRS.readData(GPRS.socket_ID,"90");
  }
  USB.print("Bytes Read: ");
  USB.println(GPRS.data_read,DEC);
  
  // Close socket
  if(GPRS.closeSocket(GPRS.socket_ID)) USB.println("Socket cerrado");
  
  delay(5000);
  
 if(GPRS.readURL("www.libelium.com")) USB.println(GPRS.data_URL);
  
  delay(5000);   
}
 

Download code

You can download the code of this example.


© 2009 Libelium Comunicaciones Distribuidas S.L.

| Terms of use