commit
a9bc348822
|
|
@ -1,5 +1,5 @@
|
|||
name=HomeSpan
|
||||
version=1.1.3
|
||||
version=1.1.4
|
||||
author=Gregg <homespan@icloud.com>
|
||||
maintainer=Gregg <homespan@icloud.com>
|
||||
sentence=A robust and extremely easy-to-use HomeKit implementation for the Espressif ESP32 running on the Arduino IDE.
|
||||
|
|
|
|||
32
src/HAP.cpp
32
src/HAP.cpp
|
|
@ -1,7 +1,7 @@
|
|||
/*********************************************************************************
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (c) 2020 Gregg E. Berman
|
||||
* Copyright (c) 2020-2021 Gregg E. Berman
|
||||
*
|
||||
* https://github.com/HomeSpan/HomeSpan
|
||||
*
|
||||
|
|
@ -58,11 +58,14 @@ void HAPClient::init(){
|
|||
} else {
|
||||
|
||||
char c[128];
|
||||
sprintf(c,"Generating SRP verification data for default Setup Code: %.3s-%.2s-%.3s\n\n",homeSpan.defaultSetupCode,homeSpan.defaultSetupCode+3,homeSpan.defaultSetupCode+5);
|
||||
sprintf(c,"Generating SRP verification data for default Setup Code: %.3s-%.2s-%.3s\n",homeSpan.defaultSetupCode,homeSpan.defaultSetupCode+3,homeSpan.defaultSetupCode+5);
|
||||
Serial.print(c);
|
||||
srp.createVerifyCode(homeSpan.defaultSetupCode,verifyData.verifyCode,verifyData.salt); // create verification code from default Setup Code and random salt
|
||||
nvs_set_blob(srpNVS,"VERIFYDATA",&verifyData,sizeof(verifyData)); // update data
|
||||
nvs_commit(srpNVS); // commit to NVS
|
||||
Serial.print("Optional QR Code: ");
|
||||
Serial.print(homeSpan.getQRCode(homeSpan.defaultSetupCode));
|
||||
Serial.print("\n\n");
|
||||
}
|
||||
|
||||
if(!nvs_get_blob(hapNVS,"ACCESSORY",NULL,&len)){ // if found long-term Accessory data in NVS
|
||||
|
|
@ -647,6 +650,8 @@ int HAPClient::postPairSetupURL(){
|
|||
|
||||
} // switch
|
||||
|
||||
return(1);
|
||||
|
||||
} // postPairSetup
|
||||
|
||||
//////////////////////////////////////
|
||||
|
|
@ -701,7 +706,7 @@ int HAPClient::postPairVerifyURL(){
|
|||
|
||||
memcpy(iosCurveKey,tlv8.buf(kTLVType_PublicKey),32); // save iosCurveKey (will persist until end of verification process)
|
||||
|
||||
int rVal=crypto_scalarmult_curve25519(sharedCurveKey,secretCurveKey,iosCurveKey); // generate (and persist) Pair Verify SharedSecret CurveKey from Accessory's Curve25519 secret key and Controller's Curve25519 public key (32 bytes)
|
||||
crypto_scalarmult_curve25519(sharedCurveKey,secretCurveKey,iosCurveKey); // generate (and persist) Pair Verify SharedSecret CurveKey from Accessory's Curve25519 secret key and Controller's Curve25519 public key (32 bytes)
|
||||
|
||||
uint8_t *accessoryPairingID = accessory.ID; // set accessoryPairingID
|
||||
size_t accessoryPairingIDLen = 17;
|
||||
|
|
@ -843,6 +848,8 @@ int HAPClient::postPairVerifyURL(){
|
|||
|
||||
} // switch
|
||||
|
||||
return(1);
|
||||
|
||||
} // postPairVerify
|
||||
|
||||
//////////////////////////////////////
|
||||
|
|
@ -925,7 +932,7 @@ int HAPClient::postPairingsURL(){
|
|||
break;
|
||||
}
|
||||
|
||||
if(newCont=findController(tlv8.buf(kTLVType_Identifier))){
|
||||
if((newCont=findController(tlv8.buf(kTLVType_Identifier)))){
|
||||
tlv8.clear(); // clear TLV records
|
||||
tlv8.val(kTLVType_State,pairState_M2); // set State=<M2>
|
||||
if(!memcmp(cPair->LTPK,newCont->LTPK,32)){ // requested Controller already exists and LTPK matches
|
||||
|
|
@ -1187,10 +1194,10 @@ int HAPClient::putPrepareURL(char *json){
|
|||
uint32_t ttl;
|
||||
uint64_t pid;
|
||||
|
||||
if(cBuf=strstr(json,ttlToken))
|
||||
sscanf(cBuf+strlen(ttlToken),"%lu",&ttl);
|
||||
if((cBuf=strstr(json,ttlToken)))
|
||||
sscanf(cBuf+strlen(ttlToken),"%u",&ttl);
|
||||
|
||||
if(cBuf=strstr(json,pidToken))
|
||||
if((cBuf=strstr(json,pidToken)))
|
||||
sscanf(cBuf+strlen(ttlToken),"%llu",&pid);
|
||||
|
||||
char jsonBuf[32];
|
||||
|
|
@ -1202,7 +1209,7 @@ int HAPClient::putPrepareURL(char *json){
|
|||
status=StatusCode::InvalidValue;
|
||||
}
|
||||
|
||||
sprintf(jsonBuf,"{\"status\":%d}",status);
|
||||
sprintf(jsonBuf,"{\"status\":%d}",(int)status);
|
||||
int nBytes=strlen(jsonBuf);
|
||||
int nChars=snprintf(NULL,0,"HTTP/1.1 200 OK\r\nContent-Type: application/hap+json\r\nContent-Length: %d\r\n\r\n",nBytes); // create Body with Content Length = size of JSON Buf
|
||||
char body[nChars+1];
|
||||
|
|
@ -1264,7 +1271,7 @@ void HAPClient::checkTimedWrites(){
|
|||
|
||||
for(auto tw=homeSpan.TimedWrites.begin(); tw!=homeSpan.TimedWrites.end(); tw++){ // loop over all Timed Writes using an iterator
|
||||
if(cTime>tw->second){ // timer has expired
|
||||
sprintf(c,"Removing PID=%llu ALARM=%lu\n",tw->first,tw->second);
|
||||
sprintf(c,"Removing PID=%llu ALARM=%u\n",tw->first,tw->second);
|
||||
LOG2(c);
|
||||
homeSpan.TimedWrites.erase(tw);
|
||||
}
|
||||
|
|
@ -1338,7 +1345,6 @@ void HAPClient::tlvRespond(){
|
|||
int HAPClient::receiveEncrypted(){
|
||||
|
||||
uint8_t buf[1042]; // maximum size of encoded message = 2+1024+16 bytes (HAP Section 6.5.2)
|
||||
int nFrames=0;
|
||||
int nBytes=0;
|
||||
|
||||
while(client.read(buf,2)==2){ // read initial 2-byte AAD record
|
||||
|
|
@ -1498,7 +1504,7 @@ Controller *HAPClient::addController(uint8_t *id, uint8_t *ltpk, boolean admin){
|
|||
|
||||
Controller *slot;
|
||||
|
||||
if(slot=findController(id)){
|
||||
if((slot=findController(id))){
|
||||
memcpy(slot->LTPK,ltpk,32);
|
||||
slot->admin=admin;
|
||||
LOG2("\n*** Updated Controller: ");
|
||||
|
|
@ -1508,7 +1514,7 @@ Controller *HAPClient::addController(uint8_t *id, uint8_t *ltpk, boolean admin){
|
|||
return(slot);
|
||||
}
|
||||
|
||||
if(slot=getFreeController()){
|
||||
if((slot=getFreeController())){
|
||||
slot->allocated=true;
|
||||
memcpy(slot->ID,id,36);
|
||||
memcpy(slot->LTPK,ltpk,32);
|
||||
|
|
@ -1553,7 +1559,7 @@ void HAPClient::removeController(uint8_t *id){
|
|||
|
||||
Controller *slot;
|
||||
|
||||
if(slot=findController(id)){ // remove controller if found
|
||||
if((slot=findController(id))){ // remove controller if found
|
||||
LOG2("\n***Removed Controller: ");
|
||||
if(homeSpan.logLevel>1)
|
||||
charPrintRow(id,36);
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
/*********************************************************************************
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (c) 2020 Gregg E. Berman
|
||||
* Copyright (c) 2020-2021 Gregg E. Berman
|
||||
*
|
||||
* https://github.com/HomeSpan/HomeSpan
|
||||
*
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
/*********************************************************************************
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (c) 2020 Gregg E. Berman
|
||||
* Copyright (c) 2020-2021 Gregg E. Berman
|
||||
*
|
||||
* https://github.com/HomeSpan/HomeSpan
|
||||
*
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
/*********************************************************************************
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (c) 2020 Gregg E. Berman
|
||||
* Copyright (c) 2020-2021 Gregg E. Berman
|
||||
*
|
||||
* https://github.com/HomeSpan/HomeSpan
|
||||
*
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
/*********************************************************************************
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (c) 2020 Gregg E. Berman
|
||||
* Copyright (c) 2020-2021 Gregg E. Berman
|
||||
*
|
||||
* https://github.com/HomeSpan/HomeSpan
|
||||
*
|
||||
|
|
|
|||
123
src/HomeSpan.cpp
123
src/HomeSpan.cpp
|
|
@ -1,7 +1,7 @@
|
|||
/*********************************************************************************
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (c) 2020 Gregg E. Berman
|
||||
* Copyright (c) 2020-2021 Gregg E. Berman
|
||||
*
|
||||
* https://github.com/HomeSpan/HomeSpan
|
||||
*
|
||||
|
|
@ -35,8 +35,6 @@
|
|||
|
||||
using namespace Utils;
|
||||
|
||||
WiFiServer hapServer(80); // HTTP Server (i.e. this acccesory) running on usual port 80 (local-scoped variable to this file only)
|
||||
|
||||
HAPClient **hap; // HAP Client structure containing HTTP client connections, parsing routines, and state variables (global-scoped variable)
|
||||
Span homeSpan; // HAP Attributes database and all related control functions for this Accessory (global-scoped variable)
|
||||
|
||||
|
|
@ -49,7 +47,7 @@ void Span::begin(Category catID, const char *displayName, const char *hostNameBa
|
|||
this->displayName=displayName;
|
||||
this->hostNameBase=hostNameBase;
|
||||
this->modelName=modelName;
|
||||
sprintf(this->category,"%d",catID);
|
||||
sprintf(this->category,"%d",(int)catID);
|
||||
|
||||
controlButton.init(controlPin);
|
||||
statusLED.init(statusPin);
|
||||
|
|
@ -127,6 +125,7 @@ void Span::poll() {
|
|||
statusLED.start(LED_WIFI_NEEDED);
|
||||
} else {
|
||||
homeSpan.statusLED.start(LED_WIFI_CONNECTING);
|
||||
hapServer=new WiFiServer(tcpPortNum,maxConnections);
|
||||
}
|
||||
|
||||
controlButton.reset();
|
||||
|
|
@ -150,10 +149,10 @@ void Span::poll() {
|
|||
|
||||
WiFiClient newClient;
|
||||
|
||||
if(newClient=hapServer.available()){ // found a new HTTP client
|
||||
int freeSlot=getFreeSlot(); // get next free slot
|
||||
if(hapServer && (newClient=hapServer->available())){ // found a new HTTP client
|
||||
int freeSlot=getFreeSlot(); // get next free slot
|
||||
|
||||
if(freeSlot==-1){ // no available free slots
|
||||
if(freeSlot==-1){ // no available free slots
|
||||
freeSlot=randombytes_uniform(maxConnections);
|
||||
LOG2("=======================================\n");
|
||||
LOG1("** Freeing Client #");
|
||||
|
|
@ -363,22 +362,34 @@ 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);
|
||||
|
||||
Serial.print("\nStarting MDNS...\n");
|
||||
Serial.print("Broadcasting as: ");
|
||||
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\n");
|
||||
Serial.print("HostName: ");
|
||||
Serial.print(hostName);
|
||||
Serial.print(".local (");
|
||||
Serial.print(".local:");
|
||||
Serial.print(tcpPortNum);
|
||||
Serial.print("\nDisplay Name: ");
|
||||
Serial.print(displayName);
|
||||
Serial.print(" / ");
|
||||
Serial.print("\nModel Name: ");
|
||||
Serial.print(modelName);
|
||||
Serial.print(")\n");
|
||||
Serial.print("\n");
|
||||
|
||||
MDNS.begin(hostName); // set server host name (.local implied)
|
||||
MDNS.setInstanceName(displayName); // set server display name
|
||||
MDNS.addService("_hap","_tcp",80); // advertise HAP service on HTTP port (80)
|
||||
MDNS.begin(hostName); // set server host name (.local implied)
|
||||
MDNS.setInstanceName(displayName); // set server display name
|
||||
MDNS.addService("_hap","_tcp",tcpPortNum); // advertise HAP service on specified port
|
||||
|
||||
// add MDNS (Bonjour) TXT records for configurable as well as fixed values (HAP Table 6-7)
|
||||
|
||||
|
|
@ -399,10 +410,21 @@ void Span::checkConnect(){
|
|||
else
|
||||
mdns_service_txt_item_set("_hap","_tcp","sf","0"); // set Status Flag = 0
|
||||
|
||||
uint8_t hashInput[22];
|
||||
uint8_t hashOutput[64];
|
||||
char setupHash[9];
|
||||
size_t len;
|
||||
|
||||
memcpy(hashInput,qrID,4); // Create the Seup ID for use with optional QR Codes. This is an undocumented feature of HAP R2!
|
||||
memcpy(hashInput+4,id,17); // Step 1: Concatenate 4-character Setup ID and 17-character Accessory ID into hashInput
|
||||
mbedtls_sha512_ret(hashInput,21,hashOutput,0); // Step 2: Perform SHA-512 hash on combined 21-byte hashInput to create 64-byte hashOutput
|
||||
mbedtls_base64_encode((uint8_t *)setupHash,9,&len,hashOutput,4); // Step 3: Encode the first 4 bytes of hashOutput in base64, which results in an 8-character, null-terminated, setupHash
|
||||
mdns_service_txt_item_set("_hap","_tcp","sh",setupHash); // Step 4: broadcast the resulting Setup Hash
|
||||
|
||||
Serial.print("\nStarting Web (HTTP) Server supporting up to ");
|
||||
Serial.print(maxConnections);
|
||||
Serial.print(" simultaneous connections...\n\n");
|
||||
hapServer.begin();
|
||||
hapServer->begin();
|
||||
|
||||
if(!HAPClient::nAdminControllers()){
|
||||
Serial.print("DEVICE NOT YET PAIRED -- PLEASE PAIR WITH HOMEKIT APP\n\n");
|
||||
|
|
@ -415,6 +437,19 @@ void Span::checkConnect(){
|
|||
|
||||
///////////////////////////////
|
||||
|
||||
void Span::setQRID(const char *id){
|
||||
|
||||
char tBuf[5];
|
||||
sscanf(id,"%4[0-9A-Za-z]",tBuf);
|
||||
|
||||
if(strlen(id)==4 && strlen(tBuf)==4){
|
||||
qrID=id;
|
||||
}
|
||||
|
||||
} // setQRID
|
||||
|
||||
///////////////////////////////
|
||||
|
||||
void Span::processSerialCommand(const char *c){
|
||||
|
||||
switch(c[0]){
|
||||
|
|
@ -504,6 +539,10 @@ void Span::processSerialCommand(const char *c){
|
|||
nvs_set_blob(HAPClient::srpNVS,"VERIFYDATA",&verifyData,sizeof(verifyData)); // update data
|
||||
nvs_commit(HAPClient::srpNVS); // commit to NVS
|
||||
Serial.print("New Code Saved!\n");
|
||||
|
||||
Serial.print("Optional QR Code: ");
|
||||
Serial.print(getQRCode(setupCode));
|
||||
Serial.print("\n\n");
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
|
@ -550,7 +589,7 @@ void Span::processSerialCommand(const char *c){
|
|||
|
||||
if(strlen(network.wifiData.ssid)>0){
|
||||
Serial.print("*** Stopping all current WiFi services...\n\n");
|
||||
hapServer.end();
|
||||
hapServer->end();
|
||||
MDNS.end();
|
||||
WiFi.disconnect();
|
||||
}
|
||||
|
|
@ -714,6 +753,32 @@ void Span::processSerialCommand(const char *c){
|
|||
|
||||
///////////////////////////////
|
||||
|
||||
const char *Span::getQRCode(const char *setupCode){
|
||||
|
||||
uint64_t n;
|
||||
uint64_t iSetupCode;
|
||||
uint64_t iCategory;
|
||||
|
||||
sscanf(category,"%llu",&iCategory);
|
||||
sscanf(setupCode,"%llu",&iSetupCode);
|
||||
|
||||
n=(iCategory << 31) | (0xA << 27) | iSetupCode;
|
||||
|
||||
qrCode="";
|
||||
|
||||
while(n>0){
|
||||
char c=n%36+48;
|
||||
if(c>57)
|
||||
c+=7;
|
||||
qrCode=c+qrCode;
|
||||
n/=36;
|
||||
}
|
||||
qrCode="X-HM://00" + qrCode + qrID;
|
||||
return(qrCode.c_str());
|
||||
}
|
||||
|
||||
///////////////////////////////
|
||||
|
||||
int Span::sprintfAttributes(char *cBuf){
|
||||
|
||||
int nBytes=0;
|
||||
|
|
@ -806,7 +871,7 @@ int Span::countCharacteristics(char *buf){
|
|||
int nObj=0;
|
||||
|
||||
const char tag[]="\"aid\"";
|
||||
while(buf=strstr(buf,tag)){ // count number of characteristic objects in PUT JSON request
|
||||
while((buf=strstr(buf,tag))){ // count number of characteristic objects in PUT JSON request
|
||||
nObj++;
|
||||
buf+=strlen(tag);
|
||||
}
|
||||
|
|
@ -988,7 +1053,7 @@ int Span::sprintfAttributes(SpanBuf *pObj, int nObj, char *cBuf){
|
|||
nChars+=snprintf(cBuf,cBuf?64:0,"{\"characteristics\":[");
|
||||
|
||||
for(int i=0;i<nObj;i++){
|
||||
nChars+=snprintf(cBuf?(cBuf+nChars):NULL,cBuf?128:0,"{\"aid\":%u,\"iid\":%d,\"status\":%d}",pObj[i].aid,pObj[i].iid,pObj[i].status);
|
||||
nChars+=snprintf(cBuf?(cBuf+nChars):NULL,cBuf?128:0,"{\"aid\":%u,\"iid\":%d,\"status\":%d}",pObj[i].aid,pObj[i].iid,(int)pObj[i].status);
|
||||
if(i+1<nObj)
|
||||
nChars+=snprintf(cBuf?(cBuf+nChars):NULL,cBuf?64:0,",");
|
||||
}
|
||||
|
|
@ -1041,7 +1106,7 @@ int Span::sprintfAttributes(char **ids, int numIDs, int flags, char *cBuf){
|
|||
|
||||
if(sFlag){ // status flag is needed - overlay at end
|
||||
nChars--;
|
||||
nChars+=snprintf(cBuf?(cBuf+nChars):NULL,cBuf?64:0,",\"status\":%d}",status[i]);
|
||||
nChars+=snprintf(cBuf?(cBuf+nChars):NULL,cBuf?64:0,",\"status\":%d}",(int)status[i]);
|
||||
}
|
||||
|
||||
if(i+1<numIDs)
|
||||
|
|
@ -1390,7 +1455,7 @@ int SpanCharacteristic::sprintfAttributes(char *cBuf, int flags){
|
|||
break;
|
||||
|
||||
case UINT32:
|
||||
nBytes+=snprintf(cBuf?(cBuf+nBytes):NULL,cBuf?64:0,",\"value\":%lu",value.UINT32);
|
||||
nBytes+=snprintf(cBuf?(cBuf+nBytes):NULL,cBuf?64:0,",\"value\":%u",value.UINT32);
|
||||
break;
|
||||
|
||||
case UINT64:
|
||||
|
|
@ -1493,17 +1558,17 @@ StatusCode SpanCharacteristic::loadUpdate(char *val, char *ev){
|
|||
break;
|
||||
|
||||
case UINT8:
|
||||
if(!sscanf(val,"%u",&newValue.UINT8))
|
||||
if(!sscanf(val,"%hhu",&newValue.UINT8))
|
||||
return(StatusCode::InvalidValue);
|
||||
break;
|
||||
|
||||
case UINT16:
|
||||
if(!sscanf(val,"%u",&newValue.UINT16))
|
||||
if(!sscanf(val,"%hu",&newValue.UINT16))
|
||||
return(StatusCode::InvalidValue);
|
||||
break;
|
||||
|
||||
case UINT32:
|
||||
if(!sscanf(val,"%llu",&newValue.UINT32))
|
||||
if(!sscanf(val,"%u",&newValue.UINT32))
|
||||
return(StatusCode::InvalidValue);
|
||||
break;
|
||||
|
||||
|
|
@ -1517,6 +1582,9 @@ StatusCode SpanCharacteristic::loadUpdate(char *val, char *ev){
|
|||
return(StatusCode::InvalidValue);
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
|
||||
} // switch
|
||||
|
||||
isUpdated=true;
|
||||
|
|
@ -1559,6 +1627,9 @@ void SpanCharacteristic::setVal(int val){
|
|||
value.UINT64=(uint64_t)val;
|
||||
newValue.UINT64=(uint64_t)val;
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
updateTime=homeSpan.snapTime;
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
/*********************************************************************************
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (c) 2020 Gregg E. Berman
|
||||
* Copyright (c) 2020-2021 Gregg E. Berman
|
||||
*
|
||||
* https://github.com/HomeSpan/HomeSpan
|
||||
*
|
||||
|
|
@ -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)
|
||||
|
|
@ -84,6 +85,7 @@ struct Span{
|
|||
int nFatalErrors=0; // number of fatal errors in user-defined configuration
|
||||
String configLog; // log of configuration process, including any errors
|
||||
boolean isBridge=true; // flag indicating whether device is configured as a bridge (i.e. first Accessory contains nothing but AccessoryInformation and HAPProtocolInformation)
|
||||
String qrCode; // optional QR Code to use for pairing
|
||||
|
||||
boolean connected=false; // WiFi connection status
|
||||
unsigned long waitTime=60000; // time to wait (in milliseconds) between WiFi connection attempts
|
||||
|
|
@ -95,7 +97,10 @@ struct Span{
|
|||
uint8_t logLevel=DEFAULT_LOG_LEVEL; // level for writing out log messages to serial monitor
|
||||
uint8_t maxConnections=DEFAULT_MAX_CONNECTIONS; // number of simultaneous HAP connections
|
||||
unsigned long comModeLife=DEFAULT_COMMAND_TIMEOUT*1000; // length of time (in milliseconds) to keep Command Mode alive before resuming normal operations
|
||||
uint16_t tcpPortNum=DEFAULT_TCP_PORT; // port for TCP communications between HomeKit and HomeSpan
|
||||
const char *qrID=DEFAULT_QR_ID; // optional Setup ID used to pair with QR Code
|
||||
|
||||
WiFiServer *hapServer; // pointer to the HAP Server connection
|
||||
Blinker statusLED; // indicates HomeSpan status
|
||||
PushButton controlButton; // controls HomeSpan configuration and resets
|
||||
Network network; // configures WiFi and Setup Code via either serial monitor or temporary Access Point
|
||||
|
|
@ -135,12 +140,16 @@ struct Span{
|
|||
void setControlPin(uint8_t pin){controlPin=pin;} // sets Control Pin
|
||||
void setStatusPin(uint8_t pin){statusPin=pin;} // sets Status Pin
|
||||
int getStatusPin(){return(statusPin);} // gets Status Pin
|
||||
void setApSSID(char *ssid){network.apSSID=ssid;} // sets Access Point SSID
|
||||
void setApPassword(char *pwd){network.apPassword=pwd;} // sets Access Point Password
|
||||
void setApSSID(const char *ssid){network.apSSID=ssid;} // sets Access Point SSID
|
||||
void setApPassword(const char *pwd){network.apPassword=pwd;} // sets Access Point Password
|
||||
void setApTimeout(uint16_t nSec){network.lifetime=nSec*1000;} // sets Access Point Timeout (seconds)
|
||||
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
|
||||
void setPortNum(uint16_t port){tcpPortNum=port;} // sets the TCP port number to use for communications between HomeKit and HomeSpan
|
||||
void setQRID(const char *id); // sets the Setup ID for optional pairing with a QR Code
|
||||
const char *getQRCode(const char *setupCode); // gets an optional QR code from setupCode
|
||||
};
|
||||
|
||||
///////////////////////////////
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
/*********************************************************************************
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (c) 2020 Gregg E. Berman
|
||||
* Copyright (c) 2020-2021 Gregg E. Berman
|
||||
*
|
||||
* https://github.com/HomeSpan/HomeSpan
|
||||
*
|
||||
|
|
@ -62,8 +62,8 @@ void Network::scan(){
|
|||
|
||||
void Network::serialConfigure(){
|
||||
|
||||
sprintf(wifiData.ssid,"");
|
||||
sprintf(wifiData.pwd,"");
|
||||
wifiData.ssid[0]='\0';
|
||||
wifiData.pwd[0]='\0';
|
||||
|
||||
Serial.print("*** WiFi Setup - Scanning for Networks...\n\n");
|
||||
|
||||
|
|
@ -400,7 +400,7 @@ int Network::getFormValue(char *formData, const char *tag, char *value, int maxS
|
|||
while(*v!='\0' && *v!='&' && len<maxSize){ // copy the value until null, '&', or maxSize is reached
|
||||
if(*v=='%'){ // this is an escaped character of form %XX
|
||||
v++;
|
||||
sscanf(v,"%2x",value++);
|
||||
sscanf(v,"%2x",(unsigned int *)value++);
|
||||
v+=2;
|
||||
} else {
|
||||
*value++=*v++;
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
/*********************************************************************************
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (c) 2020 Gregg E. Berman
|
||||
* Copyright (c) 2020-2021 Gregg E. Berman
|
||||
*
|
||||
* https://github.com/HomeSpan/HomeSpan
|
||||
*
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
/*********************************************************************************
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (c) 2020 Gregg E. Berman
|
||||
* Copyright (c) 2020-2021 Gregg E. Berman
|
||||
*
|
||||
* https://github.com/HomeSpan/HomeSpan
|
||||
*
|
||||
|
|
@ -225,7 +225,6 @@ int SRP6A::verifyProof(){
|
|||
void SRP6A::createProof(){
|
||||
|
||||
uint8_t tBuf[512]; // temporary buffer for staging
|
||||
uint8_t tHash[64]; // temporary buffer for storing SHA-512 results
|
||||
|
||||
// compute M2 = H( A | M1 | K )
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
/*********************************************************************************
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (c) 2020 Gregg E. Berman
|
||||
* Copyright (c) 2020-2021 Gregg E. Berman
|
||||
*
|
||||
* https://github.com/HomeSpan/HomeSpan
|
||||
*
|
||||
|
|
@ -29,6 +29,7 @@
|
|||
|
||||
#include <mbedtls/sha512.h>
|
||||
#include <mbedtls/bignum.h>
|
||||
#include <mbedtls/base64.h>
|
||||
|
||||
#include "HAPConstants.h"
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
/*********************************************************************************
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (c) 2020 Gregg E. Berman
|
||||
* Copyright (c) 2020-2021 Gregg E. Berman
|
||||
*
|
||||
* https://github.com/HomeSpan/HomeSpan
|
||||
*
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
/*********************************************************************************
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (c) 2020 Gregg E. Berman
|
||||
* Copyright (c) 2020-2021 Gregg E. Berman
|
||||
*
|
||||
* https://github.com/HomeSpan/HomeSpan
|
||||
*
|
||||
|
|
@ -34,7 +34,7 @@
|
|||
|
||||
#define HS_MAJOR 1
|
||||
#define HS_MINOR 1
|
||||
#define HS_PATCH 3
|
||||
#define HS_PATCH 4
|
||||
|
||||
#define STRINGIFY(x) _STR(x)
|
||||
#define _STR(x) #x
|
||||
|
|
@ -61,6 +61,8 @@
|
|||
|
||||
#define DEFAULT_SETUP_CODE "46637726" // changed during network setup or with 'S' command
|
||||
|
||||
#define DEFAULT_QR_ID "HSPN" // change with homeSpan.setQRID(qrID);
|
||||
|
||||
#define DEFAULT_CONTROL_PIN 21 // change with homeSpan.setControlPin(pin)
|
||||
#define DEFAULT_STATUS_PIN 13 // change with homeSpan.setStatusPin(pin)
|
||||
|
||||
|
|
@ -73,6 +75,7 @@
|
|||
#define DEFAULT_LOG_LEVEL 0 // change with homeSpan.setLogLevel(level)
|
||||
|
||||
#define DEFAULT_MAX_CONNECTIONS 8 // change with homeSpan.setMaxConnections(num);
|
||||
#define DEFAULT_TCP_PORT 80 // change with homeSpan.setPort(port);
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
/*********************************************************************************
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (c) 2020 Gregg E. Berman
|
||||
* Copyright (c) 2020-2021 Gregg E. Berman
|
||||
*
|
||||
* https://github.com/HomeSpan/HomeSpan
|
||||
*
|
||||
|
|
@ -90,6 +90,8 @@ int TLV<tagType, maxTags>::create(tagType tag, int maxLen, const char *name){
|
|||
tlv[numTags].len=-1;
|
||||
tlv[numTags].val=(uint8_t *)malloc(maxLen);
|
||||
numTags++;
|
||||
|
||||
return(1);
|
||||
}
|
||||
|
||||
//////////////////////////////////////
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
/*********************************************************************************
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (c) 2020 Gregg E. Berman
|
||||
* Copyright (c) 2020-2021 Gregg E. Berman
|
||||
*
|
||||
* https://github.com/HomeSpan/HomeSpan
|
||||
*
|
||||
|
|
@ -55,10 +55,11 @@ char *Utils::readSerial(char *c, int max){
|
|||
return(c); // return updated string
|
||||
}
|
||||
|
||||
c[i]=buf; // store new character
|
||||
|
||||
if(i<max) // do not store more than max characters (excluding string terminator)
|
||||
i++;
|
||||
if(buf!='\r'){ // save any character except carriage return
|
||||
c[i]=buf; // store new character
|
||||
if(i<max) // do not store more than max characters (excluding string terminator)
|
||||
i++;
|
||||
}
|
||||
|
||||
} // while(1)
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
/*********************************************************************************
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (c) 2020 Gregg E. Berman
|
||||
* Copyright (c) 2020-2021 Gregg E. Berman
|
||||
*
|
||||
* https://github.com/HomeSpan/HomeSpan
|
||||
*
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ void setup() {
|
|||
|
||||
Serial.begin(115200);
|
||||
|
||||
homeSpan.setLogLevel(2);
|
||||
homeSpan.setLogLevel(1);
|
||||
|
||||
homeSpan.begin(Category::Lighting,"HomeSpanTest");
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue