I make interfacing devices that use a mix of UDP and TCP, and usually have a small webserver for configuration. I was using embedded T3.2's, then T4's with Wiznet W5500's, but these days I largely use the Teensy 4.1 with its native ethernet.
Last year I moved a couple of projects from the NativeEthernet library to QNEthernet as NativeEthernet stalled when it received zero length payload UDP packets. This took a very long time to diagnose and it only happened with particular control equipment! But QNEthernet fixed it and I've since got into AsyncWebServer_Teensy41; so I'm fairly locked into QNEthernet.
In a new application I need to do TCP client connections.. but I'm finding QNEthernet just isn't reliable at all. The following program with NativeEthernet runs for hours without a failure. On QNEthernet I'm lucky to get a few minutes, more often than not it fails in the first 30 seconds.
The problem appears to be in the connect() function. It's returning 0 or -1 (with no discernible pattern) most of the time. For the purposes of this test I'm just pointing the program at my Macbook Pro and using
I love how well documented QNEthernet is on Github and I've tried to follow Shawn's design principles to the letter. Most other issues I've seen here appear to relate to the write function, not connect().
Here's my test code, obviously when I do the test with NativeEthernet I have to adapt it some to change out the functions it doesn't support.
Is there something I can try? Can you reproduce the same issue?
Last year I moved a couple of projects from the NativeEthernet library to QNEthernet as NativeEthernet stalled when it received zero length payload UDP packets. This took a very long time to diagnose and it only happened with particular control equipment! But QNEthernet fixed it and I've since got into AsyncWebServer_Teensy41; so I'm fairly locked into QNEthernet.
In a new application I need to do TCP client connections.. but I'm finding QNEthernet just isn't reliable at all. The following program with NativeEthernet runs for hours without a failure. On QNEthernet I'm lucky to get a few minutes, more often than not it fails in the first 30 seconds.
The problem appears to be in the connect() function. It's returning 0 or -1 (with no discernible pattern) most of the time. For the purposes of this test I'm just pointing the program at my Macbook Pro and using
nc -lvk 80 in a terminal window as my receiver.I love how well documented QNEthernet is on Github and I've tried to follow Shawn's design principles to the letter. Most other issues I've seen here appear to relate to the write function, not connect().
Here's my test code, obviously when I do the test with NativeEthernet I have to adapt it some to change out the functions it doesn't support.
C++:
#include <QNEthernet.h>
using namespace qindesign::network; // Must be before IP Address declarations
EthernetClient client;
IPAddress thisIP(192,168,10,74);
IPAddress mask(255,255,255,0);
IPAddress gwIP(192,168,10,254);
IPAddress remoteIP(192,168,10,79);
uint32_t timeMgmt;
uint16_t failRate, counter;
bool online;
void setup() {
Serial.begin(115200); // Serial Monitor
if (!Ethernet.begin(thisIP,mask,gwIP)) {
Serial.println("Failed to start Ethernet");
}
} // END SETUP
void loop() {
if (!online && Ethernet.linkState()) {
online = true;
Serial.println("System Online.");
}
if (millis()>timeMgmt) {
timeMgmt = millis() + 500;
if (online) {
char txBuf[1024];
char numAsChar[8];
uint16_t packetSize = 0;
memset(txBuf,0x00,sizeof(txBuf));
itoa(counter,numAsChar,10);
strcat(txBuf,"Let's count: ");
strcat(txBuf,numAsChar);
strcat(txBuf,"\r\n");
for (uint16_t i=0;i<sizeof(txBuf);i++) {
if (txBuf[i]==0x00) {
packetSize = i;
break;
}
}
int8_t connectStatus = client.connect(remoteIP,80);
if (connectStatus==1) {
client.writeFully(txBuf,packetSize);
client.flush();
client.close();
Serial.print("Tx: ");
for (uint16_t i=0;i<packetSize;i++) Serial.print(txBuf[i]);
} else {
Serial.print("Connection failed - error: ");
Serial.println(connectStatus);
failRate++;
}
Serial.print("Failures: ");
Serial.print(failRate);
Serial.print(" in ");
Serial.println(counter);
counter++;
}
}
} // END LOOP
Is there something I can try? Can you reproduce the same issue?