49 #include "nordic_common.h"
50 #include "nrf_delay.h"
52 #include "ble_advdata.h"
53 #include "ble_srv_common.h"
55 #include "softdevice_handler.h"
56 #include "app_error.h"
57 #include "iot_defines.h"
63 #define PRINTF(...) printf(__VA_ARGS__)
68 #define IS_SRVC_CHANGED_CHARACT_PRESENT 1
69 #define APP_ADV_TIMEOUT 0
70 #define APP_ADV_ADV_INTERVAL MSEC_TO_UNITS(333, UNIT_0_625_MS)
86 ble_enable_params_t ble_enable_params;
87 memset(&ble_enable_params, 0,
sizeof(ble_enable_params));
88 ble_enable_params.gatts_enable_params.attr_tab_size =
89 BLE_GATTS_ATTR_TAB_SIZE_DEFAULT;
90 ble_enable_params.gatts_enable_params.service_changed =
91 IS_SRVC_CHANGED_CHARACT_PRESENT;
92 err_code = sd_ble_enable(&ble_enable_params);
93 APP_ERROR_CHECK(err_code);
97 APP_ERROR_CHECK(err_code);
100 ble_gap_addr_t ble_addr;
101 err_code = sd_ble_gap_address_get(&ble_addr);
102 APP_ERROR_CHECK(err_code);
104 ble_addr.addr[5] = 0x00;
105 ble_addr.addr_type = BLE_GAP_ADDR_TYPE_PUBLIC;
107 err_code = sd_ble_gap_address_set(BLE_GAP_ADDR_CYCLE_MODE_NONE, &ble_addr);
108 APP_ERROR_CHECK(err_code);
119 ble_gap_addr_t ble_addr;
121 err_code = sd_ble_gap_address_get(&ble_addr);
122 APP_ERROR_CHECK(err_code);
124 IPV6_EUI64_CREATE_FROM_EUI48(addr, ble_addr.addr, ble_addr.addr_type);
135 ble_advdata_t advdata;
136 uint8_t flags = BLE_GAP_ADV_FLAG_BR_EDR_NOT_SUPPORTED;
137 ble_gap_conn_sec_mode_t sec_mode;
139 BLE_GAP_CONN_SEC_MODE_SET_OPEN(&sec_mode);
141 err_code = sd_ble_gap_device_name_set(&sec_mode, (
const uint8_t *)name,
143 APP_ERROR_CHECK(err_code);
145 ble_uuid_t adv_uuids[] = {{BLE_UUID_IPSP_SERVICE, BLE_UUID_TYPE_BLE}};
148 memset(&advdata, 0,
sizeof(advdata));
150 advdata.name_type = BLE_ADVDATA_FULL_NAME;
151 advdata.flags = flags;
152 advdata.uuids_complete.uuid_cnt =
sizeof(adv_uuids) /
sizeof(adv_uuids[0]);
153 advdata.uuids_complete.p_uuids = adv_uuids;
155 err_code = ble_advdata_set(&advdata,
NULL);
156 APP_ERROR_CHECK(err_code);
177 APP_ERROR_CHECK(err_code);
179 PRINTF(
"ble-core: advertising started\n");
190 for(i = 0; i <
sizeof(addr->addr); i++) {
193 }PRINTF(
"%02x", addr->addr[i]);
194 }PRINTF(
" (%d)", addr->addr_type);
204 switch(p_ble_evt->header.evt_id) {
205 case BLE_GAP_EVT_CONNECTED:
206 PRINTF(
"ble-core: connected [handle:%d, peer: ", p_ble_evt->evt.gap_evt.conn_handle);
209 sd_ble_gap_rssi_start(p_ble_evt->evt.gap_evt.conn_handle,
210 BLE_GAP_RSSI_THRESHOLD_INVALID,
214 case BLE_GAP_EVT_DISCONNECTED:
215 PRINTF(
"ble-core: disconnected [handle:%d]\n", p_ble_evt->evt.gap_evt.conn_handle);
230 ble_ipsp_evt_handler(p_ble_evt);
static void on_ble_evt(ble_evt_t *p_ble_evt)
Function for handling the Application's BLE Stack events.
static void ble_evt_dispatch(ble_evt_t *p_ble_evt)
SoftDevice BLE event callback.
static uip_ds6_addr_t * addr
Pointer to a router list entry.
#define APP_ADV_ADV_INTERVAL
The advertising interval.
static ble_gap_adv_params_t m_adv_params
Parameters to be passed to the stack when starting advertising.
void ble_advertising_init(const char *name)
Initialize BLE advertising data.
void ble_get_mac(uint8_t addr[8])
Return device EUI64 MAC address.
#define NULL
The null pointer.
void ble_advertising_start(void)
Start BLE advertising.
void ble_stack_init(void)
Initialize and enable the BLE stack.
#define APP_ADV_TIMEOUT
Time for which the device must be advertising in non-connectable mode (in seconds).
void ble_gap_addr_print(const ble_gap_addr_t *addr)
Print GAP address.