Bluetooth LE Communication

Because the library does not handle Bluetooth LE communication, users must implement the GATT operations in their target language and alert the library of any BLE notifications. All BLE functions, types, and variables are in the connection.h header file.

MblMwBtleConnection

The MblMwBtleConnection struct is a tuple of functions pointers that the API will call to interact with GATT characteristics. You will need to implement functions that read and write characteristics and assign those addresses to the struct’s function pointers.

#include "metawear/core/connection.h"

static void write_gatt_char(const MblMwGattChar *characteristic, const uint8_t *value,
        uint8_t length) {
   // Code to write the value to the characteristic goes here
}

static void read_gatt_char(const MblMwGattChar *characteristic) {
   // Code to read the value from the characteristic goes here
}

int main(int argc, char **argv) {
    MblMwBtleConnection btle_conn = { write_gatt_char, read_gatt_char };
}

Characteristic Changes

MetaWear sends notifications via characteristic changes on its notification characteristic; the METAWEAR_SERVICE_NOTIFY_CHAR constant defines the characteristic UUID and its service UUID. Enable notifications on that characteristic and call mbl_mw_connection_notify_char_changed whenever the MetaWear notification characteristic changes.

Characteristic Reads

The API will also need to read GATT characteristics. The responses from characteristic reads must be passed to the API by calling mbl_mw_connection_char_read.