Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Ethernet on Opta - slow request read times #1067

Open
@ppp-one

Description

@ppp-one

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):

#include <Arduino.h>
#include <Ethernet.h>
#include <opta_info.h>

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 = "<html><body>Hello, World!</body></html>";

  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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions