Closed jimmie11 closed 3 years ago
Your code doesn't have special functions that requires this EthernetWebServer Library.
I suggest you use the Teensy 4.1 NativeEthernet or Ethernet library directly to verify that the issue has nothing to do with this EthernetWebServer Library.
Have a look at this EthernetLarge's WebServer example that uses the similar functions provided by the Ethernetx libraries, such as
EthernetClient client = server.available();
...
client.read();
...
client.println("<!DOCTYPE HTML>");
and this is its loop()
void loop() {
// listen for incoming clients
EthernetClient client = server.available();
if (client) {
Serial.println("new client");
// an http request ends with a blank line
bool 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>");
client.println("<html>");
// output the value of each analog input pin
for (int analogChannel = 0; analogChannel < 6; analogChannel++) {
int sensorReading = analogRead(analogChannel);
client.print("analog input ");
client.print(analogChannel);
client.print(" is ");
client.print(sensorReading);
client.println("<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");
}
}
and very similar to the functions used in your code
EthernetClient client = server.available();
if (client) {
Serial.println(">>>>>>>>> NEW Client");
// an http request ends with a blank line
boolean currentLineIsBlank = true;
if (client.connected()) {
Serial.println("client.connected");
Serial.println(client .available());
while (client .available()) {
char c = client.read();
//Serial.println(c);
if (c == '\n') {
Serial.println(">>>>> request cleared");
Serial.println(request);
request = "";
} else {
request += c;
//Serial.println(request);
}
}
The attached code was working fine but is not working on the Teensy 4.1
It is a simple webserver which responds with a Table and a Submit button.
When the website is accessed, everything looks good. However, when I press the submit button, I noticed that the request never finishes on the Teensy side (suddenly stops) and the micro just hangs.
That same code worked before fine ...
webServer2.txt