add hap protocol info and accessory info
This commit is contained in:
1 parent
faa0827c7d
commit
0bcc78c296
6 files changed
+91
-7
No files matched your search
@@ -37,6 +37,37 @@
|
||||
#include <bluefruit.h>
|
||||
#include "BLEHomekit.h"
|
||||
|
||||
#define HOMEKIT_PROTOCOL_VERION 2
|
||||
#define HOMEKIT_PROTOCOL_VERSION_STR "02.01.00"
|
||||
|
||||
BLEHomekit::BLEHomekit()
|
||||
: _protocol_info(HAP_UUID_SVC_PROTOCOL_INFO), AccessoryInfo()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
err_t BLEHomekit::begin()
|
||||
{
|
||||
/*------------- Protocol Info Service -------------*/
|
||||
VERIFY_STATUS( _protocol_info.begin() );
|
||||
{
|
||||
BLECharacteristic chr(HAP_UUID_CHR_VERSION);
|
||||
|
||||
chr.setTempMemory(); // ready-only, not included in Gatt list
|
||||
chr.setProperties(CHR_PROPS_READ);
|
||||
chr.setPermission(SECMODE_ENC_NO_MITM, SECMODE_NO_ACCESS);
|
||||
chr.setFixedLen(strlen(HOMEKIT_PROTOCOL_VERSION_STR));
|
||||
|
||||
VERIFY_STATUS( chr.begin() );
|
||||
chr.write(HOMEKIT_PROTOCOL_VERSION_STR);
|
||||
}
|
||||
|
||||
/*------------- Accessory Info Service -------------*/
|
||||
VERIFY_STATUS ( AccessoryInfo.begin() );
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool BLEHomekit::setAdv(BLEAdvertisingData& adv_ref)
|
||||
{
|
||||
VERIFY(&Bluefruit.Advertising == &adv_ref);
|
||||
|
||||
@@ -62,14 +62,18 @@ enum
|
||||
HAP_CAT_AIR_PURFIER ,
|
||||
};
|
||||
|
||||
#define HOMEKIT_PROTOCOL_VERION 2
|
||||
|
||||
class BLEHomekit : public Advertisable
|
||||
{
|
||||
public:
|
||||
virtual bool setAdv(BLEAdvertisingData& adv);
|
||||
BLEHomekit();
|
||||
err_t begin();
|
||||
|
||||
HAPAccessoryInfo AccessoryInfo;
|
||||
|
||||
private:
|
||||
// Mandatory services
|
||||
BLEService _protocol_info;
|
||||
};
|
||||
|
||||
#endif /* BLEHOMEKIT_H_ */
|
||||
@@ -39,8 +39,55 @@
|
||||
#include "HapAccessoryInfo.h"
|
||||
|
||||
HAPAccessoryInfo::HAPAccessoryInfo(void)
|
||||
: BLEService(HAP_UUID_SVC_ACCESSORY_INFO)
|
||||
: BLEService(HAP_UUID_SVC_ACCESSORY_INFO), _identify(HAP_UUID_CHR_IDENTIFY)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
err_t HAPAccessoryInfo::begin(void)
|
||||
{
|
||||
VERIFY_STATUS( BLEService::begin() ); // Invoke base class begin()
|
||||
|
||||
// Identify
|
||||
_identify.setProperties(CHR_PROPS_WRITE);
|
||||
_identify.setPermission(SECMODE_NO_ACCESS, SECMODE_ENC_NO_MITM);
|
||||
_identify.setFixedLen(1);
|
||||
VERIFY_STATUS( _identify.begin() );
|
||||
|
||||
BLECharacteristic* chr;
|
||||
|
||||
|
||||
const uint8_t* uuids[] =
|
||||
{
|
||||
HAP_UUID_CHR_MANUFACTURER,
|
||||
HAP_UUID_CHR_MODEL,
|
||||
HAP_UUID_CHR_NAME,
|
||||
HAP_UUID_CHR_SERIAL_NUMBER,
|
||||
HAP_UUID_CHR_FIRMWARE_REV
|
||||
};
|
||||
|
||||
const char* strvals[] =
|
||||
{
|
||||
"Adafruit Industrial",
|
||||
"Adafruit Bluefruit nrf52",
|
||||
"Bluefruit52",
|
||||
getMcuUniqueID(),
|
||||
"0.9.0"
|
||||
};
|
||||
|
||||
for(uint8_t i=0; i<arrcount(strvals); i++)
|
||||
{
|
||||
BLECharacteristic chr(uuids[i]);
|
||||
chr.setTempMemory();
|
||||
|
||||
chr.setProperties(CHR_PROPS_READ);
|
||||
chr.setPermission(SECMODE_ENC_NO_MITM, SECMODE_NO_ACCESS);
|
||||
chr.setFixedLen( strlen(strvals[i]) );
|
||||
|
||||
VERIFY_STATUS( chr.begin() );
|
||||
chr.write(strvals[i]);
|
||||
}
|
||||
|
||||
return ERROR_NONE;
|
||||
}
|
||||
|
||||
@@ -41,8 +41,10 @@ class HAPAccessoryInfo : public BLEService
|
||||
public:
|
||||
HAPAccessoryInfo(void);
|
||||
|
||||
private:
|
||||
virtual err_t begin(void);
|
||||
|
||||
private:
|
||||
BLECharacteristic _identify;
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -39,6 +39,7 @@
|
||||
/*------------------------------------------------------------------*/
|
||||
/* Apple-defined Services
|
||||
*------------------------------------------------------------------*/
|
||||
#define HAP_UUID_SVC_PROTOCOL_INFO ((const uint8_t[]) { 0x91, 0x52, 0x76, 0xBB, 0x26, 0x00, 0x00, 0x80, 0x00, 0x10, 0x00, 0x00, 0xA2, 0x00, 0x00, 0x00 })
|
||||
#define HAP_UUID_SVC_ACCESSORY_INFO ((const uint8_t[]) { 0x91, 0x52, 0x76, 0xBB, 0x26, 0x00, 0x00, 0x80, 0x00, 0x10, 0x00, 0x00, 0x3E, 0x00, 0x00, 0x00 })
|
||||
#define HAP_UUID_SVC_FAN ((const uint8_t[]) { 0x91, 0x52, 0x76, 0xBB, 0x26, 0x00, 0x00, 0x80, 0x00, 0x10, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00 })
|
||||
#define HAP_UUID_SVC_GARAGE_DOOR_OPENER ((const uint8_t[]) { 0x91, 0x52, 0x76, 0xBB, 0x26, 0x00, 0x00, 0x80, 0x00, 0x10, 0x00, 0x00, 0x41, 0x00, 0x00, 0x00 })
|
||||
@@ -113,7 +114,7 @@
|
||||
#define HAP_UUID_CHR_TARGET_RELATIVE_HUMID ((const uint8_t[]) { 0x91, 0x52, 0x76, 0xBB, 0x26, 0x00, 0x00, 0x80, 0x00, 0x10, 0x00, 0x00, 0x34, 0x00, 0x00, 0x00 })
|
||||
#define HAP_UUID_CHR_TARGET_TEMP ((const uint8_t[]) { 0x91, 0x52, 0x76, 0xBB, 0x26, 0x00, 0x00, 0x80, 0x00, 0x10, 0x00, 0x00, 0x35, 0x00, 0x00, 0x00 })
|
||||
#define HAP_UUID_CHR_TEMP_DISPLAY_UNIT ((const uint8_t[]) { 0x91, 0x52, 0x76, 0xBB, 0x26, 0x00, 0x00, 0x80, 0x00, 0x10, 0x00, 0x00, 0x36, 0x00, 0x00, 0x00 })
|
||||
#define HAP_UUID_CHR_VERION ((const uint8_t[]) { 0x91, 0x52, 0x76, 0xBB, 0x26, 0x00, 0x00, 0x80, 0x00, 0x10, 0x00, 0x00, 0x37, 0x00, 0x00, 0x00 })
|
||||
#define HAP_UUID_CHR_VERSION ((const uint8_t[]) { 0x91, 0x52, 0x76, 0xBB, 0x26, 0x00, 0x00, 0x80, 0x00, 0x10, 0x00, 0x00, 0x37, 0x00, 0x00, 0x00 })
|
||||
#define HAP_UUID_CHR_AIR_PARTICULATE_DENSITY ((const uint8_t[]) { 0x91, 0x52, 0x76, 0xBB, 0x26, 0x00, 0x00, 0x80, 0x00, 0x10, 0x00, 0x00, 0x64, 0x00, 0x00, 0x00 })
|
||||
#define HAP_UUID_CHR_AIR_PARTICULATE_SIZE ((const uint8_t[]) { 0x91, 0x52, 0x76, 0xBB, 0x26, 0x00, 0x00, 0x80, 0x00, 0x10, 0x00, 0x00, 0x65, 0x00, 0x00, 0x00 })
|
||||
#define HAP_UUID_CHR_SECURITY_SYSTEM_CUR_STATE ((const uint8_t[]) { 0x91, 0x52, 0x76, 0xBB, 0x26, 0x00, 0x00, 0x80, 0x00, 0x10, 0x00, 0x00, 0x66, 0x00, 0x00, 0x00 })
|
||||
|
||||
+1
-2
@@ -16,7 +16,6 @@
|
||||
#include <BLEHomekit.h>
|
||||
|
||||
BLEHomekit homekit;
|
||||
HAPAccessoryInfo hap_info;
|
||||
|
||||
void setup()
|
||||
{
|
||||
@@ -30,7 +29,7 @@ void setup()
|
||||
Bluefruit.setTxPower(4);
|
||||
Bluefruit.setName("Bluefruit52");
|
||||
|
||||
hap_info.begin();
|
||||
homekit.begin();
|
||||
|
||||
// Set up and start advertising
|
||||
startAdv();
|
||||
|
||||
Reference in new issue
Block a user