This example code implements a simple iperf test server that can be used to measure how much data you can push through the WiFi link of our WiFi enabled boards.
/*
IPerf test
This short program acts as a IPerf test server that allows you
to run the iperf test program from your main computer to test
the network speed.
*/
#include <WiFiEspAT.h>
#include <ChallengerWiFi.h>
#include <SerialPIO.h>
SerialPIO PIOUart(PIN_SERIAL2_TX, PIN_SERIAL2_RX);
///////please enter your sensitive data in the Secret tab/arduino_secrets.h
const char ssid[] = ""; // your network SSID (name)
const char pass[] = ""; // your network password (use for WPA, or use as key for WEP)
#define AT_BAUD_RATE 2750000
WiFiClient client;
WiFiServer server(5001);
void setup() {
#if defined(LED_BUILTIN)
pinMode(LED_BUILTIN, OUTPUT);
digitalWrite(LED_BUILTIN, 0);
#endif
Serial.begin(115200);
while (!Serial)
delay(10);
Challenger2040WiFi.setSerial(&PIOUart);
Serial.println(F("Serial port now set to PIO Uart !"));
if (Challenger2040WiFi.reset()) {
Serial.println(F("WiFi Chip reset OK !"));
} else {
Serial.println(F("Could not reset WiFi chip !"));
while(1);
}
Serial.println("Challenger Wifi test program started !");
#if defined(LED_BUILTIN)
digitalWrite(LED_BUILTIN, HIGH);
#endif
WiFi.init(&PIOUart);
Challenger2040WiFi.changeBaudRate(AT_BAUD_RATE);
Serial.printf("Baud rate changed to %d baud !\n", AT_BAUD_RATE);
if (WiFi.status() == WL_NO_MODULE) {
Serial.println();
Serial.println("Communication with WiFi module failed!");
// don't continue
while (true);
}
Serial.println();
Serial.print("Attempting to connect to SSID: ");
Serial.println(ssid);
int status = WiFi.begin(ssid, pass);
Serial.print("Status: ");
Serial.println(status);
if (status == WL_CONNECTED) {
Serial.println();
Serial.println("Connected to WiFi network.");
printWifiStatus();
} else {
WiFi.disconnect(); // remove the WiFi connection
Serial.println();
Serial.println("Connection to WiFi network failed.");
}
// waiting for connection to Wifi network set with the SetupWiFiConnection sketch
Serial.println("Waiting for connection to WiFi");
while (WiFi.status() != WL_CONNECTED) {
delay(1000);
Serial.print('.');
}
Serial.println();
Serial.println("Connected to WiFi network.");
server.begin();
}
void printWifiStatus() {
// print the SSID of the network you're attached to:
char ssid[33];
WiFi.SSID(ssid);
Serial.print("SSID: ");
Serial.println(ssid);
// print the BSSID of the network you're attached to:
uint8_t bssid[6];
WiFi.BSSID(bssid);
Serial.print("BSSID: ");
printMacAddress(bssid);
uint8_t mac[6];
WiFi.macAddress(mac);
Serial.print("MAC: ");
printMacAddress(mac);
// print your board's IP address:
IPAddress ip = WiFi.localIP();
Serial.print("IP Address: ");
Serial.println(ip);
// print the received signal strength:
long rssi = WiFi.RSSI();
Serial.print("signal strength (RSSI):");
Serial.print(rssi);
Serial.println(" dBm");
}
void printMacAddress(byte mac[]) {
for (int i = 5; i >= 0; i--) {
if (mac[i] < 16) {
Serial.print("0");
}
Serial.print(mac[i], HEX);
if (i > 0) {
Serial.print(":");
}
}
Serial.println();
}
void loop() {
byte buf[2048];
WiFiClient client = server.available();
if (client) {
Serial.println("TCP Test client connected.");
while (client.connected()) {
if (client.available()) {
client.read(buf, 2048);
#if defined(LED_BUILTIN)
digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN));
#endif
}
}
client.stop();
Serial.println("client disonnected.");
}
}
The program uses a PIO Uart instead of the standard hardware uart found on the RP2040 core. This was done to be able to talk to the ESP device really fast. In the example we set the baudrate to 2.75 MBaud to be able to push data through at the maximum speed.
We have found that increasing the baud rate above 2.75MBaud seem to cause a problem internally in the ESP32C3 device rendering very slow network speed. The ESP8285 found on the standard Challenger RP2040 WiFi board does not support speeds over 921600 baud.
Here are some results from testing the Challenger RP2040 WiFi/BLE board:
AT Baud rate | Challenger RP2040 WiFi throughput | Challenger RP2040 WiFi/BLE throughput |
115200 | 133 KBit/s | 135 KBit/s |
230400 | 199 KBit/s | 202 KBit/s |
460800 | 328 KBit/s | 354 KBit/s |
921600 | 539 KBit/s | 629 KBit/s |
1843200 | – The ESP8285 bogs out at this speed | 1.02 MBit/s |
2750000 | – The ESP8285 bogs out at this speed | 1.32 MBit/s |
From the test results it is clear that raising the baud rate, the overall network throughput also increases, which is of course natural. The interesting thing here is that we can, from the table, directly select a baud rate that matches the requirements of the application.
The iperf command I used on the test client was as follows:
iperf -c 192.168.0.184 -p 5001
0 Comments for “Measure network speed on ESP devices”