BLE Observer example for nucleo platform
Dependencies: BLE_API X_NUCLEO_IDB0XA1 mbed
Diff: main.cpp
- Revision:
- 4:2aefa62bdce5
- Parent:
- 3:37a2f13b746d
- Child:
- 5:346bcd62f251
diff -r 37a2f13b746d -r 2aefa62bdce5 main.cpp --- a/main.cpp Fri Nov 11 21:37:44 2016 +0000 +++ b/main.cpp Mon Nov 14 10:20:45 2016 +0000 @@ -24,6 +24,8 @@ // Change your device name below const char DEVICE_NAME[] = "Nucleo_test"; +// Control Beacon read +static int beacon = 0; void periodicCallback(void) { led1 = !led1; /* Do blinky on LED1 while we're waiting for BLE events */ @@ -37,7 +39,9 @@ printf("Beacon_1: [%02x %02x %02x %02x %02x %02x] rssi %d\r\n", params->peerAddr[5], params->peerAddr[4], params->peerAddr[3], params->peerAddr[2], params->peerAddr[1], params->peerAddr[0], - params->rssi); + params->rssi); + + beacon = 1; } } @@ -46,7 +50,9 @@ if (abs(params->rssi) <= 60) { // Beacon 2 necessita di una soglia di vicinanza più alta printf("Beacon_2: [%02x %02x %02x %02x %02x %02x] rssi %d\r\n", params->peerAddr[5], params->peerAddr[4], params->peerAddr[3], params->peerAddr[2], params->peerAddr[1], params->peerAddr[0], - params->rssi); + params->rssi); + + beacon = 2; } } @@ -56,6 +62,8 @@ printf("Beacon_3: [%02x %02x %02x %02x %02x %02x] rssi %d\r\n", params->peerAddr[5], params->peerAddr[4], params->peerAddr[3], params->peerAddr[2], params->peerAddr[1], params->peerAddr[0], params->rssi); + + beacon = 3; } } @@ -81,8 +89,7 @@ ble.gap().onDisconnection(disconnectionCallback); // The Service Data data type consists of a service UUID with the data associated with that service. - // We will encode the number of button clicks in the Service Data field - // First two bytes of SERVICE_DATA field should contain the UUID of the service + // We will encode the number of beacon received //uint8_t service_data[3]; //service_data[0] = MajorID & 0xff; //service_data[1] = MinorID & 0xff; @@ -108,6 +115,8 @@ ble_Scan.gap().setScanParams(100 /* scan interval */, 50 /* scan window */, 1); } + +//extern "C" void mbed_reset(); int main(void) @@ -126,7 +135,7 @@ //ble_Scan.gap().startScan(advertisementCallback); //ble.gap().startAdvertising(); -int stato = 0; +int stato = 1; /* Infinite loop waiting for BLE events */ while (true) { @@ -141,6 +150,7 @@ ble.gap().stopAdvertising(); wait(1); stato = 1; + NVIC_SystemReset(); break; case(1): //BLE &ble_Scan = BLE::Instance(); @@ -152,6 +162,7 @@ wait(5); //ble_Scan.gap().stopScan(); stato = 0; + break; }