I have ETH01 module, i need to test the internet speed

I am trying to test internet speed using eth01 connected through LAN, but i can able to get 12.5kbps maximum, but in laptop with the same network i can get around 80mbps. which is vast difference i am uploading code here, any idea? anybody? what would be the reason?

Code:


#define ETH_PHY_TYPE ETH_PHY_LAN8720
#define ETH_PHY_MDC 23
#define ETH_PHY_MDIO 18
#define ETH_CLK_MODE ETH_CLOCK_GPIO0_IN
#include <HTTPClient.h>
#include <ETH.h>
const char* speedTestUrl = "http://httpbin.org/bytes/102400";
static bool eth_connected = false;

// WARNING: onEvent is called from a separate FreeRTOS task (thread)!
void onEvent(arduino_event_id_t event) {
  switch (event) {
    case ARDUINO_EVENT_ETH_START:
      Serial.println("ETH Started");
      // The hostname must be set after the interface is started, but needs
      // to be set before DHCP, so set it from the event handler thread.
      ETH.setHostname("esp32-ethernet");
      break;
    case ARDUINO_EVENT_ETH_CONNECTED: Serial.println("ETH Connected"); break;
    case ARDUINO_EVENT_ETH_GOT_IP:
      Serial.println("ETH Got IP");
      Serial.println(ETH);
      eth_connected = true;
      break;
    case ARDUINO_EVENT_ETH_LOST_IP:
      Serial.println("ETH Lost IP");
      eth_connected = false;
      break;
    case ARDUINO_EVENT_ETH_DISCONNECTED:
      Serial.println("ETH Disconnected");
      eth_connected = false;
      break;
    case ARDUINO_EVENT_ETH_STOP:
      Serial.println("ETH Stopped");
      eth_connected = false;
      break;
    default: break;
  }
}

///////////////////////////////
unsigned long arr[10];
void performSpeedTest(int i) {
    HTTPClient http;
    http.begin(speedTestUrl);
    int httpCode = http.GET();
    if (httpCode > 0) {
        if (httpCode == HTTP_CODE_OK) {
            int contentLength = http.getSize();
            Serial.printf("File size: %d bytes\n", contentLength);

            unsigned long startTime = millis();
            Client* stream = http.getStreamPtr();
            unsigned long totalBytesRead = 0;

            while (stream->connected() || stream->available()) {
                if (stream->available()) {
                    stream->read();
                    totalBytesRead++;
                    //Serial.println(totalBytesRead);
                }
            }

            unsigned long endTime = millis();
            float downloadTime = (endTime - startTime) / 1000.0; // Time in seconds
            unsigned long downloadSpeed = (totalBytesRead * 8) / (downloadTime * 1000); // Speed in Kbps

            Serial.printf("Download speed: %lu Kbps\n", downloadSpeed);
            arr[i] = downloadSpeed;
        }
    } else {
        Serial.printf("HTTP GET failed: %s\n", http.errorToString(httpCode).c_str());
    }
    http.end();
}

///////////////////////////////
void setup() {
  Serial.begin(115200);
  delay(3000);
  Serial.println("\n\nESP32-ETH01 <ETH.h> library");
  pinMode(16, OUTPUT);     // set pin to output
  digitalWrite(16, HIGH);  // turn on power
  delay(1000);
  Network.onEvent(onEvent);
  ETH.begin();
  delay(5000);
  while(!eth_connected)
  {
    Serial.println("connection waiting.....");  
    delay(5000);
  }
  Serial.println("connection Done....."); 
  
}

void loop() {
  for (int i =0; i<10;i++){
    performSpeedTest(i);
}
  for (int i =0; i<10;i++){
    Serial.println(arr[i]);
  }
}

Wired, wireless, bluetooth or serial to the LAN? Provide a drawing and a sketch (program code).

1 Like

It is probably the LAN adapter, it needs more support then the Arduino can supply. Maybe swapping the blue and orange wires may help. Without an annotated schematic all we can do is guess as seen above. This can be a network problem, system problem, etc.

this is the board I have, directly connected LAN cable from router to ETH01 module

it is WT32-ETH01. an esp32 with a LAN8720

Yes confirm 13Kbps.
With the following 250Kbps ( a little better ), found it here

void performSpeedTest(int i) {
    HTTPClient http;
    http.begin(speedTestUrl);
    int httpCode = http.GET();
    if (httpCode > 0) {
        if (httpCode == HTTP_CODE_OK) {
            int totalBytesRead = 0;
            int remainingFileSize = http.getSize();
            // create buffer for read
            uint8_t buff[1460] = { 0 };
            // get tcp stream
            Client * stream = http.getStreamPtr();
            // start timer
            unsigned long startTime = millis();
            // read all data from server
            while(http.connected() && (remainingFileSize > 0 || remainingFileSize == -1)) 
                {
                // get available data size
                size_t size = stream->available();
                // iteratively read all the data into the buffer, and do nothing with it.
                if(size) 
                    { 
                    // read up to 1460 byte
                    int c = stream->readBytes(buff, ((size > sizeof(buff)) ? sizeof(buff) : size));
                    // do nothing with the data
                    if(remainingFileSize > 0) 
                        {remainingFileSize -= c; totalBytesRead +=c;}
                    }
                }
            unsigned long endTime = millis();
            float downloadTime = (endTime - startTime) / 1000.0; // Time in seconds
            unsigned long downloadSpeed = (totalBytesRead * 8) / (downloadTime * 1000); // Speed in Kbps
            Serial.printf("Download speed: %lu Kbps\n", downloadSpeed);
            arr[i] = downloadSpeed;
        }
    } else {
        Serial.printf("HTTP GET failed: %s\n", http.errorToString(httpCode).c_str());
    }
    http.end();
}

I do not have one like it so no idea. Hint: Schematics and links to technical information may get you an answer. At this point swap the purple and yellow wires and see if that fixes it.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.