Arduino Function: BLEPeripheral.setAppearance

Name

setAppearance

Description

Set the appearance that will be advertised by the board.




Syntax

blePeripheral.setAppearance(appearance);

Parameters

  • appearance: unsigned short. Appearance to be advertised.
Values:
BLE_APPEARANCE_UNKNOWN
BLE_APPEARANCE_GENERIC_PHONE
BLE_APPEARANCE_GENERIC_COMPUTER
BLE_APPEARANCE_GENERIC_WATCH
BLE_APPEARANCE_WATCH_SPORTS_WATCH
BLE_APPEARANCE_GENERIC_CLOCK
BLE_APPEARANCE_GENERIC_DISPLAY
BLE_APPEARANCE_GENERIC_REMOTE_CONTROL
BLE_APPEARANCE_GENERIC_EYE_GLASSES
BLE_APPEARANCE_GENERIC_TAG
BLE_APPEARANCE_GENERIC_KEYRING
BLE_APPEARANCE_GENERIC_MEDIA_PLAYER
BLE_APPEARANCE_GENERIC_BARCODE_SCANNER
BLE_APPEARANCE_GENERIC_THERMOMETER
BLE_APPEARANCE_THERMOMETER_EAR
BLE_APPEARANCE_GENERIC_HEART_RATE_SENSOR
BLE_APPEARANCE_HEART_RATE_SENSOR_HEART_RATE_BELT
BLE_APPEARANCE_GENERIC_BLOOD_PRESSURE
BLE_APPEARANCE_BLOOD_PRESSURE_ARM
BLE_APPEARANCE_BLOOD_PRESSURE_WRIST
BLE_APPEARANCE_GENERIC_HID
BLE_APPEARANCE_HID_KEYBOARD
BLE_APPEARANCE_HID_MOUSE
BLE_APPEARANCE_HID_JOYSTICK
BLE_APPEARANCE_HID_GAMEPAD
BLE_APPEARANCE_HID_DIGITIZERSUBTYPE
BLE_APPEARANCE_HID_CARD_READER
BLE_APPEARANCE_HID_DIGITAL_PEN
BLE_APPEARANCE_HID_BARCODE
BLE_APPEARANCE_GENERIC_GLUCOSE_METER
BLE_APPEARANCE_GENERIC_RUNNING_WALKING_SENSOR
BLE_APPEARANCE_RUNNING_WALKING_SENSOR_IN_SHOE
BLE_APPEARANCE_RUNNING_WALKING_SENSOR_ON_SHOE
BLE_APPEARANCE_RUNNING_WALKING_SENSOR_ON_HIP
BLE_APPEARANCE_GENERIC_CYCLING
BLE_APPEARANCE_CYCLING_CYCLING_COMPUTER
BLE_APPEARANCE_CYCLING_SPEED_SENSOR
BLE_APPEARANCE_CYCLING_CADENCE_SENSOR
BLE_APPEARANCE_CYCLING_POWER_SENSOR
BLE_APPEARANCE_CYCLING_SPEED_CADENCE_SENSOR

Returns

none 

Examples

/*
 CTSClient.ino
 Written by Chiara Ruggeri (chiara@arduino.org)
 This example shows the client capabilities of the BLEPeripheral library.
 It acts as a CTS client and recovers the current date and time from a central every time USER1 button is pressed.
 The informations are transmitted as a string. A parse to byte type is needed to read the correct values.
 You can use nRFConnect app to set up a CTS server or use another board with CTSServer example in File->Examples->BLE->Central menu.
 To have further informations about the CTS service please refer to the Bluetooth specifications:
 https://www.bluetooth.com/specifications/gatt/viewer?attributeXmlFile=org.bluetooth.service.current_time.xml

 This example code is in the public domain.
*/

#include <BLEPeripheral.h>
#include <LowPower.h>

char * months [] = {"Unknown", "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"};
char * days [] = {"Unknown", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"};

// create peripheral instance
BLEPeripheral                 blePeripheral                         = BLEPeripheral();

// create remote service with UUID compliant to CTS service
BLERemoteService              remoteCtsService         = BLERemoteService("1805");

// create remote characteristics with UUID and properties compliant to CTS service
BLERemoteCharacteristic       remoteCtsCharacteristic        = BLERemoteCharacteristic("2a2b", BLERead | BLENotify);

void setup() {
 Serial.begin(9600);
 blePeripheral.setLocalName("CTS-Client");

 // set device name and appearance
 blePeripheral.setDeviceName("CTS client");
 blePeripheral.setAppearance(BLE_APPEARANCE_GENERIC_CLOCK);
 blePeripheral.addRemoteAttribute(remoteCtsService);
 blePeripheral.addRemoteAttribute(remoteCtsCharacteristic);

  // assign event handlers for connected, disconnected to peripheral
 blePeripheral.setEventHandler(BLEConnected, blePeripheralConnectHandler);
 blePeripheral.setEventHandler(BLEDisconnected, blePeripheralDisconnectHandler);
 blePeripheral.setEventHandler(BLERemoteServicesDiscovered, blePeripheralRemoteServicesDiscoveredHandler);

 // assign event handlers for characteristic
 remoteCtsCharacteristic.setEventHandler(BLEValueUpdated, bleRemoteCtsCharacteristicValueUpdatedHandle);

 // begin initialization
 blePeripheral.begin();

 attachInterrupt(USER1_BUTTON, readTime, LOW);
 Serial.println(F("BLE Peripheral - cts"));
}

void loop() {
 // put the board in standby mode to save power
 LowPower.standby();
}

void blePeripheralConnectHandler(BLECentral& central) {
 // central connected event handler
 Serial.print(F("Connected event, central: "));
 Serial.println(central.address());
}

void blePeripheralDisconnectHandler(BLECentral& central) {
 // central disconnected event handler
 Serial.print(F("Disconnected event, central: "));
 Serial.println(central.address());
}

void blePeripheralRemoteServicesDiscoveredHandler(BLECentral& central) {
 // central remote services discovered event handler
 Serial.print(F("Remote services discovered event, central: "));
 Serial.println(central.address());

 if (remoteCtsCharacteristic.canRead()) {
remoteCtsCharacteristic.read();
 }
}

void bleRemoteCtsCharacteristicValueUpdatedHandle(BLECentral& central, BLERemoteCharacteristic& characteristic) {
 // copy the time value in a local variable
 char currentTime[BLE_REMOTE_ATTRIBUTE_MAX_VALUE_LENGTH + 1];
 memset(currentTime, 0, sizeof(currentTime));
 memcpy(currentTime, remoteCtsCharacteristic.value(), remoteCtsCharacteristic.valueLength());

 // year is the first two bytes of the string
 byte first=currentTime[0];
 byte second=currentTime[1];
 uint16_t year=first | (second << 8);

 // month is the third byte
 byte month = currentTime[2];

 // day, hours, minutes and seconds follow
 byte day = currentTime[3];
 byte hours = currentTime[4];
 byte minutes = currentTime[5];
 byte seconds = currentTime[6];

 // day of the week
 byte dow = currentTime[7];

 // 1/256th of a second
 byte fraction = currentTime[8];

 // Print current time
 Serial.println("*** Current Time received ***");
 Serial.print(day);
 Serial.print(" ");
 Serial.print(months[month]);
 Serial.print(" ");
 Serial.print(year);
 Serial.print(", ");
 Serial.print(hours);
 Serial.print(":");
 Serial.print(minutes);
 Serial.print(":");
 Serial.println(seconds);
 Serial.print("Day of the week: ");
 Serial.println(days[dow]);
 Serial.print("Fractions: ");
 Serial.print(fraction);
 Serial.println(" / 256 s");
 Serial.println("-------------------------------------");
}

void readTime(){
 remoteCtsCharacteristic.read();
 }




Written by arduino.org