.


:




:

































 

 

 

 





. .

 

Arduino Ethernet Shield, ' Arduino Diecimila . '. setup() ethernet :

 

void setup()

{

Ethernet.begin(mac, ip);

}

 

:

Ethernet.begin(mac, ip);

Ethernet.begin(mac, ip, gateway);

Ethernet.begin(mac, ip, gateway, subnet);

, mac MAC ( );

ip IP ( 4 );

gateway IP ( 4 ). : , 1.

subnet ( 4 ). : 255.255.255.0

:

 

#include <Ethernet.h>

byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };

byte ip[] = { 10, 0, 0, 177 };

 

void setup()

{

Ethernet.begin(mac, ip);

}

 

void loop {}

 

Client Server.

Client:

Client(ip, port) 볺 .

Server:

Server(port) , .

 

ճ

1. Arduino Environment.

2. Arduino Ethernet Shield:

10 11  

 

2. ( Client):

 

#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(;;)

;

}

}

 

3. ( Server):

 

#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 = 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());

}

}

4. .

1. .

2. 볺 ?

3. ?

4. .

3





:


: 2016-11-24; !; : 358 |


:

:

: , .
==> ...

2221 - | 1846 -


© 2015-2024 lektsii.org - -

: 0.009 .