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

Create BLE Beacon #5

Open
sialalex opened this issue Feb 11, 2022 · 6 comments
Open

Create BLE Beacon #5

sialalex opened this issue Feb 11, 2022 · 6 comments

Comments

@sialalex
Copy link

sialalex commented Feb 11, 2022

Is there a way to advertise a BLE Beacon with this lib? @Emill

Thanks in advance!

@Emill
Copy link
Owner

Emill commented Feb 15, 2022

Sure.

If you follow the peripheral example at the readme page, modify the part that uses the AdvertisingDataBuilder to create advertising data that matches your desired beacon format. See https://github.com/Emill/node-ble-host/blob/master/docs/api/advertising-data-builder.md for documentation.

If you do not want your device to be connectable (i.e. it should only advertise), you can add advertisingType: 'ADV_NONCONN_IND' or advertisingType: 'ADV_SCAN_IND' to the advertising options, depending on if you need scan response data or not.

@sialalex
Copy link
Author

OK - thank you!

Do you have an example for an beacon? It is not important which type (iBeacon, AltBeacon,...)

@sialalex
Copy link
Author

I try to create something like that, but I am not able to create it!

image

@Emill
Copy link
Owner

Emill commented Feb 18, 2022

Could you post a screenshot of what pops up when you press RAW?

@sialalex
Copy link
Author

So here is the beacon i actually need - with the raw data!

MicrosoftTeams-image (3)
MicrosoftTeams-image (4)
MicrosoftTeams-image (2)

@Emill
Copy link
Owner

Emill commented Feb 18, 2022

I think this code should work to replicate that beacon, by modifying "Full GATT Server Example (Peripheral)" accordingly:

const advDataBuffer = new AdvertisingDataBuilder()
                        .addFlags(['leGeneralDiscoverableMode', 'brEdrNotSupported'])
                        .addManufacturerData(0x004C, Buffer.from([ // Apple's manufacturer ID is 0x004C
                            0x02, // Type: Beacon
                            0x15, // Length of following data: 21
                            0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, // UUID
                            0x11, 0x22, // Major
                            0x33, 0x44, // Minor
                            0x100-77])); // RSSI at 1m
                        .build();
manager.setAdvertisingData(advDataBuffer);

const scanRspDataBuffer = new AdvertisingDataBuilder()
                        .addLocalName(/*isComplete*/ true, deviceName)
                        .build();
manager.setScanResponseData(scanRspDataBuffer);

startAdv();

function startAdv() {
    manager.startAdvertising({advertisingType: 'ADV_SCAN_IND'}, connectCallback); // Make it non-connectable
}

Note that that RSSI value should be updated to match the TX power of your Bluetooth controller.

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

No branches or pull requests

2 participants