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:
Thu Jul 02 05:25:19 2015 +0000
Revision:
67:aa3a1bbed328
Parent:
66:72ca05b7a092
update to correctly BLE_Glucose_demo

Who changed what in which revision?

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