// Demonstrates usage of the new udpServer feature. // You can register the same function to multiple ports, // and multiple functions to the same port. // // 2013-4-7 Brian Lee <cybexsoft@hotmail.com> // // License: GPLv2
#include <EtherCard.h> #include <IPAddress.h>
#define STATIC 0 // set to 1 to disable DHCP (adjust myip/gwip values below)
// ethernet mac address - must be unique on your network static byte mymac[] = { 0x70,0x69,0x69,0x2D,0x30,0x31 };
byte Ethernet::buffer[500]; // tcp/ip send and receive buffer
//callback that prints received packets to the serial port void udpSerialPrint(uint16\_t dest_port, uint8\_t src_ip[IP_LEN], uint16\_t src_port, const char \*data, uint16\_t len){ IPAddress src(src_ip[0],src_ip[1],src_ip[2],src_ip[3]);
// Change 'SS' to your Slave Select pin, if you arn't using the default pin if (ether.begin(sizeof Ethernet::buffer, mymac, SS) == 0) Serial.println(F("Failed to access Ethernet controller")); #if STATIC ether.staticSetup(myip, gwip); #else if (!ether.dhcpSetup()) Serial.println(F("DHCP failed")); #endif