URI-Beacons are handy when there is a need to advertise a small amount of information (usually a URL) to any nearby device. They’re really easy to set up: the code is fully available on the mbed website, so all you’ll need to do is tell the beacon what to broadcast. The canonical source for this example lives at https://github.com/ARMmbed/mbed-os-example-ble/tree/master/BLE_URIBeacon

URI-Beacons are handy when there is a need to advertise a small amount of information (usually a URL) to any nearby device. They’re really easy to set up: the code is fully available on the mbed website, so all you’ll need to do is tell the beacon what to broadcast.

Technical details are better presented here, which happens to be the mbed-classic equivalent of this example. Please also refer to Google's URIBeacon project.

What You’ll Need

To get this going, you’ll need:

- To see URIBeacons get the *Physical Web* app installed on your phone:

- Android version

- iOS version

- One of the BLE platforms listed in the README.md of this repository, for example a Nordic DK board.

Build 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

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

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-URIBeacon/raw-file/45a261c84d32/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 60 seconds. During this time it is possible to change the URL advertised by the beacon. It is also important to note that during these 60 seconds, your device will not advertise any URL.

https://developer.mbed.org/teams/mbed-os-examples/code/mbed-os-example-ble-URIBeacon/raw-file/45a261c84d32/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-URIBeacon/raw-file/45a261c84d32/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-URIBeacon/raw-file/45a261c84d32/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-URIBeacon/raw-file/45a261c84d32/img/result.png

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

Please note that the URIBeacon spec requires the URIBeacon app to remain in config mode for the first 60 seconds before switching to being a beacon. So if you're using a physical-web app, you'll only see the beacon after this period; if you're using one of the generic apps for BLE scanning, you should see a configurable beacon being advertised for the first 60 seconds.

You'll find links on Google's project page to client apps to test URIBeacon. Here's a link that should get you an Android App; please browse to `uribeacon-sample-release.apk`. But you should begin with the links to android apps mentioned above.

Committer:
mbed_official
Date:
Wed Mar 01 18:15:53 2017 +0000
Revision:
20:aba6206ee5d9
Parent:
2:e075005e17d0
Merge pull request #55 from adbridge/master

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