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 #include "URLFrame.h"
mbed_official 3:5120491ba317 18
mbed_official 3:5120491ba317 19 URLFrame::URLFrame(void)
mbed_official 3:5120491ba317 20 {
mbed_official 3:5120491ba317 21 urlDataLength = 0;
mbed_official 3:5120491ba317 22 memset(urlData, 0, sizeof(UrlData_t));
mbed_official 3:5120491ba317 23 }
mbed_official 3:5120491ba317 24
mbed_official 3:5120491ba317 25 URLFrame::URLFrame(const char *urlDataIn)
mbed_official 3:5120491ba317 26 {
mbed_official 3:5120491ba317 27 encodeURL(urlDataIn);
mbed_official 3:5120491ba317 28 }
mbed_official 3:5120491ba317 29
mbed_official 3:5120491ba317 30 URLFrame::URLFrame(UrlData_t urlDataIn, uint8_t urlDataLengthIn)
mbed_official 3:5120491ba317 31 {
mbed_official 3:5120491ba317 32 urlDataLength = (urlDataLengthIn > URL_DATA_MAX) ? URL_DATA_MAX : urlDataLengthIn;
mbed_official 3:5120491ba317 33 memcpy(urlData, urlDataIn, urlDataLength);
mbed_official 3:5120491ba317 34 }
mbed_official 3:5120491ba317 35
mbed_official 3:5120491ba317 36 void URLFrame::constructURLFrame(uint8_t* rawFrame, int8_t advPowerLevel)
mbed_official 3:5120491ba317 37 {
mbed_official 3:5120491ba317 38 size_t index = 0;
mbed_official 3:5120491ba317 39 rawFrame[index++] = EDDYSTONE_UUID[0]; // 16-bit Eddystone UUID
mbed_official 3:5120491ba317 40 rawFrame[index++] = EDDYSTONE_UUID[1];
mbed_official 3:5120491ba317 41 rawFrame[index++] = FRAME_TYPE_URL; // 1B Type
mbed_official 3:5120491ba317 42 rawFrame[index++] = advPowerLevel; // 1B Power @ 0meter
mbed_official 3:5120491ba317 43 memcpy(rawFrame + index, urlData, urlDataLength); // Encoded URL
mbed_official 3:5120491ba317 44 }
mbed_official 3:5120491ba317 45
mbed_official 3:5120491ba317 46 size_t URLFrame::getRawFrameSize(void) const
mbed_official 3:5120491ba317 47 {
mbed_official 3:5120491ba317 48 return urlDataLength + FRAME_MIN_SIZE_URL + EDDYSTONE_UUID_SIZE;
mbed_official 3:5120491ba317 49 }
mbed_official 3:5120491ba317 50
mbed_official 3:5120491ba317 51 uint8_t* URLFrame::getEncodedURLData(void)
mbed_official 3:5120491ba317 52 {
mbed_official 3:5120491ba317 53 return urlData;
mbed_official 3:5120491ba317 54 }
mbed_official 3:5120491ba317 55
mbed_official 3:5120491ba317 56 uint8_t URLFrame::getEncodedURLDataLength(void) const
mbed_official 3:5120491ba317 57 {
mbed_official 3:5120491ba317 58 return urlDataLength;
mbed_official 3:5120491ba317 59 }
mbed_official 3:5120491ba317 60
mbed_official 3:5120491ba317 61 void URLFrame::setURLData(const char *urlDataIn)
mbed_official 3:5120491ba317 62 {
mbed_official 3:5120491ba317 63 encodeURL(urlDataIn);
mbed_official 3:5120491ba317 64 }
mbed_official 3:5120491ba317 65
mbed_official 3:5120491ba317 66 void URLFrame::setEncodedURLData(const uint8_t* urlEncodedDataIn, const uint8_t urlEncodedDataLengthIn)
mbed_official 3:5120491ba317 67 {
mbed_official 3:5120491ba317 68 urlDataLength = urlEncodedDataLengthIn;
mbed_official 3:5120491ba317 69 memcpy(urlData, urlEncodedDataIn, urlEncodedDataLengthIn);
mbed_official 3:5120491ba317 70 }
mbed_official 3:5120491ba317 71
mbed_official 3:5120491ba317 72 void URLFrame::encodeURL(const char *urlDataIn)
mbed_official 3:5120491ba317 73 {
mbed_official 3:5120491ba317 74 const char *prefixes[] = {
mbed_official 3:5120491ba317 75 "http://www.",
mbed_official 3:5120491ba317 76 "https://www.",
mbed_official 3:5120491ba317 77 "http://",
mbed_official 3:5120491ba317 78 "https://",
mbed_official 3:5120491ba317 79 };
mbed_official 3:5120491ba317 80 const size_t NUM_PREFIXES = sizeof(prefixes) / sizeof(char *);
mbed_official 3:5120491ba317 81 const char *suffixes[] = {
mbed_official 3:5120491ba317 82 ".com/",
mbed_official 3:5120491ba317 83 ".org/",
mbed_official 3:5120491ba317 84 ".edu/",
mbed_official 3:5120491ba317 85 ".net/",
mbed_official 3:5120491ba317 86 ".info/",
mbed_official 3:5120491ba317 87 ".biz/",
mbed_official 3:5120491ba317 88 ".gov/",
mbed_official 3:5120491ba317 89 ".com",
mbed_official 3:5120491ba317 90 ".org",
mbed_official 3:5120491ba317 91 ".edu",
mbed_official 3:5120491ba317 92 ".net",
mbed_official 3:5120491ba317 93 ".info",
mbed_official 3:5120491ba317 94 ".biz",
mbed_official 3:5120491ba317 95 ".gov"
mbed_official 3:5120491ba317 96 };
mbed_official 3:5120491ba317 97 const size_t NUM_SUFFIXES = sizeof(suffixes) / sizeof(char *);
mbed_official 3:5120491ba317 98
mbed_official 3:5120491ba317 99 urlDataLength = 0;
mbed_official 3:5120491ba317 100 memset(urlData, 0, sizeof(UrlData_t));
mbed_official 3:5120491ba317 101
mbed_official 3:5120491ba317 102 if ((urlDataIn == NULL) || (strlen(urlDataIn) == 0)) {
mbed_official 3:5120491ba317 103 return;
mbed_official 3:5120491ba317 104 }
mbed_official 3:5120491ba317 105
mbed_official 3:5120491ba317 106 /*
mbed_official 3:5120491ba317 107 * handle prefix
mbed_official 3:5120491ba317 108 */
mbed_official 3:5120491ba317 109 for (size_t i = 0; i < NUM_PREFIXES; i++) {
mbed_official 3:5120491ba317 110 size_t prefixLen = strlen(prefixes[i]);
mbed_official 3:5120491ba317 111 if (strncmp(urlDataIn, prefixes[i], prefixLen) == 0) {
mbed_official 3:5120491ba317 112 urlData[urlDataLength++] = i;
mbed_official 3:5120491ba317 113 urlDataIn += prefixLen;
mbed_official 3:5120491ba317 114 break;
mbed_official 3:5120491ba317 115 }
mbed_official 3:5120491ba317 116 }
mbed_official 3:5120491ba317 117
mbed_official 3:5120491ba317 118 /*
mbed_official 3:5120491ba317 119 * handle suffixes
mbed_official 3:5120491ba317 120 */
mbed_official 3:5120491ba317 121 while (*urlDataIn && (urlDataLength < URL_DATA_MAX)) {
mbed_official 3:5120491ba317 122 /* check for suffix match */
mbed_official 3:5120491ba317 123 size_t i;
mbed_official 3:5120491ba317 124 for (i = 0; i < NUM_SUFFIXES; i++) {
mbed_official 3:5120491ba317 125 size_t suffixLen = strlen(suffixes[i]);
mbed_official 3:5120491ba317 126 if (strncmp(urlDataIn, suffixes[i], suffixLen) == 0) {
mbed_official 3:5120491ba317 127 urlData[urlDataLength++] = i;
mbed_official 3:5120491ba317 128 urlDataIn += suffixLen;
mbed_official 3:5120491ba317 129 break; /* from the for loop for checking against suffixes */
mbed_official 3:5120491ba317 130 }
mbed_official 3:5120491ba317 131 }
mbed_official 3:5120491ba317 132 /* This is the default case where we've got an ordinary character which doesn't match a suffix. */
mbed_official 3:5120491ba317 133 if (i == NUM_SUFFIXES) {
mbed_official 3:5120491ba317 134 urlData[urlDataLength++] = *urlDataIn;
mbed_official 3:5120491ba317 135 ++urlDataIn;
mbed_official 3:5120491ba317 136 }
mbed_official 3:5120491ba317 137 }
mbed_official 3:5120491ba317 138 }