BLE_DEMO_SPI_HARDCODE

Dependencies:   BLE_API mbed nRF51822

Fork of BLE_Central_Light_Demo_23 by HM_IOT_Demo

Files at this revision

API Documentation at this revision

Comitter:
mbed_tw_hoehoe
Date:
Sat Nov 21 11:13:58 2015 +0000
Child:
1:2f1203d70643
Commit message:
BLE Central Test

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
mbed.bld Show annotated file Show diff for this revision Revisions of this file
nRF51822.lib Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/BLE_API.lib	Sat Nov 21 11:13:58 2015 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/teams/Bluetooth-Low-Energy/code/BLE_API/#40734dc71284
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Sat Nov 21 11:13:58 2015 +0000
@@ -0,0 +1,76 @@
+#include "mbed.h"
+#include "ble/BLE.h"
+#include "ble/DiscoveredCharacteristic.h"
+#include "ble/DiscoveredService.h"
+
+BLE ble;
+
+const uint8_t MPU6050_service_uuid[] = {
+    0x45,0x35,0x56,0x80,0x0F,0xD8,0x5F,0xB5,0x51,0x48,0x30,0x27,0x06,0x9B,0x3F,0xD9
+};
+
+const uint8_t MPU6050_Accel_Characteristic_uuid[] = {
+    0x45,0x35,0x56,0x81,0x0F,0xD8,0x5F,0xB5,0x51,0x48,0x30,0x27,0x06,0x9B,0x3F,0xD9
+};
+
+
+UUID serviceUUID(MPU6050_service_uuid);
+UUID accelUUID(MPU6050_Accel_Characteristic_uuid);
+
+
+void scanCallback(const Gap::AdvertisementCallbackParams_t *params) {
+    printf("adv peerAddr[%02x %02x %02x %02x %02x %02x] rssi %d, isScanResponse %u, AdvertisementType %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);
+    
+    ble.stopScan();
+    ble.connect(params->peerAddr, Gap::ADDR_TYPE_RANDOM_STATIC, NULL, NULL);
+}
+
+void serviceDiscoveryCallback(const DiscoveredService *service) {
+    printf("service found...\r\n");    
+}
+
+void characteristicDiscoveryCallback(const DiscoveredCharacteristic *characteristicP) {
+    printf("characteristicDiscoveryCallback\r\n");
+    ble.gattClient().read(characteristicP->getConnHandle(), characteristicP->getValueHandle(), 0);
+}
+
+void connectionCallback(const Gap::ConnectionCallbackParams_t *params) {
+    printf("GAP_EVT_CONNECTED");
+    ble.gattClient().launchServiceDiscovery(params->handle, serviceDiscoveryCallback, characteristicDiscoveryCallback, serviceUUID, accelUUID);
+}
+
+void discoveryTerminationCallback(Gap::Handle_t connectionHandle) {
+    printf("terminated SD for handle %u\r\n", connectionHandle);
+}
+
+void triggerRead(const GattReadCallbackParams *response) {
+    printf("triggerRead.....");
+    for(int i=0; i < response->len; i++){
+        printf("data %x", response->data[i]);  
+    }
+    printf("\r\n");
+}
+
+void disconnectionCallback(const Gap::DisconnectionCallbackParams_t *params){//(Gap::Handle_t handle, Gap::DisconnectionReason_t reason) {
+    printf("disconnected\r\n");
+}
+
+int main(void) {
+    wait(8.0);
+    printf("start\r\n");
+
+    ble.init();
+    ble.onConnection(connectionCallback);
+    ble.onDisconnection(disconnectionCallback);
+    ble.gattClient().onServiceDiscoveryTermination(discoveryTerminationCallback);
+    ble.gattClient().onDataRead(triggerRead);
+    //ble.gattClient().onDataWrite(triggerToggledWrite);
+
+    ble.gap().setScanParams(500, 400);
+    ble.gap().startScan(scanCallback);
+
+    while (true) {
+    }
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Sat Nov 21 11:13:58 2015 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/4f6c30876dfa
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/nRF51822.lib	Sat Nov 21 11:13:58 2015 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/teams/Nordic-Semiconductor/code/nRF51822/#bf85bf7e73d5