|
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 |
27 | 26 | // fill in your address here: |
28 | 27 | byte mac[] = { |
29 | 28 | 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 }; |
30 | 40 |
|
31 | 41 | // initialize the library instance: |
32 | | -EthernetClient client; |
| 42 | +Client client(server, 80); |
33 | 43 |
|
34 | 44 | long lastConnectionTime = 0; // last time you connected to the server, in milliseconds |
35 | 45 | boolean lastConnected = false; // state of the connection last time through the main loop |
36 | 46 | const int postingInterval = 10000; //delay between updates to Pachube.com |
37 | 47 |
|
38 | 48 | void setup() { |
39 | | - // start serial port: |
| 49 | + // start the ethernet connection and serial port: |
| 50 | + Ethernet.begin(mac, ip); |
40 | 51 | Serial.begin(9600); |
41 | | - // start the Ethernet connection: |
42 | | - if (Ethernet.begin(mac) == 0) { |
43 | | - Serial.println("Failed to configure Ethernet using DHCP"); |
44 | | - // no point in carrying on, so do nothing forevermore: |
45 | | - for(;;) |
46 | | - ; |
47 | | - } |
48 | 52 | // give the ethernet module time to boot up: |
49 | 53 | delay(1000); |
50 | 54 | } |
@@ -82,7 +86,7 @@ void loop() { |
82 | 86 | // this method makes a HTTP connection to the server: |
83 | 87 | void sendData(int thisData) { |
84 | 88 | // if there's a successful connection: |
85 | | - if (client.connect("www.pachube.com", 80)) { |
| 89 | + if (client.connect()) { |
86 | 90 | Serial.println("connecting..."); |
87 | 91 | // send the HTTP PUT request. |
88 | 92 | // fill in your feed address here: |
|
0 commit comments