BLE_HTS_Demo

This BLE_HTS_Demo program enables you to collect Temperature and Humidity data reading from sensor and transmit to collector device such as smartphone.

Below documents teach you how to install app that can connect and read data from our DELTA-DFCM-NNN40 development board. There are two versions, Android and iPhone.

/media/uploads/Marcomissyou/ios_app_for_environment_sensor_0518.pdf

/media/uploads/Marcomissyou/android_app_for_environment_sensor.pdf

Revision:
9:2ff66a3d164a
Parent:
8:4653319ba675
--- a/main.cpp	Fri Oct 21 02:35:31 2016 +0000
+++ b/main.cpp	Tue Jul 18 09:34:06 2017 +0000
@@ -15,14 +15,13 @@
  */
 
 #include "mbed.h"
-#include "BatteryService.h"
-#include "DeviceInformationService.h"
-#include "BLE.h"
+#include "ble/services/BatteryService.h"
+#include "ble/services/DeviceInformationService.h"
+#include "ble/BLE.h"
 
 #include "hts221.h"
 #include "uvis25.h"
 
-BLEDevice  ble;
 DigitalOut  led1(LED1);
 
 static const uint8_t UUID_HUMI_AND_UVI[] = {0xf5, 0x59, 0xa2, 0x49, 0xbe, 0xb1, 0x4c, 0x54, 0xa1, 0x0a, 0xc7, 0x95, 0x7e, 0x17, 0xf8, 0x67};
@@ -59,7 +58,7 @@
 //
 void disconnectionCallback(const Gap::DisconnectionCallbackParams_t *params)
 {
-    ble.startAdvertising();
+    BLE::Instance(BLE::DEFAULT_INSTANCE).gap().startAdvertising(); // restart advertising
 }
 
 void periodicCallback(void)
@@ -70,6 +69,34 @@
      * heavy-weight sensor polling from the main thread. */
     triggerSensorPolling = true;
 }
+
+void bleInitComplete(BLE::InitializationCompleteCallbackContext *params)
+{
+    BLE &ble          = params->ble;
+    ble_error_t error = params->error;
+
+    if (error != BLE_ERROR_NONE) {
+        return;
+    }
+    
+    ble.gap().onDisconnection(disconnectionCallback);
+    
+    /* Setup auxiliary services. */
+    BatteryService           battery(ble);
+    DeviceInformationService deviceInfo(ble, "Delta", "NQ620", "SN1", "hw-rev1", "fw-rev1", "soft-rev1");
+  
+    /* Setup advertising. */
+    ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::BREDR_NOT_SUPPORTED | GapAdvertisingData::LE_GENERAL_DISCOVERABLE);
+    ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LIST_16BIT_SERVICE_IDS, (uint8_t *)uuid16_list, sizeof(uuid16_list));
+    ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::GENERIC_HEART_RATE_SENSOR);
+    ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LOCAL_NAME, (uint8_t *)DEVICE_NAME, sizeof(DEVICE_NAME));
+    ble.gap().setAdvertisingType(GapAdvertisingParams::ADV_CONNECTABLE_UNDIRECTED);
+    ble.gap().setAdvertisingInterval(1000); /* 1000ms */
+    ble.gap().startAdvertising();
+    
+    ble.addService(htsService);
+}
+
 /**************************************************************************/
 /*!
     @brief  Program entry point
@@ -87,25 +114,17 @@
     Ticker ticker;
     ticker.attach(periodicCallback, 2);
     
-    ble.init();
-    ble.onDisconnection(disconnectionCallback);
+    BLE& ble = BLE::Instance(BLE::DEFAULT_INSTANCE);
+    ble.init(bleInitComplete);
+    
+    //ble.init();
+//    ble.onDisconnection(disconnectionCallback);
 
-    /* Setup auxiliary services. */
-    BatteryService           battery(ble);
-    DeviceInformationService deviceInfo(ble, "Delta", "NNN40_1.0", "SN", "EVB_1.0", "B230-n80-m92", "T_0128b");
-  
-    /* Setup advertising. */
-    ble.accumulateAdvertisingPayload(GapAdvertisingData::BREDR_NOT_SUPPORTED | GapAdvertisingData::LE_GENERAL_DISCOVERABLE);
-    ble.accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LIST_16BIT_SERVICE_IDS, (uint8_t *)uuid16_list, sizeof(uuid16_list));
-    ble.accumulateAdvertisingPayload(GapAdvertisingData::GENERIC_HEART_RATE_SENSOR);
-    ble.accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LOCAL_NAME, (uint8_t *)DEVICE_NAME, sizeof(DEVICE_NAME));
-    ble.setAdvertisingType(GapAdvertisingParams::ADV_CONNECTABLE_UNDIRECTED);
-    ble.setAdvertisingInterval(1600);
-    ble.startAdvertising();
+    /* SpinWait for initialization to complete. This is necessary because the
+     * BLE object is used in the main loop below. */
+    while (ble.hasInitialized()  == false) { /* spin loop */ }   
     
-    ble.addService(htsService);   
-    
-    while (true) {
+    while (1) {
 
             if(hts221_verify_product_id())
                 HTS221_ReadTempHumi(&tempCelsius, &humi);