Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS + nRF51822 = iBeacon?

I have a few nRF51822 sensors lying around and I would like to start playing with iOS iBeacon setup. The issues that I'm running into is in order to do

- (id)initWithProximityUUID:(NSUUID *)proximityUUID identifier:(NSString *)identifier;

you need to know the sensors proximityUUID. Looking at the CLBeacon docs it seems this is a read only attribute of the sensor, but how / where do I read this from the

- (void)centralManager:(CBCentralManager *)central didDiscoverPeripheral:(CBPeripheral *)peripheral advertisementData:(NSDictionary *)advertisementData RSSI:(NSNumber *)RSSI

and I'm seeing kCBAdvDataServiceUUID with a single string of 2500, but I don't think that's it. Anyone have any direction or insight?

Thanks

like image 349
user2812463 Avatar asked Sep 24 '13 19:09

user2812463


2 Answers

You may also have use in looking at this code snippet, first shared on Nordic's own Q&A site:

typedef __packed struct
{
    uint16_t unknown1;
    uint8_t uuid[16];
    uint16_t major;
    uint16_t minor;
    uint8_t unknown2;
} clbeacon_info_t;
...
static void advertising_init(void)
{
    uint32_t      err_code;
    uint8_t       flags = BLE_GAP_ADV_FLAG_BR_EDR_NOT_SUPPORTED;
    ble_advdata_t advdata;

    uint8_t uuid[16] = {0x01, 0x12, 0x23, 0x34, 0x45, 0x56, 0x67, 0x78, 0x89, 0x9a, 0xab, 0xbc, 0xcd, 0xde, 0xef, 0xf0};

    clbeacon_info_t beacon_info;
    beacon_info.unknown1 = 0x1502;
    memcpy(&beacon_info.uuid, &uuid, sizeof(uuid));
    beacon_info.major = 0x3412;
    beacon_info.minor = 0x7798;
    beacon_info.unknown2 = 0xC5;

    ble_advdata_manuf_data_t manuf_specific_data;
    manuf_specific_data.company_identifier = 0x004C;
    manuf_specific_data.data.p_data        = (uint8_t *) &beacon_info;
    manuf_specific_data.data.size          = sizeof(beacon_info);

    // Build and set advertising data
    memset(&advdata, 0, sizeof(advdata));

    advdata.name_type               = BLE_ADVDATA_NO_NAME;
    advdata.flags.size              = sizeof(flags);
    advdata.flags.p_data            = &flags;
    advdata.p_manuf_specific_data   = &manuf_specific_data;

    err_code = ble_advdata_set(&advdata, NULL);
    APP_ERROR_CHECK(err_code);
}


/**@brief Start advertising.
 */
static void advertising_start(void)
{
    uint32_t             err_code;
    ble_gap_adv_params_t adv_params;

    // Start advertising
    memset(&adv_params, 0, sizeof(adv_params));

    adv_params.type        = BLE_GAP_ADV_TYPE_ADV_NONCONN_IND;
    adv_params.p_peer_addr = NULL;
    adv_params.fp          = BLE_GAP_ADV_FP_ANY;
    adv_params.interval    = APP_ADV_INTERVAL;
    adv_params.timeout     = APP_ADV_TIMEOUT_IN_SECONDS;

    err_code = sd_ble_gap_adv_start(&adv_params);
    APP_ERROR_CHECK(err_code);
    nrf_gpio_pin_set(ADVERTISING_LED_PIN_NO);
}

...
like image 147
hlnd Avatar answered Nov 18 '22 18:11

hlnd


The UUID has to be set in the Advertisement Data of the BLE Device Here is a blog post describing the reverse engineering of the Advertising Package. With this format you can make a firmware for your BLE sensors that is recognized as an iBeacon by iOS.

Once you have a working Beacon Hardware of which you know the UUID you can look for it with - (void)startMonitoringForRegion:(CLRegion *)region of the CLLocationManager

like image 2
Jonas_W Avatar answered Nov 18 '22 19:11

Jonas_W