Forum Rule: Always post complete source code & details to reproduce any issue!
Page 8 of 8 FirstFirst ... 6 7 8
Results 176 to 192 of 192

Thread: T4.1 Ethernet Library

  1. #176
    Junior Member
    Join Date
    Feb 2021
    Posts
    4
    Quote Originally Posted by SGPMao23 View Post
    When I send a html page which size is more than 2000 bytes, my Teensy 4.1 gets stuck. Reducing the page to below 2000 bytes work ok. I'm not sure if it because of the Native Ethernet library or coming from another part. Do you guys know if there is a buffer somewhere I can configure to have more than 2000 bytes?
    To store the html data, I'm using: const char* document = R"rawliteral(data ... data)rawliteral";
    I'm not sure if you solved this, and this may not be the answer - but have you tried calling setSocketSize? The default socket size appears to be 2KB.

    Sorry to post a reply so late - I'm actually waiting for my T4.1 to arrive so I can start playing with this library myself. Thanks @vjmuzik for creating it!

  2. #177
    Are there any plans to add Precision Time Protocol IEEE 1588-200X to the Lib ?
    My understanding is that T4 has hardware support for PTP.

  3. #178
    Member
    Join Date
    May 2018
    Location
    Land between two rivers
    Posts
    45
    In the UdpNtpClient example "time.nist.gov" is used as the address. Often the resolving of the name fails. An alternative name that is more universal world wide is "pool.ntp.org". I almost never see a failure using it. Using the pool of NTP servers also spreads the load out much better. I also see round trip packet times that are often much less than half as long.

    Code:
    const char timeServer[] = "pool.ntp.org"; // alternative to time.nist.gov NTP server
    This is how I rewrote the loop for getting the time when I was debugging what wasn't working. The amount of '-' printed gives a crude amount of time needed to get the timestamp without setting up a proper timer. To find the reason why some name resolutions fail, it will take a deeper dive into the library to see if all possible ARP packets are being handled, and I don't have the time. Using nslookup utility under Linux I get a combined IP4/IP6 address returned for time.nist.gov and it changes each time. For pool.ntp.org I get a 4 IP4 address set for pool.ntp.org that is the same except for the order. I suspect that IP4/IP6 is tripping up the library name reolutioncode.
    Code:
    void loop() {
      int x = 500;
      sendNTPpacket(timeServer); // send an NTP packet to a time server
    
      while(x-- >= 0) {
        // wait to see if a reply is available
        delay(2);
        if (Udp.parsePacket()) {
          Serial.println('.');
          //Serial.println("packet received");
          x = -1; // kicks us out of the while loop
          // We've received a packet, read the data from it
          Udp.read(packetBuffer, NTP_PACKET_SIZE); // read the packet into the buffer
      
          // the timestamp starts at byte 40 of the received packet and is four bytes,
          // or two words, long. First, extract the two words:
      
          unsigned long highWord = word(packetBuffer[40], packetBuffer[41]);
          unsigned long lowWord = word(packetBuffer[42], packetBuffer[43]);
          // combine the four bytes (two words) into a long integer
          // this is NTP time (seconds since Jan 1 1900):
          unsigned long secsSince1900 = highWord << 16 | lowWord;
          Serial.print("Seconds since Jan 1 1900 = ");
          Serial.println(secsSince1900);
      
          // now convert NTP time into everyday time:
          Serial.print("Unix time = ");
          // Unix time starts on Jan 1 1970. In seconds, that's 2208988800:
          const unsigned long seventyYears = 2208988800UL;
          // subtract seventy years:
          unsigned long epoch = secsSince1900 - seventyYears;
          // print Unix time:
          Serial.println(epoch);
      
      
          // print the hour, minute and second:
          Serial.print("The UTC time is ");       // UTC is the time at Greenwich Meridian (GMT)
          Serial.print((epoch  % 86400L) / 3600); // print the hour (86400 equals secs per day)
          Serial.print(':');
          if (((epoch % 3600) / 60) < 10) {
            // In the first 10 minutes of each hour, we'll want a leading '0'
            Serial.print('0');
          }
          Serial.print((epoch  % 3600) / 60); // print the minute (3600 equals secs per minute)
          Serial.print(':');
          if ((epoch % 60) < 10) {
            // In the first 10 seconds of each minute, we'll want a leading '0'
            Serial.print('0');
          }
          Serial.println(epoch % 60); // print the second
        } else {
          Serial.print('-');
        }
      }
      // wait before asking for the time again
      Serial.println("delay 120 seconds");
      delay(120000);
      Ethernet.maintain();
    }

  4. #179
    Junior Member
    Join Date
    Mar 2021
    Posts
    19

    T4.1 Ethernet file server

    Hy,

    I'm currently making an CANbus logger that is attached to ethernet. The goal is to log the canmessages to the SD card and be able to download the logfile from the teensy over ethernet.

    However i'm having some troubles with the download of the files. i'm able to get the root folder displayed and download files from it. However, at around the 6-10th refresh of the page, i suddenly get a file = 0 and am not able to display the page, even tho the request is the same. After that, it keeps giving me the File Not Found Error.-

    Seriallog:
    Code:
    boot
    slowblink: 1 ,fastblink: 0
    FIFO Enabled --> Interrupt Enabled
    	FIFO Filters in use: 8
    	Remaining Mailboxes: 8
    		MB8 code: TX_INACTIVE
    		MB9 code: TX_INACTIVE
    		MB10 code: TX_INACTIVE
    		MB11 code: TX_INACTIVE
    		MB12 code: TX_INACTIVE
    		MB13 code: TX_INACTIVE
    		MB14 code: TX_INACTIVE
    		MB15 code: TX_INACTIVE
    Canbus booted
    SD card initialized
    SD card time synced
    210402.csv
    server is at 192.168.1.177
    Starting logging
    12 51 SD card  02 04 2021 ,incomming= 1, TS=92 ,ID=100 ,Length=8 ,data=A 14 0 64 80 40 20 10
    12 51 01 02 04 2021 ,incomming= 1, TS=13958 ,ID=100 ,Length=8 ,data=A 14 0 64 80 40 20 10 
    12 51 01 02 04 2021 ,incomming= 1, TS=1857 ,ID=100 ,Length=8 ,data=A 14 0 64 80 40 20 10 
    12 51 02 02 04 2021 ,incomming= 1, TS=55292 ,ID=100 ,Length=8 ,data=A 14 0 64 80 40 20 10 
    12 51 03 02 04 2021 ,incomming= 1, TS=43191 ,ID=100 ,Length=8 ,data=A 14 0 64 80 40 20 10 
    12 51 04 02 04 2021 ,incomming= 1, TS=31089 ,ID=100 ,Length=8 ,data=A 14 0 64 80 40 20 10 
    12 51 05 02 04 2021 ,incomming= 1, TS=18988 ,ID=100 ,Length=8 ,data=A 14 0 64 80 40 20 10 
    new client
    GET / HTTP/1.1
    Web request for: 
    Main site
    File Opened!
    is a directory
    client disconnected
    12 51 06 02 04 2021 ,incomming= 1, TS=6887 ,ID=100 ,Length=8 ,data=A 14 0 64 80 40 20 10 
    12 51 07 02 04 2021 ,incomming= 1, TS=60322 ,ID=100 ,Length=8 ,data=A 14 0 64 80 40 20 10 
    new client
    GET / HTTP/1.1
    Web request for: 
    Main site
    File Opened!
    is a directory
    client disconnected
    12 51 08 02 04 2021 ,incomming= 1, TS=48221 ,ID=100 ,Length=8 ,data=A 14 0 64 80 40 20 10 
    12 51 09 02 04 2021 ,incomming= 1, TS=36119 ,ID=100 ,Length=8 ,data=A 14 0 64 80 40 20 10 
    new client
    GET / HTTP/1.1
    Web request for: 
    Main site
    File Opened!
    is a directory
    client disconnected
    12 51 10 02 04 2021 ,incomming= 1, TS=24018 ,ID=100 ,Length=8 ,data=A 14 0 64 80 40 20 10 
    12 51 11 02 04 2021 ,incomming= 1, TS=11917 ,ID=100 ,Length=8 ,data=A 14 0 64 80 40 20 10 
    new client
    GET / HTTP/1.1
    Web request for: 
    Main site
    File Opened!
    is a directory
    client disconnected
    12 51 12 02 04 2021 ,incomming= 1, TS=65352 ,ID=100 ,Length=8 ,data=A 14 0 64 80 40 20 10 
    12 51 13 02 04 2021 ,incomming= 1, TS=53251 ,ID=100 ,Length=8 ,data=A 14 0 64 80 40 20 10 
    12 51 14 02 04 2021 ,incomming= 1, TS=41149 ,ID=100 ,Length=8 ,data=A 14 0 64 80 40 20 10 
    new client
    GET / HTTP/1.1
    Web request for: 
    Main site
    File Opened!
    is a directory
    client disconnected
    12 51 15 02 04 2021 ,incomming= 1, TS=29048 ,ID=100 ,Length=8 ,data=A 14 0 64 80 40 20 10 
    12 51 16 02 04 2021 ,incomming= 1, TS=16947 ,ID=100 ,Length=8 ,data=A 14 0 64 80 40 20 10 
    new client
    GET / HTTP/1.1
    Web request for: 
    Main site
    File Opened!
    is a directory
    client disconnected
    12 51 27 02 04 2021 ,incomming= 1, TS=4845 ,ID=100 ,Length=8 ,data=A 14 0 64 80 40 20 10 
    12 51 27 02 04 2021 ,incomming= 1, TS=34078 ,ID=100 ,Length=8 ,data=A 14 0 64 80 40 20 10 
    12 51 27 02 04 2021 ,incomming= 1, TS=21977 ,ID=100 ,Length=8 ,data=A 14 0 64 80 40 20 10 
    12 51 27 02 04 2021 ,incomming= 1, TS=9876 ,ID=100 ,Length=8 ,data=A 14 0 64 80 40 20 10 
    12 51 28 02 04 2021 ,incomming= 1, TS=2804 ,ID=100 ,Length=8 ,data=A 14 0 64 80 40 20 10
    12 51 29 02 04 2021 ,incomming= 1, TS=56239 ,ID=100 ,Length=8 ,data=A 14 0 64 80 40 20 10 
    12 51 30 02 04 2021 ,incomming= 1, TS=44138 ,ID=100 ,Length=8 ,data=A 14 0 64 80 40 20 10 
    12 51 31 02 04 2021 ,incomming= 1, TS=32037 ,ID=100 ,Length=8 ,data=A 14 0 64 80 40 20 10 
    new client
    GET / HTTP/1.1
    Web request for: 
    Main site
    client disconnected
    partial arduino code:
    Code:
    void ethernet_client(){
        // listen for incoming clients
        if(!client) client = server.available();
        
        if (client){
          #ifdef DEBUG
          Serial.println("new client");
          #endif
          // reset the input buffer
            char clientline[BUFSIZ];
            int index = 0;
          noInterrupts();
          while (client.connected()) {
            if (client.available()) {
              char c = client.read();
              // If it isn't a new line, add the character to the buffer
              if (c != '\n' && c != '\r') {
                clientline[index] = c;
                index++;
                // are we too big for the buffer? start tossing out data
                if (index >= BUFSIZ) 
                  index = BUFSIZ -1;
                
                // continue to read more data!
                continue;
              }
            
              // got a \n or \r new line, which means the string is done
              clientline[index] = 0;
    
              #ifdef DEBUG
              // Print it out for debugging
              Serial.println(clientline);
              #endif
              // Look for substring such as a request to get the file
              if (strstr(clientline, "GET /") != 0) {
                // this time no space after the /, so a sub-file!
                char *filename;
                
                filename = clientline + 5; // look after the "GET /" (5 chars)  *******
                // a little trick, look for the " HTTP/1.1" string and 
                // turn the first character of the substring into a 0 to clear it out.
                (strstr(clientline, " HTTP"))[0] = 0;
    
                if(filename[strlen(filename)-1] == '/') {  // Trim a directory filename
                  filename[strlen(filename)-1] = 0;        //  as Open throws error with trailing /
                }
                
                #ifdef DEBUG
                Serial.print(F("Web request for: ")); Serial.println(filename);  // print the file we want
                #endif
    
                if(true) // file request
                {
                  #ifdef DEBUG
                  Serial.println("Main site");
                  #endif    
    
                  File file = SD.open(filename, O_READ);
                  if ( file == 0 ) {  // Opening the file with return code of 0 is an error in SDFile.open
                    client.println("HTTP/1.1 404 Not Found");
                    client.println("Content-Type: text/html");
                    client.println();
                    client.println("<h2>File Not Found!</h2>");
                    client.println("<br><h3>Couldn't open the File!</h3>");
                    break;
                  }
    
                  #ifdef DEBUG
                  Serial.println("File Opened!");
                  #endif          
                  client.println("HTTP/1.1 200 OK");
        
                  if (file.isDirectory()) {
                    Serial.println("is a directory");
                    
                    client.println("Content-Type: text/html");
                    client.println("Connection: close");  // the connection will be closed after completion of the response
                    client.println();
                    client.println("<!DOCTYPE HTML>");
                    client.println("<html>");
        
                    client.println();
                    client.print("<h2>Files in /");
                    client.print(filename);
                    client.println(":</h2>");
                    //File entry = file.openNextFile(); // clear the SYSTEM~1/ folder
                    while (true) { // write out all the files and end while
                      File entry = file.openNextFile(); 
                      // done if past last used entry
                      if (! entry) {
                        // no more files
                        break;
                      }
                    
                      // print any indent spaces
                      client.print("<li><a href=\"");
                      client.print(entry.name());
                      if (entry.isDirectory()) {
                        client.println("/");
                      }
                      client.print("\">");
                        
                      // print file name with possible blank fill
                      client.print(entry.name());
                      if (entry.isDirectory()) {
                        client.println("/");
                      }
                            
                      client.print("</a>");
                      client.println("</li>");
                      entry.close();
                    }
                    client.println();
                    client.println("</html>");
                    file.close();                 
                  }
                  else { // Any non-directory clicked, server will send file to client for download
                    client.println("Content-Type: application/octet-stream");
                    client.println();
    
                    char file_buffer[ETH_BUFFER_SIZE];
                    int avail;
                    while (avail = file.available())  {
                      int to_read = min(avail, ETH_BUFFER_SIZE);
                      if (to_read != file.read(file_buffer, to_read)) {
                        break;
                      }
                      client.write(file_buffer, to_read);
                    }
                    file.close();
                  }
                }
              }
              else { // everything else is a 404
                
                client.println("HTTP/1.1 404 Not Found");
                client.println("Content-Type: text/html");
                client.println();
                client.println("<h2>Error 404: Page not found!</h2>");
              }
              break;
            }
          }
          interrupts();
          // give the web browser time to receive the data
          delay(1);
          // close the connection:
          client.stop();
          #ifdef DEBUG
          Serial.println("client disconnected");
          #endif
        }
    }
    full code: canDBC.ino

  5. #180

    Dropping UDP packets after bootup?

    When I boot up, I'm noticing that sent UDP packets are dropped for initial ~30 seconds after bootup. Is that normal?

    If I use DHCP, no dropped packets, but there is a 60 sec DHCP time.

    Static IPs, with local NTP server on a Raspberry Pi. Wireshark on port mirrored switch confirms no packets being sent. Sending every 5 sec.

    Code:
    MAC: 04:e9:e5:0c:d2:ec
    Configured Ethernet Static IP
    Starting UDP
    Requesting NTP packet
    Waiting for NTP Response
    Requesting NTP packet
    Waiting for NTP Response
    Requesting NTP packet
    Waiting for NTP Response
    Requesting NTP packet
    Waiting for NTP Response
    Requesting NTP packet
    Waiting for NTP Response
    Requesting NTP packet
    Waiting for NTP Response
    Requesting NTP packet
    Waiting for NTP Response
    Seconds since Jan 1 1900 = 3826921298
    Unix time = 1617932498
    The UTC time is 1:41:38
    Here is my code

    Code:
    /*
    
     Udp NTP Client
    
     Get the time from a Network Time Protocol (NTP) time server
     Demonstrates use of UDP sendPacket and ReceivePacket
     For more on NTP time servers and the messages needed to communicate with them,
     see http://en.wikipedia.org/wiki/Network_Time_Protocol
    
     created 4 Sep 2010
     by Michael Margolis
     modified 9 Apr 2012
     by Tom Igoe
     modified 02 Sept 2015
     by Arturo Guadalupi
    
     This code is in the public domain.
    
     */
    
    #include <SPI.h>
    #include <NativeEthernet.h>
    #include <NativeEthernetUdp.h>
    
    // Enter a MAC address for your controller below.
    // Newer Ethernet shields have a MAC address printed on a sticker on the shield
    byte mac[] = {
      0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED
    };
    
    unsigned int localPort = 8888;       // local port to listen for UDP packets
    
    const int NTP_PACKET_SIZE = 48; // NTP time stamp is in the first 48 bytes of the message
    
    byte packetBuffer[NTP_PACKET_SIZE]; //buffer to hold incoming and outgoing packets
    
    // A UDP instance to let us send and receive packets over UDP
    EthernetUDP Udp;
    
    // send an NTP request to the time server at the given address
    void sendNTPpacket(IPAddress ntpServer) {
      // set all bytes in the buffer to 0
      memset(packetBuffer, 0, NTP_PACKET_SIZE);
      // Initialize values needed to form NTP request
      // (see URL above for details on the packets)
      packetBuffer[0] = 0b11100011;   // LI, Version, Mode
      packetBuffer[1] = 0;     // Stratum, or type of clock
      packetBuffer[2] = 6;     // Polling Interval
      packetBuffer[3] = 0xEC;  // Peer Clock Precision
      // 8 bytes of zero for Root Delay & Root Dispersion
      packetBuffer[12]  = 49;
      packetBuffer[13]  = 0x4E;
      packetBuffer[14]  = 49;
      packetBuffer[15]  = 52;
    
      // all NTP fields have been given values, now
      // you can send a packet requesting a timestamp:
      Udp.beginPacket(ntpServer, 123); // NTP requests are to port 123
      Udp.write(packetBuffer, NTP_PACKET_SIZE);
      Udp.endPacket();
    }
    
    
      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]);
      }
    
    
    void setup() {
      // You can use Ethernet.init(pin) to configure the CS pin
      //Ethernet.init(10);  // Most Arduino shields
      //Ethernet.init(5);   // MKR ETH shield
      //Ethernet.init(0);   // Teensy 2.0
      //Ethernet.init(20);  // Teensy++ 2.0
      //Ethernet.init(15);  // ESP8266 with Adafruit Featherwing Ethernet
      //Ethernet.init(33);  // ESP32 with Adafruit Featherwing Ethernet
    
      // Open serial communications and wait for port to open:
      Serial.begin(115200);
      while (!Serial) {
        ; // wait for serial port to connect. Needed for native USB port only
      }
      teensyMAC(mac);
      IPAddress ip(192,168,1,17);
      IPAddress gateway(192, 168, 1, 1);
      IPAddress dns(192, 168, 1, 1);
      IPAddress subnet(255, 255, 0, 0);
      // start Ethernet and UDP
      Ethernet.begin(mac,ip, dns, gateway, subnet);
      Serial.println("Configured Ethernet Static IP");
      if (Ethernet.hardwareStatus() == EthernetNoHardware) {
        Serial.println("Ethernet shield was not found.  Sorry, can't run without hardware. :(");
      } else if (Ethernet.linkStatus() == LinkOFF) {
        Serial.println("Ethernet cable is not connected.");
      }
      Serial.println("Starting UDP");
      Udp.begin(localPort);
    }
    
    void loop() {
      IPAddress ntpServer(192,168,1,9);
      Serial.println("Requesting NTP packet");
      sendNTPpacket(ntpServer); // send an NTP packet to a time server
      // wait to see if a reply is available
      Serial.println("Waiting for NTP Response");
      delay(1000);
      if (Udp.parsePacket()) {
        // We've received a packet, read the data from it
        Udp.read(packetBuffer, NTP_PACKET_SIZE); // read the packet into the buffer
    
        // the timestamp starts at byte 40 of the received packet and is four bytes,
        // or two words, long. First, extract the two words:
    
        unsigned long highWord = word(packetBuffer[40], packetBuffer[41]);
        unsigned long lowWord = word(packetBuffer[42], packetBuffer[43]);
        // combine the four bytes (two words) into a long integer
        // this is NTP time (seconds since Jan 1 1900):
        unsigned long secsSince1900 = highWord << 16 | lowWord;
        Serial.print("Seconds since Jan 1 1900 = ");
        Serial.println(secsSince1900);
    
        // now convert NTP time into everyday time:
        Serial.print("Unix time = ");
        // Unix time starts on Jan 1 1970. In seconds, that's 2208988800:
        const unsigned long seventyYears = 2208988800UL;
        // subtract seventy years:
        unsigned long epoch = secsSince1900 - seventyYears;
        // print Unix time:
        Serial.println(epoch);
    
    
        // print the hour, minute and second:
        Serial.print("The UTC time is ");       // UTC is the time at Greenwich Meridian (GMT)
        Serial.print((epoch  % 86400L) / 3600); // print the hour (86400 equals secs per day)
        Serial.print(':');
        if (((epoch % 3600) / 60) < 10) {
          // In the first 10 minutes of each hour, we'll want a leading '0'
          Serial.print('0');
        }
        Serial.print((epoch  % 3600) / 60); // print the minute (3600 equals secs per minute)
        Serial.print(':');
        if ((epoch % 60) < 10) {
          // In the first 10 seconds of each minute, we'll want a leading '0'
          Serial.print('0');
        }
        Serial.println(epoch % 60); // print the second
      }
      // wait ten seconds before asking for the time again
      delay(5000);
      Ethernet.maintain();
    }

  6. #181
    Junior Member
    Join Date
    Apr 2021
    Posts
    2
    Hello everyone,
    just bought and started using a Tennsy 4.1 with the NativeEthernet library and got into this issue: The Teensy freezes when I try to use Ethernet.begin(mac); or Ethernet.begin(mac, ip); when the cable is not connected on powerup. It is not my code, since the issue persists even when using the LinkStatus example from the Ethernet library. There I just changed it to NativeEthernet.h and added the mac and ip byte arrays...
    If I start the example with the cable connected, the example works fine, showing ON/OFF if I connect/disconnect the cable, but freezes with the cable disconnected on powerup...
    Am I missing something? For my program I want to be able to detect if the cable is connected on startup and act accordingly...
    Thanks!
    Last edited by Robert23; 04-12-2021 at 03:41 PM. Reason: typo...

  7. #182
    Senior Member
    Join Date
    May 2019
    Posts
    116
    I thought that freezing without a Ethernet cable connected is a known issue.

  8. #183
    Junior Member
    Join Date
    Apr 2021
    Posts
    2
    Quote Originally Posted by tschrama View Post
    I thought that freezing without a Ethernet cable connected is a known issue.
    Oh, if that is the case, then my Google-fu must have been weak...
    Found it

  9. #184
    Junior Member
    Join Date
    Mar 2021
    Posts
    19
    Hy,

    I'm making a web server and was wondering if i could define an url so that i can connect using an url instead of an ip adress. The reason is, the server needs to run usign DHCP and i need a way to reliably connect to the server even if it's IP adress is changed.

  10. #185
    Junior Member
    Join Date
    Apr 2021
    Location
    Finland
    Posts
    1
    Hi,
    I moved to 4.1 and setup was easy and it seems work just fine. But when trying to use it with fast data collection with delayNanoseconds or with interrupts I can't keep stable acquisition rate. For example sometimes delayNanoseconds is just fine but sometimes it's almost twice long than previous pause , same happens when trying to do that with interrupts . I tried to disable interrupts before my collection cycle but that doesnt help.
    What would be the best way to "pause" the ethernet handling during other critical tasks ? Or is there a better option to try fixing that problem ?

  11. #186
    Member
    Join Date
    Feb 2017
    Location
    Chicago, IL
    Posts
    36
    Quote Originally Posted by vjmuzik View Post
    Native Ethernet Update:
    Code:
    Add client-side TLS support
    -Add WebClientRepeatingTLS example
    -Add client.close() to support proper HTTP close before disconnecting
    -Add functions to set client and server certificates/keys (if needed)
    Thanks vjmuzik for this library! I have been using it successfully to retrieve weather data from Open Weather. I wanted to expand to get additional information from the National Weather Service API at https://api.weather.gov/

    I ran your TLS example that connects to pjrc.com successfully:

    https://github.com/vjmuzik/NativeEth...peatingTLS.ino

    but when I replace the two instances of "pjrc.com" with "api.weather.gov", client.connect fails to connect. The base URL returns data when accessed via Chrome and CURL from my desktop. I'm a little at a loss as to what additional configuration, settings, etc. are needed to connect here; I looked through the forum and Google to see if I could stumble on anything related to your library, FNET, Certs, etc. but ended up more confused than before. Any pointers would be appreciated.

  12. #187
    Member
    Join Date
    Feb 2017
    Location
    Chicago, IL
    Posts
    36
    Update: it is dns.getHostByName(host, remote_addr) in the client.connect() method that fails to resolve the address for the server. "api.weather.gov" is an alias (CNAME) and it appears the dnsClient cannot resolve aliases.

  13. #188
    Senior Member
    Join Date
    Feb 2015
    Posts
    102

    Teensy Eithernet

    Thanks for the great work.

    I have never work with Ethernet with a micro before so I am just fumbling around.

    I developed a CAN BOB for the 4.1 which included Ethernet.

    I tried the Link example but it says there was no connection even though the cable was connected.

    But when I ran the DhcpAddressPrinter.ino and connected to a router I was served and IP and it was printed out. After that...nothing happened. No more messages. I this correct?

    I added an IP recheck at the below the case statement and no issue just kept printing out the same IP so I am assuming the PCB design is correct? Green light is blinking so I am assuming there is data going back and forth?

    Just trying to figure out an easy way to make sure my PCB design is correct.

    Thanks

    Bruce
    Attached Thumbnails Attached Thumbnails Click image for larger version. 

Name:	Capture.JPG 
Views:	25 
Size:	102.1 KB 
ID:	24774  

  14. #189
    Junior Member
    Join Date
    Apr 2021
    Posts
    2
    Hello,

    I have a Teensy 4.1 with NativeEthernet and use it to send data to a pi.
    When the pi is online it works great, but when the pi is down the Teensy freeze and I need to restart the teensy.

    Does anyone have the same problems, or any idea what the problem is?

    I use Arduino 1.8.13 / Teensyduino 1.54-beta9.
    Code:
    #include <NativeEthernet.h>
    ...
    EthernetClient pyClient;
    ...
    void sendPy(String send_string)
    {
      pyClient.setConnectionTimeout(50);
      if (pyClient.connect(pyIP, 8099)) <-- here the teensy freeze
      {
        pyClient.print(send_string);
      }
      else
      {
        Serial.println("Connection failed");
      }
      pyClient.stop();
    }
    ...

  15. #190
    Member
    Join Date
    Jun 2018
    Location
    Northeast USA
    Posts
    69
    Hello All,
    I've just got my first Teensy 4.1 here with the PJRC magjack kit. updated Teensyduino to 1.54 Beta #9, and have compiled the WebServer example. But.....I get a
    Ethernet shield was not found. Sorry, can't run without hardware. :
    message.

    My guess is the Ethernet.init call needs to be made. Is this a pin number you pass to Ethernet.init?
    Thank You,
    John
    p.s. the memory usage message for FLASH, RAM1, and RAM2 is cool. Thank You Paul & Co.

    // You can use Ethernet.init(pin) to configure the CS pin
    //Ethernet.init(10); // Most Arduino shields
    //Ethernet.init(5); // MKR ETH shield
    //Ethernet.init(0); // Teensy 2.0
    //Ethernet.init(20); // Teensy++ 2.0
    //Ethernet.init(15); // ESP8266 with Adafruit Featherwing Ethernet
    //Ethernet.init(33); // ESP32 with Adafruit Featherwing Ethernet

  16. #191
    Member KD0RC's Avatar
    Join Date
    May 2019
    Location
    Colorado, USA
    Posts
    80
    The library that you need is:
    #include "NativeEthernet.h"

    I don't think you need the init. Here is a chunk of what I do:

    In setup(), I call getIpAddress. addr is a String variable and contains the IP address once it si obtained from DHCP.

    Code:
    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)  // Ten 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, 5, 25);
      
      // start the Ethernet connection:
      Serial.println("=== Setting fixed IP address");
      
      Ethernet.begin(mac, ip);
    
    } // 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]);
    }
    I hope this helps.

    Len

    EDIT: Sorry, forgot:
    definition for mac: byte mac[6];

  17. #192
    Member
    Join Date
    Jan 2020
    Location
    Toronto, Canada
    Posts
    61
    Just created a PR Fix the DNS bug #21 for NativeEthernet library to fix the DNS issue when the host is actually an IP Address.

    Check the issue Socket.io client on Teensy Native Ethernet not working on Websockets_Generic #12

Posting Permissions

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