diff --git a/src/HomeSpan.cpp b/src/HomeSpan.cpp index a37e8f8..2cf9e1c 100644 --- a/src/HomeSpan.cpp +++ b/src/HomeSpan.cpp @@ -362,10 +362,20 @@ void Span::checkConnect(){ id[17]='\0'; // add terminating null // 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: "); diff --git a/src/HomeSpan.h b/src/HomeSpan.h index ebbf623..09c0d49 100644 --- a/src/HomeSpan.h +++ b/src/HomeSpan.h @@ -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 }; /////////////////////////////// diff --git a/src/src.ino b/src/src.ino index 9c1967b..87725b6 100644 --- a/src/src.ino +++ b/src/src.ino @@ -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