BLE EddystoneService example

This example is a fork of the following mbed-os example:

https://developer.mbed.org/teams/mbed-os-examples/code/mbed-os-example-ble-EddystoneService/

Please read the documentation in this page.

Committer:
Vincent Coubard
Date:
Tue Jul 26 14:40:25 2016 +0100
Revision:
0:4c8f8bf32a99
Child:
1:9db4d46bb63f
Update example at tag mbed-os-5.0.1-rc1

Who changed what in which revision?

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