Reference.GSMClientConnected History

Hide minor edits - Show changes to markup

March 11, 2013, at 10:12 AM by Scott Fitzgerald -
Changed lines 22-123 from:
to:

/*

  Web client

 This sketch connects to a website through a GSM shield. Specifically,
 this example downloads the URL "http://arduino.cc/" and prints it 
 to the Serial monitor.

 Circuit:
 * GSM shield attached to an Arduino
 * SIM card with a data plan

 created 8 Mar 2012
 by Tom Igoe

 http://arduino.cc/en/Tutorial/GSMExamplesWebClient

 */

// libraries

  1. include <GSM.h>

// 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;

// URL, path & port (for example: arduino.cc) char server[] = "arduino.cc"; char path[] = "/"; int port = 80; // port 80 is the default for HTTP

void setup() {

  // initialize serial communications
  Serial.begin(9600);
  Serial.println("Starting Arduino web client.");
  // connection state
  boolean notConnected = true;

  // After starting the modem with GSM.begin()
  // attach the shield to the GPRS network with the APN, login and password
  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);
    }
  }

  Serial.println("connecting...");

  // if you get a connection, report back via serial:
  if (client.connect(server, port))
  {
    Serial.println("connected");
    // Make a HTTP request:
    client.print("GET ");
    client.print(path);
    client.println(" HTTP/1.0");
    client.println();
  } 
  else
  {
    // if you didn't get a connection to the server:
    Serial.println("connection failed");
  }

}

void loop() {

  // if there are incoming bytes available 
  // from the server, read them and print them:
  if (client.available())
  {
    char c = client.read();
    Serial.print(c);
  }

  // if the server's disconnected, stop the client:
  if (!client.available() && !client.connected())
  {
    Serial.println();
    Serial.println("disconnecting.");
    client.stop();

    // do nothing forevermore:
    for(;;)
      ;
  }

}

November 16, 2012, at 01:02 AM by Scott Fitzgerald -
Changed lines 7-8 from:

Tells the server to stop listening for incoming connections.

to:

Returns whether or not the client is connected. A client is considered connected if the connection has been closed but there is still unread data.

Changed lines 11-12 from:

server.connected()

to:

client.connected()

Changed lines 14-15 from:
to:

none

Changed lines 17-18 from:
to:

boolean - Returns true if the client is connected, false if not.

October 26, 2012, at 05:29 PM by Scott Fitzgerald -
Added lines 1-26:

Share