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_PIR_BEACON by
Revision 3:4d6652dc7b43, committed 2016-09-12
- Comitter:
- wenhuanglin
- Date:
- Mon Sep 12 15:58:36 2016 +0000
- Parent:
- 2:b8632b29304e
- Commit message:
- comment out unnecessary
Changed in this revision
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Fri Sep 09 10:01:48 2016 +0000
+++ b/main.cpp Mon Sep 12 15:58:36 2016 +0000
@@ -1,19 +1,4 @@
-/* mbed Microcontroller Library
- * Copyright (c) 2006-2015 ARM Limited
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
+
#include "mbed.h"
#include "ble/BLE.h"
@@ -27,7 +12,7 @@
const static char DEVICE_NAME[] = "BLEBEACON";
/* You have up to 26 bytes of advertising data to use. */
-uint8_t AdvData[] = {0x01,0x02,0x00,0x04,0x12}; /* Example of hex data */
+uint8_t AdvData[] = {0x01,0x02,0x03,0x04,0x00}; /* Example of hex data */
const uint8_t SERVICE_UUID[] = {0xAA, 0xFE};
@@ -37,15 +22,12 @@
AdvertisementPacketHandler(BLE&);
void updatePIRValue(){
- AdvData[1] = pir_signal_pin;
-
+ AdvData[4] = pir_signal_pin;
ble.gap().clearAdvertisingPayload();
ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::BREDR_NOT_SUPPORTED | GapAdvertisingData::LE_GENERAL_DISCOVERABLE);
ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LIST_16BIT_SERVICE_IDS, SERVICE_UUID, sizeof(SERVICE_UUID));
ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::SERVICE_DATA, AdvData, sizeof(AdvData) );
ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LOCAL_NAME, (uint8_t *)DEVICE_NAME, sizeof(DEVICE_NAME));
- ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::BREDR_NOT_SUPPORTED | GapAdvertisingData::LE_GENERAL_DISCOVERABLE );
- ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::MANUFACTURER_SPECIFIC_DATA, AdvData, sizeof(AdvData));
};
private:
BLE &ble;
@@ -90,25 +72,11 @@
/* Set device name characteristic data */
ble.gap().setDeviceName((const uint8_t *) DEVICE_NAME);
- /* Configure advertisements */
- //ble.gap().setTxPower(radioPowerLevels[txPowerMode]);
ble.gap().setAdvertisingType(GapAdvertisingParams::ADV_NON_CONNECTABLE_UNDIRECTED);
- /* Set advertising interval. Longer interval == longer battery life */
+
ble.gap().setAdvertisingInterval(1000); /* 1000ms */
- //ble.gap().onRadioNotification(this, &EddystoneService::radioNotificationCallback);
- //ble.gap().initRadioNotification();
+
- /* Sacrifice 3B of 31B to Advertising Flags */
- ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::BREDR_NOT_SUPPORTED | GapAdvertisingData::LE_GENERAL_DISCOVERABLE );
-
- /* Sacrifice 2B of 31B to AdvType overhead, rest goes to AdvData array you define */
- ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::MANUFACTURER_SPECIFIC_DATA, AdvData, sizeof(AdvData));
-
- /* Optional: Add name to device */
- ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LOCAL_NAME, (uint8_t *)DEVICE_NAME, sizeof(DEVICE_NAME));
- ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LIST_16BIT_SERVICE_IDS, SERVICE_UUID, sizeof(SERVICE_UUID));
- ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::SERVICE_DATA, AdvData, sizeof(AdvData) );
-
/* Start advertising */
ble.gap().startAdvertising();
}
