Hi there doesn't seem to be an example for usage for the BLEClientCharacteristic class.
I want to be able to do something similar to the following raspbian command
gatttool -b E1:32:B8:67:D4:CC -i hci0 -t random --char-write-req --handle=0x000c --value=0100 --listen
Write the value 0100 to the service with handle 0x000c on a client and listen to notifications that are received.
Bluefruit nRF52 Feather
Moderators: adafruit_support_bill, adafruit
Please be positive and constructive with your questions and comments.
- hathach
- Posts: 1270
- Joined: Tue Apr 23, 2013 1:02 am
Re: Bluefruit nRF52 Feather
Central support is still in development. But you could check out the builtin clients service that use the BLEClientCharacteristic internally.
https://github.com/adafruit/Adafruit_nR ... rc/clients
We will add an example when the API is finalized.
https://github.com/adafruit/Adafruit_nR ... rc/clients
We will add an example when the API is finalized.
- anthony92
- Posts: 5
- Joined: Mon Nov 20, 2017 11:35 pm
Re: Bluefruit nRF52 Feather
Thanks, that is exactly what I needed.
I got the notification working with the following code snippets.
Define constants
Main initialisation
Callbacks
I got the notification working with the following code snippets.
Define constants
Code: Select all
// Battery Service : 0000180F-0000-1000-8000-00805F9B34FB
// Notification Source (0x000c) : 00002902-0000-1000-8000-00805F9B34FB
// Data Source (0x000b) : 00002A19-0000-1000-8000-00805F9B34FB
const uint8_t BMU_UUID_SERVICE[]
{
0xFB, 0x34, 0x9B, 0x5F, 0x80, 0x00, 0x00, 0x80,
0x00, 0x10, 0x00, 0x00, 0x0F, 0x18, 0x00, 0x00
};
const uint8_t BMU_UUID_CHR_NOTIFICATION[]
{
0xFB, 0x34, 0x9B, 0x5F, 0x80, 0x00, 0x00, 0x80,
0x00, 0x10, 0x00, 0x00, 0x02, 0x29, 0x00, 0x00
};
const uint8_t BMU_UUID_CHR_DATA[]
{
0xFB, 0x34, 0x9B, 0x5F, 0x80, 0x00, 0x00, 0x80,
0x00, 0x10, 0x00, 0x00, 0x19, 0x2A, 0x00, 0x00
};
// Struct containing peripheral info
typedef struct prph_info_t {
prph_info_t()
: _service(BMU_UUID_SERVICE), _notification(BMU_UUID_CHR_NOTIFICATION), _data(BMU_UUID_CHR_DATA)
{ }
char name[32];
uint8_t address[6];
uint16_t conn_handle;
BLEClientService _service;
BLEClientCharacteristic _notification;
BLEClientCharacteristic _data;
} prph_info_t;
prph_info_t prphs[BLE_CENTRAL_MAX_CONN];
Main initialisation
Code: Select all
// Init peripheral pool
for (uint8_t idx=0; idx < BLE_CENTRAL_MAX_CONN; idx++) {
// Invalid all connection handle
prphs[idx].conn_handle = BLE_CONN_HANDLE_INVALID;
prphs[idx]._service.begin();
prphs[idx]._notification.begin(&prphs[idx]._service);
prphs[idx]._data.begin(&prphs[idx]._service);
prphs[idx]._notification.setNotifyCallback(notify_callback);
prphs[idx]._data.useAdaCallback(false);
prphs[idx]._data.setNotifyCallback(notify_callback);
}
Code: Select all
/**
* Callback invoked when an connection is established
* @param conn_handle
*/
void connect_callback(uint16_t conn_handle) {
// Scan for more devices
Bluefruit.Scanner.start(0);
// Find an available ID to use
int id = findConnHandle(BLE_CONN_HANDLE_INVALID);
// Eeek: Exceeded the number of connections !!!
if ( id < 0 ) return;
prph_info_t* peer = &prphs[id];
peer->conn_handle = conn_handle;
Bluefruit.Gap.getPeerName(conn_handle, peer->name, 32);
Bluefruit.Gap.getPeerAddr(conn_handle, peer->address);
reverse_chr_array(peer->address, 6);
Serial.printf("Connected to %s ", peer->name);
Serial.printBuffer(peer->address, 6, ':');
Serial.println();
connection_num++;
// Call BLECentralService discover
peer->_service.discover(id);
// Discover characteristics
BLEClientCharacteristic* chr_arr[] = { &peer->_notification, &peer->_data };
Bluefruit.Discovery.discoverCharacteristic(id, chr_arr, 2);
Serial.println("discover chrs");
peer->_notification.enableNotify();
peer->_data.enableNotify();
}
Please be positive and constructive with your questions and comments.