-
Notifications
You must be signed in to change notification settings - Fork 1
/
advertising.c
57 lines (39 loc) · 2.12 KB
/
advertising.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#include <stdint.h>
#include "advertising.h"
#include "ble_advdata.h"
#include "ble_conn_params.h"
#include "app_error.h"
#include <stdio.h>
/****** Setting up the Eddystone advertisement *******/
static uint8_t eddystone_url_data[] = /**< Information advertised by the Eddystone URL frame type. */
{
APP_EDDYSTONE_URL_FRAME_TYPE, // Eddystone URL frame type.
APP_EDDYSTONE_RSSI, // RSSI value at 0 m.
APP_EDDYSTONE_URL_SCHEME, // Scheme or prefix for URL ("http", "http://www", etc.)
APP_EDDYSTONE_URL_URL // URL with a maximum length of 17 bytes. Last byte is suffix (".com", ".org", etc.)
};
void advertising_init_eddystone(void)
{
uint32_t err_code;
ble_advdata_t advdata;
uint8_t flags = BLE_GAP_ADV_FLAGS_LE_ONLY_GENERAL_DISC_MODE;
ble_uuid_t adv_uuids[] = {{APP_EDDYSTONE_UUID, BLE_UUID_TYPE_BLE}};
uint8_array_t eddystone_data_array; // Array for Service Data structure.
/** @snippet [Eddystone data array] */
eddystone_data_array.p_data = (uint8_t *) eddystone_url_data; // Pointer to the data to advertise.
eddystone_data_array.size = sizeof(eddystone_url_data); // Size of the data to advertise.
/** @snippet [Eddystone data array] */
ble_advdata_service_data_t service_data; // Structure to hold Service Data.
service_data.service_uuid = APP_EDDYSTONE_UUID; // Eddystone UUID to allow discoverability on iOS devices.
service_data.data = eddystone_data_array; // Array for service advertisement data.
// Build and set advertising data.
memset(&advdata, 0, sizeof(advdata));
advdata.name_type = BLE_ADVDATA_NO_NAME;
advdata.flags = flags;
advdata.uuids_complete.uuid_cnt = sizeof(adv_uuids) / sizeof(adv_uuids[0]);
advdata.uuids_complete.p_uuids = adv_uuids;
advdata.p_service_data_array = &service_data; // Pointer to Service Data structure.
advdata.service_data_count = 1;
err_code = ble_advdata_set(&advdata, NULL);
APP_ERROR_CHECK(err_code);
}