iOS + nRF51822 = iBeacon?

时间:2013-09-24 19:01:22

标签: ios bluetooth-lowenergy ibeacon

我有几个nRF51822传感器,我想开始玩iOS iBeacon设置。我遇到的问题是为了做

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

您需要知道传感器proximityUUID。看一下CLBeacon文档,它似乎是传感器的只读属性,但我是如何/从哪里读到的

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

我看到kCBAdvDataServiceUUID的单个字符串为2500,但我不认为是这样。任何人都有任何指导或见解?

由于

3 个答案:

答案 0 :(得分:4)

您也可以查看此代码段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);
}

...

答案 1 :(得分:2)

必须在BLE设备的广告数据中设置UUID Here是一篇描述广告包逆向工程的博客文章。使用此格式,您可以为您的BLE传感器制作一个被iOS识别为iBeacon的固件。

一旦你有一个工作的Beacon硬件,你知道UUID,你可以用- (void)startMonitoringForRegion:(CLRegion *)region的{​​{1}}

查找它

答案 2 :(得分:1)

您使用nRF51822传感器构建的设备将通过iBeacon协议宣传proximityUUID,据我所知,该协议尚未发布。在此之前,玩游戏的最简单方法是使用另一款宣传其存在的iOS设备。 UUID本身就是定义的东西。

This article可以很好地概述您需要做什么。