Created method setPairingCode(const char *s)
Allows for programmatic creation of Pairing Setup Code. Not recommended, but added for a convenience - should use 'S' from CLI instead.
This commit is contained in:
parent
8c93ac2e35
commit
48b21df329
|
|
@ -52,11 +52,15 @@ void HAPClient::init(){
|
||||||
otaPwdHash.getChars(homeSpan.otaPwd);
|
otaPwdHash.getChars(homeSpan.otaPwd);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(strlen(homeSpan.pairingCodeCommand)){ // load verification setup code if provided
|
||||||
|
homeSpan.processSerialCommand(homeSpan.pairingCodeCommand); // if load failed due to invalid code, the logic below still runs and will pick up previous code or use the default one
|
||||||
|
}
|
||||||
|
|
||||||
struct { // temporary structure to hold SRP verification code and salt stored in NVS
|
struct { // temporary structure to hold SRP verification code and salt stored in NVS
|
||||||
uint8_t salt[16];
|
uint8_t salt[16];
|
||||||
uint8_t verifyCode[384];
|
uint8_t verifyCode[384];
|
||||||
} verifyData;
|
} verifyData;
|
||||||
|
|
||||||
if(!nvs_get_blob(srpNVS,"VERIFYDATA",NULL,&len)){ // if found verification code data in NVS
|
if(!nvs_get_blob(srpNVS,"VERIFYDATA",NULL,&len)){ // if found verification code data in NVS
|
||||||
nvs_get_blob(srpNVS,"VERIFYDATA",&verifyData,&len); // retrieve data
|
nvs_get_blob(srpNVS,"VERIFYDATA",&verifyData,&len); // retrieve data
|
||||||
srp.loadVerifyCode(verifyData.verifyCode,verifyData.salt); // load verification code and salt into SRP structure
|
srp.loadVerifyCode(verifyData.verifyCode,verifyData.salt); // load verification code and salt into SRP structure
|
||||||
|
|
|
||||||
|
|
@ -721,11 +721,11 @@ void Span::processSerialCommand(const char *c){
|
||||||
sscanf(c+1," %9[0-9]",setupCode);
|
sscanf(c+1," %9[0-9]",setupCode);
|
||||||
|
|
||||||
if(strlen(setupCode)!=8){
|
if(strlen(setupCode)!=8){
|
||||||
Serial.print("\n*** Invalid request to change Setup Code. Code must be exactly 8 digits.\n");
|
Serial.print("\n*** Invalid request to change Setup Code. Code must be exactly 8 digits.\n\n");
|
||||||
} else
|
} else
|
||||||
|
|
||||||
if(!network.allowedCode(setupCode)){
|
if(!network.allowedCode(setupCode)){
|
||||||
Serial.print("\n*** Invalid request to change Setup Code. Code too simple.\n");
|
Serial.print("\n*** Invalid request to change Setup Code. Code too simple.\n\n");
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
sprintf(buf,"\n\nGenerating SRP verification data for new Setup Code: %.3s-%.2s-%.3s ... ",setupCode,setupCode+3,setupCode+5);
|
sprintf(buf,"\n\nGenerating SRP verification data for new Setup Code: %.3s-%.2s-%.3s ... ",setupCode,setupCode+3,setupCode+5);
|
||||||
|
|
|
||||||
|
|
@ -112,6 +112,7 @@ struct Span{
|
||||||
const char *sketchVersion="n/a"; // version of the sketch
|
const char *sketchVersion="n/a"; // version of the sketch
|
||||||
nvs_handle charNVS; // handle for non-volatile-storage of Characteristics data
|
nvs_handle charNVS; // handle for non-volatile-storage of Characteristics data
|
||||||
nvs_handle wifiNVS=0; // handle for non-volatile-storage of WiFi data
|
nvs_handle wifiNVS=0; // handle for non-volatile-storage of WiFi data
|
||||||
|
char pairingCodeCommand[12]=""; // user-specified Pairing Code - only needed if Pairing Setup Code is specified in sketch using setPairingCode()
|
||||||
|
|
||||||
boolean connected=false; // WiFi connection status
|
boolean connected=false; // WiFi connection status
|
||||||
unsigned long waitTime=60000; // time to wait (in milliseconds) between WiFi connection attempts
|
unsigned long waitTime=60000; // time to wait (in milliseconds) between WiFi connection attempts
|
||||||
|
|
@ -188,6 +189,8 @@ struct Span{
|
||||||
void setWifiCallback(void (*f)()){wifiCallback=f;} // sets an optional user-defined function to call once WiFi connectivity is established
|
void setWifiCallback(void (*f)()){wifiCallback=f;} // sets an optional user-defined function to call once WiFi connectivity is established
|
||||||
void setApFunction(void (*f)()){apFunction=f;} // sets an optional user-defined function to call when activating the WiFi Access Point
|
void setApFunction(void (*f)()){apFunction=f;} // sets an optional user-defined function to call when activating the WiFi Access Point
|
||||||
|
|
||||||
|
void setPairingCode(const char *s){sprintf(pairingCodeCommand,"S %9s",s);} // sets the Pairing Code - use is NOT recommended. Use 'S' from CLI instead
|
||||||
|
|
||||||
void enableAutoStartAP(){autoStartAPEnabled=true;} // enables auto start-up of Access Point when WiFi Credentials not found
|
void enableAutoStartAP(){autoStartAPEnabled=true;} // enables auto start-up of Access Point when WiFi Credentials not found
|
||||||
void setWifiCredentials(const char *ssid, const char *pwd); // sets WiFi Credentials
|
void setWifiCredentials(const char *ssid, const char *pwd); // sets WiFi Credentials
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue