Skip to content

Commit fde6508

Browse files
committed
Merge branch 'master' of github.com:arduino/Arduino into LUFA_bootloader
2 parents 9099375 + b5043e7 commit fde6508

File tree

3 files changed

+63
-44
lines changed

3 files changed

+63
-44
lines changed

examples/PachubeClient/PachubeClient.ino

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
* Ethernet shield attached to pins 10, 11, 12, 13
1717
1818
created 15 March 2010
19-
updated 27 Feb 2012
19+
updated 16 Mar 2012
2020
by Tom Igoe with input from Usman Haque and Joe Saavedra
2121
2222
http://arduino.cc/en/Tutorial/PachubeClient
@@ -27,8 +27,6 @@ http://arduino.cc/en/Tutorial/PachubeClient
2727
#include <SPI.h>
2828
#include <Ethernet.h>
2929

30-
31-
3230
#define APIKEY "YOUR API KEY GOES HERE" // replace your pachube api key here
3331
#define FEEDID 00000 // replace your feed ID
3432
#define USERAGENT "My Project" // user agent is the project name
@@ -45,9 +43,14 @@ IPAddress ip(10,0,1,20);
4543
// initialize the library instance:
4644
EthernetClient client;
4745

48-
long lastConnectionTime = 0; // last time you connected to the server, in milliseconds
49-
boolean lastConnected = false; // state of the connection last time through the main loop
50-
const int postingInterval = 10000; //delay between updates to Pachube.com
46+
// if you don't want to use DNS (and reduce your sketch size)
47+
// use the numeric IP instead of the name for the server:
48+
IPAddress server(216,52,233,122); // numeric IP for api.pachube.com
49+
//char server[] = "api.pachube.com"; // name address for pachube API
50+
51+
unsigned long lastConnectionTime = 0; // last time you connected to the server, in milliseconds
52+
boolean lastConnected = false; // state of the connection last time through the main loop
53+
const unsigned long postingInterval = 10*1000; //delay between updates to Pachube.com
5154

5255
void setup() {
5356
// start serial port:
@@ -93,13 +96,13 @@ void loop() {
9396
// this method makes a HTTP connection to the server:
9497
void sendData(int thisData) {
9598
// if there's a successful connection:
96-
if (client.connect("www.pachube.com", 80)) {
99+
if (client.connect(server, 80)) {
97100
Serial.println("connecting...");
98-
// send the HTTP PUT request:
101+
// send the HTTP PUT request:
99102
client.print("PUT /v2/feeds/");
100103
client.print(FEEDID);
101104
client.println(".csv HTTP/1.1");
102-
client.print("Host: api.pachube.com\n");
105+
client.println("Host: api.pachube.com");
103106
client.print("X-PachubeApiKey: ");
104107
client.println(APIKEY);
105108
client.print("User-Agent: ");
@@ -112,24 +115,24 @@ void sendData(int thisData) {
112115
client.println(thisLength);
113116

114117
// last pieces of the HTTP PUT request:
115-
client.print("Content-Type: text/csv\n");
116-
client.println("Connection: close\n");
118+
client.println("Content-Type: text/csv");
119+
client.println("Connection: close");
120+
client.println();
117121

118122
// here's the actual content of the PUT request:
119-
client.print("sensor1,");
123+
client.print("sensor1,");
120124
client.println(thisData);
121-
122-
// note the time that the connection was made:
123-
lastConnectionTime = millis();
125+
124126
}
125127
else {
126-
// if you couldn't make a connection:
128+
// if you couldn't make a connection:
127129
Serial.println("connection failed");
128130
Serial.println();
129131
Serial.println("disconnecting.");
130132
client.stop();
131-
lastConnected = client.connected();
132133
}
134+
// note the time that the connection was made or attempted:
135+
lastConnectionTime = millis();
133136
}
134137

135138

examples/PachubeClientString/PachubeClientString.ino

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
* Ethernet shield attached to pins 10, 11, 12, 13
1919
2020
created 15 March 2010
21-
updated 27 Feb 2012
21+
updated 16 Mar 2012
2222
by Tom Igoe with input from Usman Haque and Joe Saavedra
2323
2424
http://arduino.cc/en/Tutorial/PachubeClientString
@@ -40,14 +40,19 @@
4040
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED};
4141
// fill in an available IP address on your network here,
4242
// for manual configuration:
43-
IPAddress ip(10,0,0,20);
43+
IPAddress ip(10,0,1,20);
4444

4545
// initialize the library instance:
4646
EthernetClient client;
4747

48-
unsigned long lastConnectionTime = 0; // last time you connected to the server, in milliseconds
49-
boolean lastConnected = false; // state of the connection last time through the main loop
50-
const unsigned long postingInterval = 10000; //delay between updates to Pachube.com
48+
// if you don't want to use DNS (and reduce your sketch size)
49+
// use the numeric IP instead of the name for the server:
50+
//IPAddress server(216,52,233,122); // numeric IP for api.pachube.com
51+
char server[] = "api.pachube.com"; // name address for pachube API
52+
53+
unsigned long lastConnectionTime = 0; // last time you connected to the server, in milliseconds
54+
boolean lastConnected = false; // state of the connection last time through the main loop
55+
const unsigned long postingInterval = 10*1000; //delay between updates to Pachube.com
5156

5257
void setup() {
5358
// start serial port:
@@ -66,9 +71,9 @@ void loop() {
6671
// read the analog sensor:
6772
int sensorReading = analogRead(A0);
6873
// convert the data to a String to send it:
69-
74+
7075
String dataString = "sensor1,";
71-
dataString += sensorReading;
76+
dataString += sensorReading;
7277

7378
// you can append multiple readings to this String if your
7479
// pachube feed is set up to handle multiple values:
@@ -93,7 +98,7 @@ void loop() {
9398
}
9499

95100
// if you're not connected, and ten seconds have passed since
96-
// your last connection, then connect again and send data:
101+
// your last connection, then connect again and send data:
97102
if(!client.connected() && (millis() - lastConnectionTime > postingInterval)) {
98103
sendData(dataString);
99104
}
@@ -105,38 +110,36 @@ void loop() {
105110
// this method makes a HTTP connection to the server:
106111
void sendData(String thisData) {
107112
// if there's a successful connection:
108-
if (client.connect("api.pachube.com", 80)) {
113+
if (client.connect(server, 80)) {
109114
Serial.println("connecting...");
110115
// send the HTTP PUT request:
111116
client.print("PUT /v2/feeds/");
112117
client.print(FEEDID);
113118
client.println(".csv HTTP/1.1");
114-
client.print("Host: api.pachube.com\n");
119+
client.println("Host: api.pachube.com");
115120
client.print("X-PachubeApiKey: ");
116121
client.println(APIKEY);
117122
client.print("User-Agent: ");
118123
client.println(USERAGENT);
119124
client.print("Content-Length: ");
120-
client.println(thisData.length(), DEC);
125+
client.println(thisData.length());
121126

122127
// last pieces of the HTTP PUT request:
123-
client.print("Content-Type: text/csv\n");
124-
client.println("Connection: close\n");
128+
client.println("Content-Type: text/csv");
129+
client.println("Connection: close");
130+
client.println();
125131

126132
// here's the actual content of the PUT request:
127133
client.println(thisData);
128-
129-
// note the time that the connection was made:
130-
lastConnectionTime = millis();
131134
}
132135
else {
133136
// if you couldn't make a connection:
134137
Serial.println("connection failed");
135138
Serial.println();
136139
Serial.println("disconnecting.");
137140
client.stop();
138-
lastConnected = client.connected();
139141
}
142+
// note the time that the connection was made or attempted:
143+
lastConnectionTime = millis();
140144
}
141145

142-

examples/WebServer/WebServer.ino

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
1111
created 18 Dec 2009
1212
by David A. Mellis
13-
modified 4 Sep 2010
13+
modified 20 Mar 2012
1414
by Tom Igoe
1515
1616
*/
@@ -20,48 +20,59 @@
2020

2121
// Enter a MAC address and IP address for your controller below.
2222
// The IP address will be dependent on your local network:
23-
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
23+
byte mac[] = {
24+
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
2425
IPAddress ip(192,168,1, 177);
2526

2627
// Initialize the Ethernet server library
2728
// with the IP address and port you want to use
2829
// (port 80 is default for HTTP):
2930
EthernetServer server(80);
3031

31-
void setup()
32-
{
32+
void setup() {
33+
Serial.begin(9600);
3334
// start the Ethernet connection and the server:
3435
Ethernet.begin(mac, ip);
3536
server.begin();
37+
Serial.print("server is at ");
38+
Serial.println(Ethernet.localIP());
3639
}
3740

38-
void loop()
39-
{
41+
42+
void loop() {
4043
// listen for incoming clients
4144
EthernetClient client = server.available();
4245
if (client) {
46+
Serial.println("new client");
4347
// an http request ends with a blank line
4448
boolean currentLineIsBlank = true;
4549
while (client.connected()) {
4650
if (client.available()) {
4751
char c = client.read();
52+
Serial.write(c);
4853
// if you've gotten to the end of the line (received a newline
4954
// character) and the line is blank, the http request has ended,
5055
// so you can send a reply
5156
if (c == '\n' && currentLineIsBlank) {
5257
// send a standard http response header
5358
client.println("HTTP/1.1 200 OK");
5459
client.println("Content-Type: text/html");
60+
client.println("Connnection: close");
5561
client.println();
56-
62+
client.println("<!DOCTYPE HTML>");
63+
client.println("<html>");
64+
// add a meta refresh tag, so the browser pulls again every 5 seconds:
65+
client.println("<meta http-equiv=\"refresh\" content=\"5\">");
5766
// output the value of each analog input pin
5867
for (int analogChannel = 0; analogChannel < 6; analogChannel++) {
68+
int sensorReading = analogRead(analogChannel);
5969
client.print("analog input ");
6070
client.print(analogChannel);
6171
client.print(" is ");
62-
client.print(analogRead(analogChannel));
63-
client.println("<br />");
72+
client.print(sensorReading);
73+
client.println("<br />");
6474
}
75+
client.println("</html>");
6576
break;
6677
}
6778
if (c == '\n') {
@@ -78,5 +89,7 @@ void loop()
7889
delay(1);
7990
// close the connection:
8091
client.stop();
92+
Serial.println("client disonnected");
8193
}
8294
}
95+

0 commit comments

Comments
 (0)