GATT isn't just a trade agreement: creating a custom BLE Service
The upside of selecting a widely used protocol, like BLE, is that there is a great deal of information and infrastructure surrounding it. The downside is that there is a great deal of information and infrastructure surrounding it. Some of this complexity is inherent, some is due to accomodating many divergent use cases, and some is just accumulated cruft, but all of it needs to be dealt with.
In a previous update, I showed success with wireless control of the device, but using an existing service, the Nordic LED Button Service. This worked, but the service is designed just for demonstration purposes, and we will need a lot more capability. We need our own service. There’s a fair bit of detail required to do this, which I won’t rehash, instead will just link Nordic’s course. What’s currently implemented is establishing a connection, turning PWM on and off, and reporting the measured frequency when polled. Below is a screenshot:
Under the readable characteristic, we see the value of the measured frequency, in millihertz. The input is a signal generator set to 42.0 Hz, so it seems to be working. The interface is not very pretty, it’s a generic developer interface (Nordic’s nRF Connect app, on iOS), but it can be used for measurement and control. Code is here, conveniently tagged for today’s version. With some level of wireless interface in place, a measurement system, and control of a power stage, we are almost in a position where the rest of the system is just a Simple Matter of Programming. Not quite, there are a few other granular chunks to demonstrate, but getting closer.