Module for automated bluetooth advertising. Advertising is restarted on disconnect events automatically. Defaults to the following characteristics: More...

Detailed Description

Module for automated bluetooth advertising. Advertising is restarted on disconnect events automatically. Defaults to the following characteristics:

Files

file  nimble_autoadv.h
 

Macros

#define NIMBLE_AUTOADV_DEVICE_NAME   NULL
 Name of the device for the advertising procedure. More...
 
#define NIMBLE_AUTOADV_START_MANUALLY   0
 If an application is calling functions from nimble, e.g. More...
 

Functions

void nimble_autoadv_init (void)
 Initialize autoadv module.
 
void nimble_autoadv_set_ble_gap_adv_params (struct ble_gap_adv_params *params)
 Set struct for additional arguments specifying the particulars of the advertising procedure. More...
 
int nimble_autoadv_add_field (uint8_t type, const void *data, size_t data_len)
 Add a new field to the given advertising data. More...
 
void nimble_auto_adv_set_adv_duration (int32_t duration_ms)
 Set the duration for the advertising procedure. More...
 
void nimble_auto_adv_set_gap_cb (ble_gap_event_fn *cb, void *cb_arg)
 Set the callback for gap events. More...
 
void nimble_autoadv_start (void)
 Start the automated advertising procedure. More...
 
void nimble_autoadv_stop (void)
 Stop the automated advertising procedure. More...
 
void nimble_autoadv_reset (void)
 Reset all data regarding the advertising process. More...
 

Macro Definition Documentation

◆ NIMBLE_AUTOADV_DEVICE_NAME

#define NIMBLE_AUTOADV_DEVICE_NAME   NULL

Name of the device for the advertising procedure.

If this is not defined, it will be defined as NULL, resulting in not configuring a name at all.

Definition at line 43 of file nimble_autoadv.h.

◆ NIMBLE_AUTOADV_START_MANUALLY

#define NIMBLE_AUTOADV_START_MANUALLY   0

If an application is calling functions from nimble, e.g.

ble_svc_gap_device_name_set(), NIMBLE_AUTOADV_START_MANUALLY should be set to 1 and then the application should call nimble_autoadv_start() after all of its nimble calls to prevent errors like BLE_HS_EBUSY.

Defined as 0 by default.

Definition at line 56 of file nimble_autoadv.h.

Function Documentation

◆ nimble_auto_adv_set_adv_duration()

void nimble_auto_adv_set_adv_duration ( int32_t  duration_ms)

Set the duration for the advertising procedure.

     If there is an active advertising process, it will be restarted.
Parameters
[in]duration_msduration of advertising procedure in ms

◆ nimble_auto_adv_set_gap_cb()

void nimble_auto_adv_set_gap_cb ( ble_gap_event_fn *  cb,
void *  cb_arg 
)

Set the callback for gap events.

Callback is used for the logic when to start the advertising procedure.

If there is an active advertising process, it will be restarted.

Parameters
[in]cbThe callback to associate with this advertising procedure. If advertising ends, the event is reported through this callback. If advertising results in a connection, the connection inherits this callback as its event-reporting mechanism.
[in]cb_argThe optional argument to pass to the callback function.

◆ nimble_autoadv_add_field()

int nimble_autoadv_add_field ( uint8_t  type,
const void *  data,
size_t  data_len 
)

Add a new field to the given advertising data.

     If there is an active advertising process, it will be restarted.
Parameters
[in]typefield type to add
[in]datapayload for the field
[in]data_lenlength of the payload in bytes
Returns
BLUETIL_AD_OK if the new field was added
BLUETIL_AD_NOMEM if there is not enough space to write add field

◆ nimble_autoadv_reset()

void nimble_autoadv_reset ( void  )

Reset all data regarding the advertising process.

Following characteristics will be applied:

  • General discoverable mode (BLE_GAP_DISC_MODE_GEN)
  • Undirected connectable mode (BLE_GAP_CONN_MODE_UND)
  • No expiration (BLE_HS_FOREVER)
  • No name

◆ nimble_autoadv_set_ble_gap_adv_params()

void nimble_autoadv_set_ble_gap_adv_params ( struct ble_gap_adv_params *  params)

Set struct for additional arguments specifying the particulars of the advertising procedure.

Uses memcpy internally.

If there is an active advertising process, it will be restarted.

Parameters
[in]paramsstruct with customized additional arguments

◆ nimble_autoadv_start()

void nimble_autoadv_start ( void  )

Start the automated advertising procedure.

     Needs to be called manually when NIMBLE_AUTOADV_START_MANUALLY was
     set to true and after every call of nimble_autoadv_stop() to start
     advertising again.

◆ nimble_autoadv_stop()

void nimble_autoadv_stop ( void  )

Stop the automated advertising procedure.

After calling this, you have to call nimble_autoadv_start() manually to restart the process.