arduino / arduino/ArduinoCore-mbed

Ethernet on Opta - slow request read times

Open
#1,067 2 comments 0 reactions 0 assignees View on GitHub
Dominant language
C
Stars
411
Forks
225
PR merge metrics
No merged PRs in 30d

Description

I have an Opta RS485 with code compiled with the following libraries/platform:
Ethernet 1.0.0
SocketWrapper 1.0
arduino:mbed_opta 4.3.1

When running a simple http server (following a simplified version of https://opta.findernet.com/en/tutorial/web-server):

```cpp
#include
#include
#include

OptaBoardInfo *info;
OptaBoardInfo *boardInfo();

// IP address of the Opta server.
IPAddress ip(192, 168, 1, 12);
// Ethernet server on port 80.
EthernetServer server(80);

void setup()
{
Serial.begin(9600);

info = boardInfo();
// Check if secure informations are available since MAC Address is among them.
if (info->magic == 0xB5)
{
// Assign static IP address.
Ethernet.begin(info->mac_address, ip);
}
else
{
Serial.println("Error: Secure information not available. Cannot start server.");
while (1)
{
}
}

// Start the server.
server.begin();
Serial.println("Server started");
}

void loop()
{
// Check if any client is available.
EthernetClient client = server.available();
if (client)
{
unsigned long startTime = millis();
Serial.println("Client connected");

// Read the HTTP request line
unsigned long readStart = millis();
String request = client.readStringUntil('\r');
unsigned long readEnd = millis();
client.flush();

// Check if it's a GET request to "/"
unsigned long handleStart = millis();
if (request.indexOf("GET /") == 0)
{
sendHomepage(&client);
}
unsigned long handleEnd = millis();

// Close the connection
unsigned long stopStart = millis();
client.stop();
unsigned long stopEnd = millis();

unsigned long endTime = millis();
Serial.print("Client disconnected. Total handling time: ");
Serial.print(endTime - startTime);
Serial.println(" ms");

Serial.print(" Request read time: ");
Serial.print(readEnd - readStart);
Serial.println(" ms");

Serial.print(" Homepage send time: ");
Serial.print(handleEnd - handleStart);
Serial.println(" ms");

Serial.print(" Client stop time: ");
Serial.print(stopEnd - stopStart);
Serial.println(" ms");
}
}

void sendHomepage(EthernetClient *client)
{
String html = "Hello, World!";

client->println("HTTP/1.1 200 OK");
client->println("Content-Type: text/html");
client->println("Connection: close");
client->println("Content-Length: " + String(html.length()));
client->println();
client->println(html);

Serial.println("Homepage sent");
}
```

The `client.readStringUntil('\r')` is consistently around 100ms.
```
Total handling time: 102 ms
Request read time: 101 ms
Homepage send time: 1 ms
Client stop time: 0 ms
```

Is there an issue with the mbed Ethernet library?

We want to use the Opta for repeated http requests, but the 100 ms delay is unfortunately unacceptable. Any plug-and-play alternatives or ideas for a fix are welcome. Thank you.

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with the provided Opta RS485 sketch and reproduce the timing around EthernetClient::readStringUntil('\r') using Ethernet 1.0.0, SocketWrapper 1.0, and arduino:mbed_opta 4.3.1. Trace the Ethernet and SocketWrapper read path to identify why the request consistently takes about 100 ms; done means the cause and a verified fix or documented limitation are established.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
embedded-iot, networking
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.