Eddystone beacons broadcast a small amount of information, like URLs, to nearby BLE devices. The canonical source for this example lives at https://github.com/ARMmbed/mbed-os-example-ble/tree/master/BLE_EddystoneService

Eddystone beacons broadcast a small amount of information, like URLs, to nearby BLE devices.

The Eddystone Beacon sample application runs in two stages:

  • On startup, the Configuration Service (which allows modification of the beacon runs for a user-defined period (default - 30 seconds).
  • When the Configuration Service period ends, the Eddystone Service broadcasts advertisement packets.

Running the application

Requirements

You should install the *Physical Web* application on your phone:

- Android version

- iOS version

Note: It is also possible to use a regular scanner to interract with your Eddystone beacon but it requires knowledge about BLE and Eddystone beacon specification out of the scope of this document.

Hardware requirements are in the main readme.

Building instructions

Building with mbed CLI

If you'd like to use mbed CLI to build this, then you should refer to the main readme. The instructions here relate to using the developer.mbed.org Online Compiler

In order to build this example in the mbed Online Compiler, first import the example using the ‘Import’ button on the right hand side.

Next, select a platform to build for. This must either be a platform that supports BLE, for example the NRF51-DK, or one of the following:

List of platforms supporting Bluetooth Low Energy

Or you must also add a piece of hardware and the supporting library that includes a Bluetooth Low Energy driver for that hardware, for example the K64F or NUCLEO_F401RE with the X-NUCLEO-IDB05A1

List of components supporting Bluetooth Low Energy.

Once you have selected your platform, compile the example and drag and drop the resulting binary onto your board.

For general instructions on using the mbed Online Compiler, please see the mbed Handbook

Working with nRF51-based 16K targets

Because of memory constraints, you can't use the SoftDevice 130 (S130) to build for nRF51-based 16K targets. If you are using these targets, then before building:

  1. Open the ``config.json`` file in this sample.
  2. Change ``soft device`` to ``S110``.
  3. Save.

You can now build for nRF51-based 16K targets.

Setting up the beacon

By default, the beacon directs to the url ``http://mbed.org``. You can change this to your own URL in two ways:

  • Manually edit the code in ``main.cpp`` in your copy of the sample.
  • Build and run the application's default code as explained in the building instructions. When the beacon starts up, the Configuration Service runs for 30 seconds (this is the default value; you can change it in ``main.cpp``). While the Configuration Service runs, you can use a BLE scanner on your phone to edit the values the service presents.

Checking for success

  • Build the application and install it on your board as explained in the building instructions.
  • Open the *Physical Web* application on your phone. It will start to search for nearby beacons.

https://developer.mbed.org/teams/mbed-os-examples/code/mbed-os-example-ble-EddystoneService/raw-file/4c8f8bf32a99/img/app_start.png

figure 1 Start of the *Physical Web* application version 0.1.856 on Android

  • When the beacon starts up, the Configuration Service runs for 30 seconds. During this time it is possible to change the URL advertised by the beacon. It is also important to note that during these 30 seconds, your device will not advertise any URL.

https://developer.mbed.org/teams/mbed-os-examples/code/mbed-os-example-ble-EddystoneService/raw-file/4c8f8bf32a99/img/open_configuration.png

figure 2 How to open the beacon configuration view using the *Physical Web* application version 0.1.856 on Android

  • Edit the URL advertised by your beacon.

https://developer.mbed.org/teams/mbed-os-examples/code/mbed-os-example-ble-EddystoneService/raw-file/4c8f8bf32a99/img/edit_url.png

figure 3 How to edit the URL advertised by your beacon using the *Physical Web* application version 0.1.856 on Android

  • Save the URL which will be advertised by your beacon.

https://developer.mbed.org/teams/mbed-os-examples/code/mbed-os-example-ble-EddystoneService/raw-file/4c8f8bf32a99/img/save_url.png

figure 4 How to save your beacon configuration and start advertising URL using the *Physical Web* application version 0.1.856 on Android.

  • Find your device; it should advertise the URL you have set.

https://developer.mbed.org/teams/mbed-os-examples/code/mbed-os-example-ble-EddystoneService/raw-file/4c8f8bf32a99/img/result.png

figure 5 Display of URL advertised by your beacon using the *Physical Web* application version 0.1.856 on Android.

Note: You can use the Eddystone Observer sample instead of a phone application.

Committer:
mbed_official
Date:
Fri Sep 08 14:45:32 2017 +0100
Revision:
43:00b5f99e0a15
Parent:
3:5120491ba317
Merge pull request #102 from adbridge/master

Updating mbed-os to mbed-os-5.5.6
.
Commit copied from https://github.com/ARMmbed/mbed-os-example-ble

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mbed_official 3:5120491ba317 1 /* mbed Microcontroller Library
mbed_official 3:5120491ba317 2 * Copyright (c) 2006-2015 ARM Limited
mbed_official 3:5120491ba317 3 *
mbed_official 3:5120491ba317 4 * Licensed under the Apache License, Version 2.0 (the "License");
mbed_official 3:5120491ba317 5 * you may not use this file except in compliance with the License.
mbed_official 3:5120491ba317 6 * You may obtain a copy of the License at
mbed_official 3:5120491ba317 7 *
mbed_official 3:5120491ba317 8 * http://www.apache.org/licenses/LICENSE-2.0
mbed_official 3:5120491ba317 9 *
mbed_official 3:5120491ba317 10 * Unless required by applicable law or agreed to in writing, software
mbed_official 3:5120491ba317 11 * distributed under the License is distributed on an "AS IS" BASIS,
mbed_official 3:5120491ba317 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
mbed_official 3:5120491ba317 13 * See the License for the specific language governing permissions and
mbed_official 3:5120491ba317 14 * limitations under the License.
mbed_official 3:5120491ba317 15 */
mbed_official 3:5120491ba317 16
mbed_official 3:5120491ba317 17 #ifndef __EDDYSTONETYPES_H__
mbed_official 3:5120491ba317 18 #define __EDDYSTONETYPES_H__
mbed_official 3:5120491ba317 19
mbed_official 3:5120491ba317 20 #include <stdint.h>
mbed_official 3:5120491ba317 21 #include <stddef.h>
mbed_official 3:5120491ba317 22
mbed_official 3:5120491ba317 23 #ifndef YOTTA_CFG_EDDYSTONE_DEFAULT_DEVICE_NAME
mbed_official 3:5120491ba317 24 #define YOTTA_CFG_EDDYSTONE_DEFAULT_DEVICE_NAME "EDDYSTONE CONFIG"
mbed_official 3:5120491ba317 25 #endif
mbed_official 3:5120491ba317 26
mbed_official 3:5120491ba317 27 #ifndef YOTTA_CFG_EDDYSTONE_DEFAULT_URL
mbed_official 3:5120491ba317 28 #define YOTTA_CFG_EDDYSTONE_DEFAULT_URL "https://www.mbed.com/"
mbed_official 3:5120491ba317 29 #endif
mbed_official 3:5120491ba317 30
mbed_official 3:5120491ba317 31 /**
mbed_official 3:5120491ba317 32 * Macro to expand a 16-bit Eddystone UUID to 128-bit UUID.
mbed_official 3:5120491ba317 33 */
mbed_official 3:5120491ba317 34 #define UUID_URL_BEACON(FIRST, SECOND) { \
mbed_official 3:5120491ba317 35 0xee, 0x0c, FIRST, SECOND, 0x87, 0x86, 0x40, 0xba, \
mbed_official 3:5120491ba317 36 0xab, 0x96, 0x99, 0xb9, 0x1a, 0xc9, 0x81, 0xd8, \
mbed_official 3:5120491ba317 37 }
mbed_official 3:5120491ba317 38
mbed_official 3:5120491ba317 39 /**
mbed_official 3:5120491ba317 40 * Eddystone 16-bit UUID.
mbed_official 3:5120491ba317 41 */
mbed_official 3:5120491ba317 42 const uint8_t EDDYSTONE_UUID[] = {0xAA, 0xFE};
mbed_official 3:5120491ba317 43
mbed_official 3:5120491ba317 44 /**
mbed_official 3:5120491ba317 45 * 128-bit UUID for Eddystone-URL Configuration Service.
mbed_official 3:5120491ba317 46 */
mbed_official 3:5120491ba317 47 const uint8_t UUID_URL_BEACON_SERVICE[] = UUID_URL_BEACON(0x20, 0x80);
mbed_official 3:5120491ba317 48 /**
mbed_official 3:5120491ba317 49 * 128-bit UUID for Eddystone-URL Configuration Service Lock State
mbed_official 3:5120491ba317 50 * characteristic.
mbed_official 3:5120491ba317 51 */
mbed_official 3:5120491ba317 52 const uint8_t UUID_LOCK_STATE_CHAR[] = UUID_URL_BEACON(0x20, 0x81);
mbed_official 3:5120491ba317 53 /**
mbed_official 3:5120491ba317 54 * 128-bit UUID for Eddystone-URL Configuration Service Lock
mbed_official 3:5120491ba317 55 * characteristic.
mbed_official 3:5120491ba317 56 */
mbed_official 3:5120491ba317 57 const uint8_t UUID_LOCK_CHAR[] = UUID_URL_BEACON(0x20, 0x82);
mbed_official 3:5120491ba317 58 /**
mbed_official 3:5120491ba317 59 * 128-bit UUID for Eddystone-URL Configuration Service Unlock
mbed_official 3:5120491ba317 60 * characteristic.
mbed_official 3:5120491ba317 61 */
mbed_official 3:5120491ba317 62 const uint8_t UUID_UNLOCK_CHAR[] = UUID_URL_BEACON(0x20, 0x83);
mbed_official 3:5120491ba317 63 /**
mbed_official 3:5120491ba317 64 * 128-bit UUID for Eddystone-URL Configuration Service URI Data
mbed_official 3:5120491ba317 65 * characteristic.
mbed_official 3:5120491ba317 66 */
mbed_official 3:5120491ba317 67 const uint8_t UUID_URL_DATA_CHAR[] = UUID_URL_BEACON(0x20, 0x84);
mbed_official 3:5120491ba317 68 /**
mbed_official 3:5120491ba317 69 * 128-bit UUID for Eddystone-URL Configuration Service Flags
mbed_official 3:5120491ba317 70 * characteristic.
mbed_official 3:5120491ba317 71 */
mbed_official 3:5120491ba317 72 const uint8_t UUID_FLAGS_CHAR[] = UUID_URL_BEACON(0x20, 0x85);
mbed_official 3:5120491ba317 73 /**
mbed_official 3:5120491ba317 74 * 128-bit UUID for Eddystone-URL Configuration Service Advertised TX Power
mbed_official 3:5120491ba317 75 * Levels characteristic.
mbed_official 3:5120491ba317 76 */
mbed_official 3:5120491ba317 77 const uint8_t UUID_ADV_POWER_LEVELS_CHAR[] = UUID_URL_BEACON(0x20, 0x86);
mbed_official 3:5120491ba317 78 /**
mbed_official 3:5120491ba317 79 * 128-bit UUID for Eddystone-URL Configuration Service TX Power Mode
mbed_official 3:5120491ba317 80 * characteristic.
mbed_official 3:5120491ba317 81 */
mbed_official 3:5120491ba317 82 const uint8_t UUID_TX_POWER_MODE_CHAR[] = UUID_URL_BEACON(0x20, 0x87);
mbed_official 3:5120491ba317 83 /**
mbed_official 3:5120491ba317 84 * 128-bit UUID for Eddystone-URL Configuration Service Beacon Period
mbed_official 3:5120491ba317 85 * characteristic.
mbed_official 3:5120491ba317 86 */
mbed_official 3:5120491ba317 87 const uint8_t UUID_BEACON_PERIOD_CHAR[] = UUID_URL_BEACON(0x20, 0x88);
mbed_official 3:5120491ba317 88 /**
mbed_official 3:5120491ba317 89 * 128-bit UUID for Eddystone-URL Configuration Service Reset
mbed_official 3:5120491ba317 90 * characteristic.
mbed_official 3:5120491ba317 91 */
mbed_official 3:5120491ba317 92 const uint8_t UUID_RESET_CHAR[] = UUID_URL_BEACON(0x20, 0x89);
mbed_official 3:5120491ba317 93
mbed_official 3:5120491ba317 94 /**
mbed_official 3:5120491ba317 95 * Default name for the BLE Device Name characteristic.
mbed_official 3:5120491ba317 96 */
mbed_official 3:5120491ba317 97 const char DEFAULT_DEVICE_NAME[] = YOTTA_CFG_EDDYSTONE_DEFAULT_DEVICE_NAME;
mbed_official 3:5120491ba317 98
mbed_official 3:5120491ba317 99 /**
mbed_official 3:5120491ba317 100 * Default URL used by EddystoneService.
mbed_official 3:5120491ba317 101 */
mbed_official 3:5120491ba317 102 const char DEFAULT_URL[] = YOTTA_CFG_EDDYSTONE_DEFAULT_URL;
mbed_official 3:5120491ba317 103
mbed_official 3:5120491ba317 104 /**
mbed_official 3:5120491ba317 105 * Enumeration that defines the Eddystone power levels for the Eddystone-URL
mbed_official 3:5120491ba317 106 * Configuration Service TX Power Mode characteristic. Refer to
mbed_official 3:5120491ba317 107 * https://github.com/google/eddystone/blob/master/eddystone-url/docs/config-service-spec.md#37-tx-power-mode.
mbed_official 3:5120491ba317 108 */
mbed_official 3:5120491ba317 109 enum PowerModes {
mbed_official 3:5120491ba317 110 /**
mbed_official 3:5120491ba317 111 * Lowest transmit power mode.
mbed_official 3:5120491ba317 112 */
mbed_official 3:5120491ba317 113 TX_POWER_MODE_LOWEST,
mbed_official 3:5120491ba317 114 /**
mbed_official 3:5120491ba317 115 * Low transmit power mode.
mbed_official 3:5120491ba317 116 */
mbed_official 3:5120491ba317 117 TX_POWER_MODE_LOW,
mbed_official 3:5120491ba317 118 /**
mbed_official 3:5120491ba317 119 * Medium transmit power mode.
mbed_official 3:5120491ba317 120 */
mbed_official 3:5120491ba317 121 TX_POWER_MODE_MEDIUM,
mbed_official 3:5120491ba317 122 /**
mbed_official 3:5120491ba317 123 * Highest transmit power mode.
mbed_official 3:5120491ba317 124 */
mbed_official 3:5120491ba317 125 TX_POWER_MODE_HIGH,
mbed_official 3:5120491ba317 126 /**
mbed_official 3:5120491ba317 127 * Total number of power modes.
mbed_official 3:5120491ba317 128 */
mbed_official 3:5120491ba317 129 NUM_POWER_MODES
mbed_official 3:5120491ba317 130 };
mbed_official 3:5120491ba317 131
mbed_official 3:5120491ba317 132 /**
mbed_official 3:5120491ba317 133 * Type for the 128-bit for Eddystone-URL Configuration Service Lock and Unlock
mbed_official 3:5120491ba317 134 * characteristic value.
mbed_official 3:5120491ba317 135 */
mbed_official 3:5120491ba317 136 typedef uint8_t Lock_t[16];
mbed_official 3:5120491ba317 137 /**
mbed_official 3:5120491ba317 138 * Type for the 128-bit for Eddystone-URL Configuration Service Advertised TX
mbed_official 3:5120491ba317 139 * Power Levels characteristic value.
mbed_official 3:5120491ba317 140 */
mbed_official 3:5120491ba317 141 typedef int8_t PowerLevels_t[NUM_POWER_MODES];
mbed_official 3:5120491ba317 142
mbed_official 3:5120491ba317 143 /**
mbed_official 3:5120491ba317 144 * Maximum length of an encoded URL for Eddystone.
mbed_official 3:5120491ba317 145 */
mbed_official 3:5120491ba317 146 const uint16_t URL_DATA_MAX = 18;
mbed_official 3:5120491ba317 147 /**
mbed_official 3:5120491ba317 148 * Type for an encoded URL for Eddystone.
mbed_official 3:5120491ba317 149 */
mbed_official 3:5120491ba317 150 typedef uint8_t UrlData_t[URL_DATA_MAX];
mbed_official 3:5120491ba317 151
mbed_official 3:5120491ba317 152 /**
mbed_official 3:5120491ba317 153 * Size in bytes of UID namespace ID.
mbed_official 3:5120491ba317 154 */
mbed_official 3:5120491ba317 155 const size_t UID_NAMESPACEID_SIZE = 10;
mbed_official 3:5120491ba317 156 /**
mbed_official 3:5120491ba317 157 * Type for the UID namespace ID.
mbed_official 3:5120491ba317 158 */
mbed_official 3:5120491ba317 159 typedef uint8_t UIDNamespaceID_t[UID_NAMESPACEID_SIZE];
mbed_official 3:5120491ba317 160 /**
mbed_official 3:5120491ba317 161 * Size in bytes of UID instance ID.
mbed_official 3:5120491ba317 162 */
mbed_official 3:5120491ba317 163 const size_t UID_INSTANCEID_SIZE = 6;
mbed_official 3:5120491ba317 164 /**
mbed_official 3:5120491ba317 165 * Type for the UID instance ID.
mbed_official 3:5120491ba317 166 */
mbed_official 3:5120491ba317 167 typedef uint8_t UIDInstanceID_t[UID_INSTANCEID_SIZE];
mbed_official 3:5120491ba317 168
mbed_official 3:5120491ba317 169 /**
mbed_official 3:5120491ba317 170 * Type for callbacks to update Eddystone-TLM frame Batery Voltage and Beacon
mbed_official 3:5120491ba317 171 * Temperature.
mbed_official 3:5120491ba317 172 */
mbed_official 3:5120491ba317 173 typedef uint16_t (*TlmUpdateCallback_t) (uint16_t);
mbed_official 3:5120491ba317 174
mbed_official 3:5120491ba317 175 /**
mbed_official 3:5120491ba317 176 * Size of Eddystone UUID. Needed to construct all frames raw bytes.
mbed_official 3:5120491ba317 177 */
mbed_official 3:5120491ba317 178 const uint16_t EDDYSTONE_UUID_SIZE = sizeof(EDDYSTONE_UUID);
mbed_official 3:5120491ba317 179
mbed_official 3:5120491ba317 180 #endif /* __EDDYSTONETYPES_H__ */