Skip to content

Instantly share code, notes, and snippets.

@janjongboom
Created January 11, 2016 16:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save janjongboom/3e827525865b03d8758d to your computer and use it in GitHub Desktop.
Save janjongboom/3e827525865b03d8758d to your computer and use it in GitHub Desktop.
Broadcasting both Eddystone and a normal BLE package on mbed
#include "mbed-drivers/mbed.h"
#include "minar/minar.h"
#include "core-util/FunctionPointer.h"
#include "ble/BLE.h"
#include "eddystone/EddystoneService.h"
using namespace mbed::util;
// Eddystone URL
static const char defaultUrl[] = "https://control.me";
// Normal Beacon name
static char beaconName[] = "I'm a beacon!";
// Service UUIDs for the beacon
static uint16_t uuid16_list[] = { 0x8765 };
static const PowerLevels_t defaultAdvPowerLevels = {-47, -33, -21, -13};
static const PowerLevels_t radioPowerLevels = {-30, -16, -4, 4};
void disconnectionCallback(const Gap::DisconnectionCallbackParams_t *params)
{
BLE::Instance().gap().startAdvertising(); // restart advertising
}
void onBleInitError(BLE &ble, ble_error_t error)
{
(void)ble;
(void)error;
/* Initialization error handling should go here */
}
void bleInitComplete(BLE::InitializationCompleteCallbackContext *params)
{
BLE& ble = params->ble;
ble_error_t error = params->error;
if (error != BLE_ERROR_NONE) {
onBleInitError(ble, error);
return;
}
if (ble.getInstanceID() != BLE::DEFAULT_INSTANCE) {
return;
}
ble.gap().onDisconnection(disconnectionCallback);
// Set up Eddystone
auto eddyServicePtr = new EddystoneService(ble, defaultAdvPowerLevels, radioPowerLevels, 0);
eddyServicePtr->setURLData(defaultUrl);
// The name of the beacon and the service list
eddyServicePtr->setNormalFrameData(beaconName, strlen(beaconName), uuid16_list, sizeof(uuid16_list));
// Every 500 ms. Eddystone URL, then Normal frame
eddyServicePtr->setUIDFrameAdvertisingInterval(0);
eddyServicePtr->setTLMFrameAdvertisingInterval(0);
eddyServicePtr->setURLFrameAdvertisingInterval(500);
eddyServicePtr->setNormalFrameAdvertisingInterval(500);
eddyServicePtr->startBeaconService();
}
void app_start(int, char**) {
BLE::Instance().init(bleInitComplete);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment