Teensy 4.1 QNEthernet - Linkstate Success but client unavailable

ctlang

Member
I'm a beginner to Ethernet and attempting to get started following this site that includes an introduction to QNEthernet.

I'm using a Teensy 4.1 with the ethernet breakout board. Ethernet is going between Teensy to my laptop running Ubuntu 18.04

The first example of link status works as expected and prints that the link status is on.

However in this second example the ethernet server is unavailable and I'm never able to access the web server. LED on magjack is green and flashes intermittently at first before eventually going solid.

Hoping I'm just using the wrong IP or gateway addresses and I'm not sure about the enp0s31f6 disconnected line shown below. Here is the printout from my terminal when I run
Code:
route -n
and
Code:
nmcli

Screenshot from 2023-03-29 09-58-32.png

Example Code:
Code:
/*
  Teensy 4.1 WebServer Example

  This program reads 6 analog inputs on the Teensy 4.1 and sends the results to
  a webpage in a web browser

  Modify the IPAddress ip, sn and gw to match your own local network
  before downloading the program.
  
  Based on the WebServer example program
  This example uses the QNEthernet.h library
*/

#include <QNEthernet.h>

using namespace qindesign::network;

// The IP address info will be dependent on your local network
// First 3 numbers must match router, last must be unique
// 
IPAddress ip{192, 168, 68, 0};   // Unique IP
IPAddress sn{255,255,255,0};  // Subnet Mask
IPAddress gw{192, 168, 68, 1};       // Default Gateway
// Initialize the Ethernet server library with the IP address and port
// to use.  (port 80 is default for HTTP):
EthernetServer server(80);
//===============================================================================
//  Initialization
//===============================================================================
void setup() {
  Serial.begin(115200);
 // Initialize the library with a static IP so we can point a webpage to it
  if (!Ethernet.begin(ip,sn,gw)) {
    Serial.println("Failed to start Ethernet\n");
    return;
  }

  // Just for fun we are going to fetch the MAC address out of the Teensy
  // and display it
  uint8_t mac[6];
  Ethernet.macAddress(mac);  // Retrieve the MAC address and print it out
  Serial.printf("MAC = %02x:%02x:%02x:%02x:%02x:%02x\n",
         mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
  
  // Show whether a cable is plugged in or not.
  Ethernet.onLinkState([](bool state) {
    Serial.printf("[Ethernet] Link %s\n", state ? "ON" : "OFF");
  });

  // start the webserver
  server.begin();
  Serial.print("server is at ");
  Serial.println(Ethernet.localIP());

}
//===============================================================================
//  Main
//===============================================================================
void loop() {
 // listen for incoming clients
  EthernetClient client = server.available();
  if (client) {
    Serial.println("new client");
    // an http request ends with a blank line
    boolean currentLineIsBlank = true;
    while (client.connected()) {
      if (client.available()) {
        char c = client.read();
        Serial.write(c);
        // if you've gotten to the end of the line (received a newline
        // character) and the line is blank, the http request has ended,
        // so you can send a reply
        if (c == '\n' && currentLineIsBlank) {
          // send a standard http response header
          client.println("HTTP/1.1 200 OK");
          client.println("Content-Type: text/html");
          client.println("Connection: close");  // the connection will be closed after completion of the response
          client.println("Refresh: 5");  // refresh the page automatically every 5 sec
          client.println();
          client.println("<!DOCTYPE HTML>");
         // Start HTML output to be displayed
          client.println("<html>");
          client.println("Teensy 4.1 WebServer<br />");
          // output the voltage value of each analog input pin
          for (int analogChannel = 0; analogChannel < 6; analogChannel++) {
            int sensorReading = analogRead(analogChannel);
            // Convert reading to volts
            float volts = sensorReading * 3.3 / 1024.0;
            client.print("analog input ");
            client.print(analogChannel);
            client.print(" is ");
            client.print(volts);
            client.println("V<br />");
          }
          client.println("</html>");
          break;
        }
        if (c == '\n') {
          // you're starting a new line
          currentLineIsBlank = true;
        } else if (c != '\r') {
          // you've gotten a character on the current line
          currentLineIsBlank = false;
        }
      }
    }
    // give the web browser time to receive the data
    delay(1);
    // close the connection:
    client.stop();
    Serial.println("client disconnected");
  }
}

Thanks!!
 
I also keep getting a popup that "Connection Failed: Activation of network connection failed".
It looks like my ethernet port is just unable to connect to the teensy if I'm understanding this correctly. Maybe it some type of setting on my laptop itself?

Screenshot from 2023-03-29 15-19-53.png

Is there a problem that I don't see an IP address associated with the ethernet port while the teensy is plugged in?

Code:
ip addr
returns the following

Code:
2: enp0s31f6: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
    link/ether d4:81:d7:e7:e7:af brd ff:ff:ff:ff:ff:ff
3: wlp2s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default qlen 1000
    link/ether f4:96:34:1b:85:ff brd ff:ff:ff:ff:ff:ff
    inet 192.168.68.138
 
Back
Top