Simple example to demonstrate custom made BLE service and characteristics.
Fork of BLE_GATT_Example by
AckService.h
00001 00002 #define MAC_ADDR_SIZE_B (6) 00003 00004 // Template allows you to use 'constant' values on non-constant places (XD) 00005 template<uint8_t dataSize> 00006 00007 class ACKService{ 00008 public: 00009 const static uint16_t ACK_SERVICE_UUID = 0xA000; 00010 const static uint16_t ACK_CHARA_UUID = 0xA001; 00011 const static uint16_t ACK_MAC_CHAR_UUID = 0xA002; 00012 00013 ACKService(BLEDevice &_ble, uint8_t *_initValues) : ble(_ble), ACK(ACK_CHARA_UUID, _initValues), MAC(ACK_MAC_CHAR_UUID, _initValues, GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY){ 00014 GattCharacteristic *charTable[] = {&ACK, &MAC}; // Add characteristick in table 00015 GattService AckService(ACK_SERVICE_UUID, charTable, sizeof(charTable)/sizeof(GattCharacteristic *)); 00016 ble.addService(AckService); // Add service in the BLE 00017 } 00018 void updateMacAddress(uint8_t *MacAddress){ 00019 ble.gattServer().write(MAC.getValueHandle(), MacAddress, MAC_ADDR_SIZE_B); 00020 } 00021 private: 00022 BLEDevice &ble; 00023 // Create new characteristic 00024 WriteOnlyArrayGattCharacteristic<uint8_t, dataSize> ACK; 00025 ReadOnlyArrayGattCharacteristic<uint8_t, MAC_ADDR_SIZE_B> MAC; 00026 };
Generated on Tue Jul 19 2022 20:19:12 by 1.7.2