Guide to custom BLE (Peripheral) development using RAK4631 WisBlock Core
Introduction
Bluetooth Low Energy (BLE) Â is a wireless network technology used for sensor data and low-bandwidth applications where small amounts of data are transferred at lower speeds.
BLE was introduced in 2010. The original Bluetooth defined in the previous versions is referred to as Bluetooth Classic. BLE was not an upgrade to the Bluetooth Classic but rather it’s a new technology focused on the Internet of Things (IoT). BLE is sometimes referred to as  "Bluetooth Smart".
BLE Terms & Definitions
Central/Client
A device that scans and originates connections to BLE peripherals in order to perform some operation. This is typically a mobile device but it can also be an embedded device like RAK4630.
Peripheral
A device that advertises its presence and accepts connections from a Central in order to accomplish some task.
Advertising
When a BLE device wants to communicate its presence to other devices in the area, it broadcasts small packets of data which are called advertising packets or advertisements.
GAP
Generic Access Profile provides a framework that defines how BLE devices interact with each other.
GATT
The Generic Attribute Profile defines the format of the data exposed by a BLE device.
GATT Service
A collection of characteristics (data fields) that describes a feature of a device. For example the DIS (Device Information service) can contain a characteristic representing the serial number of the device.
GATT Characteristic
An entity containing meaningful data that can typically be read from or written to.
Notification
A means for a BLE peripheral to notify the Central when a characteristic’s value changes. The central doesn’t need to acknowledge that it’s received the packet.
Indication
Same as an indication, except each data packet is acknowledged by the Central. This guarantees their delivery at the cost of throughput.
UUID
Universally unique identifier, 128-bit number used to identify services, characteristics and descriptors.
Motivation
The Bluetooth Special Interest Group (SIG) manages publicly specified GATT services:
https://www.bluetooth.com/specifications/specs/
The Adafruit Bluefruit library library makes it easy to add Bluetooth Low Energy connectivity to your IoT project. Bluefruit offers common BLE services such as:
- Battery Service(BAS)
Send notifications about the battery level of the device. - DIS (Device Information Service)
Provides generic information about the device. Such as: manufacturer name, model, serial number - NUS (Nordic UART Service)
This is a proprietary service defined by Nordic Semiconductors that we can use as a baseline transport mechanism between BLE modules. You can use this service to send any kind of data from central to peripheral or vice versa.
But BLE opens up a world of endless possibilities by allowing developers to specify various custom profiles for different use cases. I decided to write this article because I can’t find good examples of custom profile BLE using Adafruit Bluefruit. If you want to create a new UUID for your application, follow the suggestion shown on the link below
https://www.novelbits.io/uuid-for-custom-services-and-characteristics/
Prerequisites
- WisBlock Starter Kit with RAK4631 and RAK5005-O - https://store.rakwireless.com/products/wisblock-starter-kit
- Mobile with nrf Connect for Mobile application installed
Android - https://play.google.com/store/apps/details?id=no.nordicsemi.android.mcp&hl=en_US&gl=US
IOS - https://apps.apple.com/us/app/nrf-connect-for-mobile/id1054362403
Install Arduino BSP for RAK4630
This guide requires the installation of an Arduino board support package. Follow the link below:
https://docs.rakwireless.com/Knowledge-Hub/Learn/Installation-of-Board-Support-Package-in-Arduino-IDE/
Testing Custom BLE sketch
Use the link below to download the sketch:
https://drive.google.com/file/d/1JsvUj7Pr2V5-xAuFhAZ5rLvfnyk80zUD/view?usp=sharing
(temporary link)
Follow these steps to upload your sketch:
- Attach the LoRa and BLE Antenna. Although this guide doesn't use LoRa it still needs to install the LoRa antenna.
- Connect your WisBlock Starter Kit to the PC using the USB cable.
- Launch Arduino IDE and choose File→Open and choose the path where you downloaded the sketch.
- On Arduino IDE and choose Tools→Board→ RAKwireless nRF modules→ WisBlock RAKwireless nRF modules →WisBlock Core RAK4631 Board to find your board in the Arduino menu.
- Choose the correct serial port for your board on Tools→Port.
- Finally, click the Upload button.
To check log messages of the application, open the  Arduino Serial Monitor.
Now launch the nRF Connect application on mobile.
1. Press the SCAN button and search for RAK4630 on the device list. If you have a WisBlock Starter Kit connected, you can see the blue LED flashing while the BLE is disconnected.
Finally press the CONNECT button as shown in the right image below.
2. The blue LED turns off when the BLE connection is established.
To send a message via custom BLE service, select the CLIENT tab and click on Unknown Service. A new Unknown Service and Characteristic window will appear. Finally click on the highlighted up arrow icon.
3. A new Write value  window will appear.
To turn off the WisBlock Starter Kit RAK5005-O Base board’s green LED, write 00 then click on the SEND button as shown on the left image. To turn on the green LED, write 01 then click on the SEND button as shown on the right image.
Use this example only as a reference to develop a more complete application.