source: rtos_arduino/trunk/arduino_lib/libraries/GSM/examples/GsmWebServer/GsmWebServer.ino@ 136

Last change on this file since 136 was 136, checked in by ertl-honda, 8 years ago

ライブラリとOS及びベーシックなサンプルの追加.

File size: 2.7 KB
Line 
1/*
2 GSM Web Server
3
4 A simple web server that shows the value of the analog input pins.
5 using a GSM shield.
6
7 Circuit:
8 * GSM shield attached
9 * Analog inputs attached to pins A0 through A5 (optional)
10
11 created 8 Mar 2012
12 by Tom Igoe
13 */
14
15// libraries
16#include <GSM.h>
17
18// PIN Number
19#define PINNUMBER ""
20
21// APN data
22#define GPRS_APN "GPRS_APN" // replace your GPRS APN
23#define GPRS_LOGIN "login" // replace with your GPRS login
24#define GPRS_PASSWORD "password" // replace with your GPRS password
25
26
27// initialize the library instance
28GPRS gprs;
29GSM gsmAccess; // include a 'true' parameter for debug enabled
30GSMServer server(80); // port 80 (http default)
31
32// timeout
33const unsigned long __TIMEOUT__ = 10 * 1000;
34
35void setup()
36{
37 // initialize serial communications and wait for port to open:
38 Serial.begin(9600);
39 while (!Serial) {
40 ; // wait for serial port to connect. Needed for Leonardo only
41 }
42
43 // connection state
44 boolean notConnected = true;
45
46 // Start GSM shield
47 // If your SIM has PIN, pass it as a parameter of begin() in quotes
48 while (notConnected)
49 {
50 if ((gsmAccess.begin(PINNUMBER) == GSM_READY) &
51 (gprs.attachGPRS(GPRS_APN, GPRS_LOGIN, GPRS_PASSWORD) == GPRS_READY))
52 notConnected = false;
53 else
54 {
55 Serial.println("Not connected");
56 delay(1000);
57 }
58 }
59
60 Serial.println("Connected to GPRS network");
61
62 // start server
63 server.begin();
64
65 //Get IP.
66 IPAddress LocalIP = gprs.getIPAddress();
67 Serial.println("Server IP address=");
68 Serial.println(LocalIP);
69}
70
71void loop() {
72
73
74 // listen for incoming clients
75 GSMClient client = server.available();
76
77
78
79 if (client)
80 {
81 while (client.connected())
82 {
83 if (client.available())
84 {
85 Serial.println("Receiving request!");
86 bool sendResponse = false;
87 while (char c = client.read()) {
88 if (c == '\n') sendResponse = true;
89 }
90
91 // if you've gotten to the end of the line (received a newline
92 // character)
93 if (sendResponse)
94 {
95 // send a standard http response header
96 client.println("HTTP/1.1 200 OK");
97 client.println("Content-Type: text/html");
98 client.println();
99 client.println("<html>");
100 // output the value of each analog input pin
101 for (int analogChannel = 0; analogChannel < 6; analogChannel++) {
102 client.print("analog input ");
103 client.print(analogChannel);
104 client.print(" is ");
105 client.print(analogRead(analogChannel));
106 client.println("<br />");
107 }
108 client.println("</html>");
109 //necessary delay
110 delay(1000);
111 client.stop();
112 }
113 }
114 }
115 }
116}
117
118
Note: See TracBrowser for help on using the repository browser.