Tutorial.GSMToolsTestGPRS History

Hide minor edits - Show changes to markup

March 11, 2013, at 10:30 AM by Scott Fitzgerald -
Changed lines 474-477 from:
to:
February 04, 2013, at 09:14 AM by Scott Fitzgerald -
Changed lines 5-8 from:

This sketch gives you diagnostic information about the modem on the GSM shield and the GPRS connection.

Not all network operators allow incoming data requests from outside their network. This means you can create a web server with the GSM shield, but you may not be able to connect to it from the public internet; only from another data enabled device from the same provider on the same network. You should check with your provider to see what specific policies they have in place regarding incoming data connections.

to:

This sketch tests the GPRS data connection on the GSM shield. It tries to connect to arduino.cc.

Changed line 13 from:
  • SIM card with a data connection
to:
  • SIM card with data connection
Changed lines 33-34 from:

Define a number of constants that contain information about the GPRS network you're going to connect to. You'll need the Access Point Name (APN), login, and password. To obtain this information, contact your network provider for the most up to date information. This page has some information about various carrier settings, but it may not be current.

to:

Initialize instances of the classes you're going to use. You're going to need the GSM, GPRS, and GSMClient classes.

Changed lines 36-38 from:
  1. define GPRS_APN "GPRS_APN"
  2. define GPRS_LOGIN "login"
  3. define GPRS_PASSWORD "password"
to:

GSMClient client; GPRS gprsAccess; GSM gsmAccess;

Changed lines 41-42 from:

Initialize instances of the classes you're going to use. You're going to need the GSM, GPRS, GSMServer, and GSMClient classes. When you instantiate the GSMServer class, you'll need to tell it which port to listen for incoming connections. Port 80 is the default port for HTTP requests.

to:

Create some status messages to send to the serial monitor:

Changed lines 44-47 from:

GSMClient client; GPRS gprs; GSM gsmAccess; GSMServer server(80);

to:

String oktext = "OK"; String errortext = "ERROR";

Changed lines 48-49 from:

Create some variables to set a timeout period, flag incoming client messages, and a buffer to read incoming bytes. to hold the server, path, and port you wish to connect to.

to:

Create some variables to hold the server, path, and proxy you wish to connect to.

Changed line 51 from:

char server[] = "arduino.cc";

to:

char url[] = "arduino.cc";

Changed line 53 from:

int port = 80;

to:

char urlproxy[] = "http://arduino.cc";

Changed lines 56-57 from:

In setup, open a serial connection to the computer. After opening the connection, send a message indicating the sketch has started.

to:

Create a variable to hold a response from the server, and a flag to indicate f you wil be using a proxy or not.

Changed lines 59-61 from:

void setup(){

  Serial.begin(9600); 
  Serial.println("Starting Arduino web client.");
to:

String response = "";

boolean use_proxy = false;

Changed lines 64-65 from:

Create a local variable to track the connection status. You'll use this to keep the sketch from starting until the SIM is connected to the network :

to:

In setup, open a serial connection to the computer.

Changed lines 67-69 from:
  boolean notConnected = true;
to:

void setup(){

  Serial.begin(9600); 

}

Changed lines 72-75 from:

Connect to the network by calling gsmAccess.begin(). It takes the SIM card's PIN as an argument. You'll also connect to the GPRS network using gprs.attachGPRS(). This requires the APN, login, and password you declared earlier. By placing this inside a while() loop, you can continually check the status of the connection and wait for them to both become true before proceeding.

When the modem does connect nd had attached itself to the GPRS network, gsmAccess() will return GSM_READY. Use this as a flag to set the notConnected variable to true or false. Once connected, the remainder of setup will run.

to:

You're going to create a custom function to handle serial input from the serial monitor. make a named function that accepts a char array as an argument.

Changed lines 75-83 from:
  while(notConnected)
to:
Changed lines 85-88 from:
    if(gsmAccess.begin(PINNUMBER)==GSM_READY)
        (gprs.attachGPRS(GPRS_APN, GPRS_LOGIN, GPRS_PASSWORD)==GPRS_READY))
      notConnected = false;
    else
to:
    while (Serial.available() > 0)
Changed lines 87-88 from:
      Serial.println("Not connected");
      delay(1000);
to:
      char inChar = Serial.read();
      if (inChar == '\n')
      {
        result[i] = '\0';
        return 0;
      }
      if(inChar!='\r')
      {
        result[i] = inChar;
        i++;
      }
Added line 100:

}

Changed lines 103-104 from:

Attempt to connect to the server using client.connect(). connect() requires two arguments, the server and port. Once connected to the server, make a HTTP request by calling client.print(). A typical web request looks like "GET pathname HTTP/1.0". print will send the message, just as a browser would.

to:

In loop(), set the proxy flag to false

Changed lines 107-116 from:
  if (client.connect(server, port))
to:
Changed lines 118-123 from:
    Serial.println("connected");
    client.print("GET ");
    client.print(path);
    client.println(" HTTP/1.0");
    client.println();
  } 
to:
    Serial.println(errortext);
    while(true);
  }
  Serial.println(oktext);
Changed lines 124-125 from:

If the connection to the server failed, make a note of it in the serial monitor, and close up setup.

to:

Create a char array to hold the APN. Use the readSerial() function you created to get the bytes from the serial monitor

Changed lines 127-131 from:
  else
  {
    Serial.println("connection failed");
  }

}

to:
 char apn[50];
  Serial.print("Enter your APN: ");
  readSerial(apn);
  Serial.println(apn);
Changed lines 133-134 from:

Inside loop, check to see if there are bytes returned from the server. If so, read them and print them to the serial monitor.

to:

Create a char array to hold the APN login. Use the readSerial() function you created to get the bytes from the serial monitor

Changed lines 136-140 from:
  if (client.available())
  {
    char c = client.read();
    Serial.print(c);
  }
to:
  char login[50];
  Serial.print("Now, enter your login: ");
  readSerial(login);
  Serial.println(login);
Changed lines 142-143 from:

If the server disconnects, which it will typically do once it has completed the HTTP request, stop the client locally and close the loop.

to:

Create a char array to hold the APN password. Use the readSerial() function you created to get the bytes from the serial monitor

Changed lines 145-156 from:
  if (!client.available() && !client.connected())
to:
Changed lines 158-164 from:
    Serial.println();
    Serial.println("disconnecting.");
    client.stop();

    // do nothing forevermore:
    for(;;)
      ;
to:
    Serial.println(errortext);
Changed lines 160-162 from:

}

to:
  else{

    Serial.println(oktext);
Changed lines 165-168 from:
to:

Create a char array to hold any proxy information you may need. Use the readSerial() function you created to get the bytes from the serial monitor.

Changed lines 168-238 from:

/*

  Pachube sensor client

 This sketch connects an analog sensor to Pachube (http://www.pachube.com)
 using a Telefonica GSM/GPRS shield.

 This example has been updated to use version 2.0 of the Pachube.com API. 
 To make it work, create a feed with a datastream, and give it the ID
 sensor1. Or change the code below to match your feed.

 Circuit:
 * Analog sensor attached to analog in 0
 * GSM shield attached to pins 10, 11, 12, 13

 created 4 March 2012
 by Tom Igoe
 and adapted for GSM shield by David Del Peral

 This code is in the public domain.

 */

// libraries

  1. include <GSM.h>

// Pachube Client data

  1. define APIKEY "YOUR API KEY GOES HERE" // replace your pachube api key here
  2. define FEEDID 00000 // replace your feed ID
  3. define USERAGENT "My Project" // user agent is the project name

// PIN Number

  1. define PINNUMBER ""

// APN data

  1. define GPRS_APN "GPRS_APN" // replace your GPRS APN
  2. define GPRS_LOGIN "login" // replace with your GPRS login
  3. define GPRS_PASSWORD "password" // replace with your GPRS password

// initialize the library instance: GSMClient client; GPRS gprs; GSM gsmAccess; // include a 'true' parameter for debug enabled

// if you don't want to use DNS (and reduce your sketch size) // use the numeric IP instead of the name for the server: //IPAddress server(216,52,233,121); // numeric IP for api.pachube.com char server[] = "api.pachube.com"; // name address for pachube API

unsigned long lastConnectionTime = 0; // last time you connected to the server, in milliseconds boolean lastConnected = false; // state of the connection last time through the main loop const unsigned long postingInterval = 10*1000; //delay between updates to Pachube.com

void setup() {

  // initialize serial communications
  Serial.begin(9600);

  // connection state
  boolean notConnected = true;

  // Start GSM shield
  // If your SIM has PIN, pass it as a parameter of begin() in quotes
  while(notConnected)
  {
    if((gsmAccess.begin(PINNUMBER)==GSM_READY) &
        (gprs.attachGPRS(GPRS_APN, GPRS_LOGIN, GPRS_PASSWORD)==GPRS_READY))
      notConnected = false;
    else
    {
      Serial.println("Not connected");
      delay(1000);
to:
Changed lines 188-232 from:
  }

}

void loop() {

  // read the analog sensor:
  int sensorReading = analogRead(A0);   

  // if there's incoming data from the net connection.
  // send it out the serial port.  This is for debugging
  // purposes only:
  if (client.available())
  {
     char c = client.read();
     Serial.print(c);
  }

  // if there's no net connection, but there was one last time
  // through the loop, then stop the client:
  if (!client.connected() && lastConnected)
  {
    client.stop();
  }

  // if you're not connected, and ten seconds have passed since
  // your last connection, then connect again and send data:
  if(!client.connected() && ((millis() - lastConnectionTime) > postingInterval))
  {
  sendData(sensorReading);
  }

  // store the state of the connection for next time through
  // the loop:
  lastConnected = client.connected();

}

/*

  This method makes a HTTP connection to the server.
  • /

void sendData(int thisData) {

  // if there's a successful connection:
  if (client.connect(server, 80))
  {
    Serial.println("connecting...");
to:
Changed lines 196-215 from:
    // send the HTTP PUT request:
    client.print("PUT /v2/feeds/");
    client.print(FEEDID);
    client.println(".csv HTTP/1.1");
    client.print("Host: api.pachube.com\n");
    client.print("X-ApiKey: ");
    client.println(APIKEY);
    client.print("User-Agent: ");
    client.println(USERAGENT);
    client.print("Content-Length: ");

    // calculate the length of the sensor reading in bytes:
    // 8 bytes for "sensor1," + number of digits of the data:
    int thisLength = 8 + getLength(thisData);
    client.println(thisLength);

    // last pieces of the HTTP PUT request:
    client.print("Content-Type: text/csv\n");
    client.println("Connection: close");
    client.println();
to:
Changed lines 235-260 from:
    // here's the actual content of the PUT request:
    client.print("sensor1,");
    client.println(thisData);
  } 
  else
  {
    // if you couldn't make a connection:
    Serial.println("connection failed");
    Serial.println();
    Serial.println("disconnecting.");
    client.stop();
  }
  // note the time that the connection was made or attempted
  lastConnectionTime = millis();

}

/*

  This method calculates the number of digits in the
  sensor reading.  Since each digit of the ASCII decimal
  representation is a byte, the number of digits equals
  the number of bytes.
  • /

int getLength(int someValue) {

  // there's at least one byte:
  int digits = 1;
to:
    boolean test = true;
    while(test)
    {
      if (client.available())
      {
        char c = client.read();
        response += c;
Changed lines 243-256 from:
  // continually divide the value by ten, 
  // adding one to the digit count for each
  // time you divide, until you're at 0:
  int dividend = someValue /10;
  while (dividend > 0)
  {
    dividend = dividend /10;
    digits++;
  }

  // return the number of digits:
  return digits;

}

to:
        char responsechar[response.length()+1];
        response.toCharArray(responsechar, response.length()+1);

        if(strstr(responsechar, "200 OK") != NULL){
          Serial.println(oktext);
          Serial.println("TEST COMPLETE!");
          test = false;
        }
      }
Added lines 253-468:
February 03, 2013, at 07:24 PM by Scott Fitzgerald -
Changed lines 1-6 from:

Examples > Make Voice Call

Using the GSM Shield to Make Calls

This example shows how to use the GSM Shield and Library to make voice calls. Please click here for more information on the GSM library.

to:

Examples > GSM library

GSM Test GPRS

This sketch gives you diagnostic information about the modem on the GSM shield and the GPRS connection.

Not all network operators allow incoming data requests from outside their network. This means you can create a web server with the GSM shield, but you may not be able to connect to it from the public internet; only from another data enabled device from the same provider on the same network. You should check with your provider to see what specific policies they have in place regarding incoming data connections.

To use a data connection with the GSM shield, you'll need your provider's Access Point Name (APN), login, and password. To obtain this information, contact the network provider for the most up to date information. This page has some information about various carrier settings, but it may not be current.

Changed line 15 from:
  • SIM card
to:
  • SIM card with a data connection
Changed lines 27-29 from:

The code below is configured for use with a GSM/GPRS shield. In the variable declaration area, you need to instantiate both the GSM and GSMVoiceCall classes. Inside setup(), call GSM.begin(), with the PINNUMBER of your SIM card as parameter. GSM.begin() will return whether the shield managed to connect to the GSM network or not.

In the loop(), the input from the Serial Monitor is used to tell the GSM Shield a phone number to call to. The code waits until the call is over before performing any other actions.

to:
Changed lines 145-326 from:
to:
Changed line 332 from:
to:
November 16, 2012, at 07:58 PM by Scott Fitzgerald -
Added lines 1-34:

Share