aboutsummaryrefslogtreecommitdiff
path: root/libraries/GSM/examples/GsmWebClient
diff options
context:
space:
mode:
authorCristian Maglie <c.maglie@bug.st>2013-04-03 13:51:04 +0200
committerCristian Maglie <c.maglie@bug.st>2013-04-03 13:51:04 +0200
commitee90e68e86dd61d86f5d17b69080338328765b22 (patch)
treee620c0edc2690ab789b665e567910640597aa6fe /libraries/GSM/examples/GsmWebClient
parent0ecdc5ebc96ad4c7c548c438a03d9ce00679db8b (diff)
parentf50c307be280dc6ece9e70c43b301c1db36291a0 (diff)
Merged 1.0.5
Merge remote-tracking branch 'arduino/master' into ide-1.5.x Conflicts: app/src/processing/app/Base.java build/shared/revisions.txt hardware/arduino/avr/cores/arduino/malloc.c hardware/arduino/cores/arduino/avr-libc/malloc.c hardware/arduino/cores/arduino/malloc.c todo.txt
Diffstat (limited to 'libraries/GSM/examples/GsmWebClient')
-rw-r--r--libraries/GSM/examples/GsmWebClient/GsmWebClient.ino106
1 files changed, 106 insertions, 0 deletions
diff --git a/libraries/GSM/examples/GsmWebClient/GsmWebClient.ino b/libraries/GSM/examples/GsmWebClient/GsmWebClient.ino
new file mode 100644
index 0000000..8a96367
--- /dev/null
+++ b/libraries/GSM/examples/GsmWebClient/GsmWebClient.ino
@@ -0,0 +1,106 @@
+/*
+ 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
+#include <GSM.h>
+
+// PIN Number
+#define PINNUMBER ""
+
+// APN data
+#define GPRS_APN "GPRS_APN" // replace your GPRS APN
+#define GPRS_LOGIN "login" // replace with your GPRS login
+#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 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.");
+ // 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(;;)
+ ;
+ }
+}