HTTP-request with a Teensy 4.1 & Ethernet module

RPTech

Member
Hi,

I'm struggling to get this working, hopefully you are help me to guide me a bit.
This is quite a brainbreaker to me, I'm working on this for months now, so please allow me to do a full explanation.

--> Intro:
I'm trying to make the following:
A teensy 4.1 with network module is connected to a computer that runs a webserver.
A button and relay are connected to the Teensy.
If someone activates the button a sequence of GET-requests is fired to the webserver which triggers light-effects.
(Note 1: This sequence exists out of a single request with at least 1 second delay till next request)
(Note 2: The server is a standard 80 port server from the light application, allowing you to control the application through webcommands.

The requests are not HTTPS as well as very basic without authentication)
The relay simply activates a standard 5mm LED to indicate visitors triggering the button is allowed.
As long as the sequence is active the LED is off.
(Note 3: all cable lengths are short, no power spikes or anything. Shielded and quality cabling is only used.)

It is important the board needs to run the script 24/7
Please know; using Postman or even Chrome to use the endpoints always worked stable.

I've made this working already first on Pi Pico W -- which was unstable due to the WiFi connection
Then on a Raspberry Pi 4B, where the board always stopped working after several days (Still not sure why, probably coding issue).
After that I've decided to go to a M5 Stack, but I'm still struggling a bit to get this working, need some more time to deep-dive into this.
I've also tried Arduino Uno + Shield but I know (for a while already) that the GET-request I'm making to the webserver (which is a default application server) is really hard to make working.
Not sure why, but all the libraries are just not working for this.
So important is that I want to script this in python. I've seen with the Pico how easy I was able to make it.

script:
Python:
# Import modules
import network
import urequests
import time
import random
from machine import Pin

# Variables
led = Pin("LED", Pin.OUT)
button = Pin("GP2", Pin.IN, Pin.PULL_UP)
relay = Pin("GP3", Pin.OUT)
activationAllowed = False
connectionAttempt = 1
debug = True
pressed = False

# Important variables
effectDuration = 10
timeOutDuration = 600     #final onsite
#timeOutDuration = 30    #temp debug

# Wlan details
ssid = ""
password = ""

# Connection details
#destinationIp = "192.168.1.148" #Office debug
destinationIp = "192.168.68.105" #Final on-site
wlan = network.WLAN(network.STA_IF)

print("Booting...")

# Connect to WLAN
def connectWifi():
    wlan.active(True)
    wlan.connect(ssid, password)
    print("Check...")

while not wlan.isconnected():
    if connectionAttempt == 10:
            led.off()
            time.sleep(2.5)
            print('Reconnecting...')
            led.on()
            time.sleep(2.5)
            continue
            time.sleep(5)
    led.off()
    activationAllowed = False
    connectWifi()
    print("attempting to (re)connect...attempt: " + str(connectionAttempt))
    connectionAttempt += 1
    led.on()
    time.sleep(0.5)
    led.off()
    time.sleep(0.5)
    pass
print('Connected to WLAN')
attempt = 0
led.on()
relay.on()

def triggeredAction():
    global activationAllowed
    if activationAllowed == True:
        if debug: print("Activation started")
        # Disable any new input
        activationAllowed = False
        # Turn LED pushbutton OFF
        relay.value(0)
        # Turn internal LED OFF to indicate active state
        led.off()
        ## print(bool(relay.value())) # Debug
        # Set fade speed to 5 seconds
        r = urequests.get("http://" + destinationIp + "/RemoteCommands/SetFadeTime=5")
        if debug: print("Statuscode request 1: " + str(r.status_code))
        r.close()
        # Wait 1 second
        time.sleep(1)
        # Turn internal LED back ON
        led.on()
        # Fade to dark
        r = urequests.get("http://" + destinationIp + "/RemoteCommands/SetStorageDeckB=S2P1")
        if debug: print("Statuscode request 2: " + str(r.status_code))
        r.close()
        # Wait 5 seconds (to complete fade)
        time.sleep(5)
        # Set fade to speed to 0 for quick change
        r = urequests.get("http://" + destinationIp + "/RemoteCommands/SetFadeTime=0")
        if debug: print("Statuscode request 3: " + str(r.status_code))
        r.close()
        # Wait 2 seconds
        time.sleep(2)
        # Trigger random effect (must be chosen between 2, 3 and 4)
        val = random.randint(2,4)
        if debug: print("Random is: " + str(val))
        r = urequests.get("http://" + destinationIp + "/RemoteCommands/SetStorageDeckB=S2P" + str(val))
        if debug: print("Statuscode request 4: " + str(r.status_code))
        r.close()
        # Keep effect active for 10 seconds
        time.sleep(effectDuration)
        # Change fade speed back to 4
        r = urequests.get("http://" + destinationIp + "/RemoteCommands/SetFadeTime=4")
        if debug: print("Statuscode request 5: " + str(r.status_code))
        r.close()
        # Wait for 4 seconds
        time.sleep(4)
        # Fade back to dark
        r = urequests.get("http://" + destinationIp + "/RemoteCommands/SetStorageDeckB=S2P1")
        if debug: print("Statuscode request 6: " + str(r.status_code))
        r.close()
        # Wait for as long as fade will take
        time.sleep(4)
        # Change fade speed to 1 second
        r = urequests.get("http://" + destinationIp + "/RemoteCommands/SetFadeTime=1")
        if debug: print("Statuscode request 7: " + str(r.status_code))
        r.close()
        # Wait for 1 second
        time.sleep(1)
        # Fade back to the normal effect
        r = urequests.get("http://" + destinationIp + "/RemoteCommands/SetFadeToDeckA")
        if debug: print("Statuscode request 8: " + str(r.status_code))
        r.close()
        if debug: print("end of activation")
        # Disable activation for 10 minutes
        time.sleep(timeOutDuration)
        if debug: print("new activation is allowed again")

  
while True:
    while wlan.isconnected():
        activationAllowed = True
      
        buttonState = button.value()
        if not buttonState:
            if not pressed:
                if debug: print("Button pressed!")
                triggeredAction()
                pressed = True
        # button not pressed (or released) (originally "else:" was here, gave an error)
        relay.value(1)
        pressed = False
        led.off()
        time.sleep(0.1)
        led.on()
    wlan.connect(ssid, password)
    time.sleep(2)


So yes, quite some money, time and boards further, and with a bit of pressure from my client I've went safe for the Teensy 4.1 + ethernet module.
I've did previous projects with Teensy so absolutely think they are reliable, but not yet with ethernet requests.
Now I do face issues on getting it working.

--> Technical:
My main problem currently is even getting the network module operational.
I've test the AsyncHttpRequest-Teensy41 in the Arduino IDE which works, however; it indicates the Teensy doesn't get an IP from the DHCP.
Which is interesting, cause the teensy is directly connected to my router through a standard LAN cable. LED indication on the connector; only green is blinking.
if I connect the lan to my computer, I get an IP-address

-- returning back to Python. I'm using Thonny, and first of all I'm trying to make a single request.
I've confirmed my board is operational by running a blink script.
I've also noticed urequests is not supported, so instead after googling I need to use Adafruit Requests.
The module is installed and confirmed as an included plug-in

Python:
import board
import digitalio
import time
import adafruit_requests

# Static IP address of the board
board_ip = "192.168.1.100"

def trigger_get_request():
    try:
        response = requests.get("http://192.168.1.101/RemoteCommands/SetFadeTime=4")
        response.raise_for_status()

    except Exception as e:
        print("Error:", e)

# Main loop
while True:
    print("Ready")
    trigger_get_request()


    time.sleep(10)


This results in no module with name 'adafruit_requests' while I still see it in my plug-ins.


Does anyone has a tip to help me a bit on how to make a GET-request with a teensy 4.1 with LAN-connection?
I would be very thankful.
 
My understanding is this: when you press a button attached to a Teeny, the Teensy makes an HTTP request to a server running elsewhere. In other words, the Teensy is an HTTP client. Is my understanding correct? How does the Teensy know when to trigger and un-trigger the relay?
 
My understanding is this: when you press a button attached to a Teeny, the Teensy makes an HTTP request to a server running elsewhere. In other words, the Teensy is an HTTP client. Is my understanding correct? How does the Teensy know when to trigger and un-trigger the relay?
That is correct.
The application runs 24/7 on the PC and has an open webserver on a specific IP that I can use in my script.

The teensy turns the relay on after boot. The relay switches the LED in the button ON.
If a user triggers the input the sequence starts, if this indeed happens the LED will turn off to indicate that you can't press the button at that moment. this will trigger approx. 10-15 http requests each with a delay in-between.
Once all the requests are done there is a longer timeout (10 minutes) to block a new input so you can't trigger it to often.
Once the 10 minutes are passed a new input is allowed again; the relay will then turn on to indicate with the LED that a new input is allowed again.
 
1710265492856.png



Do not pay to much attention to the displayed IP, it's more just example how it looks.
 
I can help you out with some things in C++. If, however, you need something in Python, I won’t be much help, currently.
 
Here's a basic HTTP client example that works:
C++:
#include <QNEthernet.h>

using namespace qindesign::network;

// Tracks if the network is up.
bool networkReady = false;

// Note: This example uses stdout for serial output, but you can use
//       Serial if you like instead.

// Main program setup.
void setup() {
  Serial.begin(115200);
  while (!Serial && millis() < 4000) {
    // Wait for Serial
  }
  printf("Starting...\r\n");

  // Print the MAC address
  uint8_t mac[6];
  Ethernet.macAddress(mac);  // This is informative; it retrieves, not sets
  printf("MAC = %02x:%02x:%02x:%02x:%02x:%02x\r\n",
         mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);

  // Listen for link changes
  Ethernet.onLinkState([](bool state) {
    printf("[Ethernet] Link %s\r\n", state ? "ON" : "OFF");

    networkReady = state && (Ethernet.localIP() != INADDR_NONE);
  });

  // Listen for address changes
  Ethernet.onAddressChanged([]() {
    IPAddress ip = Ethernet.localIP();
    bool hasIP = (ip != INADDR_NONE);
    if (hasIP) {
      IPAddress subnet = Ethernet.subnetMask();
      IPAddress gw = Ethernet.gatewayIP();
      IPAddress dns = Ethernet.dnsServerIP();

      printf(
          "[Ethernet] Address changed:\r\n"
          "    Local IP = %u.%u.%u.%u\r\n"
          "    Subnet   = %u.%u.%u.%u\r\n"
          "    Gateway  = %u.%u.%u.%u\r\n"
          "    DNS      = %u.%u.%u.%u\r\n",
          ip[0], ip[1], ip[2], ip[3],
          subnet[0], subnet[1], subnet[2], subnet[3],
          gw[0], gw[1], gw[2], gw[3],
          dns[0], dns[1], dns[2], dns[3]);
    } else {
      printf("[Ethernet] Address changed: No IP address\r\n");
    }

    networkReady = Ethernet.linkState() && hasIP;
  });

  // Start with DHCP
  if (!Ethernet.begin()) {
    printf("Error: Ethernet not started\r\n");
  }
}

// Set to 'true' when the network comes back up.
// (Need to start at true.)
bool readyToConnect = true;

// It's okay to use a string for an IPAddress as well
// For example: "192.168.0.1"
#define HOST "www.example.com"
constexpr char kHost[]{HOST};
constexpr char kRequest[]{
    "GET / HTTP/1.1\r\n"
    "Host: " HOST "\r\n"
    "Connection: close\r\n"
    "\r\n"
};
#undef HOST
constexpr uint16_t kPort = 80;

// Main program loop.
void loop() {
  if (!networkReady) {
    readyToConnect = true;
    return;
  }

  // There's many different ways to manage connection timing and how
  // many times to connect, etc. For the purposes of this example, one
  // connect will be attempted each time the network comes up. For
  // example, when there's a new IP address or the Ethernet cable gets
  // plugged back in.
  if (!readyToConnect) {
    return;
  }
  readyToConnect = false;

  // Connect
  printf("Attempting to connect to %s...\r\n", kHost);
  EthernetClient client;
  int err = client.connect(kHost, kPort);
  if (err != 1) {
    printf("Error connecting: %d\r\n", err);
    return;
  }

  // Send the request and close
  printf("Connected; sending request and closing...\r\n");
  client.writeFully(kRequest);
  client.flush();

  // Print the results
  printf("[Response]\r\n");
  while (client.connected()) {
    int avail = client.available();
    if (avail <= 0) {
      continue;
    }
    for (int i = 0; i < avail; i++) {
      putc(client.read(), stdout);
    }
    fflush(stdout);
  }
  client.close();
  printf("\r\n[Done]\r\n");
}

I think clients can be more tricky to write than servers.
 
Here's a basic HTTP client example that works:
C++:
#include <QNEthernet.h>

using namespace qindesign::network;

// Tracks if the network is up.
bool networkReady = false;

// Note: This example uses stdout for serial output, but you can use
//       Serial if you like instead.

// Main program setup.
void setup() {
  Serial.begin(115200);
  while (!Serial && millis() < 4000) {
    // Wait for Serial
  }
  printf("Starting...\r\n");

  // Print the MAC address
  uint8_t mac[6];
  Ethernet.macAddress(mac);  // This is informative; it retrieves, not sets
  printf("MAC = %02x:%02x:%02x:%02x:%02x:%02x\r\n",
         mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);

  // Listen for link changes
  Ethernet.onLinkState([](bool state) {
    printf("[Ethernet] Link %s\r\n", state ? "ON" : "OFF");

    networkReady = state && (Ethernet.localIP() != INADDR_NONE);
  });

  // Listen for address changes
  Ethernet.onAddressChanged([]() {
    IPAddress ip = Ethernet.localIP();
    bool hasIP = (ip != INADDR_NONE);
    if (hasIP) {
      IPAddress subnet = Ethernet.subnetMask();
      IPAddress gw = Ethernet.gatewayIP();
      IPAddress dns = Ethernet.dnsServerIP();

      printf(
          "[Ethernet] Address changed:\r\n"
          "    Local IP = %u.%u.%u.%u\r\n"
          "    Subnet   = %u.%u.%u.%u\r\n"
          "    Gateway  = %u.%u.%u.%u\r\n"
          "    DNS      = %u.%u.%u.%u\r\n",
          ip[0], ip[1], ip[2], ip[3],
          subnet[0], subnet[1], subnet[2], subnet[3],
          gw[0], gw[1], gw[2], gw[3],
          dns[0], dns[1], dns[2], dns[3]);
    } else {
      printf("[Ethernet] Address changed: No IP address\r\n");
    }

    networkReady = Ethernet.linkState() && hasIP;
  });

  // Start with DHCP
  if (!Ethernet.begin()) {
    printf("Error: Ethernet not started\r\n");
  }
}

// Set to 'true' when the network comes back up.
// (Need to start at true.)
bool readyToConnect = true;

// It's okay to use a string for an IPAddress as well
// For example: "192.168.0.1"
#define HOST "www.example.com"
constexpr char kHost[]{HOST};
constexpr char kRequest[]{
    "GET / HTTP/1.1\r\n"
    "Host: " HOST "\r\n"
    "Connection: close\r\n"
    "\r\n"
};
#undef HOST
constexpr uint16_t kPort = 80;

// Main program loop.
void loop() {
  if (!networkReady) {
    readyToConnect = true;
    return;
  }

  // There's many different ways to manage connection timing and how
  // many times to connect, etc. For the purposes of this example, one
  // connect will be attempted each time the network comes up. For
  // example, when there's a new IP address or the Ethernet cable gets
  // plugged back in.
  if (!readyToConnect) {
    return;
  }
  readyToConnect = false;

  // Connect
  printf("Attempting to connect to %s...\r\n", kHost);
  EthernetClient client;
  int err = client.connect(kHost, kPort);
  if (err != 1) {
    printf("Error connecting: %d\r\n", err);
    return;
  }

  // Send the request and close
  printf("Connected; sending request and closing...\r\n");
  client.writeFully(kRequest);
  client.flush();

  // Print the results
  printf("[Response]\r\n");
  while (client.connected()) {
    int avail = client.available();
    if (avail <= 0) {
      continue;
    }
    for (int i = 0; i < avail; i++) {
      putc(client.read(), stdout);
    }
    fflush(stdout);
  }
  client.close();
  printf("\r\n[Done]\r\n");
}

I think clients can be more tricky to write than servers.
Hi @shawn, thank you for your help. I appreciate it.
I've tried your code which sometimes works (but with a big delay), and sometimes it doesn't. Mostly freezes on Ethernet Link.

This is the log (of several attempts, each starting of course at "Starting..."):
Code:
09:19:18.693 -> [Ethernet] Link ON
09:23:58.590 -> Starting...
09:23:58.590 -> MAC = 04:e9:e5:17:7a:28
09:24:00.385 -> [Ethernet] Link ON
09:27:26.564 -> Starting...
09:27:26.564 -> MAC = 04:e9:e5:17:7a:28
09:27:28.526 -> [Ethernet] Link ON
09:29:32.496 -> Starting...
09:29:32.496 -> MAC = 04:e9:e5:17:7a:28
09:29:34.371 -> [Ethernet] Link ON
09:34:42.972 -> [Ethernet] Address changed:
09:34:42.972 ->     Local IP = 169.254.41.122
09:34:42.972 ->     Subnet   = 255.255.0.0
09:34:42.972 ->     Gateway  = 0.0.0.0
09:34:42.972 ->     DNS      = 0.0.0.0
09:34:42.972 -> Attempting to connect to 10.0.0.2...
09:34:42.972 -> Connected; sending request and closing...
09:34:42.972 -> [Response]
09:34:42.972 -> HTTP/1.1� 200 OK
09:34:42.972 -> Host:
09:34:42.972 -> Server: MADRIX
09:34:42.972 -> Last-Modified: Wed, 13 Mar 2024 09:34:42 GMT
09:34:42.972 -> Content-Type: 
09:34:42.972 -> Content-Length: 0
09:34:42.972 -> Cache-Control: max-age=0
09:34:42.972 -> 
09:34:42.972 -> 
09:34:42.972 -> [Done]
09:39:08.401 -> Starting...
09:39:08.401 -> MAC = 04:e9:e5:17:7a:28
09:39:10.457 -> [Ethernet] Link ON
09:44:19.546 -> [Ethernet] Address changed:
09:44:19.546 ->     Local IP = 169.254.41.122
09:44:19.546 ->     Subnet   = 255.255.0.0
09:44:19.546 ->     Gateway  = 0.0.0.0
09:44:19.546 ->     DNS      = 0.0.0.0
09:44:19.546 -> Attempting to connect to 10.0.0.2...
09:44:19.546 -> Connected; sending request and closing...
09:44:19.546 -> [Response]
09:44:19.546 -> HTTP/1.�1 200 OK
09:44:19.546 -> Host:
09:44:19.546 -> Server: MADRIX
09:44:19.546 -> Last-Modified: Wed, 13 Mar 2024 09:44:18 GMT
09:44:19.546 -> Content-Type: 
09:44:19.546 -> Content-Length: 0
09:44:19.546 -> Cache-Control: max-age=0
09:44:19.546 -> 
09:44:19.546 -> 
09:44:19.546 -> [Done]
09:46:21.507 -> [Ethernet] Link ON
09:47:09.632 -> Starting...
09:47:09.632 -> MAC = 04:e9:e5:17:7a:28
09:47:11.447 -> [Ethernet] Link ON
09:49:36.606 -> Starting...
09:49:36.606 -> MAC = 04:e9:e5:17:7a:28
09:49:38.774 -> [Ethernet] Link ON
09:51:10.402 -> Starting...
09:51:10.402 -> MAC = 04:e9:e5:17:7a:28
09:51:12.127 -> [Ethernet] Link ON
09:52:45.624 -> Starting...
09:52:45.624 -> MAC = 04:e9:e5:17:7a:28
09:52:47.200 -> [Ethernet] Link ON
 
Last edited:
It looks like it’s not getting an IP address; that 169.* address is self-assigned. Do you need to use a static IP?

The delays you’re seeing are from the pause before it realizes it hasn’t gotten an address from DHCP. The way that example is structured is it won’t make a request until it has both an IP address and a link. It might take a little while before it realizes it has to use a self-assigned IP.

When the link comes up, it makes some DHCP requests and then waits. If there’s no DHCP server, it tries again a few more times. This process might take some time if there’s no DHCP server. Finally, after a while, it decides there’s no DHCP server, self-assigns an IP address, and then makes that HTTP connection.

In other words: the behaviour you’re seeing is expected for the way my example program works when there’s no DHCP server and you haven’t used a static IP.

To use a static IP, use the Ethernet.begin(ip, mask, gateway) form.
 
Last edited:
I've made a simpler example for you:
C++:
#include <QNEthernet.h>

using namespace qindesign::network;

// Note: This example uses stdout for serial output, but you can use
//       Serial if you like instead.

// Change these to what you need:
const IPAddress kStaticIP{10, 0, 0, 100};
const IPAddress kNetmask{255, 255, 255, 0};
const IPAddress kGateway{10, 0, 0, 1};

// Main program setup.
void setup() {
  Serial.begin(115200);
  while (!Serial && millis() < 4000) {
    // Wait for Serial
  }
  printf("Starting...\r\n");

  // Print the MAC address
  uint8_t mac[6];
  Ethernet.macAddress(mac);  // This is informative; it retrieves, not sets
  printf("MAC = %02x:%02x:%02x:%02x:%02x:%02x\r\n",
         mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);

  // Listen for link changes
  Ethernet.onLinkState([](bool state) {
    printf("[Ethernet] Link %s\r\n", state ? "ON" : "OFF");
  });

  // Start with a static IP
  if (!Ethernet.begin(kStaticIP, kNetmask, kGateway)) {
    printf("Error: Ethernet not started\r\n");
    return;
  }
}

// It's okay to use a string for an IPAddress as well
// For example: "192.168.0.1"
#define HOST "www.example.com"
constexpr char kHost[]{HOST};
constexpr char kRequest[]{
    "GET / HTTP/1.1\r\n"
    "Host: " HOST "\r\n"
    "Connection: close\r\n"
    "\r\n"
};
#undef HOST
constexpr uint16_t kPort = 80;

// Does an HTTP request.
void doClient() {
  // Connect
  printf("Attempting to connect to %s...\r\n", kHost);
  EthernetClient client;
  int err = client.connect(kHost, kPort);
  if (err != 1) {
    printf("Error connecting: %d\r\n", err);
    return;
  }

  // Send the request and close
  printf("Connected; sending request and closing...\r\n");
  client.writeFully(kRequest);
  client.flush();

  // Print the results
  printf("[Response]\r\n");
  while (client.connected()) {
    int avail = client.available();
    if (avail <= 0) {
      continue;
    }
    for (int i = 0; i < avail; i++) {
      putc(client.read(), stdout);
    }
    fflush(stdout);
  }
  client.close();
  printf("\r\n[Done]\r\n");
}

// THIS LATCH IS ONLY FOR THE PURPOSES OF THIS EXAMPLE.
// It guarantees that doClient() is only called once.
bool latch = false;

// Main program loop.
void loop() {
  if (!latch) {
    if (Ethernet.linkState() && Ethernet.localIP() != INADDR_NONE) {
      doClient();
      latch = true;
    }
  }
}

This version uses a static IP and only attempts to connect once.
 
Hi @shawn

So yeah, that worked! But only once :)
The first time it worked, then I've changed the request a bit to see how stable it is.

Basically the request I make for now is "GET /RemoteCommands/SetFadeTime=8 HTTP/1.1\r\n" I've changed the 8 to a different value so I would be able to see a direct change.

I've tried some things after this as well, such as setting the connection to keep-alive
I've also changed your formatting since I thought that might had to do with it:
Code:
const IPAddress kStaticIP(10, 0, 0, 100);
const IPAddress kNetmask(255, 255, 255, 0);
const IPAddress kGateway(10, 0, 0, 1);

But it all comes with the same result.

This is the log:
Code:
07:40:53.546 -> Starting...
07:40:53.546 -> MAC = 04:e9:e5:17:7a:28
07:40:55.070 -> [Ethernet] Link ON
07:40:55.070 -> Attempting to connect to 10.0.0.2...
07:40:56.089 -> Error connecting: -1
07:41:14.787 -> Starting...
07:41:14.787 -> MAC = 04:e9:e5:17:7a:28
07:41:16.311 -> [Ethernet] Link ON
07:41:16.311 -> Attempting to connect to 10.0.0.2...
07:41:17.327 -> Error connecting: -1

I can ping the board from the server PC.
Also if I scan my network from the server PC I can see the board with the correct MAC.. So they can talk to each other.
 
It’s timing out (-1). See: https://www.arduino.cc/reference/en/libraries/ethernet/client.connect/

Are you sure the IP, netmask, and gateway are correct for your network? The values I put in the example may not be the values you need. But maybe they’re correct because you can ping the Teensy…

Are you sure the server you’re trying to connect to is up and accepting connections? Have you verified with a web browser?

Does it work every time if you use “example.com” as the host instead of changing to a local IP? (That is, if your network is connected to the internet.)
 
Last edited:
It’s timing out (-1). See: https://www.arduino.cc/reference/en/libraries/ethernet/client.connect/

Are you sure the IP, netmask, and gateway are correct for your network? The values I put in the example may not be the values you need. But maybe they’re correct because you can ping the Teensy…

Are you sure the server you’re trying to connect to is up and accepting connections? Have you verified with a web browser?

Does it work every time if you use “example.com” as the host instead of changing to a local IP? (That is, if your network is connected to the internet.)
Yes it does. It works sometimes, but sometimes it can't connect. Though I'm using a (short length) wired connection. Almost looks like timing relevant..
 
Back
Top