1 | /*
|
---|
2 | Basic Web Server
|
---|
3 |
|
---|
4 | A simple web server that replies with nothing, but prints the client's request
|
---|
5 | and the server IP address.
|
---|
6 |
|
---|
7 | Circuit:
|
---|
8 | * GSM shield attached
|
---|
9 |
|
---|
10 | created
|
---|
11 | by David Cuartielles
|
---|
12 | modified 21 Nov 2012
|
---|
13 | by Tom Igoe
|
---|
14 |
|
---|
15 | http://arduino.cc/en/Tutorial/GSMToolsTestWebServer
|
---|
16 |
|
---|
17 | This example code is part of the public domain
|
---|
18 | */
|
---|
19 | #include <GSM.h>
|
---|
20 |
|
---|
21 | // PIN Number
|
---|
22 | #define PINNUMBER ""
|
---|
23 |
|
---|
24 | // APN data
|
---|
25 | #define GPRS_APN "GPRS_APN" // replace your GPRS APN
|
---|
26 | #define GPRS_LOGIN "login" // replace with your GPRS login
|
---|
27 | #define GPRS_PASSWORD "password" // replace with your GPRS password
|
---|
28 |
|
---|
29 |
|
---|
30 | // initialize the library instance
|
---|
31 | GPRS gprs;
|
---|
32 | GSM gsmAccess; // include a 'true' parameter for debug enabled
|
---|
33 | GSMServer server(80); // port 80 (http default)
|
---|
34 |
|
---|
35 | // timeout
|
---|
36 | const unsigned long __TIMEOUT__ = 10 * 1000;
|
---|
37 |
|
---|
38 | void setup()
|
---|
39 | {
|
---|
40 | // initialize serial communications and wait for port to open:
|
---|
41 | Serial.begin(9600);
|
---|
42 | while (!Serial) {
|
---|
43 | ; // wait for serial port to connect. Needed for Leonardo only
|
---|
44 | }
|
---|
45 |
|
---|
46 | Serial.println("starting,..");
|
---|
47 | // connection state
|
---|
48 | boolean connected = true;
|
---|
49 |
|
---|
50 | // Start GSM shield
|
---|
51 | // If your SIM has PIN, pass it as a parameter of begin() in quotes
|
---|
52 | while (!connected)
|
---|
53 | {
|
---|
54 | if ((gsmAccess.begin(PINNUMBER) == GSM_READY) &
|
---|
55 | (gprs.attachGPRS(GPRS_APN, GPRS_LOGIN, GPRS_PASSWORD) == GPRS_READY))
|
---|
56 | connected = true;
|
---|
57 | else
|
---|
58 | {
|
---|
59 | Serial.println("Not connected");
|
---|
60 | delay(1000);
|
---|
61 | }
|
---|
62 | }
|
---|
63 |
|
---|
64 | Serial.println("Connected to GPRS network");
|
---|
65 |
|
---|
66 | // start server
|
---|
67 | server.begin();
|
---|
68 |
|
---|
69 | //Get IP.
|
---|
70 | IPAddress LocalIP = gprs.getIPAddress();
|
---|
71 | Serial.println("Server IP address=");
|
---|
72 | Serial.println(LocalIP);
|
---|
73 | }
|
---|
74 |
|
---|
75 | void loop() {
|
---|
76 | GSMClient client = server.available();
|
---|
77 |
|
---|
78 | if (client) {
|
---|
79 | if (client.available()) {
|
---|
80 | Serial.write(client.read());
|
---|
81 | }
|
---|
82 | }
|
---|
83 |
|
---|
84 | }
|
---|
85 |
|
---|