43 #include "nordic_common.h" 44 #include "nrf_delay.h" 46 #include "ble_advdata.h" 47 #include "ble_srv_common.h" 49 #include "softdevice_handler.h" 50 #include "app_error.h" 51 #include "iot_defines.h" 57 #define PRINTF(...) printf(__VA_ARGS__) 62 #define IS_SRVC_CHANGED_CHARACT_PRESENT 1 63 #define APP_ADV_TIMEOUT 0 64 #define APP_ADV_ADV_INTERVAL MSEC_TO_UNITS(333, UNIT_0_625_MS) 80 ble_enable_params_t ble_enable_params;
81 memset(&ble_enable_params, 0,
sizeof(ble_enable_params));
82 ble_enable_params.gatts_enable_params.attr_tab_size =
83 BLE_GATTS_ATTR_TAB_SIZE_DEFAULT;
84 ble_enable_params.gatts_enable_params.service_changed =
85 IS_SRVC_CHANGED_CHARACT_PRESENT;
86 err_code = sd_ble_enable(&ble_enable_params);
87 APP_ERROR_CHECK(err_code);
91 APP_ERROR_CHECK(err_code);
94 ble_gap_addr_t ble_addr;
95 err_code = sd_ble_gap_address_get(&ble_addr);
96 APP_ERROR_CHECK(err_code);
98 ble_addr.addr[5] = 0x00;
99 ble_addr.addr_type = BLE_GAP_ADDR_TYPE_PUBLIC;
101 err_code = sd_ble_gap_address_set(BLE_GAP_ADDR_CYCLE_MODE_NONE, &ble_addr);
102 APP_ERROR_CHECK(err_code);
113 ble_gap_addr_t ble_addr;
115 err_code = sd_ble_gap_address_get(&ble_addr);
116 APP_ERROR_CHECK(err_code);
118 IPV6_EUI64_CREATE_FROM_EUI48(addr, ble_addr.addr, ble_addr.addr_type);
129 ble_advdata_t advdata;
130 uint8_t flags = BLE_GAP_ADV_FLAG_BR_EDR_NOT_SUPPORTED;
131 ble_gap_conn_sec_mode_t sec_mode;
133 BLE_GAP_CONN_SEC_MODE_SET_OPEN(&sec_mode);
135 err_code = sd_ble_gap_device_name_set(&sec_mode, (
const uint8_t *)name,
137 APP_ERROR_CHECK(err_code);
139 ble_uuid_t adv_uuids[] = {{BLE_UUID_IPSP_SERVICE, BLE_UUID_TYPE_BLE}};
142 memset(&advdata, 0,
sizeof(advdata));
144 advdata.name_type = BLE_ADVDATA_FULL_NAME;
145 advdata.flags = flags;
146 advdata.uuids_complete.uuid_cnt =
sizeof(adv_uuids) /
sizeof(adv_uuids[0]);
147 advdata.uuids_complete.p_uuids = adv_uuids;
149 err_code = ble_advdata_set(&advdata, NULL);
150 APP_ERROR_CHECK(err_code);
171 APP_ERROR_CHECK(err_code);
173 PRINTF(
"ble-core: advertising started\n");
184 for(i = 0; i <
sizeof(addr->addr); i++) {
187 }PRINTF(
"%02x", addr->addr[i]);
188 }PRINTF(
" (%d)", addr->addr_type);
198 switch(p_ble_evt->header.evt_id) {
199 case BLE_GAP_EVT_CONNECTED:
200 PRINTF(
"ble-core: connected [handle:%d, peer: ", p_ble_evt->evt.gap_evt.conn_handle);
203 sd_ble_gap_rssi_start(p_ble_evt->evt.gap_evt.conn_handle,
204 BLE_GAP_RSSI_THRESHOLD_INVALID,
208 case BLE_GAP_EVT_DISCONNECTED:
209 PRINTF(
"ble-core: disconnected [handle:%d]\n", p_ble_evt->evt.gap_evt.conn_handle);
224 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 uip_ds6_addr_t * addr
Pointer to a nbr cache entry.
void ble_stack_init(void)
Initialize and enable the BLE stack.
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.
static void ble_evt_dispatch(ble_evt_t *p_ble_evt)
SoftDevice BLE event callback.
void ble_get_mac(uint8_t addr[8])
Return device EUI64 MAC address.
#define APP_ADV_TIMEOUT
Time for which the device must be advertising in non-connectable mode (in seconds).
void ble_advertising_start(void)
Start BLE advertising.
#define APP_ADV_ADV_INTERVAL
The advertising interval.
void ble_gap_addr_print(const ble_gap_addr_t *addr)
Print GAP address.