Example program for the Eddystone Beacon service.

Dependencies:   BLE_API mbed nRF51822 X_NUCLEO_IDB0XA1

Fork of BLE_EddystoneBeacon by URIBeacon

This example demonstrates how to set up and initialize a Eddystone Beacon. For more details on the Eddystone specification please see the Eddystone Github Page.

The Basics

An Eddystone Beacon is a Bluetooth Low Energy beacon, that means it does all of its data transfer in GAP advertising packets. Eddystone beacons, unlike other beacons, broadcast multiple types of data. Currently Eddystone beacons have 3 frame types (UID, URL, TLM) that will get swapped out periodically. This swapping of frame data allows Eddystone beacons to send many different types of data, thus increasing their usefulness over traditional beacons. Note that the UID frame type provides the same 16Bytes of UUID namespace that iBeacons do and the URL frame type provides the same functionality as a URIBeacon.

For more details see the Eddystone Specification.

Smartphone Apps

nRF Master Control Panel - this program recognizes Eddystone beacons and will display the data for all frame types.

iPhone Physical Web app

Android App

Walkthrough of Physical Web application

Technical Details

The Eddystone Specification looks like the following image. Please note that this may change over time and for up to date information the official spec should be referenced. /media/uploads/mbedAustin/scratch-1-.png

The Eddystone Frames get swapped in and out depending on what frames you have enabled. The only required frame type is the TLM frame, all others are optional and you can have any number enabled. To disable the UID or URL frames give their values a 'NULL' in the Eddystone constructor. The Eddystone spec recommends broadcasting 10 frames a second.

Note

  • The current Eddystone mbed example does not allow for combining the eddystone service with other services, this will be changes in a future update.
  • There is an Eddystone Config service that allows for updating beacons in the field. We are working on an example for this, so keep your eyes pealed for a future update.
Committer:
mbedAustin
Date:
Thu Jul 23 06:48:50 2015 +0000
Revision:
21:f4646308f363
Parent:
2:8020d6d4455a
Child:
23:05e9bb3b13af
[[Fix]] made RFU field in UID frame BigEndian Compliant (again, facepalm)

Who changed what in which revision?

UserRevisionLine numberNew contents of line
rgrover1 2:8020d6d4455a 1 /* mbed Microcontroller Library
rgrover1 2:8020d6d4455a 2 * Copyright (c) 2006-2015 ARM Limited
rgrover1 2:8020d6d4455a 3 *
rgrover1 2:8020d6d4455a 4 * Licensed under the Apache License, Version 2.0 (the "License");
rgrover1 2:8020d6d4455a 5 * you may not use this file except in compliance with the License.
rgrover1 2:8020d6d4455a 6 * You may obtain a copy of the License at
rgrover1 2:8020d6d4455a 7 *
rgrover1 2:8020d6d4455a 8 * http://www.apache.org/licenses/LICENSE-2.0
rgrover1 2:8020d6d4455a 9 *
rgrover1 2:8020d6d4455a 10 * Unless required by applicable law or agreed to in writing, software
rgrover1 2:8020d6d4455a 11 * distributed under the License is distributed on an "AS IS" BASIS,
rgrover1 2:8020d6d4455a 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
rgrover1 2:8020d6d4455a 13 * See the License for the specific language governing permissions and
rgrover1 2:8020d6d4455a 14 * limitations under the License.
rgrover1 2:8020d6d4455a 15 */
rgrover1 2:8020d6d4455a 16
rgrover1 2:8020d6d4455a 17 #include "pstorage.h"
rgrover1 2:8020d6d4455a 18 #include "nrf_error.h"
rgrover1 2:8020d6d4455a 19 #include "ConfigParamsPersistence.h"
rgrover1 2:8020d6d4455a 20
rgrover1 2:8020d6d4455a 21 /**
rgrover1 2:8020d6d4455a 22 * Nordic specific structure used to store params persistently.
rgrover1 2:8020d6d4455a 23 * It extends ZipBeaconConfigService::Params_t with a persistence signature.
rgrover1 2:8020d6d4455a 24 */
rgrover1 2:8020d6d4455a 25 struct PersistentParams_t {
rgrover1 2:8020d6d4455a 26 ZipBeaconConfigService::Params_t params;
rgrover1 2:8020d6d4455a 27 uint32_t persistenceSignature; /* This isn't really a parameter, but having the expected
rgrover1 2:8020d6d4455a 28 * magic value in this field indicates persistence. */
rgrover1 2:8020d6d4455a 29
rgrover1 2:8020d6d4455a 30 static const uint32_t MAGIC = 0x1BEAC000; /* Magic that identifies persistence */
rgrover1 2:8020d6d4455a 31 };
rgrover1 2:8020d6d4455a 32
rgrover1 2:8020d6d4455a 33 /**
rgrover1 2:8020d6d4455a 34 * The following is a module-local variable to hold configuration parameters for
rgrover1 2:8020d6d4455a 35 * short periods during flash access. This is necessary because the pstorage
rgrover1 2:8020d6d4455a 36 * APIs don't copy in the memory provided as data source. The memory cannot be
rgrover1 2:8020d6d4455a 37 * freed or reused by the application until this flash access is complete. The
rgrover1 2:8020d6d4455a 38 * load and store operations in this module initialize persistentParams and then
rgrover1 2:8020d6d4455a 39 * pass it on to the 'pstorage' APIs.
rgrover1 2:8020d6d4455a 40 */
rgrover1 2:8020d6d4455a 41 static PersistentParams_t persistentParams;
rgrover1 2:8020d6d4455a 42
rgrover1 2:8020d6d4455a 43 static pstorage_handle_t pstorageHandle;
rgrover1 2:8020d6d4455a 44
rgrover1 2:8020d6d4455a 45 /**
rgrover1 2:8020d6d4455a 46 * Dummy callback handler needed by Nordic's pstorage module. This is called
rgrover1 2:8020d6d4455a 47 * after every flash access.
rgrover1 2:8020d6d4455a 48 */
rgrover1 2:8020d6d4455a 49 static void pstorageNotificationCallback(pstorage_handle_t *p_handle,
rgrover1 2:8020d6d4455a 50 uint8_t op_code,
rgrover1 2:8020d6d4455a 51 uint32_t result,
rgrover1 2:8020d6d4455a 52 uint8_t *p_data,
rgrover1 2:8020d6d4455a 53 uint32_t data_len)
rgrover1 2:8020d6d4455a 54 {
rgrover1 2:8020d6d4455a 55 /* APP_ERROR_CHECK(result); */
rgrover1 2:8020d6d4455a 56 }
rgrover1 2:8020d6d4455a 57
rgrover1 2:8020d6d4455a 58 /* Platform-specific implementation for persistence on the nRF5x. Based on the
rgrover1 2:8020d6d4455a 59 * pstorage module provided by the Nordic SDK. */
rgrover1 2:8020d6d4455a 60 bool loadURIBeaconConfigParams(ZipBeaconConfigService::Params_t *paramsP)
rgrover1 2:8020d6d4455a 61 {
rgrover1 2:8020d6d4455a 62 static bool pstorageInitied = false;
rgrover1 2:8020d6d4455a 63 if (!pstorageInitied) {
rgrover1 2:8020d6d4455a 64 pstorage_init();
rgrover1 2:8020d6d4455a 65
rgrover1 2:8020d6d4455a 66 static pstorage_module_param_t pstorageParams = {
rgrover1 2:8020d6d4455a 67 .cb = pstorageNotificationCallback,
rgrover1 2:8020d6d4455a 68 .block_size = sizeof(PersistentParams_t),
rgrover1 2:8020d6d4455a 69 .block_count = 1
rgrover1 2:8020d6d4455a 70 };
rgrover1 2:8020d6d4455a 71 pstorage_register(&pstorageParams, &pstorageHandle);
rgrover1 2:8020d6d4455a 72 pstorageInitied = true;
rgrover1 2:8020d6d4455a 73 }
rgrover1 2:8020d6d4455a 74
rgrover1 2:8020d6d4455a 75 if ((pstorage_load(reinterpret_cast<uint8_t *>(&persistentParams), &pstorageHandle, sizeof(PersistentParams_t), 0) != NRF_SUCCESS) ||
rgrover1 2:8020d6d4455a 76 (persistentParams.persistenceSignature != PersistentParams_t::MAGIC)) {
rgrover1 2:8020d6d4455a 77 // On failure zero out and let the service reset to defaults
rgrover1 2:8020d6d4455a 78 memset(paramsP, 0, sizeof(ZipBeaconConfigService::Params_t));
rgrover1 2:8020d6d4455a 79 return false;
rgrover1 2:8020d6d4455a 80 }
rgrover1 2:8020d6d4455a 81
rgrover1 2:8020d6d4455a 82 memcpy(paramsP, &persistentParams.params, sizeof(ZipBeaconConfigService::Params_t));
rgrover1 2:8020d6d4455a 83 return true;
rgrover1 2:8020d6d4455a 84 }
rgrover1 2:8020d6d4455a 85
rgrover1 2:8020d6d4455a 86 /* Platform-specific implementation for persistence on the nRF5x. Based on the
rgrover1 2:8020d6d4455a 87 * pstorage module provided by the Nordic SDK. */
rgrover1 2:8020d6d4455a 88 void saveURIBeaconConfigParams(const ZipBeaconConfigService::Params_t *paramsP)
rgrover1 2:8020d6d4455a 89 {
rgrover1 2:8020d6d4455a 90 memcpy(&persistentParams.params, paramsP, sizeof(ZipBeaconConfigService::Params_t));
rgrover1 2:8020d6d4455a 91 if (persistentParams.persistenceSignature != PersistentParams_t::MAGIC) {
rgrover1 2:8020d6d4455a 92 persistentParams.persistenceSignature = PersistentParams_t::MAGIC;
rgrover1 2:8020d6d4455a 93 pstorage_store(&pstorageHandle,
rgrover1 2:8020d6d4455a 94 reinterpret_cast<uint8_t *>(&persistentParams),
rgrover1 2:8020d6d4455a 95 sizeof(PersistentParams_t),
rgrover1 2:8020d6d4455a 96 0 /* offset */);
rgrover1 2:8020d6d4455a 97 } else {
rgrover1 2:8020d6d4455a 98 pstorage_update(&pstorageHandle,
rgrover1 2:8020d6d4455a 99 reinterpret_cast<uint8_t *>(&persistentParams),
rgrover1 2:8020d6d4455a 100 sizeof(PersistentParams_t),
rgrover1 2:8020d6d4455a 101 0 /* offset */);
rgrover1 2:8020d6d4455a 102 }
rgrover1 2:8020d6d4455a 103 }