Connecting to the internet
In addition to the SIM card and a data plan, you will need some
additional information from your cellular provider to connect to the
internet. Every cellular provider has an Access Point Name (APN) that
serves as a bridge between the cellular network and the internet.
Sometimes, there is a username and password associated with the
connection point. For example, the Bluevia APN is bluevia.movistar.es,
but it has no password or login name.
This page
lists a number of carrier's information, but it may not be up to date.
You may need to get this information from your service provider.
The sketch below will connect to arduino.cc/latest.txt and print out its contents.
NB: Some network operators block incoming
IP traffic. You should be able to run client functions, such as the
sketch below, with no issues.
// include the GSM library
#include <GSM.h>
// PIN number if necessary
#define PINNUMBER ""
// APN information obrained from your network provider
#define GPRS_APN "GPRS_APN" // replace with your GPRS APN
#define GPRS_LOGIN "login" // replace with your GPRS login
#define GPRS_PASSWORD "password" // replace with your GPRS password
// initialize the library instances
GSMClient client;
GPRS gprs;
GSM gsmAccess;
// This example downloads the URL "http://arduino.cc/latest.txt"
char server[] = "arduino.cc"; // the base URL
char path[] = "/latest.txt"; // the path
int port = 80; // the port, 80 for HTTP
void setup()
{
// initialize serial communications
Serial.begin(9600);
Serial.println("Starting Arduino web client.");
// connection state
boolean notConnected = true;
// Start GSM shield
// pass the PIN of your SIM as a parameter of gsmAccess.begin()
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(;;)
;
}
}
#include <GSM.h>
// PIN number if necessary
#define PINNUMBER ""
// APN information obrained from your network provider
#define GPRS_APN "GPRS_APN" // replace with your GPRS APN
#define GPRS_LOGIN "login" // replace with your GPRS login
#define GPRS_PASSWORD "password" // replace with your GPRS password
// initialize the library instances
GSMClient client;
GPRS gprs;
GSM gsmAccess;
// This example downloads the URL "http://arduino.cc/latest.txt"
char server[] = "arduino.cc"; // the base URL
char path[] = "/latest.txt"; // the path
int port = 80; // the port, 80 for HTTP
void setup()
{
// initialize serial communications
Serial.begin(9600);
Serial.println("Starting Arduino web client.");
// connection state
boolean notConnected = true;
// Start GSM shield
// pass the PIN of your SIM as a parameter of gsmAccess.begin()
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(;;)
;
}
}