BLE Observer example for nucleo platform
Dependencies: BLE_API X_NUCLEO_IDB0XA1 mbed
Diff: main.cpp
- Revision:
- 1:6ec60260b682
- Parent:
- 0:39b311448c9e
- Child:
- 2:b34944e028f9
diff -r 39b311448c9e -r 6ec60260b682 main.cpp --- a/main.cpp Fri Dec 04 12:48:00 2015 +0000 +++ b/main.cpp Wed Nov 09 12:49:37 2016 +0000 @@ -13,43 +13,61 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - + #include "mbed.h" #include "BLE.h" - + BLE ble; DigitalOut led1(LED1); - + void periodicCallback(void) { led1 = !led1; /* Do blinky on LED1 while we're waiting for BLE events */ } - + void advertisementCallback(const Gap::AdvertisementCallbackParams_t *params) { - + 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); + + unsigned index; + #if DUMP_ADV_DATA - for (unsigned index = 0; index < params->advertisingDataLen; index++) { + + for (index = 0; index < params->advertisingDataLen; index++) { printf("%02x ", params->advertisingData[index]); } printf("\r\n"); + #endif /* DUMP_ADV_DATA */ + + // RSSI info + + printf("\nRSSI = %d", params -> rssi); + + + // TxPower info + uint16_t txpower; + txpower = params -> advertisingData[index-1]; + printf(" TxPower = %u \n\r", txpower); + + // Elaborate distance + } - + int main(void) { led1 = 1; Ticker ticker; ticker.attach(periodicCallback, 1); - + ble.init(); - + ble.gap().setScanParams(500 /* scan interval */, 200 /* scan window */); ble.gap().startScan(advertisementCallback); - + while (true) { ble.waitForEvent(); } -} +} \ No newline at end of file