/*********************** 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(Myip[0],Myip[1],Myip[2],Myip[3]);
// IPAddress gateway(MyGateway[0],MyGateway[1],MyGateway[2], MyGateway[3]);
// IPAddress subnet(MyMask[0], MyMask[1], MyMask[2], MyMask[3]);
// IPAddress ip(169, 254, 5, 25);
// IPAddress gateway(169, 254, 0, 1);
// IPAddress dns(169, 254, 27, 252);
// IPAddress subnet(255, 255, 0, 0);
// start the Ethernet connection:
Serial.println("=== Setting fixed IP address");
Ethernet.begin(mac, ip);
// Ethernet.begin(mac, ip, dns);
// Ethernet.begin(mac, ip, dns, gateway, subnet);
} // 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]);
}