1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-07-30 16:24:09 +03:00

Adding ethernet library.

This commit is contained in:
David A. Mellis
2008-07-30 14:47:36 +00:00
parent c85f5ba754
commit 92797b603e
17 changed files with 3033 additions and 0 deletions

View File

@ -0,0 +1,34 @@
/*
* Chat Server
*
* A simple server that distributes any incoming messages to all
* connected clients. To use telnet to 10.0.0.177 and type!
*/
#include <Ethernet.h>
// network configuration. gateway and subnet are optional.
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
byte ip[] = { 10, 0, 0, 177 };
byte gateway[] = { 10, 0, 0, 1 };
byte subnet[] = { 255, 255, 0, 0 };
// telnet defaults to port 23
Server server(23);
void setup()
{
// initialize the ethernet device
Ethernet.begin(mac, ip, gateway, subnet);
// start listening for clients
server.begin();
}
void loop()
{
Client client = server.available();
if (client) {
server.write(client.read());
}
}

View File

@ -0,0 +1,53 @@
/*
* Echo Server
*
* Echoes back the headers of the web request. Good for
* learning how the HTTP protocol works.
*/
#include <Ethernet.h>
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
byte ip[] = { 10, 0, 0, 177 };
Server server(80);
void setup()
{
Client client(255);
Ethernet.begin(mac, ip);
Serial.begin(9600);
server.begin();
}
void loop()
{
char buf[512];
int i = 0;
Client client = server.available();
if (client) {
boolean previous_is_newline = false;
while (client.connected()) {
if (client.available()) {
char c = client.read();
if (c == '\n' && previous_is_newline) {
buf[i] = 0;
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println();
client.println("<pre>");
client.println(buf);
client.println("</pre>");
break;
}
if (i < 511)
buf[i++] = c;
if (c == '\n')
previous_is_newline = true;
else if (c != '\r')
previous_is_newline = false;
}
}
client.stop();
}
}

View File

@ -0,0 +1,41 @@
#include <Ethernet.h>
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
byte ip[] = { 10, 0, 0, 177 };
byte server[] = { 64, 233, 187, 99 }; // Google
Client client(server, 80);
void setup()
{
Ethernet.begin(mac, ip);
Serial.begin(9600);
delay(1000);
Serial.println("connecting...");
if (client.connect()) {
Serial.println("connected");
client.println("GET /search?q=arduino HTTP/1.0");
client.println();
} else {
Serial.println("connection failed");
}
}
void loop()
{
if (client.available()) {
char c = client.read();
Serial.print(c);
}
if (!client.connected()) {
Serial.println();
Serial.println("disconnecting.");
client.stop();
for(;;)
;
}
}