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!!!
Diff: main.cpp
- Revision:
- 1:4a25d917fb6a
- Parent:
- 0:0217a862b047
- Child:
- 2:c77c2b06d604
--- a/main.cpp Wed Dec 10 16:54:58 2014 +0000 +++ b/main.cpp Thu Dec 11 13:44:13 2014 +0000 @@ -3,6 +3,7 @@ // This sample includes code from several projects found on http://developer.mbed.org, including but not limited to: // - http://developer.mbed.org/teams/Bluetooth-Low-Energy/code/BLE_HeartRate/ // - https://developer.mbed.org/teams/Bluetooth-Low-Energy/code/BLE_LoopbackUART/ +// - https://developer.mbed.org/users/takafuminaka/code/BLE_HTM_by_InTempSensr/ // - miscellaneous adopted from more samples... // Reference: // - http://developer.mbed.org/teams/Bluetooth-Low-Energy/code/BLE_API/ @@ -42,13 +43,14 @@ //==========Includes========== #include "mbed.h" -#include "BLEDevice.h" +#include "BLEDevice.h" // BLE +#include "nrf_soc.h" // nRF Internal Temperature Sensor //Services #include "BatteryService.h" #include "DeviceInformationService.h" //#include "DFUService" //TODO: DFU and FOTA Support -//#include "HealthThermometerService.h" //TODO: Temperature, #include "ble_hts.h" +#include "HealthThermometerService.h" //TODO: Temperature, #include "ble_hts.h" #include "HeartRateService.h" //#include "UARTService.h" //TODO: Add a UART Channel for streaming data like logs? @@ -73,11 +75,47 @@ BLEDevice ble; const static char pcDeviceName[] = "blePRv04"; //PR: Why can App nRF-MCP modify this even though flagged as Const, maybe only temporary mod till App restarts? static const uint16_t uuid16_list[] = { //Service List (Pre-defined standard 16bit 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_HEART_RATE_SERVICE, //0x180D //HRM, BosyLocation,ControlPoint - GattService::UUID_BATTERY_SERVICE, //0x180F //BatteryLevel - GattService::UUID_DEVICE_INFORMATION_SERVICE}; //0x180A //sManufacturer, sModelNumber, sSerialNumber, sHWver, sFWver, sSWver + //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_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_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 // + //GattService::UUID_ALERT_NOTIFICATION_SERVICE, = 0x1811, + //GattService::UUID_CURRENT_TIME_SERVICE, = 0x1805, + //GattService::UUID_HUMAN_INTERFACE_DEVICE_SERVICE, = 0x1812, + //GattService::UUID_IMMEDIATE_ALERT_SERVICE, = 0x1802, + //GattService::UUID_LINK_LOSS_SERVICE, = 0x1803, + //GattService::UUID_PHONE_ALERT_STATUS_SERVICE, = 0x180E, + //GattService::UUID_REFERENCE_TIME_UPDATE_SERVICE, = 0x1806, + //GattService::UUID_SCAN_PARAMETERS_SERVICE, = 0x1813, + }; + +//==========Internal Temperature========== +//Adopted From: https://developer.mbed.org/users/takafuminaka/code/BLE_HTM_by_InTempSensr/ +// Service: https://developer.bluetooth.org/gatt/services/Pages/ServiceViewer.aspx?u=org.bluetooth.service.health_thermometer.xml +// HTM Char: https://developer.bluetooth.org/gatt/characteristics/Pages/CharacteristicViewer.aspx?u=org.bluetooth.characteristic.temperature_measurement.xml +uint8_t thermTempPayload[5] = { 0, 0, 0, 0, 0 }; +GattCharacteristic tempChar (GattCharacteristic::UUID_TEMPERATURE_MEASUREMENT_CHAR, + thermTempPayload, sizeof(thermTempPayload), sizeof(thermTempPayload), + GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_INDICATE); +GattCharacteristic *htmChars[] = {&tempChar, }; +GattService htmService(GattService::UUID_HEALTH_THERMOMETER_SERVICE, htmChars, + sizeof(htmChars) / sizeof(GattCharacteristic *)); + +//==========Battery========== +//Adopted From: https://developer.mbed.org/users/takafuminaka/code/BLE_HTM_by_InTempSensr/ +///int8_t batt = 98; /* Battery level */ +//uint8_t read_batt = 0; /* Variable to hold battery level reads */ +//static uint8_t bpm2[1] = {batt}; +//GattCharacteristic battLevel ( GattCharacteristic::UUID_BATTERY_LEVEL_CHAR, bpm2, sizeof(bpm2), sizeof(bpm2), +// GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY | +// GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ); +//GattCharacteristic *battChars[] = {&battLevel, }; +//GattService battService(GattService::UUID_BATTERY_SERVICE, battChars, sizeof(battChars) / sizeof(GattCharacteristic *)); + //==========Functions:Timer========== static volatile bool b_Ticker1 = false;//Volatile, don't optimize, changes under interrupt control @@ -144,7 +182,7 @@ static volatile unsigned uSentBLE; void Callback_BLE_onDataSent(unsigned uSent){ uSentBLE=uSent; - DEBUG("BLEi: SentI %ubytes", uSent); //TODO: PR: Why uSent always "1", expected it to match sent bytes length + DEBUG("BLEi: SentI(%u)", uSent); //TODO: PR: Why uSent always "1", expected it to match sent bytes length bSent = true; //PR: onDataSent() maybe only occuring when confirmed receive by phone, as onDataSent() didn't happen when phone moved out of range. } @@ -167,7 +205,8 @@ { f_led1level = 1; pwm_led1 = f_led1level;//Start LED1=OnMax f_led2level = 1; pwm_led2 = f_led2level;//Start LED2=OnMax - DEBUG("\nBLE:___%s___\nConnect App for Data: nRF-MCP, nRF-Toolbox:HRM, etc.\n", pcDeviceName); //Restart TeraTerm just before Pressing Reset on mbed + DEBUG("\nBLE: ___%s___\n", pcDeviceName); //Restart TeraTerm just before Pressing Reset on mbed + DEBUG("BLE: Connect App for Data: nRF-MCP, nRF-Toolbox:HRM, etc.\n"); Ticker ticker1; //PR: Timer Object(Structure) //ticker1.attach(CallbackTicker1, 1.0); //PR: Timer Handler, Float=PeriodSeconds