iBeacon implementation

Hi,
I'm trying to implement iBeacon functionality and am not sure if I'm doing this properly. Since there is no longer an iOS sample and we need to use the wrapped C++ api, I'm not sure if I'm setting the uuid properly. Please have a look at my code snippet below. Any help would be appreciated. the variable "device" is a MetaWear object.

To disconnect from the board, do I call mbl_mw_debug_disconnect or device.cancelConnection()?

=========================================
var uuid = device.peripheral.identifier.uuid
withUnsafeMutableBytes(of: &uuid) {
rawPointer in
let typedPointer = rawPointer.baseAddress!.assumingMemoryBound(to: UInt8.self)
uuid_generate(typedPointer)
mbl_mw_ibeacon_set_uuid(device.board, typedPointer)
}

        mbl_mw_ibeacon_set_major(device.board, 1)             
         mbl_mw_ibeacon_set_minor(device.board, 1)
         mbl_mw_ibeacon_set_rx_power(device.board, -55)
         mbl_mw_ibeacon_set_tx_power(device.board, -12)
         mbl_mw_ibeacon_set_period(device.board, 240)
         mbl_mw_ibeacon_enable(device.board)

Comments

  • Is there nobody that has implemented iBeacon on iOS using the latest SDK? I have to say that the latest SDK has pretty thin documentation on iOS. the documentation was much better on previous SDK version. Any help from anyone would be appreciated. Thanks

  • @mlin34
    We are working on updating the documentation. It should be updated by next week.

  • Great to hear. In the meantime is there any guidance you can provide with my question above?

  • I put up example code for you, find it here: https://github.com/mbientlab/MetaWear-SDK-iOS-macOS-tvOS/tree/master/MetaWearApiTest

    Don't forget that once you setup iBeacon mode, you have to disconnect from the board so that it starts "beaconing"

  • Thanks I will have a look. At first glance the example just enabled and disables the board for iBeacon and doesn't set any of the parameters I mention above. As it's a C++ API, I'm not sure if I'm passing raw pointers in properly (as per the snippet on my original post). ****Also, to disconnect from the board, do I call mbl_mw_debug_disconnect or device.cancelConnection()? it's not clear on the documentation. Thanks in advance****

  • Please read our tutorials.

  • @Laura said:
    I put up example code for you, find it here: https://github.com/mbientlab/MetaWear-SDK-iOS-macOS-tvOS/tree/master/MetaWearApiTest

    Don't forget that once you setup iBeacon mode, you have to disconnect from the board so that it starts "beaconing"

    Hi Laura,
    The sample code doesn't show how to set the other iBeacon parameters. As per the comment, it's a "To do" task (code snippet from your sample below).
    Do you have a sample on how to set the uuid? This is the first issue I had posted in this forum. the iOS CLBeaconRegion call the uuid. Thanks in advance for your help.

    ===========
    @IBAction func startiBeaconPressed(_ sender: Any) {
    // TODO: Expose the other iBeacon parameters
    mbl_mw_ibeacon_enable(device.board)
    }

  • What other items are you looking for?

  • @Laura said:
    What other items are you looking for?

    Setting the uuid. Since what you provide is a wrapper for a C++ API, if you can provide a Swift example of how the parameter can be passed in as a pointer it would help. The signature of the C++ API is below. I'm looking for an example in Swift on how the UUID parameter is passed into this. Thanks.

    void mbl_mw_ibeacon_set_uuid(const MblMwMetaWearBoard *board, uint8_t ad_uuid[16]) {
    SET_PARAM_NBYTES(IBEACON_UUID, ad_uuid, 16);
    }

  • edited February 24

    You should be able to use the C++ calls directly. Most of the swift calls are just wrappers around the C++ (just take a look at the code).

    ...unless the C++ functions aren't exposed at all in the swift bridge...
    Let me know. I haven't checked.

    If they aren't exposed you will need to make a pull or change request (ideally a pull if you can code this yourself).

Sign In or Register to comment.