Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added API for creating iBeacons #28

Merged
merged 1 commit into from
Feb 13, 2015

Conversation

BlackstoneEngineering
Copy link
Contributor

Problem

making iBeacons is really really really hard

The iBeacon example program on the website has code that looks like this:

   /**
     * The Beacon payload (encapsulated within the MSD advertising data structure)
     * has the following composition:
     * 128-Bit UUID = E2 0A 39 F4 73 F5 4B C4 A1 2F 17 D1 AD 07 A9 61
     * Major/Minor  = 0000 / 0000
     * Tx Power     = C8 (-56dB)
     */
    const static uint8_t iBeaconPayload[] = {
        0x4C, 0x00, // Company identifier code (0x004C == Apple)
        0x02,       // ID
        0x15,       // length of the remaining payload
        0xE2, 0x0A, 0x39, 0xF4, 0x73, 0xF5, 0x4B, 0xC4, // location UUID
        0xA1, 0x2F, 0x17, 0xD1, 0xAD, 0x07, 0xA9, 0x61,
        0x00, 0x00, // the major value to differentiate a location
        0x00, 0x00, // the minor value to differentiate a location
        0xC8        // 2's complement of the Tx power (-56dB)
    };

int main(void)
{
    /* Initialize BLE baselayer */
    ble.init();

    /* Set up iBeacon data*/
    ble.accumulateAdvertisingPayload(GapAdvertisingData::BREDR_NOT_SUPPORTED | GapAdvertisingData::LE_GENERAL_DISCOVERABLE );
    ble.accumulateAdvertisingPayload(GapAdvertisingData::MANUFACTURER_SPECIFIC_DATA, iBeaconPayload, sizeof(iBeaconPayload));

    /* Set advertising interval. Longer interval = longer battery life */
    ble.setAdvertisingType(GapAdvertisingParams::ADV_NON_CONNECTABLE_UNDIRECTED);
    ble.setAdvertisingInterval(160); /* 100ms; in multiples of 0.625ms. */
    ble.startAdvertising();

Solution

add this "service" to hide the bullshit and make it easier to use. Now the same code looks like this:

uint8_t uuid[] = {0xE2, 0x0A, 0x39, 0xF4, 0x73, 0xF5, 0x4B, 0xC4,
                  0xA1, 0x2F, 0x17, 0xD1, 0xAD, 0x07, 0xA9, 0x61
                 };
uint16_t majorNumber = 0x1122;
uint16_t minorNumber = 0x3344;
uint16_t txPower = 0xC8;

int main(void)
{
    // Initialize BLE baselayer
    ble.init();

    // Initialize ibeacon
    iBeaconService ibeacon(ble, uuid, majorNumber, minorNumber, txPower);

    // Set advertising time
    ble.setAdvertisingInterval(160); /* 100ms; in multiples of 0.625ms. */
    ble.startAdvertising();

The API exposes the 4 key characteristics required for an iBeacon, the UUID, Major Number, Minor Number, and TxPower level.

@rgrover @jaustin @sg-

I have an update pending and ready for the example code, will push it once this is added to the BLE library and pulled into the website code base.

rgrover added a commit that referenced this pull request Feb 13, 2015
@rgrover rgrover merged commit d375dd7 into ARMmbed:master Feb 13, 2015
@rgrover
Copy link
Contributor

rgrover commented Feb 13, 2015

Updated the iBeacon demo as well.

@BlackstoneEngineering
Copy link
Contributor Author

What did you change on the demo? I thought i had already updated it

@rgrover
Copy link
Contributor

rgrover commented Feb 13, 2015

nothing much. just simplified the initialization of the iBeacon service.

@BlackstoneEngineering
Copy link
Contributor Author

Rohit,

On the demo I see you removed the iBeaconService.h, thats cool, its in the BLE_API/services folder now, groovy.

But please change the example code back to what it was. Having the comments inline in the API call is terribly confusing. They code was explicitly setup with the variables listed out first and then passed into the API for a reason, to make it easy to read and teach with.

@rgrover
Copy link
Contributor

rgrover commented Feb 13, 2015

I'm happy to have the variables back. Could you please do that? Thanks.

@BlackstoneEngineering
Copy link
Contributor Author

done

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants