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:
mbed_official
Date:
Thu Jul 28 23:14:36 2016 +0100
Revision:
1:9db4d46bb63f
Parent:
0:4c8f8bf32a99
Child:
2:9ee673e0b86a
Merge branch 'master' of https://github.com/ARMmbed/mbed-os-example-ble


Commit copied from ./src/github.com/ARMmbed/mbed-os-example-ble

Who changed what in which revision?

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