Updating logic that determined HAP Configuration Number (MDNS=c#)
This commit is contained in:
parent
f48cea8afb
commit
628c29c6b6
|
|
@ -149,8 +149,8 @@ void HAPClient::init(){
|
||||||
Serial.print("\n");
|
Serial.print("\n");
|
||||||
|
|
||||||
uint8_t tHash[48];
|
uint8_t tHash[48];
|
||||||
TempBuffer <char> tBuf(homeSpan.sprintfAttributes(NULL)+1);
|
TempBuffer <char> tBuf(homeSpan.sprintfAttributes(NULL,GET_META|GET_PERMS|GET_TYPE|GET_DESC)+1);
|
||||||
homeSpan.sprintfAttributes(tBuf.buf);
|
homeSpan.sprintfAttributes(tBuf.buf,GET_META|GET_PERMS|GET_TYPE|GET_DESC);
|
||||||
mbedtls_sha512_ret((uint8_t *)tBuf.buf,tBuf.len(),tHash,1); // create SHA-384 hash of JSON (can be any hash - just looking for a unique key)
|
mbedtls_sha512_ret((uint8_t *)tBuf.buf,tBuf.len(),tHash,1); // create SHA-384 hash of JSON (can be any hash - just looking for a unique key)
|
||||||
|
|
||||||
if(memcmp(tHash,homeSpan.hapConfig.hashCode,48)){ // if hash code of current HAP database does not match stored hash code
|
if(memcmp(tHash,homeSpan.hapConfig.hashCode,48)){ // if hash code of current HAP database does not match stored hash code
|
||||||
|
|
@ -1071,7 +1071,7 @@ int HAPClient::getCharacteristicsURL(char *urlBuf){
|
||||||
numIDs++;
|
numIDs++;
|
||||||
|
|
||||||
char *ids[numIDs]; // reserve space for number of IDs found
|
char *ids[numIDs]; // reserve space for number of IDs found
|
||||||
int flags=GET_AID; // flags indicating which characteristic fields to include in response (HAP Table 6-13)
|
int flags=GET_VALUE|GET_AID; // flags indicating which characteristic fields to include in response (HAP Table 6-13)
|
||||||
numIDs=0; // reset number of IDs found
|
numIDs=0; // reset number of IDs found
|
||||||
|
|
||||||
char *lastSpace=strchr(urlBuf,' ');
|
char *lastSpace=strchr(urlBuf,' ');
|
||||||
|
|
|
||||||
|
|
@ -899,6 +899,17 @@ void Span::processSerialCommand(const char *c){
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|
||||||
|
case 'C': {
|
||||||
|
|
||||||
|
char cNum[16];
|
||||||
|
sprintf(cNum,"%d",++hapConfig.configNumber);
|
||||||
|
mdns_service_txt_item_set("_hap","_tcp","c#",cNum); // Accessory Current Configuration Number (updated whenever config of HAP Accessory Attribute Database is updated)
|
||||||
|
|
||||||
|
Serial.printf("\n*** Configuration number updated to: %d\n\n",hapConfig.configNumber);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
case 'i':{
|
case 'i':{
|
||||||
|
|
||||||
Serial.print("\n*** HomeSpan Info ***\n\n");
|
Serial.print("\n*** HomeSpan Info ***\n\n");
|
||||||
|
|
@ -1001,8 +1012,11 @@ void Span::processSerialCommand(const char *c){
|
||||||
|
|
||||||
} // Accessories
|
} // Accessories
|
||||||
|
|
||||||
Serial.printf("\nConfigured as Bridge: %s\n\n",isBridge?"YES":"NO");
|
Serial.printf("\nConfigured as Bridge: %s\n",isBridge?"YES":"NO");
|
||||||
Serial.printf("Database Validation: Warnings=%d, Errors=%d\n\n",nWarnings,nErrors);
|
if(hapConfig.configNumber>0)
|
||||||
|
Serial.printf("Configuration Number: %d\n",hapConfig.configNumber);
|
||||||
|
Serial.printf("\nDatabase Validation: Warnings=%d, Errors=%d\n\n",nWarnings,nErrors);
|
||||||
|
|
||||||
|
|
||||||
char d[]="------------------------------";
|
char d[]="------------------------------";
|
||||||
Serial.printf("%-30s %8s %10s %s %s %s %s %s\n","Service","UUID","AID","IID","Update","Loop","Button","Linked Services");
|
Serial.printf("%-30s %8s %10s %s %s %s %s %s\n","Service","UUID","AID","IID","Update","Loop","Button","Linked Services");
|
||||||
|
|
@ -1100,14 +1114,14 @@ void Span::setWifiCredentials(const char *ssid, const char *pwd){
|
||||||
|
|
||||||
///////////////////////////////
|
///////////////////////////////
|
||||||
|
|
||||||
int Span::sprintfAttributes(char *cBuf){
|
int Span::sprintfAttributes(char *cBuf, int flags){
|
||||||
|
|
||||||
int nBytes=0;
|
int nBytes=0;
|
||||||
|
|
||||||
nBytes+=snprintf(cBuf,cBuf?64:0,"{\"accessories\":[");
|
nBytes+=snprintf(cBuf,cBuf?64:0,"{\"accessories\":[");
|
||||||
|
|
||||||
for(int i=0;i<Accessories.size();i++){
|
for(int i=0;i<Accessories.size();i++){
|
||||||
nBytes+=Accessories[i]->sprintfAttributes(cBuf?(cBuf+nBytes):NULL);
|
nBytes+=Accessories[i]->sprintfAttributes(cBuf?(cBuf+nBytes):NULL,flags);
|
||||||
if(i+1<Accessories.size())
|
if(i+1<Accessories.size())
|
||||||
nBytes+=snprintf(cBuf?(cBuf+nBytes):NULL,cBuf?64:0,",");
|
nBytes+=snprintf(cBuf?(cBuf+nBytes):NULL,cBuf?64:0,",");
|
||||||
}
|
}
|
||||||
|
|
@ -1358,7 +1372,7 @@ int Span::sprintfNotify(SpanBuf *pObj, int nObj, char *cBuf, int conNum){
|
||||||
if(notifyFlag) // already printed at least one other characteristic
|
if(notifyFlag) // already printed at least one other characteristic
|
||||||
nChars+=snprintf(cBuf?(cBuf+nChars):NULL,cBuf?64:0,","); // add preceeding comma before printing next characteristic
|
nChars+=snprintf(cBuf?(cBuf+nChars):NULL,cBuf?64:0,","); // add preceeding comma before printing next characteristic
|
||||||
|
|
||||||
nChars+=pObj[i].characteristic->sprintfAttributes(cBuf?(cBuf+nChars):NULL,GET_AID+GET_NV); // get JSON attributes for characteristic
|
nChars+=pObj[i].characteristic->sprintfAttributes(cBuf?(cBuf+nChars):NULL,GET_VALUE|GET_AID|GET_NV); // get JSON attributes for characteristic
|
||||||
notifyFlag=true;
|
notifyFlag=true;
|
||||||
|
|
||||||
} // notification requested
|
} // notification requested
|
||||||
|
|
@ -1476,13 +1490,13 @@ SpanAccessory::SpanAccessory(uint32_t aid){
|
||||||
|
|
||||||
///////////////////////////////
|
///////////////////////////////
|
||||||
|
|
||||||
int SpanAccessory::sprintfAttributes(char *cBuf){
|
int SpanAccessory::sprintfAttributes(char *cBuf, int flags){
|
||||||
int nBytes=0;
|
int nBytes=0;
|
||||||
|
|
||||||
nBytes+=snprintf(cBuf,cBuf?64:0,"{\"aid\":%u,\"services\":[",aid);
|
nBytes+=snprintf(cBuf,cBuf?64:0,"{\"aid\":%u,\"services\":[",aid);
|
||||||
|
|
||||||
for(int i=0;i<Services.size();i++){
|
for(int i=0;i<Services.size();i++){
|
||||||
nBytes+=Services[i]->sprintfAttributes(cBuf?(cBuf+nBytes):NULL);
|
nBytes+=Services[i]->sprintfAttributes(cBuf?(cBuf+nBytes):NULL,flags);
|
||||||
if(i+1<Services.size())
|
if(i+1<Services.size())
|
||||||
nBytes+=snprintf(cBuf?(cBuf+nBytes):NULL,cBuf?64:0,",");
|
nBytes+=snprintf(cBuf?(cBuf+nBytes):NULL,cBuf?64:0,",");
|
||||||
}
|
}
|
||||||
|
|
@ -1535,7 +1549,7 @@ SpanService *SpanService::addLink(SpanService *svc){
|
||||||
|
|
||||||
///////////////////////////////
|
///////////////////////////////
|
||||||
|
|
||||||
int SpanService::sprintfAttributes(char *cBuf){
|
int SpanService::sprintfAttributes(char *cBuf, int flags){
|
||||||
int nBytes=0;
|
int nBytes=0;
|
||||||
|
|
||||||
nBytes+=snprintf(cBuf,cBuf?64:0,"{\"iid\":%d,\"type\":\"%s\",",iid,type);
|
nBytes+=snprintf(cBuf,cBuf?64:0,"{\"iid\":%d,\"type\":\"%s\",",iid,type);
|
||||||
|
|
@ -1559,7 +1573,7 @@ int SpanService::sprintfAttributes(char *cBuf){
|
||||||
nBytes+=snprintf(cBuf?(cBuf+nBytes):NULL,cBuf?64:0,"\"characteristics\":[");
|
nBytes+=snprintf(cBuf?(cBuf+nBytes):NULL,cBuf?64:0,"\"characteristics\":[");
|
||||||
|
|
||||||
for(int i=0;i<Characteristics.size();i++){
|
for(int i=0;i<Characteristics.size();i++){
|
||||||
nBytes+=Characteristics[i]->sprintfAttributes(cBuf?(cBuf+nBytes):NULL,GET_META|GET_PERMS|GET_TYPE|GET_DESC);
|
nBytes+=Characteristics[i]->sprintfAttributes(cBuf?(cBuf+nBytes):NULL,flags);
|
||||||
if(i+1<Characteristics.size())
|
if(i+1<Characteristics.size())
|
||||||
nBytes+=snprintf(cBuf?(cBuf+nBytes):NULL,cBuf?64:0,",");
|
nBytes+=snprintf(cBuf?(cBuf+nBytes):NULL,cBuf?64:0,",");
|
||||||
}
|
}
|
||||||
|
|
@ -1609,7 +1623,7 @@ int SpanCharacteristic::sprintfAttributes(char *cBuf, int flags){
|
||||||
if(flags&GET_TYPE)
|
if(flags&GET_TYPE)
|
||||||
nBytes+=snprintf(cBuf?(cBuf+nBytes):NULL,cBuf?64:0,",\"type\":\"%s\"",type);
|
nBytes+=snprintf(cBuf?(cBuf+nBytes):NULL,cBuf?64:0,",\"type\":\"%s\"",type);
|
||||||
|
|
||||||
if(perms&PR){
|
if((perms&PR) && (flags&GET_VALUE)){
|
||||||
if(perms&NV && !(flags&GET_NV))
|
if(perms&NV && !(flags&GET_NV))
|
||||||
nBytes+=snprintf(cBuf?(cBuf+nBytes):NULL,cBuf?64:0,",\"value\":null");
|
nBytes+=snprintf(cBuf?(cBuf+nBytes):NULL,cBuf?64:0,",\"value\":null");
|
||||||
else
|
else
|
||||||
|
|
|
||||||
|
|
@ -59,7 +59,7 @@ enum {
|
||||||
GET_EV=16,
|
GET_EV=16,
|
||||||
GET_DESC=32,
|
GET_DESC=32,
|
||||||
GET_NV=64,
|
GET_NV=64,
|
||||||
GET_ALL=255
|
GET_VALUE=128
|
||||||
};
|
};
|
||||||
|
|
||||||
///////////////////////////////
|
///////////////////////////////
|
||||||
|
|
@ -215,7 +215,8 @@ struct Span{
|
||||||
void commandMode(); // allows user to control and reset HomeSpan settings with the control button
|
void commandMode(); // allows user to control and reset HomeSpan settings with the control button
|
||||||
void processSerialCommand(const char *c); // process command 'c' (typically from readSerial, though can be called with any 'c')
|
void processSerialCommand(const char *c); // process command 'c' (typically from readSerial, though can be called with any 'c')
|
||||||
|
|
||||||
int sprintfAttributes(char *cBuf); // prints Attributes JSON database into buf, unless buf=NULL; return number of characters printed, excluding null terminator, even if buf=NULL
|
int sprintfAttributes(char *cBuf, int flags=GET_VALUE|GET_META|GET_PERMS|GET_TYPE|GET_DESC); // prints Attributes JSON database into buf, unless buf=NULL; return number of characters printed, excluding null terminator
|
||||||
|
|
||||||
void prettyPrint(char *buf, int nsp=2); // print arbitrary JSON from buf to serial monitor, formatted with indentions of 'nsp' spaces
|
void prettyPrint(char *buf, int nsp=2); // print arbitrary JSON from buf to serial monitor, formatted with indentions of 'nsp' spaces
|
||||||
SpanCharacteristic *find(uint32_t aid, int iid); // return Characteristic with matching aid and iid (else NULL if not found)
|
SpanCharacteristic *find(uint32_t aid, int iid); // return Characteristic with matching aid and iid (else NULL if not found)
|
||||||
|
|
||||||
|
|
@ -282,7 +283,7 @@ struct SpanAccessory{
|
||||||
|
|
||||||
SpanAccessory(uint32_t aid=0);
|
SpanAccessory(uint32_t aid=0);
|
||||||
|
|
||||||
int sprintfAttributes(char *cBuf); // prints Accessory JSON database into buf, unless buf=NULL; return number of characters printed, excluding null terminator, even if buf=NULL
|
int sprintfAttributes(char *cBuf, int flags); // prints Accessory JSON database into buf, unless buf=NULL; return number of characters printed, excluding null terminator, even if buf=NULL
|
||||||
};
|
};
|
||||||
|
|
||||||
///////////////////////////////
|
///////////////////////////////
|
||||||
|
|
@ -307,7 +308,7 @@ struct SpanService{
|
||||||
SpanService *addLink(SpanService *svc); // adds svc as a Linked Service and returns pointer to self
|
SpanService *addLink(SpanService *svc); // adds svc as a Linked Service and returns pointer to self
|
||||||
vector<SpanService *> getLinks(){return(linkedServices);} // returns linkedServices vector for use as range in "for-each" loops
|
vector<SpanService *> getLinks(){return(linkedServices);} // returns linkedServices vector for use as range in "for-each" loops
|
||||||
|
|
||||||
int sprintfAttributes(char *cBuf); // prints Service JSON records into buf; return number of characters printed, excluding null terminator
|
int sprintfAttributes(char *cBuf, int flags); // prints Service JSON records into buf; return number of characters printed, excluding null terminator
|
||||||
|
|
||||||
virtual boolean update() {return(true);} // placeholder for code that is called when a Service is updated via a Controller. Must return true/false depending on success of update
|
virtual boolean update() {return(true);} // placeholder for code that is called when a Service is updated via a Controller. Must return true/false depending on success of update
|
||||||
virtual void loop(){} // loops for each Service - called every cycle and can be over-ridden with user-defined code
|
virtual void loop(){} // loops for each Service - called every cycle and can be over-ridden with user-defined code
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue