i have tried Make Voice Call example without giving pin number and worked well.
but when i tried gsm web client, it is showing error.
i am not getting any positive response for
/*
Web client
This sketch connects to a website through a GSM shield. Specifically,
this example downloads the URL "http://arduino.cc/asciilogo.txt" 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
#include <GSM.h>
// PIN Number
#define PINNUMBER "1234"
// APN data
#define GPRS_APN "airtelgprs.com" // replace your GPRS APN
#define GPRS_LOGIN " " // replace with your GPRS login
#define GPRS_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[] = "/asciilogo.txt";
int port = 80; // port 80 is the default for HTTP
void setup()
{
// initialize serial communications and wait for port to open:
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for Leonardo only
}
Serial.println("Starting Arduino web client.");
// After starting the modem with GSM.begin()
// attach the shield to the GPRS network with the APN, login and password
Serial.println(gsmAccess.begin(PINNUMBER));
Serial.println(GSM_READY);
Serial.println(gprs.attachGPRS(GPRS_APN, GPRS_LOGIN, GPRS_PASSWORD));
Serial.println(GPRS_READY);
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.1");
client.print("Host: ");
client.println(server);
client.println("Connection: close");
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(;;)
;
}
}
johnwasser:
It would help to see the rest of the sketch, a pointer to the hardware, and any third-party libraries you are using.
/*
Web client
This sketch connects to a website through a GSM shield. Specifically,
this example downloads the URL "http://arduino.cc/asciilogo.txt" 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
#include <GSM.h>
// PIN Number
#define PINNUMBER "1234"
// APN data
#define GPRS_APN "airtelgprs.com" // replace your GPRS APN
#define GPRS_LOGIN " " // replace with your GPRS login
#define GPRS_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[] = "/asciilogo.txt";
int port = 80; // port 80 is the default for HTTP
void setup()
{
// initialize serial communications and wait for port to open:
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for Leonardo only
}
Serial.println("Starting Arduino web client.");
// After starting the modem with GSM.begin()
// attach the shield to the GPRS network with the APN, login and password
Serial.println(gsmAccess.begin(PINNUMBER));
Serial.println(GSM_READY);
Serial.println(gprs.attachGPRS(GPRS_APN, GPRS_LOGIN, GPRS_PASSWORD));
Serial.println(GPRS_READY);
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.1");
client.print("Host: ");
client.println(server);
client.println("Connection: close");
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(;;)
;
}
}
I use a SIM900 breakout board, connected to arduino via TX1,RX0 and GND wire.
I uploaded this sketch and i'm able to get google page.
///////////// This code is for leonardo
// for boards with one serial port use software serial and replace Serial1 with mySerial
//#include <SoftwareSerial.h>
//SoftwareSerial mySerial(3, 8);
void setup()
{
Serial.begin(9600); // the GPRS baud rate
while (!Serial) { ; }
Serial1.begin(9600); // the GPRS baud rate
}
void loop()
{
//after start up the program, you can using terminal to connect the serial of gprs shield,
//if you input 't' in the terminal, the program will execute SendTextMessage(), it will show how to send a sms message,
Serial1.println("AT+CSQ");
delay(100);
ShowSerialData();// this code is to show the data from gprs shield, in order to easily see the process of how the gprs shield submit a http request, and the following is for this purpose too.
Serial1.println("AT+CGATT?");
delay(100);
ShowSerialData();
Serial1.println("AT+SAPBR=3,1,\"CONTYPE\",\"GPRS\"");//setting the SAPBR, the connection type is using gprs
delay(1000);
ShowSerialData();
Serial1.println("AT+SAPBR=3,1,\"APN\",\"CMNET\"");//setting the APN, the second need you fill in your local apn server
delay(4000);
ShowSerialData();
Serial1.println("AT+SAPBR=1,1");//setting the SAPBR, for detail you can refer to the AT command mamual
delay(2000);
ShowSerialData();
Serial1.println("AT+HTTPINIT"); //init the HTTP request
delay(2000);
ShowSerialData();
Serial1.println("AT+HTTPPARA=\"URL\",\"www.google.com\"");// setting the httppara, the second parameter is the website you want to access
delay(1000);
ShowSerialData();
Serial1.println("AT+HTTPACTION=0");//submit the request
delay(10000);//the delay is very important, the delay time is base on the return from the website, if the return datas are very large, the time required longer.
//while(!Serial1.available());
ShowSerialData();
Serial1.println("AT+HTTPREAD");// read the data from the website you access
delay(300);
while(1) { ShowSerialData(); }
//Serial1.println("");
//delay(100);
}
void ShowSerialData()
{
while(Serial1.available()!=0)
Serial.write(Serial1.read());
}