Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions examples/wifi/embassy_https_speedtest/.cargo/config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
[build]
target = "xtensa-esp32s3-none-elf"

[target.xtensa-esp32s3-none-elf]
runner = "espflash flash --monitor"
rustflags = [
# GNU LD
"-C", "link-arg=-Wl,-Tlinkall.x",
"-C", "link-arg=-nostartfiles",
]

[env]
ESP_LOG = "info"
SSID = "SSID"
PASSWORD = "PASSWORD"

[unstable]
build-std = ["core", "alloc"]
3 changes: 3 additions & 0 deletions examples/wifi/embassy_https_speedtest/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.tools/
server-cert.*
server-key.pem
60 changes: 60 additions & 0 deletions examples/wifi/embassy_https_speedtest/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
[package]
name = "embassy-https-speedtest"
version = "0.0.0"
edition = "2024"
publish = false

[dependencies]
embassy-executor = "0.10.0"
embassy-net = { version = "0.9.0", features = [
"dhcpv4",
"medium-ethernet",
"tcp",
"dns",
] }
embassy-time = "0.5.0"
embedded-io = "0.7.0"
embedded-io-async = "0.7.0"
embedded-tls = { version = "0.19.0", default-features = false, features = [
"rsa",
"log",
"p384",
] }
heapless = "0.9.0"
rand_core = { version = "0.6", default-features = false }
static_cell = "2.1.0"

esp-alloc = { path = "../../../esp-alloc" }
esp-backtrace = { path = "../../../esp-backtrace", features = [
"panic-handler",
"println",
] }
esp-bootloader-esp-idf = { path = "../../../esp-bootloader-esp-idf" }
esp-hal = { path = "../../../esp-hal", features = ["log-04", "unstable"] }
esp-println = { path = "../../../esp-println", features = ["log-04"] }
esp-radio = { path = "../../../esp-radio", features = [
"log-04",
"unstable",
"wifi",
] }
esp-rtos = { path = "../../../esp-rtos", features = ["esp-radio", "embassy", "log-04"] }

[features]
esp32s3 = [
"esp-alloc/esp32s3",
"esp-backtrace/esp32s3",
"esp-bootloader-esp-idf/esp32s3",
"esp-hal/esp32s3",
"esp-radio/esp32s3",
"esp-rtos/esp32s3",
]

# Disable TLS entirely: both directions run over plain HTTP so the result
# measures the wifi link without the encryption overhead.
plain-http = []

[profile.release]
debug = true
debug-assertions = true
lto = "fat"
codegen-units = 1
53 changes: 53 additions & 0 deletions examples/wifi/embassy_https_speedtest/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
SERVER_IP ?= $(shell (hostname -I 2>/dev/null || ip -4 -o addr show scope global 2>/dev/null) | awk '{print $$1}' | cut -d/ -f1 | head -1)
TLS_PORT ?= 8443
HTTP_PORT ?= 8080
SSID ?= SSID
PASSWORD ?= PASSWORD

GO_HTTPBIN_VERSION ?= v2.25.0
GO_HTTPBIN_URL ?= https://github.com/mccutchen/go-httpbin/releases/download/$(GO_HTTPBIN_VERSION)/go-httpbin-linux-amd64.tar.gz
GO_HTTPBIN_DIR ?= .tools
GO_HTTPBIN ?= $(GO_HTTPBIN_DIR)/go-httpbin
# 0 disables go-httpbin's request read timeouts
GO_HTTPBIN_ARGS ?= -max-body-size 10000000 -max-duration 60s -srv-read-timeout 0 -srv-read-header-timeout 0

export RUSTUP_TOOLCHAIN ?= esp

CERT_FILES = server-cert.pem server-key.pem server-cert.der

.PHONY: help cert serve serve-http run run-http

help:
@echo "Targets: cert, serve, serve-http, run, run-http"
@echo "Detected SERVER_IP: $(SERVER_IP)"

server-key.pem server-cert.pem server-cert.der:
openssl req -x509 -newkey ec -pkeyopt ec_paramgen_curve:P-256 \
-keyout server-key.pem -out server-cert.pem -days 3650 -nodes \
-subj "/CN=$(SERVER_IP)" -addext "subjectAltName=DNS:$(SERVER_IP)"
openssl x509 -in server-cert.pem -outform DER -out server-cert.der
@echo "Certificate generated for $(SERVER_IP)"

cert: server-key.pem server-cert.pem server-cert.der

$(GO_HTTPBIN):
mkdir -p $(GO_HTTPBIN_DIR)
wget -q -O $(GO_HTTPBIN_DIR)/go-httpbin.tar.gz $(GO_HTTPBIN_URL)
tar -xzf $(GO_HTTPBIN_DIR)/go-httpbin.tar.gz -C $(GO_HTTPBIN_DIR)

serve: cert $(GO_HTTPBIN)
$(GO_HTTPBIN) $(GO_HTTPBIN_ARGS) -host 0.0.0.0 -port $(TLS_PORT) \
-https-cert-file server-cert.pem -https-key-file server-key.pem

serve-http: $(GO_HTTPBIN)
$(GO_HTTPBIN) $(GO_HTTPBIN_ARGS) -host 0.0.0.0 -port $(HTTP_PORT)

run: cert
SERVER_IP=$(SERVER_IP) SSID=$(SSID) PASSWORD=$(PASSWORD) \
cargo build --release --features esp32s3
espflash flash --monitor target/xtensa-esp32s3-none-elf/release/embassy-https-speedtest

run-http: cert
SERVER_IP=$(SERVER_IP) SSID=$(SSID) PASSWORD=$(PASSWORD) \
cargo build --release --features esp32s3,plain-http
espflash flash --monitor target/xtensa-esp32s3-none-elf/release/embassy-https-speedtest
31 changes: 31 additions & 0 deletions examples/wifi/embassy_https_speedtest/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Embassy HTTPS speed test

An wifi speed test that measures download and upload throughput against a
local test server over both HTTPS and plain HTTP. The server is a local
[go-httpbin](https://github.com/mccutchen/go-httpbin) instance, using
self-signed certs that the the firmware verifies.

## Running over HTTPS

```sh
make install-server
make server
# in a new tmux pane/terminal
make flash SSID=mywifi PASSWORD=secret
```

## Running over plain HTTP

```sh
make server-http
# in a new tmux pane/terminal
make flash-plain SSID=mywifi PASSWORD=secret
```

## Troubleshooting

- Only tested on Linux.
- Auto-guesses the correct LAN IP of the server/host, set with SERVER_IP if the
guess is wrong
- Make sure the ESP32 is on the same network as the host and that the host's
firewall allows connections to ports 8443/8080.
Loading