├── .gitignore ├── .cargo └── config.toml ├── Cargo.toml ├── run.bat ├── README.md ├── src └── main.rs └── Cargo.lock /.gitignore: -------------------------------------------------------------------------------- 1 | /target 2 | -------------------------------------------------------------------------------- /.cargo/config.toml: -------------------------------------------------------------------------------- 1 | [build] 2 | 3 | target = "armv7-linux-androideabi" 4 | -------------------------------------------------------------------------------- /Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "bench" 3 | version = "0.1.0" 4 | edition = "2021" 5 | 6 | [dependencies] 7 | pretty_env_logger = "0.5.0" 8 | log = "0.4.0" 9 | -------------------------------------------------------------------------------- /run.bat: -------------------------------------------------------------------------------- 1 | set ANDROID_NDK_HOME=\tools\android-ndk-r26c\ 2 | cargo ndk --target=armv7-linux-androideabi build --release 3 | \tools\adb\adb.exe push target\armv7-linux-androideabi\release\bench /data/local/tmp 4 | \tools\adb\adb.exe shell chmod +x /data/local/tmp/bench 5 | \tools\adb\adb.exe shell /data/local/tmp/bench 6 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # esp-wifi bench server on Android 2 | 3 | This is https://github.com/esp-rs/esp-wifi/tree/main/extras/bench-server for Android. 4 | 5 | ## Needed 6 | 7 | - android-ndk 8 | - cargo-ndk 9 | - toolchain installed (`rustup target add armv7-linux-androideabi`) 10 | 11 | ## How to compile 12 | 13 | set ANDROID_NDK_HOME \tools\android-ndk-r26c\ 14 | cargo ndk --target=armv7-linux-androideabi build --release 15 | \tools\adb\adb.exe push target\armv7-linux-androideabi\release\bench /data/local/tmp 16 | \tools\adb\adb.exe shell 17 | 18 | In the shell 19 | ``` 20 | cd /data/local/tmp 21 | chmod +x bench 22 | ./bench 23 | ``` 24 | 25 | or just use `run.bat` 26 | 27 | ## How to use with the benchmark 28 | 29 | Start a hotspot on your Android phone. Figure out the HOST_IP (e.g. connect with `dhcp` example and use the gateway address). 30 | Then use `bench` or `embassy_bench`. 31 | 32 | ## Why 33 | 34 | My idea was to put the phone and the ESP32 into a shielded box but I haven't found anything that shields signals good enough. 35 | Still I can put the two devices aside and get less varying results. 36 | -------------------------------------------------------------------------------- /src/main.rs: -------------------------------------------------------------------------------- 1 | use std::io::{Read, Write}; 2 | use std::net::{TcpListener, TcpStream}; 3 | use std::thread::spawn; 4 | use std::time::Duration; 5 | 6 | use log::info; 7 | 8 | fn main() { 9 | pretty_env_logger::init(); 10 | spawn(|| rx_listen()); 11 | spawn(|| rxtx_listen()); 12 | tx_listen(); 13 | } 14 | 15 | fn tx_listen() { 16 | let listener = TcpListener::bind("0.0.0.0:4321").unwrap(); 17 | loop { 18 | let (socket, addr) = listener.accept().unwrap(); 19 | info!("tx: received connection from: {}", addr); 20 | spawn(|| tx_conn(socket)); 21 | } 22 | } 23 | 24 | fn tx_conn(mut socket: TcpStream) { 25 | socket.set_read_timeout(Some(Duration::from_secs(30))).unwrap(); 26 | socket.set_write_timeout(Some(Duration::from_secs(30))).unwrap(); 27 | 28 | let buf = [0; 1024]; 29 | loop { 30 | if let Err(e) = socket.write_all(&buf) { 31 | info!("tx: failed to write to socket; err = {:?}", e); 32 | return; 33 | } 34 | } 35 | } 36 | 37 | fn rx_listen() { 38 | let listener = TcpListener::bind("0.0.0.0:4322").unwrap(); 39 | loop { 40 | let (socket, addr) = listener.accept().unwrap(); 41 | info!("rx: received connection from: {}", addr); 42 | spawn(|| rx_conn(socket)); 43 | } 44 | } 45 | 46 | fn rx_conn(mut socket: TcpStream) { 47 | socket.set_read_timeout(Some(Duration::from_secs(30))).unwrap(); 48 | socket.set_write_timeout(Some(Duration::from_secs(30))).unwrap(); 49 | 50 | let mut buf = [0; 1024]; 51 | loop { 52 | if let Err(e) = socket.read_exact(&mut buf) { 53 | info!("rx: failed to read from socket; err = {:?}", e); 54 | return; 55 | } 56 | } 57 | } 58 | 59 | fn rxtx_listen() { 60 | let listener = TcpListener::bind("0.0.0.0:4323").unwrap(); 61 | loop { 62 | let (socket, addr) = listener.accept().unwrap(); 63 | info!("rxtx: received connection from: {}", addr); 64 | spawn(|| rxtx_conn(socket)); 65 | } 66 | } 67 | 68 | fn rxtx_conn(mut socket: TcpStream) { 69 | socket.set_read_timeout(Some(Duration::from_secs(30))).unwrap(); 70 | socket.set_write_timeout(Some(Duration::from_secs(30))).unwrap(); 71 | 72 | let mut buf = [0; 1024]; 73 | loop { 74 | match socket.read(&mut buf) { 75 | Ok(n) => { 76 | if let Err(e) = socket.write_all(&buf[..n]) { 77 | info!("rxtx: failed to write to socket; err = {:?}", e); 78 | return; 79 | } 80 | } 81 | Err(e) => { 82 | info!("rxtx: failed to read from socket; err = {:?}", e); 83 | return; 84 | } 85 | } 86 | } 87 | } -------------------------------------------------------------------------------- /Cargo.lock: -------------------------------------------------------------------------------- 1 | # This file is automatically @generated by Cargo. 2 | # It is not intended for manual editing. 3 | version = 3 4 | 5 | [[package]] 6 | name = "aho-corasick" 7 | version = "1.1.2" 8 | source = "registry+https://github.com/rust-lang/crates.io-index" 9 | checksum = "b2969dcb958b36655471fc61f7e416fa76033bdd4bfed0678d8fee1e2d07a1f0" 10 | dependencies = [ 11 | "memchr", 12 | ] 13 | 14 | [[package]] 15 | name = "bench" 16 | version = "0.1.0" 17 | dependencies = [ 18 | "log", 19 | "pretty_env_logger", 20 | ] 21 | 22 | [[package]] 23 | name = "env_logger" 24 | version = "0.10.2" 25 | source = "registry+https://github.com/rust-lang/crates.io-index" 26 | checksum = "4cd405aab171cb85d6735e5c8d9db038c17d3ca007a4d2c25f337935c3d90580" 27 | dependencies = [ 28 | "humantime", 29 | "is-terminal", 30 | "log", 31 | "regex", 32 | "termcolor", 33 | ] 34 | 35 | [[package]] 36 | name = "hermit-abi" 37 | version = "0.3.6" 38 | source = "registry+https://github.com/rust-lang/crates.io-index" 39 | checksum = "bd5256b483761cd23699d0da46cc6fd2ee3be420bbe6d020ae4a091e70b7e9fd" 40 | 41 | [[package]] 42 | name = "humantime" 43 | version = "2.1.0" 44 | source = "registry+https://github.com/rust-lang/crates.io-index" 45 | checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4" 46 | 47 | [[package]] 48 | name = "is-terminal" 49 | version = "0.4.12" 50 | source = "registry+https://github.com/rust-lang/crates.io-index" 51 | checksum = "f23ff5ef2b80d608d61efee834934d862cd92461afc0560dedf493e4c033738b" 52 | dependencies = [ 53 | "hermit-abi", 54 | "libc", 55 | "windows-sys", 56 | ] 57 | 58 | [[package]] 59 | name = "libc" 60 | version = "0.2.153" 61 | source = "registry+https://github.com/rust-lang/crates.io-index" 62 | checksum = "9c198f91728a82281a64e1f4f9eeb25d82cb32a5de251c6bd1b5154d63a8e7bd" 63 | 64 | [[package]] 65 | name = "log" 66 | version = "0.4.20" 67 | source = "registry+https://github.com/rust-lang/crates.io-index" 68 | checksum = "b5e6163cb8c49088c2c36f57875e58ccd8c87c7427f7fbd50ea6710b2f3f2e8f" 69 | 70 | [[package]] 71 | name = "memchr" 72 | version = "2.7.1" 73 | source = "registry+https://github.com/rust-lang/crates.io-index" 74 | checksum = "523dc4f511e55ab87b694dc30d0f820d60906ef06413f93d4d7a1385599cc149" 75 | 76 | [[package]] 77 | name = "pretty_env_logger" 78 | version = "0.5.0" 79 | source = "registry+https://github.com/rust-lang/crates.io-index" 80 | checksum = "865724d4dbe39d9f3dd3b52b88d859d66bcb2d6a0acfd5ea68a65fb66d4bdc1c" 81 | dependencies = [ 82 | "env_logger", 83 | "log", 84 | ] 85 | 86 | [[package]] 87 | name = "regex" 88 | version = "1.10.3" 89 | source = "registry+https://github.com/rust-lang/crates.io-index" 90 | checksum = "b62dbe01f0b06f9d8dc7d49e05a0785f153b00b2c227856282f671e0318c9b15" 91 | dependencies = [ 92 | "aho-corasick", 93 | "memchr", 94 | "regex-automata", 95 | "regex-syntax", 96 | ] 97 | 98 | [[package]] 99 | name = "regex-automata" 100 | version = "0.4.5" 101 | source = "registry+https://github.com/rust-lang/crates.io-index" 102 | checksum = "5bb987efffd3c6d0d8f5f89510bb458559eab11e4f869acb20bf845e016259cd" 103 | dependencies = [ 104 | "aho-corasick", 105 | "memchr", 106 | "regex-syntax", 107 | ] 108 | 109 | [[package]] 110 | name = "regex-syntax" 111 | version = "0.8.2" 112 | source = "registry+https://github.com/rust-lang/crates.io-index" 113 | checksum = "c08c74e62047bb2de4ff487b251e4a92e24f48745648451635cec7d591162d9f" 114 | 115 | [[package]] 116 | name = "termcolor" 117 | version = "1.4.1" 118 | source = "registry+https://github.com/rust-lang/crates.io-index" 119 | checksum = "06794f8f6c5c898b3275aebefa6b8a1cb24cd2c6c79397ab15774837a0bc5755" 120 | dependencies = [ 121 | "winapi-util", 122 | ] 123 | 124 | [[package]] 125 | name = "winapi" 126 | version = "0.3.9" 127 | source = "registry+https://github.com/rust-lang/crates.io-index" 128 | checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" 129 | dependencies = [ 130 | "winapi-i686-pc-windows-gnu", 131 | "winapi-x86_64-pc-windows-gnu", 132 | ] 133 | 134 | [[package]] 135 | name = "winapi-i686-pc-windows-gnu" 136 | version = "0.4.0" 137 | source = "registry+https://github.com/rust-lang/crates.io-index" 138 | checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" 139 | 140 | [[package]] 141 | name = "winapi-util" 142 | version = "0.1.6" 143 | source = "registry+https://github.com/rust-lang/crates.io-index" 144 | checksum = "f29e6f9198ba0d26b4c9f07dbe6f9ed633e1f3d5b8b414090084349e46a52596" 145 | dependencies = [ 146 | "winapi", 147 | ] 148 | 149 | [[package]] 150 | name = "winapi-x86_64-pc-windows-gnu" 151 | version = "0.4.0" 152 | source = "registry+https://github.com/rust-lang/crates.io-index" 153 | checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" 154 | 155 | [[package]] 156 | name = "windows-sys" 157 | version = "0.52.0" 158 | source = "registry+https://github.com/rust-lang/crates.io-index" 159 | checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" 160 | dependencies = [ 161 | "windows-targets", 162 | ] 163 | 164 | [[package]] 165 | name = "windows-targets" 166 | version = "0.52.0" 167 | source = "registry+https://github.com/rust-lang/crates.io-index" 168 | checksum = "8a18201040b24831fbb9e4eb208f8892e1f50a37feb53cc7ff887feb8f50e7cd" 169 | dependencies = [ 170 | "windows_aarch64_gnullvm", 171 | "windows_aarch64_msvc", 172 | "windows_i686_gnu", 173 | "windows_i686_msvc", 174 | "windows_x86_64_gnu", 175 | "windows_x86_64_gnullvm", 176 | "windows_x86_64_msvc", 177 | ] 178 | 179 | [[package]] 180 | name = "windows_aarch64_gnullvm" 181 | version = "0.52.0" 182 | source = "registry+https://github.com/rust-lang/crates.io-index" 183 | checksum = "cb7764e35d4db8a7921e09562a0304bf2f93e0a51bfccee0bd0bb0b666b015ea" 184 | 185 | [[package]] 186 | name = "windows_aarch64_msvc" 187 | version = "0.52.0" 188 | source = "registry+https://github.com/rust-lang/crates.io-index" 189 | checksum = "bbaa0368d4f1d2aaefc55b6fcfee13f41544ddf36801e793edbbfd7d7df075ef" 190 | 191 | [[package]] 192 | name = "windows_i686_gnu" 193 | version = "0.52.0" 194 | source = "registry+https://github.com/rust-lang/crates.io-index" 195 | checksum = "a28637cb1fa3560a16915793afb20081aba2c92ee8af57b4d5f28e4b3e7df313" 196 | 197 | [[package]] 198 | name = "windows_i686_msvc" 199 | version = "0.52.0" 200 | source = "registry+https://github.com/rust-lang/crates.io-index" 201 | checksum = "ffe5e8e31046ce6230cc7215707b816e339ff4d4d67c65dffa206fd0f7aa7b9a" 202 | 203 | [[package]] 204 | name = "windows_x86_64_gnu" 205 | version = "0.52.0" 206 | source = "registry+https://github.com/rust-lang/crates.io-index" 207 | checksum = "3d6fa32db2bc4a2f5abeacf2b69f7992cd09dca97498da74a151a3132c26befd" 208 | 209 | [[package]] 210 | name = "windows_x86_64_gnullvm" 211 | version = "0.52.0" 212 | source = "registry+https://github.com/rust-lang/crates.io-index" 213 | checksum = "1a657e1e9d3f514745a572a6846d3c7aa7dbe1658c056ed9c3344c4109a6949e" 214 | 215 | [[package]] 216 | name = "windows_x86_64_msvc" 217 | version = "0.52.0" 218 | source = "registry+https://github.com/rust-lang/crates.io-index" 219 | checksum = "dff9641d1cd4be8d1a070daf9e3773c5f67e78b4d9d42263020c057706765c04" 220 | --------------------------------------------------------------------------------