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

Revision:
4:83c07b0e93d6
Parent:
2:a34d554282b0
Child:
8:63addc0221e7
--- a/main.cpp	Thu Sep 04 07:14:25 2014 +0000
+++ b/main.cpp	Mon Sep 22 10:47:20 2014 +0000
@@ -20,9 +20,10 @@
 #include "DHT.h"
 
 BLEDevice  ble;
+DigitalOut led1(LED1);
 DHT        sensor(D10, DHT11);
 
-#define NEED_CONSOLE_OUTPUT 1 /* Set this if you need debug messages on the console;
+#define NEED_CONSOLE_OUTPUT 0 /* Set this if you need debug messages on the console;
                                * it will have an impact on code-size and power consumption. */
 
 #if NEED_CONSOLE_OUTPUT
@@ -45,6 +46,8 @@
 
 void periodicCallback(void)
 {
+    led1 = !led1; /* Do blinky on LED1 while we're waiting for BLE events */
+
     /* Note that the periodicCallback() executes in interrupt context, so it is safer to do
      * heavy-weight sensor polling from the main thread. */
     triggerSensorPolling = true;
@@ -52,8 +55,9 @@
 
 int main(void)
 {
+    led1 = 1;
     Ticker ticker;
-    ticker.attach(periodicCallback, 3);
+    ticker.attach(periodicCallback, 1);
 
     DEBUG("Initialising the nRF51822\n\r");
     ble.init();
@@ -71,18 +75,19 @@
     float initialTemperature = 39.6;
     HealthThermometerService thermometerService(ble, initialTemperature, HealthThermometerService::LOCATION_EAR);
 
+    int error = 0;
+    float c = 0.0f;
+
     while (true) {
         if (triggerSensorPolling) {
             triggerSensorPolling = false;
 
-            wait(2);
-            
             /* Do blocking calls or whatever is necessary for sensor polling. */
             /* In our case, we simply update the dummy HRM measurement. */
-            int error = sensor.readData();
-            DEBUG("sensor read returned %d\r\n", error);
+            error = sensor.readData();
             if (!error) {
-                thermometerService.updateTemperature(sensor.ReadTemperature(CELCIUS));
+                c = sensor.ReadTemperature(CELCIUS);
+                thermometerService.updateTemperature(c);
             }
         } else {
             ble.waitForEvent();