Demo Glucose Service

Dependencies:   BLE_API mbed nRF51822

Fork of BLE_HeartRate by Bluetooth Low Energy

BLE_Glucose_demo implements the Glucose Service which enables a collector device to connect and interact with.

There is a brief sample code edited with Android Studio for demo this BLE_Glucose_demo example, and it is public on github, everyone can clone it by this URL: https://github.com/Marcomissyou/BluetoothLeGlucose.git. It is convenient for you to development your BLE idea.

There is also provided apk file so you can download and install it directly then demo this code, but make sure your Android phone supports Bluetooth 4.0. /media/uploads/Marcomissyou/bleglucoseservice.apk

Committer:
Marcomissyou
Date:
Fri Jun 26 06:18:17 2015 +0000
Revision:
64:8cd9416028a7
Parent:
63:fc6117c32419
update BLE_API and modify code to consistent with the newest BLE_API

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ktownsend 0:87a7fc231fae 1 #include "mbed.h"
Marcomissyou 64:8cd9416028a7 2 #include "BLE.h"
rgrover1 42:06ebef2e0e44 3 #include "DeviceInformationService.h"
Marcomissyou 63:fc6117c32419 4 #include "GlucoseService.h"
Marcomissyou 63:fc6117c32419 5
rgrover1 52:6bbf62943106 6 #define UPDATE_PARAMS_FOR_LONGER_CONNECTION_INTERVAL 0
Marcomissyou 63:fc6117c32419 7
Rohit Grover 10:2436164b692e 8 BLEDevice ble;
Marcomissyou 63:fc6117c32419 9 DigitalOut led01(LED1);
Marcomissyou 63:fc6117c32419 10 Serial uart(p25,p23);
Marcomissyou 63:fc6117c32419 11
Marcomissyou 63:fc6117c32419 12 const static char DEVICE_NAME[] = "Glucose Machine";
Marcomissyou 63:fc6117c32419 13 static const uint16_t uuid16_list[] = {GattService::UUID_GLUCOSE_SERVICE,
rgrover1 42:06ebef2e0e44 14 GattService::UUID_DEVICE_INFORMATION_SERVICE};
rgrover1 39:6390604f904c 15 static volatile bool triggerSensorPolling = false;
Marcomissyou 63:fc6117c32419 16
rgrover1 41:9cef0129da5f 17 void disconnectionCallback(Gap::Handle_t handle, Gap::DisconnectionReason_t reason)
ktownsend 0:87a7fc231fae 18 {
rgrover1 46:ee7c55907f36 19 ble.startAdvertising(); // restart advertising
rgrover1 7:daab8ba5139e 20 }
Marcomissyou 63:fc6117c32419 21
Rohit Grover 11:1d9aafee4984 22 void periodicCallback(void)
Rohit Grover 11:1d9aafee4984 23 {
Marcomissyou 63:fc6117c32419 24 led01 = !led01; /* Do blinky on LED1 while we're waiting for BLE events */
rgrover1 39:6390604f904c 25 triggerSensorPolling = true;
Rohit Grover 11:1d9aafee4984 26 }
Marcomissyou 63:fc6117c32419 27
ktownsend 0:87a7fc231fae 28 int main(void)
Marcomissyou 63:fc6117c32419 29 { uart.printf("Starting Glucose Service\n");
Marcomissyou 63:fc6117c32419 30 led01 = 1;
Rohit Grover 11:1d9aafee4984 31 Ticker ticker;
Marcomissyou 63:fc6117c32419 32 ticker.attach(periodicCallback, 1);
Marcomissyou 63:fc6117c32419 33
Rohit Grover 15:7ba28817e31e 34 ble.init();
rgrover1 7:daab8ba5139e 35 ble.onDisconnection(disconnectionCallback);
Marcomissyou 63:fc6117c32419 36
rgrover1 45:98c5a34b07a4 37 /* Setup primary service. */
Marcomissyou 63:fc6117c32419 38 float glucoseValue = 100.0f; // 100 Kg/L
Marcomissyou 63:fc6117c32419 39 GlucoseService GluService(ble, glucoseValue);
Marcomissyou 63:fc6117c32419 40
mbedAustin 55:3a7d497a3e03 41 /* Setup auxiliary service. */
rgrover1 45:98c5a34b07a4 42 DeviceInformationService deviceInfo(ble, "ARM", "Model1", "SN1", "hw-rev1", "fw-rev1", "soft-rev1");
rgrover1 45:98c5a34b07a4 43 /* Setup advertising. */
Rohit Grover 29:76d865c718a6 44 ble.accumulateAdvertisingPayload(GapAdvertisingData::BREDR_NOT_SUPPORTED | GapAdvertisingData::LE_GENERAL_DISCOVERABLE);
rgrover1 40:e73130c6f2bb 45 ble.accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LIST_16BIT_SERVICE_IDS, (uint8_t *)uuid16_list, sizeof(uuid16_list));
Marcomissyou 63:fc6117c32419 46 ble.accumulateAdvertisingPayload(GapAdvertisingData::GENERIC_GLUCOSE_METER);
Rohit Grover 29:76d865c718a6 47 ble.accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LOCAL_NAME, (uint8_t *)DEVICE_NAME, sizeof(DEVICE_NAME));
rgrover1 7:daab8ba5139e 48 ble.setAdvertisingType(GapAdvertisingParams::ADV_CONNECTABLE_UNDIRECTED);
rgrover1 56:83623419d5e4 49 ble.setAdvertisingInterval(1000);
rgrover1 7:daab8ba5139e 50 ble.startAdvertising();
Marcomissyou 63:fc6117c32419 51
mbedAustin 55:3a7d497a3e03 52 while (1) {
rgrover1 50:477004d54431 53 if (triggerSensorPolling && ble.getGapState().connected) {
Rohit Grover 36:ea2a1b4f51c1 54 triggerSensorPolling = false;
Marcomissyou 63:fc6117c32419 55 glucoseValue = glucoseValue + 1.0f;
Marcomissyou 63:fc6117c32419 56 GluService.updateGlucoseMeasurement(glucoseValue);
Marcomissyou 63:fc6117c32419 57 if (glucoseValue > 175.0f) {
Marcomissyou 63:fc6117c32419 58 glucoseValue = 100.0f;
Marcomissyou 63:fc6117c32419 59 }
Marcomissyou 63:fc6117c32419 60 if(GluService.is_GluReceived()){
Marcomissyou 63:fc6117c32419 61 uint8_t *RxBuffer;
Marcomissyou 63:fc6117c32419 62 RxBuffer = GluService.getControlPoint();
Marcomissyou 63:fc6117c32419 63 GluService.CleanFlag();
Marcomissyou 63:fc6117c32419 64 printf("Receive data Op Code = %d\n", RxBuffer[0]-48);
Marcomissyou 63:fc6117c32419 65 printf("Receive data Operator = %d\n", RxBuffer[1]-48);
Marcomissyou 63:fc6117c32419 66 printf("Receive data Operand[0] = %d\n", RxBuffer[2]-48);
Marcomissyou 63:fc6117c32419 67 printf("Receive data Operand[1] = %d\n", RxBuffer[3]-48);
Marcomissyou 63:fc6117c32419 68 }
Marcomissyou 63:fc6117c32419 69
Rohit Grover 36:ea2a1b4f51c1 70 } else {
Marcomissyou 63:fc6117c32419 71 ble.waitForEvent();
Rohit Grover 36:ea2a1b4f51c1 72 }
ktownsend 0:87a7fc231fae 73 }
Marcomissyou 63:fc6117c32419 74 }