ruuvi.drivers.c
${PROJECT_VERSION}
Drivers for external sensors and peripherals on embedded systems.
|
Bluetooth Low Energy advertising. More...
Files | |
file | ruuvi_task_advertisement.c |
file | ruuvi_task_advertisement.h |
Data Structures | |
struct | rt_adv_init_t |
Initial configuration for advertisement. PHY will be transferred to GATT. More... | |
Macros | |
#define | SCAN_RSP_NAME_MAX_LEN (11U) |
Longer name gets truncated when advertised with UUID. More... | |
#define | RT_ADV_SCAN_WINDOW_MS (7000U) |
Window of one scan per channel. Scan takes this * num_channels time. More... | |
#define | RT_ADV_SCAN_INTERVAL_MS (7000U) |
Functions | |
rd_status_t | rt_adv_init (rt_adv_init_t *const adv_init_settings) |
Initializes data advertising. More... | |
rd_status_t | rt_adv_uninit (void) |
Uninitializes data advertising. More... | |
rd_status_t | rt_adv_stop (void) |
Stops advertising. This is relevant only if the message was on repeat. More... | |
rd_status_t | rt_adv_send_data (ri_comm_message_t *const msg) |
Send given message as a BLE advertisement. More... | |
rd_status_t | rt_adv_connectability_set (const bool enable, const char *const device_name) |
Start advertising BLE GATT connection. More... | |
bool | rt_adv_is_init (void) |
check if advertisement is initialized More... | |
rd_status_t | rt_adv_scan_start (const ri_comm_evt_handler_fp_t on_evt) |
Start scanning BLE advertisements. More... | |
rd_status_t | rt_adv_scan_stop (void) |
Abort scanning. More... | |
Bluetooth Low Energy advertising.
#define RT_ADV_SCAN_INTERVAL_MS (7000U) |
Definition at line 55 of file ruuvi_task_advertisement.h.
#define RT_ADV_SCAN_WINDOW_MS (7000U) |
Window of one scan per channel. Scan takes this * num_channels time.
Interval of one scan within a window. Can be at most equal to scan window. */
Definition at line 54 of file ruuvi_task_advertisement.h.
#define SCAN_RSP_NAME_MAX_LEN (11U) |
Longer name gets truncated when advertised with UUID.
Definition at line 51 of file ruuvi_task_advertisement.h.
rd_status_t rt_adv_connectability_set | ( | const bool | enable, |
const char *const | device_name | ||
) |
Start advertising BLE GATT connection.
This function configures the primary advertisement to be SCANNABLE_CONNECTABLE and sets up a scan response which has given device name (max 10 characters + NULL) and UUID of Nordic UART Service.
Be sure to configure the GATT before calling this function, as behaviour is undefined if someone tries to connect to tag while GATT is not configured.
[in] | enable | true to enable connectability, false to disable. |
[in] | device_name | NULL-terminated string representing device name, max 10 Chars + NULL. |
RD_SUCCESS | if operation was finished as expected. |
RD_ERROR_NULL | if name is NULL and trying to enable the scan response |
RD_ERROR_INVALID_STATE | if advertising isn't initialized or started. |
RD_ERROR_INVALID_LENGTH | if name size exceeds 10 bytes + NULL |
rd_status_t rt_adv_init | ( | rt_adv_init_t *const | adv_init_settings | ) |
Initializes data advertising.
The function setups advertisement interval, advertisement power, advertisement type, manufacturer ID for manufacturer specific data according to constants in application_config.h and ruuvi_boards.h.
It also configures a callback to be executed after advertisement for internal use. After calling this function advertisement data can be queued into advertisement buffer.
[in,out] | adv_init_settings | Input: Desired setup. Output: Configured setup. |
RD_SUCCESS | on success. |
RD_ERROR_INVALID_STATE | if advertising is already initialized. |
RD_ERROR_INVALID_PARAM | if configuration constant is invalid. Not initialized. |
bool rt_adv_is_init | ( | void | ) |
check if advertisement is initialized
rd_status_t rt_adv_scan_start | ( | const ri_comm_evt_handler_fp_t | on_evt | ) |
Start scanning BLE advertisements.
This is non-blocking, you'll need to handle incoming events.
PHY to be scanned is determined by radio initialization. If you have selected 2 MBit / s PHY, primary advertisements are scanned at 1 Mbit / s and secondary extended advertisement can be scanned at at 2 MBit / s.
Scan is done at 7000 ms window and interval, this consumes a lot of power and may collapse a coin cell battery.
Events are:
[in] | on_evt | Event handler for scan results. |
RD_SUCCESS | Scanning was started. |
RD_ERROR_INVALID_STATE | Advertising isn't initialized. |
rd_status_t rt_adv_scan_stop | ( | void | ) |
Abort scanning.
After calling this function scanning is immediately stopped.
rd_status_t rt_adv_send_data | ( | ri_comm_message_t *const | msg | ) |
Send given message as a BLE advertisement.
This function configures the primary advertisement packet with the flags and manufacturer specific data. Payload of the msg will be sent as the manufacturer specific data payload. Manufacturer ID is defined by RUUVI_BOARD_BLE_MANUFACTURER_ID in ruuvi_boards.h.
If the device is connectable, call
to setup the scan response and flags to advertise connectability.
Call rt_adv_stop to stop advertisements on repeat.
[in] | msg | message to be sent as manufacturer specific data payload. |
RD_ERROR_NULL | if msg is NULL. |
RD_ERROR_INVALID_STATE | if advertising isn't initialized or started. |
RD_ERROR_DATA_SIZE | if payload size is larger than 24 bytes. |
rd_status_t rt_adv_stop | ( | void | ) |
Stops advertising. This is relevant only if the message was on repeat.
RD_SUCCESS | on success |
rd_status_t rt_adv_uninit | ( | void | ) |
Uninitializes data advertising.
Can be called even if advertising was not initialized. Clears previous advertisement data if there was any.
RD_SUCCESS | on success |