Added new method homeSpan.setHostNameSuffix()
Allows user to replace the 6-byte AccessoryID "suffix" in the hostName with a custom suffix, included a blank string. To do: Add to documentation.
This commit is contained in:
parent
b4df9578ca
commit
b87a3d1dc3
|
|
@ -363,9 +363,19 @@ void Span::checkConnect(){
|
|||
|
||||
// create broadcaset name from server base name plus accessory ID (without ':')
|
||||
|
||||
int nChars=snprintf(NULL,0,"%s-%.2s%.2s%.2s%.2s%.2s%.2s",hostNameBase,id,id+3,id+6,id+9,id+12,id+15);
|
||||
int nChars;
|
||||
|
||||
if(!hostNameSuffix)
|
||||
nChars=snprintf(NULL,0,"%s-%.2s%.2s%.2s%.2s%.2s%.2s",hostNameBase,id,id+3,id+6,id+9,id+12,id+15);
|
||||
else
|
||||
nChars=snprintf(NULL,0,"%s%s",hostNameBase,hostNameSuffix);
|
||||
|
||||
char hostName[nChars+1];
|
||||
sprintf(hostName,"%s-%.2s%.2s%.2s%.2s%.2s%.2s",hostNameBase,id,id+3,id+6,id+9,id+12,id+15);
|
||||
|
||||
if(!hostNameSuffix)
|
||||
sprintf(hostName,"%s-%.2s%.2s%.2s%.2s%.2s%.2s",hostNameBase,id,id+3,id+6,id+9,id+12,id+15);
|
||||
else
|
||||
sprintf(hostName,"%s%s",hostNameBase,hostNameSuffix);
|
||||
|
||||
Serial.print("\nStarting MDNS...\n");
|
||||
Serial.print("Broadcasting as: ");
|
||||
|
|
|
|||
|
|
@ -75,7 +75,8 @@ struct SpanConfig {
|
|||
struct Span{
|
||||
|
||||
const char *displayName; // display name for this device - broadcast as part of Bonjour MDNS
|
||||
const char *hostNameBase; // base of host name of this device - full host name broadcast by Bonjour MDNS will have 6-byte accessoryID as well as '.local' automatically appended
|
||||
const char *hostNameBase; // base of hostName of this device - full host name broadcast by Bonjour MDNS will have 6-byte accessoryID as well as '.local' automatically appended
|
||||
const char *hostNameSuffix=NULL; // optional "suffix" of hostName of this device. If specified, will be used as the hostName suffix instead of the 6-byte accessoryID
|
||||
char *hostName; // full host name of this device - constructed from hostNameBase and 6-byte AccessoryID
|
||||
const char *modelName; // model name of this device - broadcast as Bonjour field "md"
|
||||
char category[3]=""; // category ID of primary accessory - broadcast as Bonjour field "ci" (HAP Section 13)
|
||||
|
|
@ -141,6 +142,7 @@ struct Span{
|
|||
void setCommandTimeout(uint16_t nSec){comModeLife=nSec*1000;} // sets Command Mode Timeout (seconds)
|
||||
void setLogLevel(uint8_t level){logLevel=level;} // sets Log Level for log messages (0=baseline, 1=intermediate, 2=all)
|
||||
void setMaxConnections(uint8_t nCon){maxConnections=nCon;} // sets maximum number of simultaneous HAP connections (HAP requires devices support at least 8)
|
||||
void setHostNameSuffix(const char *suffix){hostNameSuffix=suffix;} // sets the hostName suffix to be used instead of the 6-byte AccessoryID
|
||||
};
|
||||
|
||||
///////////////////////////////
|
||||
|
|
|
|||
|
|
@ -10,6 +10,8 @@ void setup() {
|
|||
|
||||
homeSpan.setLogLevel(2);
|
||||
|
||||
homeSpan.setHostNameSuffix("");
|
||||
|
||||
homeSpan.begin(Category::Lighting,"HomeSpanTest");
|
||||
|
||||
new SpanAccessory(); // Begin by creating a new Accessory using SpanAccessory(), which takes no arguments
|
||||
|
|
|
|||
Loading…
Reference in New Issue