The world's first Cowboy key-fob
Last year I got my Cowboy 3 e-bike and I love it. Every day I start riding the bike it feels great, it makes cycling even better than it already is. My only gripe is unlocking the app with the app, which takes about 15 seconds. This post is about how I built a BLE powered 3 button key that unlocks my bike, and the physical key unlocks the battery.
Here it is in action:
tldr: It doesn't make sense, but I learned a lot and it was fun.
I used the official Cowboy app with a cheap Android phone (Moto G7 Play) and also an my wife's iPhone SE (both first and second gen). On the iPhones the Bluetooth works a lot better, once the app opens it's almost instant. But: unlocking takes about 15 seconds: taking your phone out of your pocket while you're fiddling with the lock (7s), finding the app (3s), opening it (3s), unlocking (2s). If you do this 2 times a day for 365 days it will take 3 hours. So, I decided to spend a week and a couple hundred euros building a solution for this... :D
I wanted the experience to be more like my car key. So, I set out to build a foldable key fob with 3 buttons: turn on, turn off, toggle the lights. The physical key should unlock the battery.
Here is the result:
Starting with ESP32
First I built a prototype with an ESP32 dev board using the Arduino IDE. Got everything working, but then figured out that even the separate chip would never fit in a car key enclosing and could not be powered by a CR 2032 coin cell, as the ESP requires quite a lot of power. I have to say that the ESP32 was a joy to program. Learning about BLE GATT took some time, but then copying the commands and UUIDS from the Bronco Unleashed source code was super easy. But anyway, in the end it didn't work because of the power constraints.
Going for nRF52
After doing some more research I found the nRF52 ecosystem. The chips are tiny and very low power. It should easily be able to last a year on a CR2032. However, the programming experience was much much worse than the Arduino IDE. There is a big migration from the nRF5 SDK to the nRF Connect SDK, and most posts don't mention this. Also, the IDE targets SVN instead of GIT., it is all very niche. Nevertheless, after a couple of weekends I got it to work.
- Fanstel BC805M or BT832A, I tried both, the cheaper one is good enough.
- 3 buttons
- A led + resistor
- A CR2032 or CR2025 3v coin cell battery
- Diodes for routing power only when the buttons are pressed
- Car key fob shell, look on eBay
- Source code (also contains the ESP32 code)
- nNR52-DK for debugging and flashing the chip
- Glue gun
- Dremel for cutting out the original key and for making room in the new key fob shell
- The nRF toolkit plus horrible cMake configuration options...
- Sniffing BLE network traffic
- Brushed up my skills in C, soldering micro connections, electronics
That the bike sends a trip summary even without the app! The full route details are not there, but the distance and destination is recorded.
- Update: untrue, I did not unpair my phone so in the background it would sometimes connect, get the latest trip data and synchronize with the Cowboy servers. After unpairing my phone completely, the trips did not show up in the app anymore.
- Battery usage profiling is difficult. The battery would drain in a couple of days. I solved this by using diodes to only power the chip while a button is pressed. As this takes +/- 2 seconds it also prevents against some accidental presses.
- For some weird reason I can't switch the lights on and off. See this thread
- Solved! I figured out that you need to be subscribed to the notify of the UART RX characteristic. Updated in the (horrible!) source code.
- Now that the light is solved, I'd like to toggle it. The next question is how to decode the Dashboard service data. This is variable length and will require some reverse engineering or insider knowledge ;)
- Solved too! You can read out the memory.
- It's very important for me to switch between speed limits 24km/h and 25km/h by pressing a combination of buttons.
- Solved too.
- Obviously this project is not complete without some kind of "beep beep" sound when unlocking. I don't think the Cowboy has a speaker, but this has to be fixed somehow.
- Update: The battery is not replaceable as I could not fit this into the existing enclosure. I went on and designed my very first custom PCB that will allow for user replaceable batteries. Currently waiting for the components and will do a follow-up post once everything works.