Build World Class Health Tech Products with Bluetooth - Part 1.
What is Bluetooth(BLE) Custom protocol?

Search for a command to run...
What is Bluetooth(BLE) Custom protocol?

No comments yet. Be the first to comment.
Are you aware of AWS Amplify? If not that’s ok. Well, if you are into software product development you know how painful is it to hire people and keep them happy and the amount of programming you need to do. If you want to avoid the programming part t...
Build locally first npm run build Fix errors if any, Once we're able to build locally, we can connect our github repo branch to amplify, so that it'll automatically build. Goto project in Amplify on AWS Console, Give github permissions to your repo...

Let add Analytics to our Bakery Front end.

initialize amplify, add services and make backend ready.

We would like to build a NextJS App from scratch for our Bakery.

There are two major technologies within the bluetooth core specification
Bluetooth Classic and
Bluetooth Smart(Bluetooth Low Energy).
Bluetooth Low Energy (BLE) is a wireless communication protocol designed for low power consumption.
Power Consumption.
Application with Periodic transfer of data.
Simultaneous connections upto 20.
BLE has 3 layers:
Application.
Host.
Controller.
BLE has two types of packets (Advertising and data packets). Advertising packet:
Discover slaves & connect
Broadcast data for Application
Advertising packets can carry up to 31 Bytes of data payload along with the header information with the advertising interval from 20ms to 10.24s.
The shorter advertising interval increase the frequency at which advertising packets are broadcast.
Advertising uses a maximum of 3 frequency channels (37, 38 & 39).
GAP is a mechanism by which two devices get connected. E.g: Mobile Phone and Blood Glucose Monitor (device)
GAP specifies 4 roles:
Broadcaster - transmit only application.
Observer - receive only applications.
Central - multiple connections e.g smartphone (GATT Client).
Peripheral - use advertising packet to allow central to find it
To build Bluetooth Blood Glucose Monitor we need Peripheral type.
GATT is the way that connected devices exchange data. GAP enables the connection and GATT to exchange the data.
The device which wants to read or write the data is called the GATT client. E.g Cell Phone. All BLE peripherals are required to implement a GAP and a GATT service. GAP is a protocol that defines how the device connects. We can configure the advertising parameters for the device in GAP.
E.g Device Name, Device address OR UUID, Local Name, Service UUID, Service Data, etc.

A custom protocol in BLE refers to a user-defined protocol that is based on the BLE protocol, but has been customized to meet the specific needs of a particular application or use case. Custom protocols can be used to add additional functionality or features to BLE, or to optimize the protocol for a particular type of device or network. BLE custom protocols are often used in IoT (Internet of Things) applications, where they can help to improve the performance, reliability, and security of the network. Credit: #ChatGPT.
Service is a thing that the device can do, & the characteristics are the information that can be shared. Both the service and characteristics are specified by Bluetooth. We can create our service and characteristics.
Blood Glucose Custom Profile
Service UUID: 0xDTS11
Characteristics:
UUID: 0xDTSC1 Localname: DT-MEASURE2.
UUID: 0xDTSC3 Localname: DT-Control Point
Let's suppose you have all details about the sensor you need to connect your mobile to fetch data from, we need the Library to connect from Mobile App, bets way is to go with React Native.
Installing ble manager in React Native:
npm i --save react-native-ble-manager
For Android, we need to add the following permissions in AndroidManifest.xml file
<uses-permissionandroid:name="android.permission.BLUETOOTH"/>
<uses-permissionandroid:name="android.permission.BLUETOOTH_ADMIN"/>
<uses-permissionandroid:name="android.permission.ACCESS_COARSE_LOCATION" />
import BleManager from'react-native-ble-manager';
BleManager.start({ showAlert: false });
BleManager.scan([], 5, true).then(() =>
{
//Scan BLE Devices for 5 Seconds
console.log('Scan started'); // Success code});
}
HandleDiscoverPeripheral gets the devices list & update on the UI.
Connection and Disconnection
BleManager.connect('XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX')
.then(() => { console.log('Connected'); }).
catch((error) => { console.log(error); });
});
BleManager.disconnect('XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX').
then(() => { console.log('Connected');}).
catch((error) => { console.log(error);
});
Read Data from BLE Device
To read the current value of specified characteristics ID we need to call read method with deviceId, ServiceUUID & CharacteristicsUUID.
Before calling read we need to call retrieve services to get services and characteristics of BLE Device.
BleManager.retrieveServices(deviceId).then((peripheralInfo) => {BleManager.read(deviceId, ServiceUUID, CharacteristicsUUID).then((readData) => {
console.log('Read: '+ readData);
}).
catch((error) => { console.log(error); });
});
Write Data to BLE Device
For writing data to BLE Device we need to first call retrieve services & then We need to call write function with deviceId, ServiceUUID & Characteristics UUID.
For write function data must be in byte format
BleManager.retrieveServices(deviceId).then((peripheralInfo) => {BleManager.write(deviceId, ServiceUUID, CharacteristicsUUID, data).
then(() => {
console.log('Write: '+ data);
}) // Data Must be in Byte Format.
catch((error) => {
console.log(error);
});
});
Notify Service
For Notify also we need to call retrieve services first & then we need to call startNotification() deviceId, ServiceUUID & CharacteristicsUUID.Whenever the device sends data notify service gets called and we can read data through notify.
BleManager.retrieveServices(deviceId).
then((peripheralInfo) => {
BleManager.startNotification(deviceId, ServiceUUID, CharacteristicsUUID).
then(() => {
console.log('Notification started'); }).
catch((error) => { console.log(error); });
});
Custom Commands in BLE
We can write custom commands to BLE device using write functionality.
We can use BleManager.write()
to write our custom command.
We need to pass the command data in the byte format.
And we will get response in notify service.
E.g. '@110101020000000*'
This is the input format for write custom command.
11 is Command Type,
01 -> Data Type,
01 -> Data Type Size &
02 -> No. of Data in Packet
@ & * are the start and end indicator for data & remaining 0’s for completing 17 bytes in complete command.

Delighteck is your digital innovation partner. We help organisations to build human-centric technology solutions through cutting-edge services.
Delighteck helps with strategies and provides product development services for Health Tech. Do talk to us! contact@delighteck.com | +65 83854477