Experimental BLE project showing how IO can be made with an App over BLE. Pointer to matching App will be added when ready, initially this works with: - Android App [nRF-Master Control Panel], supports Write,Read,Notify - Android Project [BluetoothLeGatt]

Dependencies:   BLE_API mbed nRF51822

This is an experimental project for BLE (Bluetooth LE == Bluetooth Low Energy == Bluetooth Smart).

  • It supports general IO over BLE with Read/Notify/Write support.
  • It is compatible with FOTA using Android App "nRF Master Control Panel" (20150126)
  • IO supported by:
    • Custom Android App is in the WIKI under: Android-App, developed from Android Sample "BluetoothLeGatt"
    • Android App: nRF-MCP (Master Control Panel)
    • iOS App LightBlue.
    • General HRM, HTM, Battery and similar apps should be able to access the matching services.
  • It includes combinations of code from other projects, alternative code included can be tried by moving comments (, //)
  • 20150126 bleIO r25: It compiles for both "Nordic nRF51822" and "Nordic nRF51822 FOTA" platforms
  • 20150126 The matching bleIO App (in wiki) doesn't support FOTA yet, use Android App "nRF Master Control Panel"

Feedback and ideas greatly appreciated!!!

Revision:
4:976394791d7a
Parent:
3:a98203f84063
Child:
5:d36bbb315e31
--- a/main.cpp	Sat Dec 13 23:45:32 2014 +0000
+++ b/main.cpp	Sun Dec 14 00:11:39 2014 +0000
@@ -84,13 +84,13 @@
 
 //UUID List by Advertised 16bit UUID list (PartA)
 static const uint16_t uuid16_list[]     = { //Service List (Pre-defined standard 16bit services)
-    //*This list seems different from that shown in App:nRF-MCP, 
+    // *Order here doesn't affect order in nRF-MCP Discovery of Services
     //BLE_UUID_GAP  UUID_GENERIC_ACCESS                 //0x1800    //Included by Default, DeviceName, Appearance, PreferredConnectionParam
     //BLE_UUID_GATT UUID_GENERIC ATTRIBUTE              //0x1801    //Included by Default, ServiceChanged, 
     GattService::UUID_HEALTH_THERMOMETER_SERVICE,       //0x1809    //HTM (Might need to be first for nRF App)
-    GattService::UUID_BATTERY_SERVICE,                  //0x180F    //BatteryLevel
     GattService::UUID_DEVICE_INFORMATION_SERVICE,       //0x180A    //sManufacturer, sModelNumber, sSerialNumber, sHWver, sFWver, sSWver
     GattService::UUID_HEART_RATE_SERVICE,               //0x180D    //HRM, BodyLocation, ControlPoint
+    GattService::UUID_BATTERY_SERVICE,                  //0x180F    //BatteryLevel
 //    GattService::UUID_HEALTH_THERMOMETER_SERVICE,       //0x1809    //HTM
     //x GattService::UUID_DFU,                          //0x1530 - See UARTServiceShortUUID in BLE_API:DFUService.cpp  //
     //x GattService::UARTService,                       //0x0001 - See DFUServiceShortUUID  in BLE_API:UARTService.cpp //
@@ -105,6 +105,10 @@
  };
  
 //========== Prep UUID list (before main()) ==========
+// Adopted 2014Dec from http://developer.mbed.org/users/Bobty/code/BLE_ScoringDevice/
+
+//TODO: Unfinished new code style from http://developer.mbed.org/users/Bobty/code/BLE_ScoringDevice/
+
 //UUID List by Advertised 128bit UUID list (PartA, ToDo:)
 // Gatt characteristic and service UUIDs - Readable to UUID
 const UUID stringToUUID(const char* str) {
@@ -236,14 +240,15 @@
 //ble_error_t readCharacteristicValue  ( uint16_t  handle,    uint8_t *const  buffer,    uint16_t *const  lengthP  ) 
 //ble_error_t  updateCharacteristicValue (uint16_t handle, const uint8_t *value, uint16_t size, bool localOnly=false) 
 
-//UUID List by Services that are setup (Maybe this is what nRF-MCP discovers?)
+//UUID List by Services that are setup
     //BLE2: Setup Services
     DEBUG("BLE: Setup Services\n");
-    HeartRateService            hrmService(ble, (uint8_t)111, HeartRateService::LOCATION_FINGER);
+    // *Order here affects order in nRF-MCP Discovery of Services
     HealthThermometerService    htmService(ble, 30.0, HealthThermometerService::LOCATION_EAR); 
     BatteryService              battService(ble, 11);//Declare the service for BLE:BATTERY
-    DeviceInformationService    deviceInfo(ble, "Maker", pcDeviceName, "sn1234", "hw00", "fw00", "sw00");
-                                //(BLEDevice), pcManufacturer, pcModelNumber, pcSerialNumber, pcHWver, pcFWver, pcSWver
+    HeartRateService            hrmService(ble, (uint8_t)111, HeartRateService::LOCATION_FINGER);
+    DeviceInformationService    deviceInfo(ble, "Maker", pcDeviceName, "sn1234", "hw00", "fw00", "sw00");//(BLEDevice), pcManufacturer, pcModelNumber, pcSerialNumber, pcHWver, pcFWver, pcSWver
+
     //BLE3: Setup advertising
     DEBUG("BLE: Setup Advertising\n");
     ble.setAdvertisingInterval(Gap::MSEC_TO_ADVERTISEMENT_DURATION_UNITS(1000)); //PR: Advertise 1sec (1Hz)
@@ -267,11 +272,12 @@
             b_Ticker1 = false; // Clear flag for next Ticker1, see CallbackTicker1()
   
             // Read Sensors, and update matching Service Characteristics (only if connected)
+            // *Order here doesn't affect order in nRF-MCP Discovery of Services
+            float   update_htm(void); //prototype
             uint8_t update_hrm(void); //prototype
-            float   update_htm(void); //prototype
             uint8_t update_batt(void);//prototype
+            htmService.updateTemperature( update_htm() );
             hrmService.updateHeartRate( update_hrm() );
-            htmService.updateTemperature( update_htm() );
             battService.updateBatteryLevel( update_batt() );
             
             DEBUG("BLE: Wakes:%u Delta:%d ", u32_wakeevents, u32_wakeevents-u32_wakelast); //For Evaluating Timing
@@ -317,6 +323,15 @@
     sd_temp_get(&i32_temp);   //Read the nRF Internal Temperature (Die in 0.25'C steps, Counting From TBD), TODO:Check Scaling
     float fTemperature = (float(i32_temp)/4.0) - 16.0;   // Scale&Shift (0.25'C from -16'C?)
     DEBUG("[HTMi:%d HTMf:%f]", i32_temp, fTemperature);
+
+    //{//Force to IEEE format to match needs of Apps like nRF-HTM and nRF-Toolbox:HTM
+    // PR: Didn't work 20141213, might need more of style from BLE_HTM_by_InTempSensr if this is really necessary. OK in nRF-MCP for now.
+    //    uint8_t  exponent = 0xFE; //exponent is -2
+    //    uint32_t mantissa = (uint32_t)(fTemperature*100);
+    //    uint32_t temp_ieee11073 = ((((uint32_t)exponent) << 24) | (mantissa)); //Note: Assumes Mantissa within 24bits
+    //    memcpy(((uint8_t*)&fTemperature)+1, (uint8_t*)&temp_ieee11073, 4); //Overwrite with IEEE format float
+    //}
+
     return(fTemperature);
 }
 //==========Battery==========