sandeepmistry / arduino-BLEPeripheral

An Arduino library for creating custom BLE peripherals with Nordic Semiconductor's nRF8001 or nR51822.
MIT License
462 stars 179 forks source link

combining iBeacon and gatt profile #162

Closed lorenzoromagnoli closed 7 years ago

lorenzoromagnoli commented 7 years ago

I'm trying to combine iBeacon and a very simple GATT profile on the same device but it doesn't seem to be working. I'm actually not even sure this is allowed by the iBeacon standard, but I think it should as you can with eddiestone beacons.

Following issue #42 I wrote this code

#include <SPI.h>
#include <BLEPeripheral.h>
#include <iBeacon.h>

#if !defined(NRF51) && !defined(NRF52) && !defined(__RFduino__)
#error "This example only works with nRF51 boards"
#endif

char* serviceUUID="a196c876-de8c-4c47-ab5a-d7afd5ae7127";
char* callCharacteristicUUID="a196c876-de8c-4c47-ab5a-d7afd5ae7128";

char* localName="vineriaMinerva";
unsigned short major         = 0;
unsigned short minor         = 1;
unsigned short measuredPower = -55;

BLEPeripheral blePeripheral = BLEPeripheral();

BLEService doorBellService = BLEService(serviceUUID);

BLEIntCharacteristic callCharacteristic = BLEIntCharacteristic(callCharacteristicUUID,  BLEWrite);

iBeacon beacon;

void setup(){

  beacon.setLocalName(localName);
  beacon.addAttribute(doorBellService);
  beacon.addAttribute(callCharacteristic);

  callCharacteristic.setEventHandler(BLEWritten, doorbellRings);

  beacon.begin(serviceUUID, major, minor, measuredPower);
}

void loop() {
  beacon.loop();
}

void doorbellRings(BLECentral& central, BLECharacteristic& characteristic) {
  // central wrote new value to characteristic, update LED
  Serial.print(F("Characteristic event, writen: "));

}

using the nRF Connect app I can see that the beacon infos are correctly broadcasted, but I cannot view any gatt attributes or connect to the device.

lorenzoromagnoli commented 7 years ago

I was forgetting to configure the beacon as connectable. added beacon.setConnectable(true); to the setup and now works.