UART Over Bluetooth Low Energy
A universal asynchronous receiver/transmitter (UART) is the most popular protocol used for talking to a computer device over serial port. What I am talking here is not exactly UART in traditional sense. It's an emulation of serial port over BLE. It's not part of profiles defined by Bluetooth SIG. It's a custom defined service. It's so popular that it has become a standard. It's an equivalent of SPP (Serial Port Profile) in Bluetooth Classic but community defined. Almost all (Nordic, Adafruit, mbed) BLE hardware providers support it.
I think since Nordic started it. They defined the UUIDs and details of the service ➡️ Nordic UART Service (UUID: 0x0001). The UUID of the Nordic UART Service is 6E400001-B5A3-F393-E0A9-E50E24DCCA9E. As of now every vendor uses these UUIDs for UART.
Nordic's UART Android client is a great application if you like to test your UART implementation. It's Open source and available on Play store.
Below is the configuration of the Service and Characteristics that I used on a hardware device (Server or GATT Server) and then I used nRF UART 2.0 Android app (Client) to connect. The service definition below is for GATT Server. Characteristic names are from client's point of view. For testing purpose you could import this into nRF Connect and make it a GATT Server. Then you can use nRF UART 2.0 to connect and then to chat. One can implement custom protocol over that chat.
<server-configuration name="UART OVER BLE GATT SERVER"> <service uuid="6e400001-b5a3-f393-e0a9-e50e24dcca9e"> <characteristic name="TX for Client Characteristic" uuid="6e400002-b5a3-f393-e0a9-e50e24dcca9e"> <permission name="WRITE"/> <property name="WRITE"/> </characteristic> <characteristic name="RX for Client Characteristic" uuid="6e400003-b5a3-f393-e0a9-e50e24dcca9e"> <permission name="READ"/> <property name="READ"/> <property name="NOTIFY"/> </characteristic> </service> </server-configuration>
Since the services above are implemented on the GATT Server. The TX Characteristic will have the WRITE permission enabled so a client can write where as a client can only READ from a RX Characteristic1. Essentially two characteristic work like register to which a client can write or read from. The picture below should make it clear.
PS1:I am doing lot of experiments with Bluetooth Low Energy. I have started to like Bluetooth again. So you will see more posts.
PS2: A more complicated picture of the BLE UART.
PS3:I have implemented a rudimentary UART GATT server on Android. You might want to check it out.
- Read this chapter to understand how the permissions in BLE work. Actually this is one of he best book on BLE. So read the book. ↩
[…] In most cases Android is used as client (GATT Client). But one can also use Android as GATT Server. There are use cases where running a GATT Server on Android can be useful. For example lets say you want a desktop app displays notification of a SMS arrival. Its easy to write a GATT server (on Phone) that pushes the message to Client (Desktop) as and when it arrives. Now, there can be many other useful use-cases but in the example code I am implementing the UART Protocol over BLE. […]