Creates the BLEPeripheralObserver object. Pin Arguments are optional as pins are self detecting. See https://github.com/sandeepmistry/arduino-BLEPeripheral#pinouts
BLEPeripheralObserver(unsigned char req = BLE_DEFAULT_REQ, unsigned char rdy = BLE_DEFAULT_RDY, unsigned char rst = BLE_DEFAULT_RST);
- req - REQ pin
- rdy - RDY pin
- rst - RST pin, can be
UNUSED
void setLocalName(const char *localName);
- localName - local name to advertise (up to: 20 characters on nRF8001, 29 characters on nRF51822)
void setAdvertisedServiceUuid(const char* advertisedServiceUuid);
- advertisedServiceUuid - service UUID to advertise
void setManufacturerData(const unsigned char manufacturerData[], unsigned char manufacturerDataLength);
- manufacturerData - array of bytes
- manufacturerDataLength - length of array, up to: 20 bytes on nRF8001, 26 bytes on nRF51822
void setAdvertisingInterval(unsigned short advertisingInterval);
- set advertising interval in ms, default is 100ms
Sets the connection interval to use after a connection has been established.
void setConnectionInterval(unsigned short minimumConnectionInterval, unsigned short maximumConnectionInterval);
- minimumConnectionInterval - minimum connection interval in 1.25 ms increments
- maximumConnectionInterval - maximum connection interval in 1.25 ms increments
Note: Both parameters must be between 0x0006 (7.5 ms) and 0x0c80 (4 s), values outside of this range will be ignored.
bool setTxPower(int txPower);
- set TX power in dBm, default value is 0 dBm, must be called after
begin
. Returnstrue
on success,false
otherwise.
Note: only certain values can be set with exactly, otherwise the next settable value is used
- nRF8001: -18, -12, -6, 0
- nRF51822: -40, -30, -20, -16, -12, -8, -4, 0, 4
void setConnectable(bool connectable);
- make peripheral connectable (default) or non-connectable (broadcast only)
void setBondStore(BLEBondStore& bondStore);
- enable unauthenticated security (pairing), use the bond store to persist bonding data.
void setDeviceName(const char* deviceName);
- deviceName - device name, up to: 20 characters on nRF8001 and nRF51822 - default value is
"Arduino"
void setAppearance(unsigned short appearance);
- appearance - appearance, default value is
0x0000
void addAttribute(BLEAttribute& attribute);
- attribute - attribute to add, can be
BLEService
,BLECharacteristic
, orBLEDescriptor
Call from setup
.
void begin();
Call from loop
.
void poll();
Is the peripheral connected to a central?
bool connected();
Central the peripheral is connected to. Bool value evaluates to false
if not connected.
BLECentral central()
void setEventHandler(BLEPeripheralEvent event, BLEPeripheralEventHandler eventHandler);
// callback signature
void blePeripheralEventHandler(BLECentral& central) {
// ....
}
- event -
BLEConnected
orBLEDisconnected
- eventHandler - function callback for event
void disconnect();
Disconnect connected central.
Is this a valid central?
BLECentral central;
// ...
if (central) {
// central is valid
} else {
// central is invalid
}
Is the central connected?
bool connected();
Bluetooth address of central as string.
const char* address();
void disconnect();
Disconnect central if connected.
void end();
Disconnects central if connected, stops advertising, and disables radio.
Call from loop
, while connected.
void poll();
BLEService(const char* uuid);
- uuid - UUID of service
BLECharacteristic(const char* uuid, unsigned char properties, unsigned char valueSize);
BLECharacteristic(const char* uuid, unsigned char properties, const char* value);
- uuid - UUID of characteristic
- properties - combination of (|'ed):
BLEBroadcast
BLERead
BLEWriteWithoutResponse
BLEWrite
BLENotify
BLEIndicate
Choice of:
- valueSize - size of characteristic in bytes (max: 20 characters on nRF8001 and nRF51822)
or
- value - string value (max: 20 characters on nRF8001 and nRF51822)
const unsigned char* value();
unsigned char valueLength();
Will automatically notify/indicate central, if characteristic has notify/indicate property and central is subscribed and update broadcasted value if broadcasting.
bool setValue(const unsigned char value[], unsigned char length);
- value - value bytes
- length - value length (up to value size)
Returns true on success (central notified/indicated, if applicable), false on failure (cannot be notified/indicated, if applicable)
bool setValue(const char* value);
- value - new value as string
Returns true on success (central notified/indicated, if applicable), false on failure (cannot be notified/indicated, if applicable)
Broadcast characteristic value in advertisement data.
bool broadcast();
Returns true on success, false on failure
Has the central written a new value since the last call to this method? (only for write or write without response characteristics)
bool written();
Is the central subscribed (via notify or indicate) to the characteristic? (only for notify/indicate characteristics)
bool subscribed();
Can the central be notified/indicated of when the value is set. Only applies to characteristics with notify and/or indicate properties when a central is connected and subscribed
bool canNotify();
bool canIndicate();
void setEventHandler(BLECharacteristicEvent event, BLECharacteristicEventHandler eventHandler);
// callback signature
void bleCharacteristicEventHandler(BLECentral& central, BLECharacteristic& characteristic) {
// ....
}
- event -
BLEWritten
,BLESubscribed
, orBLEUnsubscribed
- eventHandler - function callback for event
Data Type | Class |
---|---|
bool |
BLEBoolCharacteristic |
char |
BLECharCharacteristic |
unsigned char |
BLEUnsignedCharCharacteristic |
short |
BLEShortCharacteristic |
unsigned short |
BLEUnsignedShortCharacteristic |
int |
BLEIntCharacteristic |
unsigned int |
BLEUnsignedIntCharacteristic |
long |
BLELongCharacteristic |
unsigned long |
BLEUnsignedLongCharacteristic |
float |
BLEFloatCharacteristic |
double |
BLEDoubleCharacteristic |
BLE<Data Type>Characteristic(const char* uuid, unsigned char properties);
See BLECharacteristic
<Data Type> value();
<Data Type> valueLE(); // little endian
<Data Type> valueBE(); // big endian
bool setValue(<Data Type> value);
bool setValueLE(<Data Type> value); // little endian
bool setValueBE(<Data Type> value); // big endian
Returns true on success (central notified/indicated, if applicable), false on failure (cannot be notified/indicated, if applicable)
- Subclass of
BLECharacteristic
, value is a fixed length
BLEFixedLengthCharacteristic(const char* uuid, unsigned char properties, unsigned char valueSize);
BLEFixedLengthCharacteristic(const char* uuid, unsigned char properties, const char* value);
- uuid - UUID of characteristic
- properties - combination of (|'ed):
BLEBroadcast
BLERead
BLEWriteWithoutResponse
BLEWrite
BLENotify
BLEIndicate
Choice of:
- valueSize - size of characteristic in bytes (max: 20 characters on nRF8001 and nRF51822)
or
- value - string value (max: 20 characters on nRF8001 and nRF51822)
- Subclass of
BLEFixedLengthCharacteristic
, value is constant and a fixed length. Is read only and,setValue
API does nothing.
BLEConstantCharacteristic(const char* uuid, const unsigned char value[], unsigned char length);
BLEConstantCharacteristic(const char* uuid, const char* value);
- uuid - UUID of characteristic
Choice of:
- value - value of characteristic
- length - size of characteristic in bytes
or
- value - string value (max: 20 characters on nRF8001 and nRF51822)
BLEDescriptor(const char* uuid, const unsigned char value[], unsigned char valueSize);
BLEDescriptor(const char* uuid, const char* value);
- uuid - UUID of descriptor
Choice of:
- value - value data
- valueLength - length of value data in bytes
or
- value - string value
const unsigned char* value();
unsigned char valueLength();
BLEBondStore(int offset = 0);
- offset - offset in persistent storage (AVR: EEPROM, NRF51: Flash, others RAM)
void clearData();
Clear bond data from store, must be called before blePeripheral.begin()