10 Interface
10 Interface
10 Interface
Ethernet
Ethernet
Dva ipa: ENC i Wiznet
Wiznet integriraniji i manji,
ENC vei manje integrirani
Mi emo koristiti
ENC28j60
ip integrira sve funkcije
etherneta osim filtera koji
je u konektoru
Spoj ipa je sa SPI
sabirnicom
Spoj
EtherCard library
Inicijalizacija
uint8_t Ethernet::buffer[700]; // configure buffer size to 700 octets
static uint8_t mymac[] = { 0x74,0x69,0x69,0x2D,0x30,0x31 }; // define (MAC) address
uint8_type nFirmwareVersion ether.begin(sizeof Ethernet::buffer, mymac);
if(0 == nFirmwareVersion) // handle failure to initiate network interface
Adresa preko DHCP
if(!ether.dhcpSetup()) // handle failure to obtain IP address via DHCP
ether.printIp("IP: ", ether.myip); // output IP address to Serial
ether.printIp("GW: ", ether.gwip); // output gateway address to Serial
ether.printIp("Mask: ", ether.mymask); // output netmask to Serial
ether.printIp("DHCP server: ", ether.dhcpip); // output IP address of the DHCP server
Statika IP adresa
const static uint8_t ip[] = {192,168,0,100}; const static uint8_t gw[] = {192,168,0,254};
const static uint8_t dns[] = {192,168,0,1};
if(!ether.staticSetup(ip, gw, dns) // handle failure to configure static IP address
DNS lookup
if(!ether.dnsLookup("google.com")) // handle failure of DNS lookup
ether.printIp("Server: ", ether.hispip);
EtherCard library
DHCP
Povucite adresu
sa DHCP
posluitelja.
Ispiite je na
serijskom portu
#include <EtherCard.h>
static byte mymac[] = { 0x74,0x69,0x69,0x2D,0x30,0x31 };
byte Ethernet::buffer[500];
BufferFiller bfill;
void setup () {
Serial.begin(9600);
if (ether.begin(sizeof Ethernet::buffer, mymac) == 0) Serial.println( "Fail");
if(!ether.dhcpSetup()) Serial.println("DHCP failed");
ether.printIp("IP:",ether.myip);
ether.printIp("NETMASK:",ether.mymask);
ether.printIp("GW:",ether.gwip);
ether.printIp("DNS:",ether.dnsip);
}
void loop () {
}
Zadatak
#include <EtherCard.h>
static byte mymac[] = { 0x74,0x69,0x69,0x2D,0x30,0x31 };
static byte myip[] = { 192,168,10,205 };
byte Ethernet::buffer[500];
BufferFiller bfill;
Poaljite UDP
void setup () {
paket na adresu
if (ether.begin(sizeof Ethernet::buffer, mymac) == 0) Serial.println( "Failed to ac
ether.staticSetup(myip);
ureaja, ispiite
ether.hisport = 7777;
paket na serijskom ether.udpServerListenOnPort(&udpSerialPrint, 7777);
Serial.begin(9600);
Serial.println("finish setup");
portu
}
void loop () {
ether.packetLoop(ether.packetReceive());
}
//callback that prints received packets to the serial port
void udpSerialPrint(word port, byte ip[4], const char *data, word len) {
Serial.println(data);
}
Slanje paketa
http://packetsender.com/
UDP server
Zadatak
#include <EtherCard.h>
static byte mymac[] = { 0x74,0x69,0x69,0x2D,0x30,0x31 };
static byte myip[] = { 192,168,10,205 };
static byte remoteip[] = { 192,168,10,99 };
byte Ethernet::buffer[500];
BufferFiller bfill;
char string1[3]="OK";
void setup () {
if (ether.begin(sizeof Ethernet::buffer, mymac) == 0) Serial.println( "Fail ");
ether.staticSetup(myip);
ether.hisport = 7777;
ether.udpServerListenOnPort(&udpSerialPrint, 7777);
Serial.begin(9600);
}
void loop () {
ether.packetLoop(ether.packetReceive());
}
//callback that prints received packets to the serial port
void udpSerialPrint(word port, byte ip[4], const char *data, word len) {
Serial.println(data);
ether.sendUdp ((char*) string1, 3, 7776, remoteip, 7776);
}
Zadatak
Osigurajte web stranicu na statikoj adresi koja odbrojava
Koliko je vremena proteklo od paljenja ureaja.
Vrijeme mora biti prikazano na razini sekunde, stranica se
Treba osvjeavati na razini sekunde.
#include <EtherCard.h>
// ethernet interface mac address, must be unique on the LAN
static byte mymac[] = { 0x74,0x69,0x69,0x2D,0x30,0x31 };
static byte myip[] = { 192,168,1,203 };
byte Ethernet::buffer[500];
BufferFiller bfill;
void setup () {
if (ether.begin(sizeof Ethernet::buffer, mymac) == 0)
Serial.println( "Failed to access Ethernet controller");
ether.staticSetup(myip);
}
void loop () {
word len = ether.packetReceive();
word pos = ether.packetLoop(len);