Here is version that will compile:
Code:
// Test of NativeEthernet - trying to get a good ip address
#include "NativeEthernet.h"
#define BAUD_RATE 115200
String addr;
byte mac[] = {0xA8, 0x61, 0x0A, 0xAE, 0x5D, 0xAE};
unsigned long TimeIt;
void setup()
{
}
void loop()
{
}
/*********************** getIpAddress *********************/
void getIpAddress()
{
// start the Ethernet connection:
Serial.println("=== Waiting for IP address");
teensyMAC(mac); // Get MAC address from Teensy
TimeIt = millis();
while (Ethernet.begin(mac) == 0)
{
if(millis() - TimeIt > 10000) // Five seconds to get a DHCP served address
{
Serial.println("Failed to configure Ethernet using DHCP");
getFixedIpAddress();
break;
}
}
addr=String(Ethernet.localIP()[0]) + "." +
String(Ethernet.localIP()[1]) + "." +
String(Ethernet.localIP()[2]) + "." +
String(Ethernet.localIP()[3]);
Serial.print("IP address is: "); Serial.println(Ethernet.localIP());
}
/*********************** getFixedIpAddress *********************/
void getFixedIpAddress()
{
IPAddress ip(169, 254, 0, 25);
IPAddress gateway(169, 254, 0, 1);
IPAddress dns(169, 254, 27, 252);
IPAddress subnet(255, 255, 0, 0);
Serial.println(ip);
Serial.println(dns);
Serial.println(gateway);
Serial.println(subnet);
// start the Ethernet connection:
Serial.println("=== Setting fixed IP address");
Ethernet.setLocalIP(ip); // Won't get an address without this...
Ethernet.setSubnetMask(subnet);
Ethernet.setGatewayIP(gateway);
Ethernet.setDnsServerIP(dns);
// Ethernet.begin(mac, ip, dns, gateway, subnet); // None of these work - always return 0.0.0.0
// Ethernet.begin(mac, ip, dns);
// Ethernet.begin(mac, ip);
Serial.print("IP address is: ");
Serial.println(Ethernet.localIP());
} // end getFixedIpAddress
/*********************** teensyMAC *********************/
void teensyMAC(uint8_t *mac)
{
for(uint8_t by=0; by<2; by++) mac[by]=(HW_OCOTP_MAC1 >> ((1-by)*8)) & 0xFF;
for(uint8_t by=0; by<4; by++) mac[by+2]=(HW_OCOTP_MAC0 >> ((3-by)*8)) & 0xFF;
Serial.printf("MAC: %02x:%02x:%02x:%02x:%02x:%02x\n", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
}