7 years, 7 months ago.

nrf51 dongle scan and advertise (mbed coding)

Hi ,

I have 2 nrf51 dongle compiled with a code which can scan and advertise ibeacon constantly. Whenever receive advertisement packet from each other , they are able to print out the uuid,major,minor and rssi value of the received packets.

My next task is to advertise out the scanned Rssi (probably highest three in a certain time) and the mac address/uuid of that scanned device. Example, dongle A receive advertisement packet from dongle B , dongleA will then advertise out an advertisement packet that consist of information of the dongleB's Mac address/uuid and the measured Rssi value. Any way i can change the advertisement packet in (mbed coding) to achieve this or any other advice?

Thank you.

1 Answer

7 years, 7 months ago.

It is really simple:

  • clear your advertisement payload by calling Gap::clearAdvertisingPayload.
  • Fill it with your new data by calling: Gap::accumulateAdvertisingPayload.

The data advertised are typed: https://developer.mbed.org/teams/Bluetooth-Low-Energy/code/BLE_API/docs/65474dc93927/classGapAdvertisingData.html#a405dc77179a4a9e1c6ad0a6d252bebae

The type used to advertise non standard things is usually: MANUFACTURER_SPECIFIC_DATA. The first two bytes of the payload should be the one of your manufacturer ID.

Hi ,

Sorry I'm new to mbed coding. Below is my code, can you help on this ? Thank you.

  1. include "mbed.h"
  2. include "BLE.h"
  3. include "iBeaconScan.h"
  4. include "ble/services/iBeacon.h"

DigitalOut led1(LED1); union unionType u;

const uint8_t PeerAddr[] = {0x0b, 0xc1, 0x90, 0xc4, 0x12, 0xed}; const uint8_t uuid[] = {0x33, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22};

uint16_t majorNumber = 2233; uint16_t minorNumber = 3344; uint16_t txPower = 0xC8;

BLE ble;

void bleInitComplete(BLE::InitializationCompleteCallbackContext *params) { BLE &ble = params->ble; ble_error_t error = params->error;

if (error != BLE_ERROR_NONE) { return; }

iBeacon *ibeacon = new iBeacon(ble, uuid, majorNumber, minorNumber, txPower);

ble.setAdvertisingType(GapAdvertisingParams::ADV_CONNECTABLE_UNDIRECTED); added ble.gap().setAdvertisingInterval(20); /* 1000ms. */ /*300 changed to 100*/ /*100 change to 20*/ }

void AdvertisementReportCallback(const Gap::AdvertisementCallbackParams_t *params) { led1 = !led1; uint8_t i; uint8_t j = 0;

memset(u.rawData, 0 , sizeof(u.rawData)); memcpy(u.rawData, params->advertisingData,params->advertisingDataLen);

for( i = 0; i < 6; i++) { if ((params->peerAddr[i]) == PeerAddr[i]) { j++; } else { return; } }

if (j == 6) { printf("bluetooth address match \r\n"); j =0; } else { printf("wrong bluetooth address \r\n"); j = 0; }

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); printf("\r\n");

}

static void adv_scan_start(void) { iBeaconStartScan(); ble.gap().startAdvertising(); }

int main(void) { ble.init(bleInitComplete); while (!ble.hasInitialized()) { /* spin loop */ }

iBeaconInit(); adv_scan_start(); while(1) {

} }

posted by jinchau ng 23 Sep 2016