Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: BLE_API mbed nRF51822
Fork of BLE_Observer by
Revision 6:af32aad52c44, committed 2015-08-17
- Comitter:
- DDUdui
- Date:
- Mon Aug 17 09:47:40 2015 +0000
- Parent:
- 5:103717ce54e5
- Commit message:
- test2
;
Changed in this revision
diff -r 103717ce54e5 -r af32aad52c44 BLE_API.lib --- a/BLE_API.lib Sat Jun 20 23:40:04 2015 +0000 +++ b/BLE_API.lib Mon Aug 17 09:47:40 2015 +0000 @@ -1,1 +1,1 @@ -http://mbed.org/teams/Bluetooth-Low-Energy/code/BLE_API/#9f4251b3355c +http://mbed.org/teams/Bluetooth-Low-Energy/code/BLE_API/#8d316a3271a8
diff -r 103717ce54e5 -r af32aad52c44 main.cpp
--- a/main.cpp Sat Jun 20 23:40:04 2015 +0000
+++ b/main.cpp Mon Aug 17 09:47:40 2015 +0000
@@ -15,10 +15,15 @@
*/
#include "mbed.h"
-#include "BLE.h"
-
+#include "ble/BLE.h"
+#include "ble/DiscoveredCharacteristic.h"
+#include "ble/DiscoveredService.h"
BLE ble;
DigitalOut led1(LED1);
+DigitalOut led2(P0_28);
+DigitalOut led3(P0_29);
+Serial pc(USBTX, USBRX);
+
void periodicCallback(void)
{
@@ -26,29 +31,96 @@
}
void advertisementCallback(const Gap::AdvertisementCallbackParams_t *params) {
-
- printf("Adv peerAddr: [%02x %02x %02x %02x %02x %02x] rssi %d, ScanResp: %u, AdvType: %u\r\n",
+ if (params->peerAddr[0] == 0xcb) { /* !ALERT! Alter this filter to suit your device. */
+ return;
+ }
+ pc.printf("Adv peerAddr: [%02x %02x %02x %02x %02x %02x] rssi %d, ScanResp: %u, AdvType: %u\r\n",
params->peerAddr[5], params->peerAddr[4], params->peerAddr[3], params->peerAddr[2], params->peerAddr[1], params->peerAddr[0],
params->rssi, params->isScanResponse, params->type);
-#if DUMP_ADV_DATA
+/*
for (unsigned index = 0; index < params->advertisingDataLen; index++) {
- printf("%02x ", params->advertisingData[index]);
+ pc.printf("%02x ", params->advertisingData[index]);
+ }
+ pc.printf("\r\n");
+ /* DUMP_ADV_DATA */
+
+ ble.gap().connect(params->peerAddr, Gap::ADDR_TYPE_RANDOM_STATIC, NULL, NULL);
+
+}
+
+void serviceDiscoveryCallback(const DiscoveredService *service) {
+ if (service->getUUID().shortOrLong() == UUID::UUID_TYPE_SHORT) {
+ pc.printf("S UUID-%x attrs[%u %u]\r\n", service->getUUID().getShortUUID(), service->getStartHandle(), service->getEndHandle());
+ } else {
+ printf("S UUID-");
+ const uint8_t *longUUIDBytes = service->getUUID().getBaseUUID();
+ for (unsigned i = 0; i < UUID::LENGTH_OF_LONG_UUID; i++) {
+ printf("%02x", longUUIDBytes[i]);
+ }
+ pc.printf(" attrs[%u %u]\r\n", service->getStartHandle(), service->getEndHandle());
}
- printf("\r\n");
-#endif /* DUMP_ADV_DATA */
+}
+
+void characteristicDiscoveryCallback(const DiscoveredCharacteristic *characteristicP) {
+
+}
+
+void discoveryTerminationCallback(Gap::Handle_t connectionHandle) {
+ pc.printf("terminated SD for handle %u\r\n", connectionHandle);
}
+
+void connectionCallback(const Gap::ConnectionCallbackParams_t *params) {
+ pc.printf("Connected!!\r\n");
+ led2=0;
+ led3=1;
+ ble.stopAdvertising();
+ wait(3);
+ if (params->role == Gap::CENTRAL) {
+ ble.gattClient().onServiceDiscoveryTermination(discoveryTerminationCallback);
+ ble.gattClient().launchServiceDiscovery(params->handle, serviceDiscoveryCallback, characteristicDiscoveryCallback, 0xa000, 0xa001);
+ }/*
+ ble.gap().disconnect(0,Gap::REMOTE_USER_TERMINATED_CONNECTION);
+*/
+}
+void disconnectionCallback(Gap::Handle_t handle, Gap::DisconnectionReason_t reason)
+{
+ pc.printf("Disconnected\r\n");
+ pc.printf("Rescan\r\n");
+ led2=1;
+ led3=0;
+ ble.startScan(advertisementCallback);
+ ble.startAdvertising();
+}
+
int main(void)
{
led1 = 1;
+ led2 = 1;
+ led3 = 0;
Ticker ticker;
ticker.attach(periodicCallback, 1);
+ ble.onConnection(connectionCallback);
+ ble.onDisconnection(disconnectionCallback);
ble.init();
+
+ pc.baud(9600);
+ pc.printf("Observer Init \r\n");
+
+
+ /* */
+ ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::BREDR_NOT_SUPPORTED);
+ ble.gap().setAdvertisingType(GapAdvertisingParams::ADV_CONNECTABLE_UNDIRECTED);
+ ble.accumulateAdvertisingPayload(GapAdvertisingData::SHORTENED_LOCAL_NAME,
+ (const uint8_t *)"RAMO2", sizeof("RAMO2") - 1);
+
+ ble.gap().setAdvertisingInterval(100); /* 1second. */
+ ble.gap().startAdvertising();
ble.gap().setScanParams(500 /* scan interval */, 200 /* scan window */);
ble.gap().startScan(advertisementCallback);
-
+
while (true) {
ble.waitForEvent();
}
diff -r 103717ce54e5 -r af32aad52c44 mbed.bld --- a/mbed.bld Sat Jun 20 23:40:04 2015 +0000 +++ b/mbed.bld Mon Aug 17 09:47:40 2015 +0000 @@ -1,1 +1,1 @@ -http://mbed.org/users/mbed_official/code/mbed/builds/7cff1c4259d7 \ No newline at end of file +http://mbed.org/users/mbed_official/code/mbed/builds/b9ad9a133dc7 \ No newline at end of file
diff -r 103717ce54e5 -r af32aad52c44 nRF51822.lib --- a/nRF51822.lib Sat Jun 20 23:40:04 2015 +0000 +++ b/nRF51822.lib Mon Aug 17 09:47:40 2015 +0000 @@ -1,1 +1,1 @@ -http://mbed.org/teams/Nordic-Semiconductor/code/nRF51822/#7c68c8d67e1f +http://mbed.org/teams/Nordic-Semiconductor/code/nRF51822/#ca9c9c2cfc6a
