Forum Rule: Always post complete source code & details to reproduce any issue!
Page 6 of 6 FirstFirst ... 4 5 6
Results 126 to 146 of 146

Thread: T4.1 Ethernet Library

  1. #126
    Senior Member vjmuzik's Avatar
    Join Date
    Apr 2017
    Posts
    691
    NativeEthernet Update:
    Code:
    Various bug fixes/improvements
    - 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

  2. #127
    Member
    Join Date
    May 2019
    Location
    Colorado, USA
    Posts
    40
    @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

  3. #128
    Senior Member vjmuzik's Avatar
    Join Date
    Apr 2017
    Posts
    691
    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.

  4. #129
    Member
    Join Date
    May 2019
    Location
    Colorado, USA
    Posts
    40
    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.

  5. #130
    Senior Member vjmuzik's Avatar
    Join Date
    Apr 2017
    Posts
    691
    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.

  6. #131
    Member
    Join Date
    May 2019
    Location
    Colorado, USA
    Posts
    40
    It worked perfectly! Thanks for sticking with me on this, I really appreciate it.
    Len

  7. #132
    Yeh, thanks for updating this lib��

  8. #133
    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);
      }
    }

  9. #134
    Senior Member+ defragster's Avatar
    Join Date
    Feb 2015
    Posts
    12,701
    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.

  10. #135
    Thanks. Working now.

  11. #136
    Senior Member+ defragster's Avatar
    Join Date
    Feb 2015
    Posts
    12,701
    Quote Originally Posted by Ausplex View Post
    Thanks. Working now.
    Awesome. Enjoy!

  12. #137
    Junior Member
    Join Date
    Jul 2020
    Posts
    8
    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();
    }

  13. #138
    Senior Member vjmuzik's Avatar
    Join Date
    Apr 2017
    Posts
    691
    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

  14. #139
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    23,041
    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.

  15. #140
    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?

  16. #141
    Senior Member vjmuzik's Avatar
    Join Date
    Apr 2017
    Posts
    691
    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.

  17. #142
    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?

  18. #143
    Senior Member vjmuzik's Avatar
    Join Date
    Apr 2017
    Posts
    691
    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.

  19. #144
    Junior Member
    Join Date
    Dec 2020
    Posts
    2
    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.

  20. #145
    Senior Member vjmuzik's Avatar
    Join Date
    Apr 2017
    Posts
    691
    Quote Originally Posted by Calibretto View Post
    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

  21. #146
    Junior Member
    Join Date
    Dec 2020
    Posts
    2
    Wow, that was quick. And it works! Thanks, you saved my day.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •