Connect the BLE_UART Console to a PC USB/Serial Console. Data written to PC console is sent over BLE UART Data received from BLE UART is displayed in PC console
Dependencies: BLE_API mbed nRF51822
Fork of BLE_LED_Controller by
Revision 18:5f8cd32ff343, committed 2015-02-13
- Comitter:
- tumaku
- Date:
- Fri Feb 13 16:33:42 2015 +0000
- Parent:
- 17:4aa151182398
- Commit message:
- UPdated with comments
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
diff -r 4aa151182398 -r 5f8cd32ff343 main.cpp --- a/main.cpp Fri Feb 13 16:05:26 2015 +0000 +++ b/main.cpp Fri Feb 13 16:33:42 2015 +0000 @@ -13,6 +13,10 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + +//This simple program bridges the BLE UART service to the PC Serial conection available over USB +// Based on the work of team UCL-IoT for BLE_UART_LEDCOntrol +// https://developer.mbed.org/teams/UCL-IoT/code/BLE_UART_LEDControl_Echo/ #include "mbed.h" #include "BLEDevice.h" @@ -28,7 +32,7 @@ #define DEBUG(...) /* nothing */ #endif /* #if NEED_CONSOLE_OUTPUT */ -Serial pcUart(USBTX, USBRX); // tx, rx +Serial pcUart(USBTX, USBRX); // tx, rx Still required to read data coming from the PC BLEDevice ble; // Create Bluetooth object @@ -41,6 +45,7 @@ DEBUG("Restarting the advertising process\n\r"); ble.startAdvertising(); } + /* BLE UART data received callback */ void onDataWritten(const GattCharacteristicWriteCBParams *params) { @@ -48,17 +53,16 @@ uint16_t bytesRead = params->len; DEBUG("received %u bytes\n\r", bytesRead); DEBUG("Received string: '"); + //Note the size of data expands to the largest string received. Need to use bytesRead to resize. for (int i=0;i<bytesRead; i++) { DEBUG("%c",params->data[i]); } - //DEBUG((const char *)params->data); //Note the size of data expands to the largest string received. Need to use bytesRead to resize. - DEBUG("'\n\r"); - + DEBUG("'\n\r"); // ble.updateCharacteristicValue(uartServicePtr->getRXCharacteristicHandle(), params->data,bytesRead); // Echo received characters back over BLE } } -/* Periodic Ticker callback */ +/* pcUART read callback */ void rxInterrupt(void) { while (pcUart.readable()) { @@ -74,7 +78,7 @@ int main(void) { - pcUart.attach(&rxInterrupt,Serial::RxIrq); + pcUart.attach(&rxInterrupt,Serial::RxIrq); //interrupt for incoming data available from PC connection DEBUG("Initialising the nRF51822\n\r"); ble.init();