Bluetooth Low Energy

Riotee has limited support for BLE. You can use the API to send advertisement packets with a custom payload on the three advertising channels.

The implementation is not standard-conformant. You may only use it for evaluation purposes in dedicated facilities where it cannot interfere with other spectrum users.

Important

Always check the return code of riotee_ble_advertise(...) to distinguish between a power failure (RIOTEE_ERR_RESET) and successful advertising (RIOTEE_SUCCESS).

Example usage

 1
 2#include "riotee.h"
 3#include "riotee_ble.h"
 4#include "riotee_timing.h"
 5
 6const uint8_t adv_address[] = {0x01, 0xEE, 0xC0, 0xFF, 0x03, 0x02};
 7const char adv_name[] = "RIOTEE";
 8
 9static struct {
10  unsigned int counter;
11} ble_data;
12
13void lateinit(void) {
14  riotee_ble_init();
15}
16
17int main() {
18  riotee_ble_adv_cfg_t adv_cfg = {.addr = adv_address,
19                                  .name = adv_name,
20                                  .name_len = 6,
21                                  .data = &ble_data,
22                                  .data_len = sizeof(ble_data),
23                                  .manufacturer_id = RIOTEE_BLE_ADV_MNF_NORDIC};
24  riotee_ble_adv_cfg(&adv_cfg);
25  ble_data.counter = 0;
26  for (;;) {
27    riotee_wait_cap_charged();
28    riotee_ble_advertise(ADV_CH_ALL);
29    ble_data.counter++;
30    /* Sleep at least 250ms before next advertising round */
31    riotee_sleep_ms(250);
32  }
33}

API reference

enum riotee_adv_pdu_type_t

Type of advertisement.

Values:

enumerator ADV_IND

Undirected, connectable advertisement.

enumerator ADV_DIRECT_IND

Directed, connectable advertisement.

enumerator ADV_NONCONN_IND

Undirected, unconnectable advertisement.

enumerator SCAN_REQ

Scan request.

enumerator SCAN_RSP

Scan response.

enumerator CONNECT_REQ

Connection request.

enumerator ADV_SCAN_IND

Scannable undirected advertisement.

enum riotee_adv_ch_t

Values:

enumerator ADV_CH_37
enumerator ADV_CH_38
enumerator ADV_CH_39
enumerator ADV_CH_ALL
riotee_rc_t riotee_ble_adv_cfg(riotee_ble_adv_cfg_t *cfg)

Sets up the internal packet buffer for advertisting with given name, address and payload size.

Parameters:
  • adv_addr – Pointer to address buffer.

  • adv_name – Advertising name of the device.

  • data – Pointer to payload.

  • data_len – Size of the payload.

Return values:
  • RIOTEE_SUCCESS – Successfully prepared advertisement.

  • RIOTEE_ERR_OVERFLOW – At least one argument is too long.

riotee_rc_t riotee_ble_advertise(riotee_adv_ch_t ch)

Advertises the given payload on the selected channel(s)

Parameters:

ch – Channel(s) on which advertisement should be sent.

Return values:
  • RIOTEE_SUCCESS – Advertisement successfully sent.

  • RIOTEE_ERR_RESET – Reset occured while sending advertisement.

  • RIOTEE_ERR_TEARDOWN – Teardown occured while sending advertisement.

void riotee_ble_init(void)

Initializes BLE driver.

RIOTEE_BLE_ADV_MNF_NORDIC
struct riotee_ble_adv_addr_t
struct riotee_ble_adv_header_t
struct riotee_adv_pck_t
#include <riotee_ble.h>

Common packet format for some ADV PDU types.

struct riotee_ble_adv_cfg_t
#include <riotee_ble.h>

BLE advertising configuration.