Send VDD voltage data and chip temperature data via BLE UART Service. You can see the data on iPhone nRF Toolbox UART application.
Fork of BLE_UARTConsole by
Revision 11:368bd6332d02, committed 2018-08-09
- Comitter:
- kenjiArai
- Date:
- Thu Aug 09 11:04:42 2018 +0000
- Parent:
- 10:38852d243fb2
- Commit message:
- run on as of latest mbed-os(5.9.4)
Changed in this revision
diff -r 38852d243fb2 -r 368bd6332d02 BLE_API.lib --- a/BLE_API.lib Sun Jan 24 04:21:09 2016 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1 +0,0 @@ -http://mbed.org/teams/Bluetooth-Low-Energy/code/BLE_API/#ff83f0020480
diff -r 38852d243fb2 -r 368bd6332d02 main.cpp --- a/main.cpp Sun Jan 24 04:21:09 2016 +0000 +++ b/main.cpp Thu Aug 09 11:04:42 2018 +0000 @@ -16,23 +16,25 @@ /* * January 6th, 2016 Modified by Kenji Arai - * January 24th, 2016 + * August 9th, 2018 TY51822r3 runs on mbed-os-5.9.4 + * * http://www.page.sannet.ne.jp/kenjia/index.html * http://mbed.org/users/kenjiArai/ - * - * Original: - * 1) BLE_UARTConsole - * https://developer.mbed.org/teams/Bluetooth-Low-Energy/code/BLE_UARTConsole/ - * 2) BLE_HTM_by_InTempSensr_pub - * https://developer.mbed.org/users/takafuminaka/code/BLE_HTM_by_InTempSensr_pub/ - * Tanks Takafumi Naka san! - * Tested Controller Device: + * Original: + * 1) BLE_UARTConsole + * https://developer.mbed.org/teams/ + Bluetooth-Low-Energy/code/BLE_UARTConsole/ + * 2) BLE_HTM_by_InTempSensr_pub + * https://developer.mbed.org/users/ + takafuminaka/code/BLE_HTM_by_InTempSensr_pub/ + * Tanks Takafumi Naka san! + * Tested Controller Device: * iPhone6 UART application in nRF Toolbox * https://itunes.apple.com/jp/app/nrf-toolbox/id820906058?mt=8 * Please check data on "Show log" screen */ -// Include --------------------------------------------------------------------------------------- +// Include -------------------------------------------------------------------- #include <string.h> #include "mbed.h" #include "BLE.h" @@ -40,31 +42,31 @@ #include "nrf_soc.h" // for internal Thermo sensoer #include "nRF51_Vdd.h" // Read nRF51 Vdd voltage -// Definition ------------------------------------------------------------------------------------ +// Definition ----------------------------------------------------------------- -// Object ---------------------------------------------------------------------------------------- -BLE ble; +// Object --------------------------------------------------------------------- +BLE& ble_x = BLE::Instance(); UARTService *uart; nRF51_Vdd vdd(3.6f, 2.6f); -// RAM ------------------------------------------------------------------------------------------- +// RAM ------------------------------------------------------------------------ static volatile bool triggerSensorPolling = false; -// ROM / Constant data --------------------------------------------------------------------------- +// ROM / Constant data -------------------------------------------------------- const char *deviceName = "mbedBLE"; -// Function prototypes --------------------------------------------------------------------------- +// Function prototypes -------------------------------------------------------- void Update_Values(void); -//------------------------------------------------------------------------------------------------- +//------------------------------------------------------------------------------ // Control Program -//------------------------------------------------------------------------------------------------- +//------------------------------------------------------------------------------ void disconnectionCallback(const Gap::DisconnectionCallbackParams_t *params){ if (uart){ uart->writeString("Disconnected!\r\n"); uart->writeString("Restarting the advertising process\r\n"); } - ble.startAdvertising(); + ble_x.startAdvertising(); } void periodicCallback(void){ @@ -76,31 +78,35 @@ Ticker ticker; ticker.attach(periodicCallback, 5); // Opening screen - printf("\r\nInitialising the nRF51822\r\n"); + printf("\r\nInitialising TY51822r3\r\n"); printf("Temperature and CPU Vdd voltage via UART service\r\n"); // setup BLE - ble.init(); - ble.setDeviceName((const uint8_t *)deviceName); - ble.onDisconnection(disconnectionCallback); + ble_x.init(); + ble_x.setDeviceName((const uint8_t *)deviceName); + ble_x.onDisconnection(disconnectionCallback); // BLE Uart - uart = new UARTService(ble); + uart = new UARTService(ble_x); // setup advertising - ble.accumulateAdvertisingPayload(GapAdvertisingData::BREDR_NOT_SUPPORTED); - ble.setAdvertisingType(GapAdvertisingParams::ADV_CONNECTABLE_UNDIRECTED); - ble.accumulateAdvertisingPayload(GapAdvertisingData::SHORTENED_LOCAL_NAME, - (const uint8_t *)deviceName, - strlen(deviceName)); - ble.accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LIST_128BIT_SERVICE_IDS, - (const uint8_t *)UARTServiceUUID_reversed, - sizeof(UARTServiceUUID_reversed)); - ble.setAdvertisingInterval(160); /* 100ms; in multiples of 0.625ms. */ - ble.startAdvertising(); + ble_x.accumulateAdvertisingPayload(GapAdvertisingData::BREDR_NOT_SUPPORTED); + ble_x.setAdvertisingType(GapAdvertisingParams::ADV_CONNECTABLE_UNDIRECTED); + ble_x.accumulateAdvertisingPayload( + GapAdvertisingData::SHORTENED_LOCAL_NAME, + (const uint8_t *)deviceName, + strlen(deviceName) + ); + ble_x.accumulateAdvertisingPayload( + GapAdvertisingData::COMPLETE_LIST_128BIT_SERVICE_IDS, + (const uint8_t *)UARTServiceUUID_reversed, + sizeof(UARTServiceUUID_reversed) + ); + ble_x.setAdvertisingInterval(160); /* 100ms; in multiples of 0.625ms. */ + ble_x.startAdvertising(); while (true){ if (triggerSensorPolling){ triggerSensorPolling = false; Update_Values(); } else { - ble.waitForEvent(); + ble_x.waitForEvent(); } } } @@ -112,7 +118,7 @@ // Update a temperature (inside nRF51822 chip) sd_temp_get(&p_temp); - temperature = float(p_temp)/4.0f - 16.0f; + temperature = float(p_temp) / 4.0f; // 12 89 sprintf(buf,"T:%+4.1fdC", temperature); if (uart){
diff -r 38852d243fb2 -r 368bd6332d02 mbed-os.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed-os.lib Thu Aug 09 11:04:42 2018 +0000 @@ -0,0 +1,1 @@ +https://github.com/ARMmbed/mbed-os/#485bdeee150e2bc8ed75e27d936060fb63a7a7d1
diff -r 38852d243fb2 -r 368bd6332d02 mbed.bld --- a/mbed.bld Sun Jan 24 04:21:09 2016 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1 +0,0 @@ -http://mbed.org/users/mbed_official/code/mbed/builds/4f6c30876dfa \ No newline at end of file
diff -r 38852d243fb2 -r 368bd6332d02 nRF51822.lib --- a/nRF51822.lib Sun Jan 24 04:21:09 2016 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1 +0,0 @@ -http://mbed.org/teams/Nordic-Semiconductor/code/nRF51822/#1751e2e2637a