Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
9 years, 1 month ago.
ibeacon advertise and scan at the same time on nrf51 dongle
Hi , Thanks for your advice. I compiled the code below into nrf51 dongle 1, and pure scan code to nrf51 dongle 2 to check if nrf51 dongle 1 constantly transmitting signal. Transmitting part of nrf51 dongle 1 - nrf51 dongle 2 (with the pure scan code) is able to detect signal from nrf51 dongle 1 for a period of time then stop receiving after that. Scanning part of nrf51 dongle 1 - I tested the nrf51 dongle 1 scan part by tranmistting ibeacon from my phone app, and the nrf51 dongle 1 can receive without any problem on teraterm. Can you help on this?
below is my code :
- include "mbed.h"
- include "BLE.h"
- include "iBeaconScan.h"
- include "ble/services/iBeacon.h"
DigitalOut led1(LED1); union unionType u;
uint8_t RX_Flag = 0; int R_S_S_I;
BLE ble;
void bleInitComplete(BLE::InitializationCompleteCallbackContext *params) { BLE &ble = params->ble; ble_error_t error = params->error;
if (error != BLE_ERROR_NONE) { return; }
const uint8_t uuid[] = {0xE4, 0x0A, 0x39, 0xF4, 0x73, 0xF5, 0x4B, 0xC4, 0xA1, 0x2F, 0x17, 0xD1, 0xAD, 0x07, 0xA9, 0x61}; uint16_t majorNumber = 3344; uint16_t minorNumber = 4455; uint16_t txPower = 0xC8; iBeacon *ibeacon = new iBeacon(ble, uuid, majorNumber, minorNumber, txPower);
ble.gap().setAdvertisingInterval(150); /* 150ms. */
}
void AdvertisementReportCallback(const Gap::AdvertisementCallbackParams_t *params) { led1 = !led1; printf("Advertisement packet received.\r\n"); uint8_t i;
memset(u.rawData, 0 , sizeof(u.rawData)); memcpy(u.rawData, params->advertisingData,params->advertisingDataLen);
printf("uuid:"); for( i = 0; i < 16; i++){ printf("%02x ",u.iBeaconPayload_m.uuid[i]); }
printf("\r\n"); printf("majorNumber:%02x %02x\r\n",u.iBeaconPayload_m.majorNumber[0], u.iBeaconPayload_m.majorNumber[1]); printf("minorNumber:%02x %02x\r\n",u.iBeaconPayload_m.minorNumber[0], u.iBeaconPayload_m.minorNumber[1]); printf("txPower:%d\r\n",u.iBeaconPayload_m.txPower); printf("RSSI:%d\r\n",params->rssi);
}
int main(void) { ble.init(bleInitComplete); while (!ble.hasInitialized()) { /* spin loop */ }
iBeaconInit();
while(1) { ble.gap().startAdvertising(); wait(20); ble.gap().stopAdvertising();
iBeaconStartScan(); wait(130); iBeaconStopScan(); } }
1 Answer
9 years, 1 month ago.
We're missing half your code, but fine. Do you have it working if you do it in one mode? So only scanning or only broadcasting? If yes, then you should almost be there, although you need to stop scanning before broadcasting and vice versa. That can be quick, f.e. broadcast for 20 ms. then scan for 980 ms.
Hi , Thanks for your advice. I compiled the code below into nrf51 dongle 1, and pure scan code to nrf51 dongle 2 to check if nrf51 dongle 1 constantly transmitting signal. Transmitting part of nrf51 dongle 1 - nrf51 dongle 2 (with the pure scan code) is able to detect signal from nrf51 dongle 1 for a period of time then stop receiving after that. Scanning part of nrf51 dongle 1 - I tested the nrf51 dongle 1 scan part by tranmistting ibeacon from my phone app, and the nrf51 dongle 1 can receive without any problem on teraterm. Can you help on this?
- include "mbed.h"
- include "BLE.h"
- include "iBeaconScan.h"
- include "ble/services/iBeacon.h"
Serial pc(TX_PIN_NUMBER, RX_PIN_NUMBER); DigitalOut led1(LED1); union unionType u;
uint8_t RX_Flag = 0; int R_S_S_I;
BLE ble;
void bleInitComplete(BLE::InitializationCompleteCallbackContext *params) { BLE &ble = params->ble; ble_error_t error = params->error;
if (error != BLE_ERROR_NONE) { return; }
/**
- The Beacon payload has the following composition:
- 128-Bit / 16byte UUID = E2 0A 39 F4 73 F5 4B C4 A1 2F 17 D1 AD 07 A9 61
- Major/Minor = 0x1122 / 0x3344
- Tx Power = 0xC8 = 200, 2's compliment is 256-200 = (-56dB)
- Note: please remember to calibrate your beacons TX Power for more accurate results.
- / const uint8_t uuid[] = {0xE4, 0x0A, 0x39, 0xF4, 0x73, 0xF5, 0x4B, 0xC4, 0xA1, 0x2F, 0x17, 0xD1, 0xAD, 0x07, 0xA9, 0x61}; uint16_t majorNumber = 3344; uint16_t minorNumber = 4455; uint16_t txPower = 0xC8; iBeacon *ibeacon = new iBeacon(ble, uuid, majorNumber, minorNumber, txPower);
ble.gap().setAdvertisingInterval(150); /* 150ms. */
}
void AdvertisementReportCallback(const Gap::AdvertisementCallbackParams_t *params) { led1 = !led1; printf("Advertisement packet received.\r\n"); uint8_t i;
memset(u.rawData, 0 , sizeof(u.rawData)); memcpy(u.rawData, params->advertisingData,params->advertisingDataLen);
printf("uuid:"); for( i = 0; i < 16; i++){ printf("%02x ",u.iBeaconPayload_m.uuid[i]); }
printf("\r\n"); printf("majorNumber:%02x %02x\r\n",u.iBeaconPayload_m.majorNumber[0], u.iBeaconPayload_m.majorNumber[1]); printf("minorNumber:%02x %02x\r\n",u.iBeaconPayload_m.minorNumber[0], u.iBeaconPayload_m.minorNumber[1]); printf("txPower:%d\r\n",u.iBeaconPayload_m.txPower); printf("RSSI:%d\r\n",params->rssi);
}
int main(void) { ble.init(bleInitComplete); while (!ble.hasInitialized()) { /* spin loop */ }
iBeaconInit();
while(1) { ble.gap().startAdvertising(); wait(20); ble.gap().stopAdvertising();
iBeaconStartScan(); wait(130); iBeaconStopScan(); } }
posted by 08 Sep 2016