Hello everyone
I'm trying to get started with the Teensy 4.1 and its built in ethernet capabilities with the NativeEthernet library. I have tried using a static IP and DHCP in two seperate program attempts and both options work great. I'm now trying to first establich a DHCP connection to the network and if that doesn't work the Teensy should use a static IP address.
If the DHCP fails and uses a static IP i get following message form Ethernet.localIP() in the serial monitor:
Failed to configure Ethernet using DHCP
Using static IP: 0.0.0.0
Already checked:
I tried the code on the Arduino with an ethernet shield and it worked just fine and gave me the assigned IP address instead of nulls.
Is there anyone with a clue on what I did wrong in my code?
Thanks in advance for helping.
I'm trying to get started with the Teensy 4.1 and its built in ethernet capabilities with the NativeEthernet library. I have tried using a static IP and DHCP in two seperate program attempts and both options work great. I'm now trying to first establich a DHCP connection to the network and if that doesn't work the Teensy should use a static IP address.
Code:
#include <SPI.h>
#include <NativeEthernet.h>
#include <EEPROM.h>
//mac address for the Teensy:
byte mac[] = {...}; //in my code of course i did put a mac address here :)
//the IP address:
IPAddress ip;
// the subnet mask:
IPAddress subnet(255, 255, 255, 0 );
//port 23
EthernetServer server = EthernetServer(23);
void setup()
{
//Serial for testing purposes
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for native USB port only
}
// start the Ethernet connection and the server:
if(Ethernet.begin(mac) == 0)
{
Serial.println("Failed to configure Ethernet using DHCP");
// DHCP connection failed, use ip from EEPROM
ip = IPAddress(EEPROM.read(0), EEPROM.read(1), EEPROM.read(2), EEPROM.read(3));
Ethernet.begin(mac,ip);
}
Ethernet.setSubnetMask(subnet);
// Check for Ethernet hardware
if (Ethernet.hardwareStatus() == EthernetNoHardware)
{
Serial.println("Ethernet Hardware problem with the WizChip :(");
}
if (Ethernet.linkStatus() == LinkOFF)
{
Serial.println("Ethernet cable is not connected.");
}
// start the server
server.begin();
Serial.print("Using static IP: ");
Serial.println(Ethernet.localIP());
// client = server.available();
}
void loop()
{
...
}
If the DHCP fails and uses a static IP i get following message form Ethernet.localIP() in the serial monitor:
Failed to configure Ethernet using DHCP
Using static IP: 0.0.0.0
Already checked:
- EEPROM content is correct
- Content of the ip variable right before and right after Ethernet.begin(mac,ip); is correct
- Pinging the Teensy under the assigned IP address didn't work
- Assigning the numbers directly to the ip variable without the EEPROM.read function worked but still gave me nulls in the serial screen
I tried the code on the Arduino with an ethernet shield and it worked just fine and gave me the assigned IP address instead of nulls.
Is there anyone with a clue on what I did wrong in my code?
Thanks in advance for helping.