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