BLE Chat with Serial
Dependencies: LinkNode_SimpleChat mbed nRF51822
Fork of nRF51822_SimpleChat by
Revision 3:17f2d639f37b, committed 2016-04-13
- Comitter:
- helloqi
- Date:
- Wed Apr 13 12:45:39 2016 +0000
- Parent:
- 2:4b66b69c7ecb
- Commit message:
- 8? BLE Chat with Serial
Changed in this revision
BLE_API.lib | Show annotated file Show diff for this revision Revisions of this file |
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
diff -r 4b66b69c7ecb -r 17f2d639f37b BLE_API.lib --- a/BLE_API.lib Mon Jul 27 06:52:44 2015 +0000 +++ b/BLE_API.lib Wed Apr 13 12:45:39 2016 +0000 @@ -1,1 +1,1 @@ -http://mbed.org/teams/Bluetooth-Low-Energy/code/BLE_API/#4cd3b18607ec +https://developer.mbed.org/users/helloqi/code/LinkNode_SimpleChat/#e4628f8f4b1d
diff -r 4b66b69c7ecb -r 17f2d639f37b main.cpp --- a/main.cpp Mon Jul 27 06:52:44 2015 +0000 +++ b/main.cpp Wed Apr 13 12:45:39 2016 +0000 @@ -36,8 +36,9 @@ BLE ble; -Serial pc(USBTX, USBRX); - +Serial pc(P0_23,P0_25); +DigitalOut LED_G(P0_19); +DigitalOut LED_R(P0_20); // The Nordic UART Service static const uint8_t uart_base_uuid[] = {0x71, 0x3D, 0, 0, 0x50, 0x3E, 0x4C, 0x75, 0xBA, 0x94, 0x31, 0x48, 0xF1, 0x8D, 0x94, 0x1E}; @@ -45,7 +46,6 @@ static const uint8_t uart_rx_uuid[] = {0x71, 0x3D, 0, 2, 0x50, 0x3E, 0x4C, 0x75, 0xBA, 0x94, 0x31, 0x48, 0xF1, 0x8D, 0x94, 0x1E}; static const uint8_t uart_base_uuid_rev[] = {0x1E, 0x94, 0x8D, 0xF1, 0x48, 0x31, 0x94, 0xBA, 0x75, 0x4C, 0x3E, 0x50, 0, 0, 0x3D, 0x71}; - uint8_t txPayload[TXRX_BUF_LEN] = {0,}; uint8_t rxPayload[TXRX_BUF_LEN] = {0,}; @@ -67,7 +67,7 @@ { pc.printf("Disconnected \r\n"); pc.printf("Restart advertising \r\n"); - ble.startAdvertising(); + ble.startAdvertising(); } void WrittenHandler(const GattWriteCallbackParams *Handler) @@ -80,14 +80,9 @@ ble.readCharacteristicValue(txCharacteristic.getValueAttribute().getHandle(), buf, &bytesRead); memset(txPayload, 0, TXRX_BUF_LEN); memcpy(txPayload, buf, TXRX_BUF_LEN); - pc.printf("WriteHandler \r\n"); - pc.printf("Length: "); - pc.putc(bytesRead); - pc.printf("\r\n"); - pc.printf("Data: "); for(index=0; index<bytesRead; index++) { - pc.putc(txPayload[index]); + pc.putc(txPayload[index]); } pc.printf("\r\n"); } @@ -101,9 +96,6 @@ if(rx_len>=20 || rx_buf[rx_len-1]=='\0' || rx_buf[rx_len-1]=='\n') { ble.updateCharacteristicValue(rxCharacteristic.getValueAttribute().getHandle(), rx_buf, rx_len); - pc.printf("RecHandler \r\n"); - pc.printf("Length: "); - pc.putc(rx_len); pc.printf("\r\n"); rx_len = 0; break; @@ -121,14 +113,13 @@ pc.printf("SimpleChat Init \r\n"); pc.attach( uartCB , pc.RxIrq); - // setup advertising ble.accumulateAdvertisingPayload(GapAdvertisingData::BREDR_NOT_SUPPORTED); ble.setAdvertisingType(GapAdvertisingParams::ADV_CONNECTABLE_UNDIRECTED); ble.accumulateAdvertisingPayload(GapAdvertisingData::SHORTENED_LOCAL_NAME, (const uint8_t *)"Biscuit", sizeof("Biscuit") - 1); ble.accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LIST_128BIT_SERVICE_IDS, (const uint8_t *)uart_base_uuid_rev, sizeof(uart_base_uuid)); - // 100ms; in multiples of 0.625ms. + // 100ms; in multiples of 0.625ms. ble.setAdvertisingInterval(160); ble.addService(uartService); @@ -136,6 +127,9 @@ ble.startAdvertising(); pc.printf("Advertising Start \r\n"); + LED_R=0; + LED_G=0; + while(1) { ble.waitForEvent();