|
11 | 11 | * Ethernet shield attached to pins 10, 11, 12, 13
|
12 | 12 |
|
13 | 13 | created 15 March 2010
|
14 |
| - updated 4 Sep 2010 |
| 14 | + updated 26 Oct 2011 |
15 | 15 | by Tom Igoe
|
16 | 16 |
|
17 | 17 | http://www.tigoe.net/pcomp/code/category/arduinowiring/873
|
|
23 | 23 | #include <Ethernet.h>
|
24 | 24 |
|
25 | 25 | // assign a MAC address for the ethernet controller.
|
| 26 | +// Newer Ethernet shields have a MAC address printed on a sticker on the shield |
26 | 27 | // fill in your address here:
|
27 | 28 | byte mac[] = {
|
28 | 29 | 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED};
|
29 |
| -// assign an IP address for the controller: |
30 |
| -byte ip[] = { |
31 |
| - 192,168,1,20 }; |
32 |
| -byte gateway[] = { |
33 |
| - 192,168,1,1}; |
34 |
| -byte subnet[] = { |
35 |
| - 255, 255, 255, 0 }; |
36 |
| - |
37 |
| -// The address of the server you want to connect to (pachube.com): |
38 |
| -byte server[] = { |
39 |
| - 173,203,98,29 }; |
40 | 30 |
|
| 31 | +// fill in an available IP address on your network here, |
| 32 | +// for manual configuration: |
| 33 | +IPAddress ip(10,0,1,20); |
41 | 34 | // initialize the library instance:
|
42 |
| -Client client(server, 80); |
| 35 | +EthernetClient client; |
43 | 36 |
|
44 | 37 | long lastConnectionTime = 0; // last time you connected to the server, in milliseconds
|
45 | 38 | boolean lastConnected = false; // state of the connection last time through the main loop
|
46 | 39 | const int postingInterval = 10000; //delay between updates to Pachube.com
|
47 | 40 |
|
48 | 41 | void setup() {
|
49 |
| - // start the ethernet connection and serial port: |
50 |
| - Ethernet.begin(mac, ip); |
| 42 | + // start serial port: |
51 | 43 | Serial.begin(9600);
|
52 | 44 | // give the ethernet module time to boot up:
|
53 | 45 | delay(1000);
|
| 46 | + // start the Ethernet connection: |
| 47 | + if (Ethernet.begin(mac) == 0) { |
| 48 | + Serial.println("Failed to configure Ethernet using DHCP"); |
| 49 | + // Configure manually: |
| 50 | + Ethernet.begin(mac, ip); |
| 51 | + } |
54 | 52 | }
|
55 | 53 |
|
56 | 54 | void loop() {
|
@@ -86,7 +84,7 @@ void loop() {
|
86 | 84 | // this method makes a HTTP connection to the server:
|
87 | 85 | void sendData(int thisData) {
|
88 | 86 | // if there's a successful connection:
|
89 |
| - if (client.connect()) { |
| 87 | + if (client.connect("www.pachube.com", 80)) { |
90 | 88 | Serial.println("connecting...");
|
91 | 89 | // send the HTTP PUT request.
|
92 | 90 | // fill in your feed address here:
|
|
0 commit comments