BLE demo for the Health-Thermometer service.

Dependencies:   BLE_API mbed nRF51822 X_NUCLEO_IDB0XA1

This example demonstrates how to use the Health Thermometer Service. The Health Thermometer service reports two pieces of information, Temperature and Sensor Location.

API

Import library

Public Types

enum SensorLocation_t {
LOCATION_ARMPIT = 1, LOCATION_BODY , LOCATION_EAR , LOCATION_FINGER ,
LOCATION_GI_TRACT , LOCATION_MOUTH , LOCATION_RECTUM , LOCATION_TOE ,
LOCATION_EAR_DRUM
}

Public Member Functions

HealthThermometerService ( BLE &_ble, float initialTemp, uint8_t _location)
Add the Health Thermometer Service to an existing BLE object, initialize with temperature and location.
void updateTemperature (float temperature)
Update the temperature being broadcast.
void updateLocation ( SensorLocation_t loc)
Update the location.

Technical Details

Further Technical Details can be found at the following links

Committer:
mbedAustin
Date:
Tue Dec 09 22:23:42 2014 +0000
Revision:
8:63addc0221e7
Parent:
4:83c07b0e93d6
Child:
10:9a7e23066427
Simplified the Example, removed the external Temperature sensor

Who changed what in which revision?

UserRevisionLine numberNew contents of line
rgrover1 0:d01bde90471b 1 /* mbed Microcontroller Library
rgrover1 0:d01bde90471b 2 * Copyright (c) 2006-2013 ARM Limited
rgrover1 0:d01bde90471b 3 *
rgrover1 0:d01bde90471b 4 * Licensed under the Apache License, Version 2.0 (the "License");
rgrover1 0:d01bde90471b 5 * you may not use this file except in compliance with the License.
rgrover1 0:d01bde90471b 6 * You may obtain a copy of the License at
rgrover1 0:d01bde90471b 7 *
rgrover1 0:d01bde90471b 8 * http://www.apache.org/licenses/LICENSE-2.0
rgrover1 0:d01bde90471b 9 *
rgrover1 0:d01bde90471b 10 * Unless required by applicable law or agreed to in writing, software
rgrover1 0:d01bde90471b 11 * distributed under the License is distributed on an "AS IS" BASIS,
rgrover1 0:d01bde90471b 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
rgrover1 0:d01bde90471b 13 * See the License for the specific language governing permissions and
rgrover1 0:d01bde90471b 14 * limitations under the License.
rgrover1 0:d01bde90471b 15 */
rgrover1 0:d01bde90471b 16
rgrover1 0:d01bde90471b 17 #include "mbed.h"
rgrover1 0:d01bde90471b 18 #include "BLEDevice.h"
rgrover1 0:d01bde90471b 19 #include "HealthThermometerService.h"
rgrover1 0:d01bde90471b 20
rgrover1 0:d01bde90471b 21 BLEDevice ble;
rgrover1 4:83c07b0e93d6 22 DigitalOut led1(LED1);
rgrover1 0:d01bde90471b 23
rgrover1 0:d01bde90471b 24 const static char DEVICE_NAME[] = "Therm";
rgrover1 0:d01bde90471b 25 static const uint16_t uuid16_list[] = {GattService::UUID_HEALTH_THERMOMETER_SERVICE};
rgrover1 0:d01bde90471b 26 static volatile bool triggerSensorPolling = false;
rgrover1 0:d01bde90471b 27
mbedAustin 8:63addc0221e7 28 /* Restart Advertising on disconnection*/
rgrover1 1:2deb859ed1a3 29 void disconnectionCallback(Gap::Handle_t handle, Gap::DisconnectionReason_t reason)
rgrover1 0:d01bde90471b 30 {
rgrover1 0:d01bde90471b 31 ble.startAdvertising();
rgrover1 0:d01bde90471b 32 }
rgrover1 0:d01bde90471b 33
rgrover1 0:d01bde90471b 34 int main(void)
rgrover1 0:d01bde90471b 35 {
rgrover1 4:83c07b0e93d6 36 led1 = 1;
mbedAustin 8:63addc0221e7 37
mbedAustin 8:63addc0221e7 38 /* Initialize BLE baselayer*/
rgrover1 0:d01bde90471b 39 ble.init();
rgrover1 0:d01bde90471b 40 ble.onDisconnection(disconnectionCallback);
rgrover1 0:d01bde90471b 41
rgrover1 0:d01bde90471b 42 /* setup advertising */
rgrover1 0:d01bde90471b 43 ble.accumulateAdvertisingPayload(GapAdvertisingData::BREDR_NOT_SUPPORTED | GapAdvertisingData::LE_GENERAL_DISCOVERABLE);
rgrover1 0:d01bde90471b 44 ble.accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LIST_16BIT_SERVICE_IDS, (uint8_t *)uuid16_list, sizeof(uuid16_list));
rgrover1 0:d01bde90471b 45 ble.accumulateAdvertisingPayload(GapAdvertisingData::THERMOMETER_EAR);
rgrover1 0:d01bde90471b 46 ble.accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LOCAL_NAME, (uint8_t *)DEVICE_NAME, sizeof(DEVICE_NAME));
rgrover1 0:d01bde90471b 47 ble.setAdvertisingType(GapAdvertisingParams::ADV_CONNECTABLE_UNDIRECTED);
rgrover1 0:d01bde90471b 48 ble.setAdvertisingInterval(1600); /* 1000ms; in multiples of 0.625ms. */
rgrover1 0:d01bde90471b 49
mbedAustin 8:63addc0221e7 50 /* setup Thermometer*/
rgrover1 0:d01bde90471b 51 float initialTemperature = 39.6;
rgrover1 0:d01bde90471b 52 HealthThermometerService thermometerService(ble, initialTemperature, HealthThermometerService::LOCATION_EAR);
rgrover1 0:d01bde90471b 53
mbedAustin 8:63addc0221e7 54 /* Start Advertising*/
mbedAustin 8:63addc0221e7 55 ble.startAdvertising();
rgrover1 0:d01bde90471b 56
mbedAustin 8:63addc0221e7 57 /* incriment temperature by 1 degree every second*/
mbedAustin 8:63addc0221e7 58 while (true) {
mbedAustin 8:63addc0221e7 59 thermometerService.updateTemperature((initialTemperature++));
mbedAustin 8:63addc0221e7 60 wait(2);
mbedAustin 8:63addc0221e7 61 led1 = !led1; /* Flash LED*/
rgrover1 0:d01bde90471b 62 }
rgrover1 0:d01bde90471b 63 }