Reading and Writing Data to BLE Characteristics

How to Read and Write Data to Characteristics

A good way to get familiar with BLE is to read and write to individual Characteristics using the Nordic nRF Connect app for Android and iOS

NOTE: the Android version is much more feature rich than the iOS version, but you can use either for these examples.

nRF Connect

First, download and install nRF Connect on your mobile device (you cannot use the PC/Mac app without a special Nordic dongle).

Launch the app and you'll see a list of BLE peripheral devices that are broadcasting their advertisements.

Screw the bulb into a standard lamp socket and turn it on.

Find the LEDBlue device and click on the Connect button. (In case it doesn't show up at first, press the Scan button to refresh the list.)

The app will first show the Advertisement Data screen, indicating signal strength of the Magic Light. Swipe left to go to the Services page.

Unfortunately, there isn't much helpful info here about what these three Services are, so we'll need to dig deeper into the Characteristics to fine what we need.

Through some poking around in the Android version of the app we discovered that the Service with UUID of FFE5 is the one that contains the Characteristics for RGB color we want.

By pressing the down arrow Read icons for each Characteristic we can request Attributes from the Magic Bulb. Now we see that the Characteristic with UUID FFE6 has an associated User Description Characteristic with the Attribute of "Red"!

By pressing the up arrow "Write" icon next to the FFE6 Characteristic we can open the Write Value dialog box to send an attribute value byte array. In this case we can send anything from 00 to FF in hex (this is 0-255 levels). Type in FF for full blast red, then press the WRITE button (on Android it is labeled SEND).

How the MagicLight RGB Color Characteristic Works

The MagicLight Service has a characteristic each for Red, Green, Blue, and White, which we explored above, as well as a combined characteristic for RGBW (although the White element does not seem to be enabled in this characteristic for some reason).

In order to write to the RGB combined attribute, use the UUID FFE9. The byte array looks like this:

56 FF FF FF 00 F0 AA 

The critical components here are the second, third, and fourth bytes, which are red, green, and blue. The range is 00-FF (or 0-255 in decimal) so that byte array command would tell the bulb to go full blast red, green, and blue.

Next, we'll set up the Circuit Playground Bluefruit with CircuitPython, libraries, and code so we can use it as a Central and a Client to work with the Magic Light bulb.

This guide was first published on Jan 15, 2020. It was last updated on Jan 15, 2020.
This page (Reading and Writing Data to BLE Characteristics) was last updated on Aug 15, 2020.