/**@brief Function for application main entry. */ int main(void) { uint32_t err_code; bool erase_bonds; // Initialize. timers_init(); buttons_leds_init(&erase_bonds); ble_stack_init(); device_manager_init(erase_bonds); gap_params_init(); advertising_init(); services_init(); conn_params_init(); saadc_init(); // Start execution. application_timers_start(); err_code = ble_advertising_start(BLE_ADV_MODE_FAST); APP_ERROR_CHECK(err_code); // Enter main loop. for (;;) { // trigger next ADC conversion nrf_drv_saadc_sample_convert(0,&adc_sample); advdata.p_manuf_specific_data->data.p_data[0] = adc_sample/100 + '0'; advdata.p_manuf_specific_data->data.p_data[1] = adc_sample%100/10 + '0'; advdata.p_manuf_specific_data->data.p_data[2] = adc_sample%10 + '0'; nrf_delay_ms(100); ble_advdata_set(&advdata, NULL); } }
/**@brief Function for initializing the Advertising functionality. * * @details Encodes the required advertising data and passes it to the stack. * Also builds a structure to be passed to the stack when starting advertising. */ static void advertising_init(void) { uint32_t err_code; ble_advdata_t advdata; uint8_t flags = BLE_GAP_ADV_FLAGS_LE_ONLY_LIMITED_DISC_MODE; ble_uuid_t ancs_uuid; ancs_uuid.uuid = ((ble_ancs_base_uuid128.uuid128[12]) | (ble_ancs_base_uuid128.uuid128[13] << 8)); ancs_uuid.type = m_ancs_uuid_type; // Build and set advertising data. memset(&advdata, 0, sizeof(advdata)); advdata.name_type = BLE_ADVDATA_FULL_NAME; advdata.include_appearance = true; advdata.flags.size = sizeof(flags); advdata.flags.p_data = &flags; advdata.uuids_complete.uuid_cnt = 0; advdata.uuids_complete.p_uuids = NULL; advdata.uuids_solicited.uuid_cnt = 1; advdata.uuids_solicited.p_uuids = &ancs_uuid; err_code = ble_advdata_set(&advdata, NULL); APP_ERROR_CHECK(err_code); }
/** * @brief Initialize BLE advertiser */ void init_advertising(void) { ble_advdata_t advertising_data; ble_advdata_t scan_response_data; uint8_t flags = BLE_GAP_ADV_FLAGS_LE_ONLY_LIMITED_DISC_MODE; ble_uuid_t adv_uuids[] = { {tree_service.uuid.uuid, tree_service.uuid.type} }; memset(&advertising_data, 0, sizeof(advertising_data)); advertising_data.name_type = BLE_ADVDATA_FULL_NAME; // advdata.include_appearance = false; advertising_data.include_appearance = true; advertising_data.flags.size = sizeof(flags); advertising_data.flags.p_data = &flags; memset(&scan_response_data, 0, sizeof(scan_response_data)); scan_response_data.uuids_complete.uuid_cnt = sizeof(adv_uuids) / sizeof(adv_uuids[0]); scan_response_data.uuids_complete.p_uuids = adv_uuids; uint32_t retval = ble_advdata_set(&advertising_data, &scan_response_data); APP_ERROR_CHECK(retval); }
void ble_device_set_name(const char* new_device_name) { uint32_t err_code; ble_gap_conn_sec_mode_t sec_mode; ble_advdata_t advdata; ble_uuid_t juma_service_uuid; device_name = new_device_name; BLE_GAP_CONN_SEC_MODE_SET_OPEN(&sec_mode); err_code = sd_ble_gap_device_name_set(&sec_mode, (const uint8_t *)device_name, strlen(device_name)); APP_ERROR_CHECK(err_code); // Build and set scan response data. memset(&advdata, 0, sizeof(advdata)); advdata.flags = BLE_GAP_ADV_FLAG_BR_EDR_NOT_SUPPORTED; advdata.name_type = BLE_ADVDATA_FULL_NAME; advdata.uuids_complete.uuid_cnt = 1; juma_service_uuid.type = BLE_UUID_TYPE_BLE; juma_service_uuid.uuid = 0xFE90; advdata.uuids_complete.p_uuids = &juma_service_uuid; err_code = ble_advdata_set(&advdata, NULL); APP_ERROR_CHECK(err_code); }
/**@brief Function for initializing the Advertising functionality. * * @details Encodes the required advertising data and passes it to the stack. * Also builds a structure to be passed to the stack when starting advertising. */ static void advertising_init(void) { uint32_t err_code; ble_advdata_t advdata; ble_advdata_t scanrsp; // Build advertising data struct to pass into @ref ble_advertising_init. memset(&advdata, 0, sizeof(advdata)); advdata.name_type = BLE_ADVDATA_FULL_NAME; advdata.include_appearance = true; advdata.flags = BLE_GAP_ADV_FLAGS_LE_ONLY_GENERAL_DISC_MODE; ble_uuid_t scan_uuids[] = {{BLE_UUID_BATTERY_SERVICE, BLE_UUID_TYPE_BLE}, {BLE_UUID_DEVICE_INFORMATION_SERVICE, BLE_UUID_TYPE_BLE}, {BLE_UUID_OSSW_SERVICE, m_ossw.uuid_type}}; /**< Universally unique service identifiers. */ memset(&scanrsp, 0, sizeof(scanrsp)); scanrsp.uuids_complete.uuid_cnt = sizeof(scan_uuids) / sizeof(scan_uuids[0]); scanrsp.uuids_complete.p_uuids = scan_uuids; err_code = ble_advdata_set(&advdata, &scanrsp); APP_ERROR_CHECK(err_code); ble_adv_modes_config_t options = {0}; options.ble_adv_fast_enabled = BLE_ADV_FAST_ENABLED; options.ble_adv_fast_interval = APP_ADV_INTERVAL; options.ble_adv_fast_timeout = APP_ADV_TIMEOUT_IN_SECONDS; err_code = ble_advertising_init(&advdata, NULL, &options, on_adv_evt, NULL); APP_ERROR_CHECK(err_code); }
/**@brief Advertising functionality initialization. * * @details Encodes the required advertising data and passes it to the stack. * Also builds a structure to be passed to the stack when starting advertising. */ static void advertising_init(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[] = { {0x9998, BLE_UUID_TYPE_BLE}, {0x9999, BLE_UUID_TYPE_BLE} }; // Build and set advertising data memset(&advdata, 0, sizeof(advdata)); advdata.name_type = BLE_ADVDATA_FULL_NAME; advdata.include_appearance = false; advdata.flags = flags; advdata.uuids_complete.uuid_cnt = sizeof(adv_uuids) / sizeof(adv_uuids[0]); advdata.uuids_complete.p_uuids = adv_uuids; err_code = ble_advdata_set(&advdata, NULL); APP_ERROR_CHECK(err_code); // Initialise advertising parameters (used when starting advertising) memset(&m_adv_params, 0, sizeof(m_adv_params)); m_adv_params.type = BLE_GAP_ADV_TYPE_ADV_IND; m_adv_params.p_peer_addr = NULL; m_adv_params.fp = BLE_GAP_ADV_FP_ANY; m_adv_params.interval = APP_ADV_INTERVAL; m_adv_params.timeout = APP_ADV_TIMEOUT_IN_SECONDS; }
/**@brief Advertising functionality initialization. * * @details Encodes the required advertising data and passes it to the stack. * Also builds a structure to be passed to the stack when starting advertising. */ static void advertising_init(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[] = { {BLE_UUID_CYCLING_SPEED_AND_CADENCE, BLE_UUID_TYPE_BLE}, {BLE_UUID_BATTERY_SERVICE, BLE_UUID_TYPE_BLE}, {BLE_UUID_DEVICE_INFORMATION_SERVICE, BLE_UUID_TYPE_BLE} }; // Build and set advertising data memset(&advdata, 0, sizeof(advdata)); advdata.name_type = BLE_ADVDATA_FULL_NAME; advdata.include_appearance = true; advdata.flags.size = sizeof(flags); advdata.flags.p_data = &flags; advdata.uuids_complete.uuid_cnt = sizeof(adv_uuids) / sizeof(adv_uuids[0]); advdata.uuids_complete.p_uuids = adv_uuids; err_code = ble_advdata_set(&advdata, NULL); APP_ERROR_CHECK(err_code); // Initialise advertising parameters (used when starting advertising) memset(&m_adv_params, 0, sizeof(m_adv_params)); m_adv_params.type = BLE_GAP_ADV_TYPE_ADV_IND; m_adv_params.p_peer_addr = NULL; // Undirected advertisement m_adv_params.fp = BLE_GAP_ADV_FP_ANY; m_adv_params.interval = APP_ADV_INTERVAL; m_adv_params.timeout = APP_ADV_TIMEOUT_IN_SECONDS; }
/**@brief Function for initializing the Advertising functionality. * * @details Encodes the required advertising data and passes it to the stack. * Also builds a structure to be passed to the stack when starting advertising. * * @param[in] adv_flags Indicates which type of advertisement to use, see @ref BLE_GAP_DISC_MODES. * */ static void advertising_init(uint8_t adv_flags) { uint32_t err_code; ble_advdata_t advdata; int8_t tx_power_level = TX_POWER_LEVEL; ble_uuid_t adv_uuids[] = { {BLE_UUID_TX_POWER_SERVICE, BLE_UUID_TYPE_BLE}, {BLE_UUID_IMMEDIATE_ALERT_SERVICE, BLE_UUID_TYPE_BLE}, {BLE_UUID_LINK_LOSS_SERVICE, BLE_UUID_TYPE_BLE} }; m_advertising_mode = BLE_NO_ADV; // Build and set advertising data memset(&advdata, 0, sizeof(advdata)); advdata.name_type = BLE_ADVDATA_FULL_NAME; advdata.include_appearance = true; advdata.flags = adv_flags; advdata.p_tx_power_level = &tx_power_level; advdata.uuids_complete.uuid_cnt = sizeof(adv_uuids) / sizeof(adv_uuids[0]); advdata.uuids_complete.p_uuids = adv_uuids; err_code = ble_advdata_set(&advdata, NULL); APP_ERROR_CHECK(err_code); }
static void adv_physweb(void) { uint32_t err_code; // Physical Web data uint8_t url_frame_length = 3 + strlen(PHYSWEB_URL); // Change to 4 if URLEND is applied uint8_t m_url_frame[url_frame_length]; m_url_frame[0] = PHYSWEB_URL_TYPE; m_url_frame[1] = PHYSWEB_TX_POWER; m_url_frame[2] = PHYSWEB_URLSCHEME_HTTP; for (uint8_t i=0; i<strlen(PHYSWEB_URL); i++) { m_url_frame[i+3] = PHYSWEB_URL[i]; } //m_url_frame[url_frame_length-1] = PHYSWEB_URLEND_COMSLASH; // Remember to change url_frame_length // Physical web service ble_advdata_service_data_t service_data; service_data.service_uuid = PHYSWEB_SERVICE_ID; service_data.data.p_data = m_url_frame; service_data.data.size = url_frame_length; // Build and set advertising data memset(&advdata, 0, sizeof(advdata)); advdata.flags = BLE_GAP_ADV_FLAGS_LE_ONLY_GENERAL_DISC_MODE; advdata.p_service_data_array = &service_data; advdata.service_data_count = 1; advdata.uuids_complete = PHYSWEB_SERVICE_LIST; // Actually set advertisement data err_code = ble_advdata_set(&advdata, NULL); APP_ERROR_CHECK(err_code); }
/**@brief Function for initializing the Advertising functionality. * * @details Encodes the required advertising data and passes it to the stack. * Also builds a structure to be passed to the stack when starting advertising. */ static void advertising_init(void) { uint32_t err_code; uint8_t flags = BLE_GAP_ADV_FLAG_BR_EDR_NOT_SUPPORTED; manuf_specific_data.company_identifier = APP_COMPANY_IDENTIFIER; manuf_specific_data.data.p_data = (uint8_t *) m_beacon_info; manuf_specific_data.data.size = APP_BEACON_INFO_LENGTH; // Build and set advertising data. memset(&advdata, 0, sizeof(advdata)); advdata.name_type = BLE_ADVDATA_NO_NAME; advdata.flags.size = sizeof(flags); advdata.flags.p_data = &flags; advdata.p_manuf_specific_data = &manuf_specific_data; err_code = ble_advdata_set(&advdata, NULL); APP_ERROR_CHECK(err_code); // Initialize advertising parameters (used when starting advertising). memset(&m_adv_params, 0, sizeof(m_adv_params)); m_adv_params.type = BLE_GAP_ADV_TYPE_ADV_NONCONN_IND; m_adv_params.p_peer_addr = NULL; // Undirected advertisement. m_adv_params.fp = BLE_GAP_ADV_FP_ANY; m_adv_params.interval = NON_CONNECTABLE_ADV_INTERVAL; m_adv_params.timeout = APP_CFG_NON_CONN_ADV_TIMEOUT; }
/**@brief Function for initializing the Advertising functionality. * * @details Encodes the required advertising data and passes it to the stack. * Also builds a structure to be passed to the stack when starting advertising. */ static void advdata_update(void) { uint32_t err_code; ble_advdata_t advdata; uint8_t flags = BLE_GAP_ADV_FLAG_BR_EDR_NOT_SUPPORTED; ble_advdata_service_data_t service_data[2]; uint8_t battery_data = battery_level_get(); uint32_t temperature_data = temperature_data_get(); service_data[0].service_uuid = BLE_UUID_BATTERY_SERVICE; service_data[0].data.size = sizeof(battery_data); service_data[0].data.p_data = &battery_data; service_data[1].service_uuid = BLE_UUID_HEALTH_THERMOMETER_SERVICE; service_data[1].data.size = sizeof(temperature_data); service_data[1].data.p_data = (uint8_t *) &temperature_data; // Build and set advertising data memset(&advdata, 0, sizeof(advdata)); advdata.name_type = BLE_ADVDATA_FULL_NAME; advdata.include_appearance = false; advdata.flags.size = sizeof(flags); advdata.flags.p_data = &flags; advdata.service_data_count = 2; advdata.p_service_data_array = service_data; err_code = ble_advdata_set(&advdata, NULL); APP_ERROR_CHECK(err_code); }
//============================================================================// static void advertising_init(void) { uint32_t err_code; ble_advdata_t advdata; // Build advertising data struct to pass into @ref ble_advertising_init. memset(&advdata, 0, sizeof(advdata)); advdata.name_type = BLE_ADVDATA_FULL_NAME; //advdata.include_appearance = true; advdata.flags = BLE_GAP_ADV_FLAGS_LE_ONLY_GENERAL_DISC_MODE; //advdata.uuids_complete.uuid_cnt = sizeof(m_adv_uuids) / sizeof(m_adv_uuids[0]); //advdata.uuids_complete.p_uuids = m_adv_uuids; err_code = ble_advdata_set(&advdata, NULL); APP_ERROR_CHECK(err_code); ble_adv_modes_config_t options = {0}; options.ble_adv_fast_enabled = BLE_ADV_FAST_ENABLED; options.ble_adv_fast_interval = APP_ADV_INTERVAL; options.ble_adv_fast_timeout = APP_ADV_TIMEOUT_IN_SECONDS; err_code = ble_advertising_init(&advdata, 0, &options, on_adv_evt, NULL); APP_ERROR_CHECK(err_code); }
void nrf_adv_conn_init(void) { uint32_t error_code; /* Fill advertisement data struct: */ uint8_t flags = BLE_GAP_ADV_FLAG_BR_EDR_NOT_SUPPORTED; memset(&ble_adv_data, 0, sizeof(ble_adv_data)); ble_adv_data.flags.size = 1; ble_adv_data.flags.p_data = &flags; ble_adv_data.name_type = BLE_ADVDATA_FULL_NAME; //ble_adv_data.p_manuf_specific_data = &man_data; ble_gap_conn_sec_mode_t name_sec_mode = {1, 1}; ble_gap_addr_t my_addr; error_code = sd_ble_gap_address_get(&my_addr); APP_ERROR_CHECK(error_code); char name[64]; sprintf(name, "rbc_mesh #%d", ((uint16_t) my_addr.addr[4] << 8) | (my_addr.addr[5])); error_code = sd_ble_gap_device_name_set(&name_sec_mode, (uint8_t*) name, strlen(name)); APP_ERROR_CHECK(error_code); /* Set advertisement data with ble_advdata-lib */ error_code = ble_advdata_set(&ble_adv_data, NULL); APP_ERROR_CHECK(error_code); /* Start advertising */ error_code = sd_ble_gap_adv_start(&ble_adv_params); APP_ERROR_CHECK(error_code); }
/**@brief Function for the Advertising functionality initialization. * * @details Encodes the required advertising data and passes it to the stack. * Also builds a structure to be passed to the stack when starting advertising. */ static void advertising_init(void) { uint32_t err_code; ble_advdata_t advdata; ble_uuid_t service_uuid; uint8_t flags = BLE_GAP_ADV_FLAGS_LE_ONLY_GENERAL_DISC_MODE; service_uuid.type = m_dfu.uuid_type; service_uuid.uuid = BLE_DFU_SERVICE_UUID; // Build and set advertising data. memset(&advdata, 0, sizeof(advdata)); advdata.name_type = BLE_ADVDATA_FULL_NAME; advdata.include_appearance = false; advdata.flags.size = sizeof(flags); advdata.flags.p_data = &flags; advdata.uuids_more_available.uuid_cnt = 1; advdata.uuids_more_available.p_uuids = &service_uuid; err_code = ble_advdata_set(&advdata, NULL); APP_ERROR_CHECK(err_code); // Initialize advertising parameters (used when starting advertising). memset(&m_adv_params, 0, sizeof(m_adv_params)); m_adv_params.type = BLE_GAP_ADV_TYPE_ADV_IND; m_adv_params.p_peer_addr = NULL; m_adv_params.fp = BLE_GAP_ADV_FP_ANY; m_adv_params.interval = APP_ADV_INTERVAL; m_adv_params.timeout = APP_ADV_TIMEOUT_IN_SECONDS; }
static void adv_sensors(void) { uint32_t err_code; uint8_t flags = BLE_GAP_ADV_FLAGS_LE_ONLY_GENERAL_DISC_MODE; ble_advdata_manuf_data_t manuf_specific_data; memcpy(&m_beacon_info[0], &m_sensor_info.temp, 4); memcpy(&m_beacon_info[4], &m_sensor_info.humidity, 4); memcpy(&m_beacon_info[8], &m_sensor_info.light, 4); memcpy(&m_beacon_info[12], &m_sensor_info.pressure, 4); //memcpy(&m_beacon_info[16], &m_sensor_info.acceleration, 2); manuf_specific_data.company_identifier = APP_COMPANY_IDENTIFIER; manuf_specific_data.data.p_data = (uint8_t *) m_beacon_info; manuf_specific_data.data.size = APP_BEACON_INFO_LENGTH; // Build and set advertising data. memset(&advdata, 0, sizeof(advdata)); advdata.name_type = BLE_ADVDATA_FULL_NAME; advdata.flags = flags; advdata.p_manuf_specific_data = &manuf_specific_data; err_code = ble_advdata_set(&advdata, NULL); APP_ERROR_CHECK(err_code); }
/**@brief Advertising functionality initialization. * * @details Encodes the required advertising data and passes it to the stack. * Also builds a structure to be passed to the stack when starting advertising. */ void bleApp_advertisingInit() { uint32_t err_code; ble_advdata_t advdata; ble_advdata_t scanrsp; ble_advdata_manuf_data_t manuf_data; uint8_t spp_key[3] = {0x00, 0x00, 0x00}; uint8_t flags = BLE_GAP_ADV_FLAGS_LE_ONLY_GENERAL_DISC_MODE; // YOUR_JOB: Use UUIDs for service(s) used in your application. ble_uuid_t adv_uuids[] = {{SPS_UUID_SERVICE, m_sps.service_uuid_type}}; // Build and set advertising data memset(&advdata, 0, sizeof(advdata)); advdata.name_type = BLE_ADVDATA_NO_NAME; //advdata.include_appearance = true; advdata.flags.size = sizeof(flags); advdata.flags.p_data = &flags; advdata.uuids_complete.uuid_cnt = sizeof(adv_uuids) / sizeof(adv_uuids[0]); advdata.uuids_complete.p_uuids = adv_uuids; manuf_data.company_identifier = 0xFFFF; manuf_data.data.size = 3; manuf_data.data.p_data = spp_key; advdata.p_manuf_specific_data = &manuf_data; memset(&scanrsp, 0, sizeof(scanrsp)); scanrsp.name_type = BLE_ADVDATA_FULL_NAME; scanrsp.include_appearance = true; err_code = ble_advdata_set(&advdata, &scanrsp); APP_ERROR_CHECK(err_code); }
void advertising_init(void) { ble_advdata_t advdata; uint8_t flags = BLE_GAP_ADV_FLAGS_LE_ONLY_GENERAL_DISC_MODE; // Set advertising data memset(&advdata, 0, sizeof(advdata)); advdata.name_type = BLE_ADVDATA_FULL_NAME; advdata.include_appearance = false; advdata.flags.size = sizeof(flags); advdata.flags.p_data = &flags; // Use manufacturer specific data to broadcast imu data ble_advdata_manuf_data_t adv_manuf_data; uint8_array_t adv_manuf_data_array; uint8_t adv_manuf_data_data[sizeof(imu_data_t)]; adv_manuf_data_array.p_data = (uint8_t*) get_imu_data( (imu_data_t*) adv_manuf_data_data ); adv_manuf_data_array.size = sizeof(adv_manuf_data_data); // Company identifier of Nordic adv_manuf_data.company_identifier = 0x0059; adv_manuf_data.data = adv_manuf_data_array; advdata.p_manuf_specific_data = &adv_manuf_data; // Advertise, but no scan response APP_ERROR_CHECK(ble_advdata_set(&advdata, NULL)); }
/*JSON{ "type" : "staticmethod", "class" : "NRF", "name" : "setAdvertising", "generate" : "jswrap_nrf_bluetooth_setAdvertising", "params" : [ ["data","JsVar","The data to advertise as an object - see below for more info"] ] } Data is of the form `{ UUID : data_as_byte_array }`. For example to return battery level at 95%, do: ``` NRF.setAdvertising({ 0x180F : [95] }); ``` Or you could report the current temperature: ``` setInterval(function() { NRF.setAdvertising({ 0x1809 : [0|E.getTemperature()] }); }, 30000); ``` */ void jswrap_nrf_bluetooth_setAdvertising(JsVar *data) { uint32_t err_code; ble_advdata_t advdata; setup_advdata(&advdata); if (jsvIsObject(data)) { ble_advdata_service_data_t *service_data = (ble_advdata_service_data_t*)alloca(jsvGetChildren(data)*sizeof(ble_advdata_service_data_t)); int n = 0; JsvObjectIterator it; jsvObjectIteratorNew(&it, data); while (jsvObjectIteratorHasValue(&it)) { service_data[n].service_uuid = jsvGetIntegerAndUnLock(jsvObjectIteratorGetKey(&it)); JsVar *v = jsvObjectIteratorGetValue(&it); JSV_GET_AS_CHAR_ARRAY(dPtr, dLen, v); jsvUnLock(v); service_data[n].data.size = dLen; service_data[n].data.p_data = dPtr; jsvObjectIteratorNext(&it); n++; } jsvObjectIteratorFree(&it); advdata.service_data_count = n; advdata.p_service_data_array = service_data; } else if (!jsvIsUndefined(data)) { jsExceptionHere(JSET_TYPEERROR, "Expecting object or undefined, got %t", data); } err_code = ble_advdata_set(&advdata, NULL); if (err_code) jsExceptionHere(JSET_ERROR, "Got BLE error code %d", err_code); }
/**@brief Function for initializing the Advertising functionality. */ static void advertising_init(void) { uint32_t err_code; ble_advdata_t advdata; setup_advdata(&advdata); err_code = ble_advdata_set(&advdata, NULL); APP_ERROR_CHECK(err_code); }
static void advertising_init(uint8_t *data, uint8_t size) { #define COMPANY_IDENTIFIER (0x1000) /* reserver ID */ static ble_advdata_manuf_data_t manuf_specific_data; /**< Manufacturer specific data. */ uint32_t err_code; ble_advdata_t advdata; ble_advdata_t scanrsp; uint8_t flags = BLE_GAP_ADV_FLAGS_LE_ONLY_LIMITED_DISC_MODE; ble_uuid_t adv_uuids[] = {{BLE_UUID_NUS_SERVICE,m_nus.uuid_type}}; memset(&advdata, 0, sizeof(advdata)); advdata.name_type = BLE_ADVDATA_FULL_NAME; advdata.include_appearance = false; advdata.flags = flags; memset(&scanrsp, 0, sizeof(scanrsp)); scanrsp.uuids_complete.uuid_cnt = sizeof(adv_uuids) / sizeof(adv_uuids[0]); scanrsp.uuids_complete.p_uuids = adv_uuids; manuf_specific_data.company_identifier = COMPANY_IDENTIFIER; manuf_specific_data.data.p_data = &data[0]; manuf_specific_data.data.size = size; advdata.p_manuf_specific_data = &manuf_specific_data; err_code = ble_advdata_set(&advdata, &scanrsp); APP_ERROR_CHECK(err_code); }
/**@brief Function for initializing the Advertising functionality. * * @details Encodes the required advertising data and passes it to the stack. * Also builds a structure to be passed to the stack when starting advertising. */ static void advertising_init(void) { uint32_t err_code; // Use the simplest send adv packets only mode uint8_t flags = BLE_GAP_ADV_FLAG_BR_EDR_NOT_SUPPORTED; // More manufacturing only stuff that might get added back in ble_advdata_manuf_data_t manuf_specific_data; manuf_specific_data.company_identifier = APP_COMPANY_IDENTIFIER; #if defined(USE_UICR_FOR_MAJ_MIN_VALUES) // If USE_UICR_FOR_MAJ_MIN_VALUES is defined, the major and minor values will be read from the // UICR instead of using the default values. The major and minor values obtained from the UICR // are encoded into advertising data in big endian order (MSB First). // To set the UICR used by this example to a desired value, write to the address 0x10001080 // using the nrfjprog tool. The command to be used is as follows. // nrfjprog --snr <Segger-chip-Serial-Number> --memwr 0x10001080 --val <your major/minor value> // For example, for a major value and minor value of 0xabcd and 0x0102 respectively, the // the following command should be used. // nrfjprog --snr <Segger-chip-Serial-Number> --memwr 0x10001080 --val 0xabcd0102 uint16_t major_value = ((*(uint32_t *)UICR_ADDRESS) & 0xFFFF0000) >> 16; uint16_t minor_value = ((*(uint32_t *)UICR_ADDRESS) & 0x0000FFFF); uint8_t index = MAJ_VAL_OFFSET_IN_BEACON_INFO; m_beacon_info[index++] = MSB(major_value); m_beacon_info[index++] = LSB(major_value); m_beacon_info[index++] = MSB(minor_value); m_beacon_info[index++] = LSB(minor_value); #endif manuf_specific_data.data.p_data = (uint8_t *) m_beacon_info; manuf_specific_data.data.size = APP_BEACON_INFO_LENGTH; // Build and set advertising data. memset(&advdata, 0, sizeof(advdata)); advdata.name_type = BLE_ADVDATA_FULL_NAME; advdata.include_appearance = false; advdata.flags.size = sizeof(flags); advdata.flags.p_data = &flags; //advdata.p_manuf_specific_data = &manuf_specific_data; err_code = ble_advdata_set(&advdata, NULL); APP_ERROR_CHECK(err_code); // Initialize advertising parameters (used when starting advertising). memset(&m_adv_params, 0, sizeof(m_adv_params)); m_adv_params.type = BLE_GAP_ADV_TYPE_ADV_NONCONN_IND; //m_adv_params.type = BLE_GAP_ADV_TYPE_ADV_IND; m_adv_params.p_peer_addr = NULL; // Undirected advertisement. m_adv_params.fp = BLE_GAP_ADV_FP_ANY; m_adv_params.interval = NON_CONNECTABLE_ADV_INTERVAL; m_adv_params.timeout = APP_CFG_NON_CONN_ADV_TIMEOUT; }
static void set_advertisment(int32_t temperature, uint8_t temperature_exponent, uint8_t battery, uint16_t humidity) { uint32_t err_code; ble_advdata_t advdata; uint8_t flags = BLE_GAP_ADV_FLAG_BR_EDR_NOT_SUPPORTED; // device name ble_gap_conn_sec_mode_t sec_mode; BLE_GAP_CONN_SEC_MODE_SET_OPEN(&sec_mode); err_code = sd_ble_gap_device_name_set(&sec_mode, (const uint8_t *)DEVICE_NAME, strlen(DEVICE_NAME)); // battery level ble_advdata_service_data_t srv_data[3]; uint8_array_t data_array; uint8_t data; data = 99; data_array.p_data = &data; data_array.size = 1; srv_data[0].service_uuid = BLE_UUID_BATTERY_SERVICE; srv_data[0].data = data_array; // temperature uint8_array_t data_array2; uint8_t data2[4]; data2[0] = ((uint8_t *)&temperature)[0]; data2[1] = ((uint8_t *)&temperature)[1]; data2[2] = ((uint8_t *)&temperature)[2]; data2[3] = temperature_exponent; //exponent data_array2.p_data = data2; data_array2.size = sizeof(data2); srv_data[1].service_uuid = BLE_UUID_TEMPERATURE_SERVICE; srv_data[1].data = data_array2; // humidity uint8_array_t data_array3; uint8_t data3[2]; data3[0] = ((uint8_t *)&humidity)[0]; data3[1] = ((uint8_t *)&humidity)[1]; data_array3.p_data = data3;; data_array3.size = 2; srv_data[2].service_uuid = BLE_UUID_HUMIDITY_SERVICE; srv_data[2].data = data_array3; // Build and set advertising data. memset(&advdata, 0, sizeof(advdata)); advdata.p_service_data_array = srv_data; advdata.service_data_count = 3; advdata.name_type = BLE_ADVDATA_FULL_NAME; advdata.flags = flags; err_code = ble_advdata_set(&advdata, NULL); APP_ERROR_CHECK(err_code); }
/**@brief Function for initializing the Advertising functionality. * * @details Encodes the required advertising data and passes it to the stack. * Also builds a structure to be passed to the stack when starting advertising. */ static void advertising_init(void) { uint32_t err_code; ble_advdata_t advdata; // Struct containing advertising parameters uint8_t flags = BLE_GAP_ADV_FLAGS_LE_ONLY_GENERAL_DISC_MODE; // Defines how your device is seen (or not seen) by other devices ble_uuid_t adv_uuids[] = {{0x1816, BLE_UUID_TYPE_BLE}}; // Random example User Unique Identifier /* commented out so can fit full device name in advertisement manufacturer data set in scan response instead ble_advdata_manuf_data_t manuf_data; uint8_t data[] = "SomeData!"; manuf_data.company_identifier = 0x0059; manuf_data.data.p_data = data; manuf_data.data.size = sizeof(data); */ // Populate the advertisement packet // Always initialize all fields in structs to zero or you might get unexpected behaviour memset(&advdata, 0, sizeof(advdata)); advdata.name_type = BLE_ADVDATA_FULL_NAME; advdata.include_appearance = false; //advdata.short_name_len = 6; advdata.flags = flags; // Must be included, but not discussed in this tutorial advdata.uuids_complete.uuid_cnt = sizeof(adv_uuids) / sizeof(adv_uuids[0]); // Must be included, but not discussed in this tutorial advdata.uuids_complete.p_uuids = adv_uuids; // Must be included, but not discussed in this tutorial // commented out so can fit full device name in advertisement // manufacturer data is set in scan response instead //advdata.p_manuf_specific_data = &manuf_data; /*ble_advdata_manuf_data_t manuf_data_response; uint8_t dataresponse[] = "LotsOfWords"; manuf_data_response.company_identifier = 0x0059; manuf_data_response.data.p_data = dataresponse; manuf_data_response.data.size = sizeof(dataresponse); */ ble_uuid_t m_adv_uuids[] = {{BLE_UUID_OUR_SERVICE, BLE_UUID_TYPE_VENDOR_BEGIN}}; ble_advdata_t advdata_response; // always initialize all fields in structs to zero or else might get unexpected behavior memset(&advdata_response, 0, sizeof(advdata_response)); // populate scan response packet //advdata_response.name_type = BLE_ADVDATA_NO_NAME; //advdata_response.p_manuf_specific_data = &manuf_data_response; advdata_response.uuids_complete.uuid_cnt = sizeof(m_adv_uuids) / sizeof(m_adv_uuids[0]); advdata_response.uuids_complete.p_uuids = m_adv_uuids; // Set the advertisement and scan response packet. err_code = ble_advdata_set(&advdata, NULL); APP_ERROR_CHECK(err_code);// Check for errors }
static void bluetooth_init(void) { uint32_t err_code; ble_gap_conn_params_t gppcp; ble_advdata_t advdata; ble_gap_conn_sec_mode_t sec_mode; uint8_t flags = BLE_GAP_ADV_FLAGS_LE_ONLY_LIMITED_DISC_MODE; // Initialise SoftDevice, and enable BLE event interrupt. BLE_STACK_HANDLER_INIT(NRF_CLOCK_LFCLKSRC_XTAL_20_PPM, BLE_L2CAP_MTU_DEF, ble_evt_dispatch, false); // Set GAP parameters BLE_GAP_CONN_SEC_MODE_SET_OPEN(&sec_mode); err_code = sd_ble_gap_device_name_set(&sec_mode, DEVICE_NAME, strlen(DEVICE_NAME)); APP_ERROR_CHECK(err_code); err_code = sd_ble_gap_appearance_set(BLE_APPEARANCE_GENERIC_TAG); APP_ERROR_CHECK(err_code); memset(&gppcp, 0, sizeof(gppcp)); gppcp.min_conn_interval = MIN_CONN_INTERVAL; gppcp.max_conn_interval = MAX_CONN_INTERVAL; gppcp.slave_latency = SLAVE_LATENCY; gppcp.conn_sup_timeout = CONN_SUP_TIMEOUT; err_code = sd_ble_gap_ppcp_set(&gppcp); APP_ERROR_CHECK(err_code); // Build and set advertising data. memset(&advdata, 0, sizeof(advdata)); advdata.name_type = BLE_ADVDATA_FULL_NAME; advdata.include_appearance = true; advdata.flags.size = sizeof(flags); advdata.flags.p_data = &flags; err_code = ble_advdata_set(&advdata, NULL); APP_ERROR_CHECK(err_code); // Initialise advertising parameters (used when starting advertising). memset(&m_adv_params, 0, sizeof(m_adv_params)); m_adv_params.type = BLE_GAP_ADV_TYPE_ADV_IND; m_adv_params.p_peer_addr = NULL; // Undirected advertisement. m_adv_params.fp = BLE_GAP_ADV_FP_ANY; m_adv_params.interval = APP_ADV_INTERVAL; m_adv_params.timeout = APP_ADV_TIMEOUT_IN_SECONDS; // Start advertising when entering main loop. m_start_adv_flag = true; }
/**@brief Function for initializing the Advertising functionality. * * @details Encodes the required advertising data and passes it to the stack. * Also builds a structure to be passed to the stack when starting advertising. */ static void advertising_init(void) { uint32_t err_code; ble_advdata_t advdata; uint8_t flags = BLE_GAP_ADV_FLAG_BR_EDR_NOT_SUPPORTED; ble_gap_conn_sec_mode_t sec_mode; ble_gap_addr_t my_addr; BLE_GAP_CONN_SEC_MODE_SET_OPEN(&sec_mode); err_code = sd_ble_gap_device_name_set(&sec_mode, (const uint8_t *)DEVICE_NAME, strlen(DEVICE_NAME)); APP_ERROR_CHECK(err_code); err_code = sd_ble_gap_address_get(&my_addr); APP_ERROR_CHECK(err_code); my_addr.addr_type = BLE_GAP_ADDR_TYPE_PUBLIC; my_addr.addr[5] = 0x00; err_code = sd_ble_gap_address_set(&my_addr); APP_ERROR_CHECK(err_code); IPV6_EUI64_CREATE_FROM_EUI48 (eui64_local_iid.identifier, my_addr.addr, my_addr.addr_type); ble_uuid_t adv_uuids[] = { {BLE_UUID_IPSP_SERVICE, BLE_UUID_TYPE_BLE} }; //Build and set advertising data. memset(&advdata, 0, sizeof(advdata)); advdata.name_type = BLE_ADVDATA_FULL_NAME; advdata.flags.size = sizeof(flags); advdata.flags.p_data = &flags; advdata.uuids_complete.uuid_cnt = sizeof(adv_uuids) / sizeof(adv_uuids[0]); advdata.uuids_complete.p_uuids = adv_uuids; err_code = ble_advdata_set(&advdata, NULL); APP_ERROR_CHECK(err_code); //Initialize advertising parameters (used when starting advertising). memset(&m_adv_params, 0, sizeof(m_adv_params)); m_adv_params.type = BLE_GAP_ADV_TYPE_ADV_IND; m_adv_params.p_peer_addr = NULL; // Undirected advertisement. m_adv_params.fp = BLE_GAP_ADV_FP_ANY; m_adv_params.interval = APP_ADV_ADV_INTERVAL; m_adv_params.timeout = APP_ADV_TIMEOUT; }
/**@brief Function for starting connectable advertising of the eddystone beacon to register it * @details Used by the eddystone_registration_ui module as a callback when the registration button is pressed. */ static void eddystone_ble_registr_adv_cb(void) { if (m_is_connectable_adv != true && m_is_connected == false) { all_advertising_halt(); uint32_t err_code; ble_advdata_t adv_data; ble_advdata_t scrsp_data; ble_uuid_t adv_uuids[] = {{EDDYSTONE_UUID, BLE_UUID_TYPE_BLE}}; ble_uuid_t scrp_uuids[] = {{BLE_UUID_ECS_SERVICE, m_ecs_uuid_type}}; uint8_array_t eddystone_data_array; // Array for Service Data structure. eddystone_data_array.size = 0; eddystone_data_array.p_data = NULL; 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(&adv_data, 0, sizeof(adv_data)); adv_data.name_type = BLE_ADVDATA_NO_NAME; adv_data.flags = BLE_GAP_ADV_FLAGS_LE_ONLY_GENERAL_DISC_MODE; adv_data.uuids_complete.uuid_cnt = sizeof(adv_uuids) / sizeof(adv_uuids[0]); adv_data.uuids_complete.p_uuids = adv_uuids; adv_data.p_service_data_array = &service_data; // Pointer to Service Data structure. adv_data.service_data_count = 1; memset(&scrsp_data, 0, sizeof(scrsp_data)); scrsp_data.name_type = BLE_ADVDATA_FULL_NAME; scrsp_data.include_appearance = false; scrsp_data.uuids_complete.uuid_cnt = sizeof(scrp_uuids) / sizeof(scrp_uuids[0]); scrsp_data.uuids_complete.p_uuids = scrp_uuids; err_code = ble_advdata_set(&adv_data, &scrsp_data); APP_ERROR_CHECK(err_code); memset(&m_conn_adv_params, 0, sizeof(m_conn_adv_params)); m_conn_adv_params.type = BLE_GAP_ADV_TYPE_ADV_IND; m_non_conn_adv_params.p_peer_addr = NULL; // Undirected advertisement. m_non_conn_adv_params.fp = BLE_GAP_ADV_FP_ANY; m_conn_adv_params.interval = MSEC_TO_UNITS(APP_CFG_CONNECTABLE_ADV_INTERVAL_MS, UNIT_0_625_MS); m_conn_adv_params.timeout = APP_CFG_CONNECTABLE_ADV_TIMEOUT; m_is_connectable_adv = true; eddystone_ble_advertising_start(EDDYSTONE_BLE_ADV_CONNECTABLE_TRUE); } }
uint32_t iot_gateway_adv (char* post_url_str, uint8_t incentive_program_level, uint8_t reliability_level, uint8_t sensors, uint8_t* data, uint8_t data_len, const ble_advdata_t* scan_response_data) { uint32_t err_code; // Check inputs if (incentive_program_level > 0xf) return NRF_ERROR_INVALID_PARAM; if (reliability_level > 0xf) return NRF_ERROR_INVALID_PARAM; if (data_len > 10) return NRF_ERROR_INVALID_PARAM; // Buffer to craft the adv packet format uint8_t gateway_api[IOT_GATEWAY_PKT_MAX_LEN] = {0}; // First 14 bytes are destination URL strncpy((char*) gateway_api, post_url_str, IOT_GATEWAY_PKT_URL_MAX_LEN); // Next byte is the incentive program and reliability gateway_api[14] = (incentive_program_level << 4) | reliability_level; // The which sensors the app wants gateway_api[15] = sensors; // Finally app-specific arbitrary data memcpy(gateway_api+16, data, data_len); ble_advdata_service_data_t service_data; service_data.service_uuid = (((uint16_t) gateway_api[0])<<8) + gateway_api[1]; service_data.data.p_data = gateway_api+2; service_data.data.size = IOT_GATEWAY_PKT_HEADER_LEN-2 + data_len; // Build and set advertising data. ble_advdata_t advdata; memset(&advdata, 0, sizeof(advdata)); advdata.flags = BLE_GAP_ADV_FLAGS_LE_ONLY_GENERAL_DISC_MODE; advdata.p_service_data_array = &service_data; advdata.service_data_count = 1; // Actually set advertisement data err_code = ble_advdata_set(&advdata, scan_response_data); APP_ERROR_CHECK(err_code); // Start the advertisement advertising_start(); return NRF_SUCCESS; }
void PacketData_Update() { uint8_t flags = BLE_GAP_ADV_FLAG_BR_EDR_NOT_SUPPORTED; PACKET_INCR++; //Incrementing the value incr_cnt++; if(incr_cnt==50) { incr_cnt = 0; SensorsInit(); } supercap_measure_start(); TWI_init(); //Initializing TWI and reading values __HUMIDITY = HDC1008_ReadHumidity(); __PRESSURE = MPL3115A2_Read_Baro()>>6; __PRESSURE/=10; //Result in tens of Pascals (9500 equals 95000 Pa etc.) __TEMP = MPL3115A2_Read_Temp(); HDC1008_TriggerHumidity(); TWI_powerdown(); //Power-down of TWI m_beacon_info[6] = __PRESSURE>>8; //Putting data into 2.4 Ghz beacon packet and update advertising data m_beacon_info[7] = (__PRESSURE & 0xFF); m_beacon_info[8] = __TEMP>>8; m_beacon_info[9] = (__TEMP & 0xFF); m_beacon_info[10] = __HUMIDITY; m_beacon_info[4] = PACKET_INCR; m_beacon_info[12] = __SUPERCAP_VOLTAGE>>8; m_beacon_info[13] = __SUPERCAP_VOLTAGE&0xFF; manuf_specific_data.data.p_data = (uint8_t *) m_beacon_info; // Build and set advertising data. memset(&advdata, 0, sizeof(advdata)); advdata.flags.size = sizeof(flags); advdata.flags.p_data = &flags; advdata.p_manuf_specific_data = &manuf_specific_data; ble_advdata_set(&advdata, NULL); CC110L_PACKETCONTENT[2+6] = __PRESSURE>>8; //Putting data into 868 Mhz packet CC110L_PACKETCONTENT[2+7] = (__PRESSURE & 0xFF); CC110L_PACKETCONTENT[2+8] = __TEMP>>8; CC110L_PACKETCONTENT[2+9] = (__TEMP & 0xFF); CC110L_PACKETCONTENT[2+10] = __HUMIDITY; CC110L_PACKETCONTENT[2+4] = PACKET_INCR; CC110L_PACKETCONTENT[2+12] = __SUPERCAP_VOLTAGE>>8; CC110L_PACKETCONTENT[2+13] = __SUPERCAP_VOLTAGE&0xFF; }
/**@brief Function for setting up advertising data. */ static void advertising_data_set(void) { uint32_t err_code; ble_advdata_t const adv_data = { .name_type = BLE_ADVDATA_FULL_NAME, .flags = BLE_GAP_ADV_FLAGS_LE_ONLY_GENERAL_DISC_MODE, .include_appearance = false, }; err_code = ble_advdata_set(&adv_data, NULL); APP_ERROR_CHECK(err_code); } /**@brief Function for starting advertising. */ void advertising_start(void) { ble_gap_adv_params_t const adv_params = { .type = BLE_GAP_ADV_TYPE_ADV_IND, .p_peer_addr = NULL, .fp = BLE_GAP_ADV_FP_ANY, .interval = ADV_INTERVAL, .timeout = 0, }; NRF_LOG_INFO("Starting advertising.\r\n"); uint32_t err_code; err_code = sd_ble_gap_adv_start(&adv_params); APP_ERROR_CHECK(err_code); bsp_board_led_on(LED_SCANNING_ADVERTISING); } /**@brief Function to start scanning. */ void scan_start(void) { NRF_LOG_INFO("Starting scan.\r\n"); ret_code_t err_code; err_code = sd_ble_gap_scan_start(&m_scan_param); APP_ERROR_CHECK(err_code); bsp_board_led_on(LED_SCANNING_ADVERTISING); }
/**@brief Function for initializing the Advertising functionality. * * @details Encodes the required advertising data and passes it to the stack. * Also builds a structure to be passed to the stack when starting advertising. */ static void advertising_init(void) { uint32_t err_code; ble_advdata_t advdata; ble_advdata_t scanrsp; uint8_t flags = BLE_GAP_ADV_FLAGS_LE_ONLY_GENERAL_DISC_MODE; ble_advdata_manuf_data_t data; uint64_t id; ble_uuid_t blueio_uuids[] = { {LMXBLUE_UUID_SERVICE, g_LmxServ.uuid_type}, }; ble_uuid_t std_uuids[] = { // {BLE_UUID_BATTERY_SERVICE, BLE_UUID_TYPE_BLE}, {BLE_UUID_DEVICE_INFORMATION_SERVICE, BLE_UUID_TYPE_BLE} }; id = ((uint64_t)NRF_FICR->DEVICEID[1] << 32) | (uint64_t)NRF_FICR->DEVICEID[0]; data.company_identifier = 0x2082; data.data.p_data = (uint8_t*)&id; data.data.size = sizeof(id); // Build and set advertising data memset(&advdata, 0, sizeof(advdata)); advdata.name_type = BLE_ADVDATA_FULL_NAME; advdata.include_appearance = true; //advdata.flags.size = sizeof(flags); //advdata.flags.p_data = &flags; advdata.flags = flags; advdata.uuids_complete.uuid_cnt = sizeof(std_uuids) / sizeof(std_uuids[0]); advdata.uuids_complete.p_uuids = std_uuids; memset(&scanrsp, 0, sizeof(scanrsp)); scanrsp.uuids_complete.uuid_cnt = sizeof(blueio_uuids) / sizeof(blueio_uuids[0]); scanrsp.uuids_complete.p_uuids = blueio_uuids; scanrsp.p_manuf_specific_data = &data; err_code = ble_advdata_set(&advdata, &scanrsp); APP_ERROR_CHECK(err_code); }