diff options
author | Cristian Maglie <c.maglie@bug.st> | 2012-05-23 09:22:52 +0200 |
---|---|---|
committer | Cristian Maglie <c.maglie@bug.st> | 2012-05-23 09:22:52 +0200 |
commit | a3dbb49c078176fca1610f4a61b0d1b23e3f37c9 (patch) | |
tree | 97c6f70b3f54da526db9acf93ed0b4ef24248b4e /libraries/Ethernet | |
parent | 3786e337e0211ca1ef94b37b03e891adfb3b5f9a (diff) | |
parent | 810803c6d3ab33a4496a89f41ef7e1dda15e8680 (diff) |
Merge of arduino-1.0.1. Work in progress...
Diffstat (limited to 'libraries/Ethernet')
12 files changed, 94 insertions, 27 deletions
diff --git a/libraries/Ethernet/examples/ChatServer/ChatServer.ino b/libraries/Ethernet/examples/ChatServer/ChatServer.ino index de75257..d50e5a6 100644 --- a/libraries/Ethernet/examples/ChatServer/ChatServer.ino +++ b/libraries/Ethernet/examples/ChatServer/ChatServer.ino @@ -12,7 +12,7 @@ created 18 Dec 2009 by David A. Mellis - modified 12 March 2012 + modified 9 Apr 2012 by Tom Igoe */ @@ -39,8 +39,13 @@ void setup() { Ethernet.begin(mac, ip, gateway, subnet); // start listening for clients server.begin(); - // open the serial port + // Open serial communications and wait for port to open: Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for Leonardo only + } + + Serial.print("Chat server address:"); Serial.println(Ethernet.localIP()); } diff --git a/libraries/Ethernet/examples/DhcpAddressPrinter/DhcpAddressPrinter.ino b/libraries/Ethernet/examples/DhcpAddressPrinter/DhcpAddressPrinter.ino index 630dd17..5eaaf24 100644 --- a/libraries/Ethernet/examples/DhcpAddressPrinter/DhcpAddressPrinter.ino +++ b/libraries/Ethernet/examples/DhcpAddressPrinter/DhcpAddressPrinter.ino @@ -9,6 +9,7 @@ * Ethernet shield attached to pins 10, 11, 12, 13 created 12 April 2011 + modified 9 Apr 2012 by Tom Igoe */ @@ -27,8 +28,13 @@ byte mac[] = { EthernetClient client; void setup() { - // start the serial library: + // Open serial communications and wait for port to open: Serial.begin(9600); + // this check is only needed on the Leonardo: + while (!Serial) { + ; // wait for serial port to connect. Needed for Leonardo only + } + // start the Ethernet connection: if (Ethernet.begin(mac) == 0) { Serial.println("Failed to configure Ethernet using DHCP"); diff --git a/libraries/Ethernet/examples/DhcpChatServer/DhcpChatServer.ino b/libraries/Ethernet/examples/DhcpChatServer/DhcpChatServer.ino index 5082054..09cbd43 100644 --- a/libraries/Ethernet/examples/DhcpChatServer/DhcpChatServer.ino +++ b/libraries/Ethernet/examples/DhcpChatServer/DhcpChatServer.ino @@ -12,6 +12,7 @@ * Ethernet shield attached to pins 10, 11, 12, 13 created 21 May 2011 + modified 9 Apr 2012 by Tom Igoe Based on ChatServer example by David A. Mellis @@ -34,8 +35,14 @@ EthernetServer server(23); boolean gotAMessage = false; // whether or not you got a message from the client yet void setup() { - // open the serial port + // Open serial communications and wait for port to open: Serial.begin(9600); + // this check is only needed on the Leonardo: + while (!Serial) { + ; // wait for serial port to connect. Needed for Leonardo only + } + + // start the Ethernet connection: Serial.println("Trying to get an IP address using DHCP"); if (Ethernet.begin(mac) == 0) { diff --git a/libraries/Ethernet/examples/DnsWebClient/DnsWebClient.ino b/libraries/Ethernet/examples/DnsWebClient/DnsWebClient.ino index 5c7a53a..c14abf4 100644 --- a/libraries/Ethernet/examples/DnsWebClient/DnsWebClient.ino +++ b/libraries/Ethernet/examples/DnsWebClient/DnsWebClient.ino @@ -9,7 +9,7 @@ created 18 Dec 2009 by David A. Mellis - modified 12 April 2011 + modified 9 Apr 2012 by Tom Igoe, based on work by Adrian McEwen */ @@ -28,8 +28,13 @@ char serverName[] = "www.google.com"; EthernetClient client; void setup() { - // start the serial library: + // Open serial communications and wait for port to open: Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for Leonardo only + } + + // start the Ethernet connection: if (Ethernet.begin(mac) == 0) { Serial.println("Failed to configure Ethernet using DHCP"); diff --git a/libraries/Ethernet/examples/PachubeClient/PachubeClient.ino b/libraries/Ethernet/examples/PachubeClient/PachubeClient.ino index 4d4290d..dfd2d40 100644 --- a/libraries/Ethernet/examples/PachubeClient/PachubeClient.ino +++ b/libraries/Ethernet/examples/PachubeClient/PachubeClient.ino @@ -16,7 +16,7 @@ * Ethernet shield attached to pins 10, 11, 12, 13 created 15 March 2010 - updated 16 Mar 2012 + modified 9 Apr 2012 by Tom Igoe with input from Usman Haque and Joe Saavedra http://arduino.cc/en/Tutorial/PachubeClient @@ -53,8 +53,13 @@ boolean lastConnected = false; // state of the connection last t const unsigned long postingInterval = 10*1000; //delay between updates to Pachube.com void setup() { - // start serial port: + // Open serial communications and wait for port to open: Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for Leonardo only + } + + // start the Ethernet connection: if (Ethernet.begin(mac) == 0) { Serial.println("Failed to configure Ethernet using DHCP"); diff --git a/libraries/Ethernet/examples/PachubeClientString/PachubeClientString.ino b/libraries/Ethernet/examples/PachubeClientString/PachubeClientString.ino index 3535287..2a96e9f 100644 --- a/libraries/Ethernet/examples/PachubeClientString/PachubeClientString.ino +++ b/libraries/Ethernet/examples/PachubeClientString/PachubeClientString.ino @@ -1,12 +1,12 @@ /* - Pachube sensor client with Strings + Cosm sensor client with Strings - This sketch connects an analog sensor to Pachube (http://www.pachube.com) + This sketch connects an analog sensor to Cosm (http://www.cosm.com) using a Wiznet Ethernet shield. You can use the Arduino Ethernet shield, or the Adafruit Ethernet shield, either one will work, as long as it's got a Wiznet Ethernet module on board. - This example has been updated to use version 2.0 of the Pachube.com API. + This example has been updated to use version 2.0 of the Cosm.com API. To make it work, create a feed with two datastreams, and give them the IDs sensor1 and sensor2. Or change the code below to match your feed. @@ -18,10 +18,10 @@ * Ethernet shield attached to pins 10, 11, 12, 13 created 15 March 2010 - updated 16 Mar 2012 + modified 9 Apr 2012 by Tom Igoe with input from Usman Haque and Joe Saavedra - http://arduino.cc/en/Tutorial/PachubeClientString + http://arduino.cc/en/Tutorial/CosmClientString This code is in the public domain. */ @@ -30,14 +30,16 @@ #include <Ethernet.h> -#define APIKEY "YOUR API KEY GOES HERE" // replace your pachube api key here +/#define APIKEY "YOUR API KEY GOES HERE" // replace your Cosm api key here #define FEEDID 00000 // replace your feed ID #define USERAGENT "My Project" // user agent is the project name + // assign a MAC address for the ethernet controller. // fill in your address here: byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED}; + // fill in an available IP address on your network here, // for manual configuration: IPAddress ip(10,0,1,20); @@ -47,16 +49,21 @@ EthernetClient client; // if you don't want to use DNS (and reduce your sketch size) // use the numeric IP instead of the name for the server: -//IPAddress server(216,52,233,122); // numeric IP for api.pachube.com -char server[] = "api.pachube.com"; // name address for pachube API +IPAddress server(216,52,233,121); // numeric IP for api.cosm.com +//char server[] = "api.cosm.com"; // name address for Cosm API unsigned long lastConnectionTime = 0; // last time you connected to the server, in milliseconds boolean lastConnected = false; // state of the connection last time through the main loop -const unsigned long postingInterval = 10*1000; //delay between updates to Pachube.com +const unsigned long postingInterval = 10*1000; //delay between updates to Cosm.com void setup() { - // start serial port: + // Open serial communications and wait for port to open: Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for Leonardo only + } + + // give the ethernet module time to boot up: delay(1000); // start the Ethernet connection: @@ -76,7 +83,7 @@ void loop() { dataString += sensorReading; // you can append multiple readings to this String if your - // pachube feed is set up to handle multiple values: + // Cosm feed is set up to handle multiple values: int otherSensorReading = analogRead(A1); dataString += "\nsensor2,"; dataString += otherSensorReading; @@ -116,8 +123,8 @@ void sendData(String thisData) { client.print("PUT /v2/feeds/"); client.print(FEEDID); client.println(".csv HTTP/1.1"); - client.println("Host: api.pachube.com"); - client.print("X-PachubeApiKey: "); + client.println("Host: api.cosm.com"); + client.print("X-CosmApiKey: "); client.println(APIKEY); client.print("User-Agent: "); client.println(USERAGENT); diff --git a/libraries/Ethernet/examples/TelnetClient/TelnetClient.ino b/libraries/Ethernet/examples/TelnetClient/TelnetClient.ino index 5cf1ad8..3457125 100644 --- a/libraries/Ethernet/examples/TelnetClient/TelnetClient.ino +++ b/libraries/Ethernet/examples/TelnetClient/TelnetClient.ino @@ -13,6 +13,7 @@ * Ethernet shield attached to pins 10, 11, 12, 13 created 14 Sep 2010 + modified 9 Apr 2012 by Tom Igoe */ @@ -38,8 +39,13 @@ EthernetClient client; void setup() { // start the Ethernet connection: Ethernet.begin(mac, ip); - // start the serial library: + // Open serial communications and wait for port to open: Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for Leonardo only + } + + // give the Ethernet shield a second to initialize: delay(1000); Serial.println("connecting..."); diff --git a/libraries/Ethernet/examples/TwitterClient/TwitterClient.ino b/libraries/Ethernet/examples/TwitterClient/TwitterClient.ino index a3b397d..3587d72 100644 --- a/libraries/Ethernet/examples/TwitterClient/TwitterClient.ino +++ b/libraries/Ethernet/examples/TwitterClient/TwitterClient.ino @@ -17,6 +17,7 @@ * Ethernet shield attached to pins 10, 11, 12, 13 created 21 May 2011 + modified 9 Apr 2012 by Tom Igoe This code is in the public domain. @@ -51,8 +52,13 @@ void setup() { currentLine.reserve(256); tweet.reserve(150); - // initialize serial: + // Open serial communications and wait for port to open: Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for Leonardo only + } + + // attempt a DHCP connection: Serial.println("Attempting to get an IP address using DHCP:"); if (!Ethernet.begin(mac)) { diff --git a/libraries/Ethernet/examples/UdpNtpClient/UdpNtpClient.ino b/libraries/Ethernet/examples/UdpNtpClient/UdpNtpClient.ino index b4e24b8..93ffe39 100644 --- a/libraries/Ethernet/examples/UdpNtpClient/UdpNtpClient.ino +++ b/libraries/Ethernet/examples/UdpNtpClient/UdpNtpClient.ino @@ -9,7 +9,7 @@ created 4 Sep 2010 by Michael Margolis - modified 17 Sep 2010 + modified 9 Apr 2012 by Tom Igoe This code is in the public domain. @@ -38,7 +38,12 @@ EthernetUDP Udp; void setup() { + // Open serial communications and wait for port to open: Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for Leonardo only + } + // start Ethernet and UDP if (Ethernet.begin(mac) == 0) { diff --git a/libraries/Ethernet/examples/WebClient/WebClient.ino b/libraries/Ethernet/examples/WebClient/WebClient.ino index 1806854..5d5d7f2 100644 --- a/libraries/Ethernet/examples/WebClient/WebClient.ino +++ b/libraries/Ethernet/examples/WebClient/WebClient.ino @@ -8,6 +8,7 @@ * Ethernet shield attached to pins 10, 11, 12, 13 created 18 Dec 2009 + modified 9 Apr 2012 by David A. Mellis */ @@ -26,8 +27,12 @@ IPAddress server(173,194,33,104); // Google EthernetClient client; void setup() { - // start the serial library: + // Open serial communications and wait for port to open: Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for Leonardo only + } + // start the Ethernet connection: if (Ethernet.begin(mac) == 0) { Serial.println("Failed to configure Ethernet using DHCP"); diff --git a/libraries/Ethernet/examples/WebServer/WebServer.ino b/libraries/Ethernet/examples/WebServer/WebServer.ino index 7cf2c53..ce8dbb1 100644 --- a/libraries/Ethernet/examples/WebServer/WebServer.ino +++ b/libraries/Ethernet/examples/WebServer/WebServer.ino @@ -10,7 +10,7 @@ created 18 Dec 2009 by David A. Mellis - modified 20 Mar 2012 + modified 9 Apr 2012 by Tom Igoe */ @@ -30,7 +30,13 @@ IPAddress ip(192,168,1, 177); EthernetServer server(80); void setup() { + // Open serial communications and wait for port to open: Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for Leonardo only + } + + // start the Ethernet connection and the server: Ethernet.begin(mac, ip); server.begin(); diff --git a/libraries/Ethernet/utility/w5100.h b/libraries/Ethernet/utility/w5100.h index 153aedb..8dccd9f 100755 --- a/libraries/Ethernet/utility/w5100.h +++ b/libraries/Ethernet/utility/w5100.h @@ -327,7 +327,11 @@ private: inline static void initSS() { DDRB |= _BV(4); }; inline static void setSS() { PORTB &= ~_BV(4); }; inline static void resetSS() { PORTB |= _BV(4); }; -#elif defined(__AVR_ATmega32U4__) || defined(__AVR_AT90USB1286__) || defined(__AVR_AT90USB646__) || defined(__AVR_AT90USB162__) +#elif defined(__AVR_ATmega32U4__) + inline static void initSS() { DDRB |= _BV(6); }; + inline static void setSS() { PORTB &= ~_BV(6); }; + inline static void resetSS() { PORTB |= _BV(6); }; +#elif defined(__AVR_AT90USB1286__) || defined(__AVR_AT90USB646__) || defined(__AVR_AT90USB162__) inline static void initSS() { DDRB |= _BV(0); }; inline static void setSS() { PORTB &= ~_BV(0); }; inline static void resetSS() { PORTB |= _BV(0); }; |