get arduino peripheral demo to work

This commit is contained in:
Matthias Ringwald 2015-06-01 00:19:40 +02:00
parent f3d3706333
commit 66a3dca25d

View File

@ -2,11 +2,11 @@
#include <BTstack.h>
#include <SPI.h>
static uint16_t value_handle;
static char characteristic_data = 'H';
void setup(void){
setup_printf(9600);
Serial.begin(9600);
// set callbacks
BTstack.setBLEDeviceConnectedCallback(deviceConnectedCallback);
@ -15,15 +15,18 @@ void setup(void){
BTstack.setGATTCharacteristicWrite(gattWriteCallback);
// setup GATT Database
int flags = 0;
uint8_t * data = NULL;
uint16_t data_len = 0;
BTstack.addGATTService(new UUID("B8E06067-62AD-41BA-9231-206AE80AB550"));
value_handle = BTstack.addGATTCharacteristic(new UUID("f897177b-aee8-4767-8ecc-cc694fd5fcee"), flags, "This is a String!");
BTstack.addGATTService(new UUID("B8E06067-62AD-41BA-9231-206AE80AB551"));
BTstack.addGATTCharacteristic(new UUID("f897177b-aee8-4767-8ecc-cc694fd5fcef"), ATT_PROPERTY_READ, "This is a String!");
BTstack.addGATTCharacteristicDynamic(new UUID("f897177b-aee8-4767-8ecc-cc694fd5fce0"), ATT_PROPERTY_READ | ATT_PROPERTY_WRITE | ATT_PROPERTY_NOTIFY, 0);
// use dummy address to force refresh on iOS devices
bd_addr_t dummy = { 1,2,3,4,5,6};
BTstack.setPublicBdAddr(dummy);
// startup Bluetooth and activate advertisements
BTstack.setup();
BTstack.startAdvertising();
// BTstack.enablePacketLogger();
}
@ -34,7 +37,7 @@ void loop(void){
void deviceConnectedCallback(BLEStatus status, BLEDevice *device) {
switch (status){
case BLE_STATUS_OK:
printf("Device connected!\n");
Serial.println("Device connected!");
break;
default:
break;
@ -42,7 +45,7 @@ void deviceConnectedCallback(BLEStatus status, BLEDevice *device) {
}
void deviceDisconnectedCallback(BLEDevice * device){
printf("Disconnected.\n");
Serial.println("Disconnected.");
}
// ATT Client Read Callback for Dynamic Data
@ -52,8 +55,12 @@ void deviceDisconnectedCallback(BLEDevice * device){
// @param buffer
// @param buffer_size
uint16_t gattReadCallback(uint16_t value_handle, uint8_t * buffer, uint16_t buffer_size){
printf("gattReadCallback, handle %u\n", value_handle);
return 0;
if (buffer){
Serial.print("gattReadCallback, value: ");
Serial.println(characteristic_data, HEX);
buffer[0] = characteristic_data;
}
return 1;
}
// ATT Client Write Callback for Dynamic Data
@ -62,7 +69,9 @@ uint16_t gattReadCallback(uint16_t value_handle, uint8_t * buffer, uint16_t buff
// @param buffer_size
// @returns 0 if write was ok, ATT_ERROR_INVALID_OFFSET if offset is larger than max buffer
int gattWriteCallback(uint16_t value_handle, uint8_t *buffer, uint16_t buffer_size){
printf("gattWriteCallback, handle %u\n", value_handle);
characteristic_data = buffer[0];
Serial.print("gattWriteCallback , value ");
Serial.println(characteristic_data, HEX);
return 0;
}