T4.1 Ethernet Library

NativeEthernet Update:
Code:
[B]Various bug fixes/improvements[/B]
- Add non-blocking method for client.connect
- Add WebClientPollRepeatingTLS example showing non-blocking method
- Add method to set server port number in setup, e.g. server.begin(80)
- Set clients IP Address on socket accept instead of first packet
- Allow using Ethernet.begin(mac, ip) after Ethernet.begin(mac) if dhcp fails
- Fix socket overflow when using client/server
- Fix missing data from client in certain cases
 
@vjmuzik Hi vj, I loaded the latest library from Github, but it did not solve my issue (- Allow using Ethernet.begin(mac, ip) after Ethernet.begin(mac) if dhcp fails). If I go straight to Ethernet.begin(mac, ip) without trying Ethernet.begin(mac) first, it works fine (as it did before). It does set the ethernet ip properly, and I do get an initial connect. Once a little data goes back and forth, the connection quits. It feels like a timeout parameter or something. I also see a timeout parm of 60000 ms. When I am not connecting via DHCP, it takes the full 60 seconds to connect. If I cut this value to 6000, I get the connect in 6 seconds. I am not sure if this is related, but thought I would mention it.
In NativeEthernet.h:
static int begin(uint8_t *mac, unsigned long timeout = 60000, unsigned long responseTimeout = 4000);

Thanks,
Len
 
The timeout is related, it's there to give the DHCP server time to respond if there is one available, if it didn't wait at least a little bit then it might miss the DHCP messages. Those timeout values are just the defaults that the old Ethernet library used, they can be changed from the sketch so it's not really an issue, if DHCP is there it shouldn't need longer than a couple of seconds so setting it at a lower value won't be a problem.
 
Ok, thanks for that insight, I will adjust accordingly. I still have the problem where an Ethernet.begin(mac) followed by Ethernet.begin(mac, ip) in the case of no DHCP server connects briefly, then drops. It is like something is not being reset from the first .begin.
 
I finally was able to replicate this, and it was the DHCP client not being released like it said it would when you manually change the IP Address, I just pushed another update to fix this.
 
Hi. First time using Ethernet on Arduino. I have a Teensy 4.1 with the Ethernet adaptor provide by PJRC. I'm using Teensyduino Version 1.53 and Arduino 1.8.13

I've downloaded this library (https://github.com/vjmuzik/NativeEthernet) but need a few tips to get it going. I've installed the library in the Sketchbook folder under libraries. I'm attempting to use the Arduino UDP sample code as shown below. It compiles OK, but I understand I need to change <Ethernet.h> to <NativeEthernet.h>. When I do that it doesn't compile and I get dozens of errors. Obviously I don't get something.

Code:
#include <SPI.h>
#include <Ethernet.h>
#include <EthernetUdp.h>

// Enter a MAC address and IP address for your controller below.
// The IP address will be dependent on your local network:
byte mac[] = {
  0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED
};
IPAddress ip(192, 168, 1, 177);

unsigned int localPort = 8888;      // local port to listen on

// An EthernetUDP instance to let us send and receive packets over UDP
EthernetUDP Udp;

char packetBuffer[UDP_TX_PACKET_MAX_SIZE]; //buffer to hold incoming packet,

void setup() {
  // start the Ethernet and UDP:
  Ethernet.begin(mac, ip);
  Udp.begin(localPort);

}

void loop() {

  int packetSize = Udp.parsePacket();
  if (packetSize)
  {
    Serial.print("Received packet of size ");
    Serial.println(packetSize);
    Serial.print("From ");
    IPAddress remote = Udp.remoteIP();
    for (int i = 0; i < 4; i++)
    {
      Serial.print(remote[i], DEC);
      if (i < 3)
      {
        Serial.print(".");
      }
    }
    Serial.print(", port ");
    Serial.println(Udp.remotePort());

    // read the packet into packetBufffer
    Udp.read(packetBuffer, UDP_TX_PACKET_MAX_SIZE);
    Serial.println("Contents:");
    Serial.println(packetBuffer);
  }
}
 
There is a UDP example in the library :: ...\libraries\NativeEthernet\examples\UdpNtpClient\UdpNtpClient.ino

It indeed starts like this:
Code:
...#include <SPI.h>
#include <NativeEthernet.h>
#include <NativeEthernetUdp.h>
...

perhaps starting with that example - or make edits in line with that sample and post the verbose compile errors shown.
 
I made a simple test program due to issues when connection to a MQTT broker. The problem is that when I connect to the MQTT broker when it is offline I get not the expected false but the system hangs.
So I made a small test, ran it in the Arduino IDE and it works great, but in PlatformIO it fails (same code!). I have no clue what the problem is and I am completely stuck :-(

Only when the broker is not online I get the difference between Arduino IDE and PlatformIO. PlatformIO hangs but Arduino IDE returns a 0 (failed to connect). When the broker is online they both work as expected.

Suggestions are very welcome!

#include <Arduino.h>
#include <SPI.h>
#include <NativeEthernet.h>

byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
EthernetClient testcl;

void connectMQTT3()
{
char sIp[15] = "192.168.2.44";
IPAddress MQTTbrokerIP(192,168,2,44);
Serial.println("initMQTT");
int result = testcl.connect(MQTTbrokerIP, 1883);
delay(200);
Serial.print("result: ");
Serial.println(result);
}

void setup() {
Serial.begin(9600);
Ethernet.begin(mac);
}

void loop() {

auto link = Ethernet.linkStatus();
Serial.print("Link status: ");
switch (link) {
case Unknown:
Serial.println("Unknown");
break;
case LinkON:
Serial.println("ON");
break;
case LinkOFF:
Serial.println("OFF");
break;
}
delay(1000);
connectMQTT3();
}
 
Now that I've learned how to make use of C++ objects from C code I figured I would finally add the missing Serial functions from FNET so that it's services that make use of it will actually function. To go along with that I made a short example showcasing the FNET Shell service that makes it easy to setup and read commands from the Serial monitor. The good thing is that you don't need any Ethernet hardware connected to the Teensy 4.1 to use the Shell service by itself so it can be used with other projects that don't necessarily need Ethernet access. If anyone needs the Shell to work with other Teensy models let me know and I can work on adding in a stripped down compatibility layer for them so that it only compiles what it needs for the shell without including the rest of FNET since the rest isn't really usable on other models.

FNET: https://github.com/vjmuzik/FNET
NativeEthernet: https://github.com/vjmuzik/NativeEthernet
 
I pulled in the latest FNET and NativeEthernet in prep for 1.54-beta5.

The WebClient example seems to no longer work. I get this:

Code:
Initialize Ethernet with DHCP:
  DHCP assigned IP 192.168.195.167
connecting to www.google.com...

But then it never connects. The WebClient for regular Ethernet works with a WIZ850io, so I'm pretty sure my ethernet connection is good.

I was able able to run NativeEthernet's WebServer example and connect to it from my browser.
 
Is Native Ethernet IPv6 on the T4.1 supported? I have a host that has a IPv6-only stack. Played around with the underlaying FNET config but no luck. If there is support, a small example would do be very much appreciated. If not, is this planned?
 
FNET itself does support it, though I’ve turned it off in the config since the original Ethernet.h library didn’t support. At the moment there aren’t plans to add it because I’m working on other projects right now, but in the future it’ll be something I will add.
 
thanks for the quick answer. I tried to simply turn it on in fnet_user_config.h but realized that NativeEthernet itself uses the ipv4 variants of the commands. So there isn't an easy hack, right?
 
Basically any function that uses ipv4 would need an ipv6 equivalent, I’m not sure how much of it could stay as is without changes so I don’t know if it’s a quick fix.
 
First of all: Hi everyone and soo much thanks to vjmuzik for this great library.

I have the same problem as Paul: WebClient example isn't working anymore, forever hanging in the connecting state. This isn't a problem with the example itself though - it seems to be in the DNS lookup of the library. I also experienced this in my own project, so after some researching I got it to work only if I use IPAddress() as a parameter to connect(). Hostnames are not working. At first I thought it was a problem with my network, so I tried DHCP and static IP config, as well as different DNS servers, none of that helped though.
 
First of all: Hi everyone and soo much thanks to vjmuzik for this great library.

I have the same problem as Paul: WebClient example isn't working anymore, forever hanging in the connecting state. This isn't a problem with the example itself though - it seems to be in the DNS lookup of the library. I also experienced this in my own project, so after some researching I got it to work only if I use IPAddress() as a parameter to connect(). Hostnames are not working. At first I thought it was a problem with my network, so I tried DHCP and static IP config, as well as different DNS servers, none of that helped though.

I forgot to look at this when Paul mentioned it, here's the fix: https://github.com/vjmuzik/NativeEthernet
 
Try updating your libraries first, I know there was a problem at one time with availableForWrite not returning correctly, but after a quick test on my end I can verify that it is working now.
FNET: https://github.com/vjmuzik/FNET
NativeEthernet: https://github.com/vjmuzik/NativeEthernet

Thank you for your quick reply. I am confirming that I am using the latest versions of both libraries (0.1.3m and 1.0.5) but still getting that error.

When I comment out the "availableforwrite" statement on the code I attached, the program stops working so I am assuming there is still a bug?
 
I'm curious why writeBuffer.available() would return 0 which as far as I can tell is calling client.available() which didn't return a 0 in the statement before that.
 
Back
Top