Part 1: Getting Started
Creating a Bluetooth Service in Zephyr is a wonderfully easy task. I’ve had a high startup cost doing simple things like PWM drivers in Zephyr, but Bluetooth is just great.
The latest version of my application uses the nrf5x library and C++ code to create a standard procedural application. It has a main() and runs in a single thread. It’s about 25,000 lines of code.
Although it’s very efficient in space and resources the entire application had to be built from the ground up. Using Zephyr gives me lots of useful libraries (like Logging) that I don’t have to build from scratch — and that I don’t have to maintain.
The most important thing, though, is that the nrf5x library from Nordic Semiconductor relies on a Bluetooth library that comes as binary only. There is no source code and it only logs to the Nordic logging subsystem — which is useless. Worst of all, you can’t debug anything when the Bluetooth stack is running because it just hard crashes.
So, although the Nordic nrf5x library and Bluetooth driver seem very robust and reliable they are the world’s worst when it comes to developing. Conversely, the Zephyr Bluetooth library is open source and it has extensive logging that goes to the stock Zephyr logger — so you can watch the Bluetooth logging in real-time.
One reliable undebuggable core vs one open-source seemingly reliable debug-able threaded operating system. No contest. So, I’ve been moving to Zephyr.
Getting Started with Bluetooth
First, one must correctly set the prj.conf bluetooth defines. Here are mine…
# -- bluetooth stuff
# --- we're a peripheral
# --- connection definitions
# --- debugging
It’s very short. Most of the debugging and connection definitions are optional and have reasonable defaults.
Next there’s a simple bluetooth startup routine. This routine mainly sets up the advertising data (which lists all of the services provided by this Bluetooth peripheral) and the advertising parameters (power, iteration cycle, …) and then starts advertising.
Don’t be confused by the length of the file. The many callbacks just print out a diagnostic.
Since gists flow in Medium this ends part 1: