Making a sub 10ms response time WIFI HID device.

I’ve always wondered why haven’t we tried making wifi enabled keyboards. I mean we’ve already tried Bluetooth and RF …… what’s wrong with Wi-Fi. So I wanted to find out. On my pervious post on this topic I scratched the surface of making an HID device using esp8266. It was okay as a first proof concept but it was an unreliable mess. The latency spikes, sudden disconnects, terrible average response times and incompatibility across different systems out-of-the-box made it pretty terrible even for hobbyist use. So I set on to see what can I improve for version 2.0.

First thing that I wanted to do was replace python with some compiled language. Python is a great language for lightening fast prototyping but its interpreted nature makes it terrible for high-performance applications. This bundled with the difficulty to package/ship it and make it cross compatible – is a a huge pain in the culo. Believe me I’ve tried everything from freezing to virtual environments to py2exe. I just could not get the packaging right.

In the end I had two options on my plate ….. GoLang and C++. I had more experience building stuff in C++ than go, so I knew how much pain in the ass it would to write somewhat decent c++ code. So decided to give golang a try and honestly…. my dev journey with it was better than I expected. I feel like the go has best of both worlds. Flexibility, prototype(ability?) , and readability of python and performance and bundled/compiled nature of c++.

Second I wanted to reduce the latency. Like REALLY eliminate it. Because I have a project in mind to use this for custom bindings in doom eternal and if you lag even for a 100ms on you UN run its probably run over for you. I tried using http requests – which were slow as a turtle with 50-60ms average response times. Tried using MQTT(the protocol) – which was supposed to be fast but still hung around at 20-25ms ping (I have no clue why. Maybe somewhere I fucked it up somewhere in my implementation of it…. not sure…. maybe I’ll retry using MQTT in the future). In the end I decided to give pain old TCP sockets a try and here were the results -> average latency over 10000 requests -> 5-7ms average response time. 😀

Compare this to the flagship wireless HID technology in the market – Logitech lightspeed wireless – coming in at 1ms…. My iteration was not too shabby. Its good enough for my TAG1 UN run.

Third thing was battery life…… Which I still haven’t figured out yet. ESP consumes around 100mA during normal mode. When couple with a single AAA battery with a boost converter gives about ~8 Hours of use time. (Compare this to the 250 hours I get on my g305). WIFI(esp) consumes wayyyyyy too much power for a portable battery powered device. Which is the reason I guess why Wi-Fi HID devices haven’t been popular. Stay tuned for part 3 when/if I figure it out to make this thing last longer either by using a different SOC or using sleep and interrupts on esp.

Here’s the source….

I am planning to create a go HID library to support precise thumbstick/mouse inputs for CAD applications. Now that I can achieve sub 10ms this shouldn’t be impractical. So stay tuned for that. GGs till then.