diff --git a/src/HomeSpan.cpp b/src/HomeSpan.cpp index c6d45a9..792ecd2 100644 --- a/src/HomeSpan.cpp +++ b/src/HomeSpan.cpp @@ -4,7 +4,6 @@ #include #include "HAP.h" -#include "Network.h" using namespace Utils; @@ -159,12 +158,11 @@ void Span::poll() { statusLED.start(500); } - if(controlButton.triggered(3000,10000)){ + if(controlButton.triggered(5000,10000)){ if(controlButton.longPress()){ statusLED.start(200); delay(2000); statusLED.off(); - ESP.restart(); processSerialCommand("W"); // DELETE WiFi Data and Restart } else { statusLED.off(); @@ -191,7 +189,7 @@ int Span::getFreeSlot(){ void Span::initWifi(){ - Network network; // initialization of WiFi credentials and Setup Code +// Network network; // initialization of WiFi credentials and Setup Code char id[18]; // create string version of Accessory ID for MDNS broadcast memcpy(id,HAPClient::accessory.ID,17); // copy ID bytes @@ -424,7 +422,7 @@ void Span::processSerialCommand(char *c){ case 'S': { - Network network; +// Network network; char buf[128]; char setupCode[10]; diff --git a/src/HomeSpan.h b/src/HomeSpan.h index 9b120e7..2c27fdd 100644 --- a/src/HomeSpan.h +++ b/src/HomeSpan.h @@ -8,6 +8,7 @@ #include "Settings.h" #include "Utils.h" +#include "Network.h" using std::vector; using std::unordered_map; @@ -55,6 +56,7 @@ struct Span{ 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 SpanConfig hapConfig; // track configuration changes to the HAP Accessory database; used to increment the configuration number (c#) when changes found vector Accessories; // vector of pointers to all Accessories @@ -87,7 +89,8 @@ struct Span{ void setControlPin(uint8_t pin){controlPin=pin;} // sets Control Pin void setStatusPin(uint8_t pin){statusPin=pin;} // sets Status Pin - + void setApPassword(char *pwd){network.apPassword=pwd;} // sets Access Point Password + void setApTimeout(uint16_t nSec){network.lifetime=nSec*1000;} // sets Access Point Timeout (seconds) }; /////////////////////////////// diff --git a/src/Network.cpp b/src/Network.cpp index 3ab9ed0..ae3f98a 100644 --- a/src/Network.cpp +++ b/src/Network.cpp @@ -1,8 +1,7 @@ #include -#include "Network.h" -#include "HAP.h" +#include "HomeSpan.h" using namespace Utils; @@ -242,7 +241,7 @@ void Network::apConfigure(char *apName){ LOG2("\n"); - } // process HAP Client + } // process Client if(client){ Serial.print("*** Stopping Client ***\n"); diff --git a/src/Network.h b/src/Network.h index 0cdd4e1..64abfff 100644 --- a/src/Network.h +++ b/src/Network.h @@ -9,9 +9,9 @@ using std::unordered_set; struct Network { - const int MAX_HTTP=4095; // max number of bytes in HTTP message - const char *apPassword="homespan"; // Access Point password (does not need to be secret - only used to ensure excrypted WiFi connection) - const unsigned long lifetime=120000; // length of time (in milliseconds) to keep Access Point alive before shutting down and re-starting + const int MAX_HTTP=4095; // max number of bytes in HTTP message + char *apPassword=DEFAULT_AP_PASSWORD; // Access Point password (does not need to be secret - only used to ensure excrypted WiFi connection) + unsigned long lifetime=DEFAULT_AP_TIMEOUT*1000; // length of time (in milliseconds) to keep Access Point alive before shutting down and re-starting char **ssidList=NULL; int numSSID; diff --git a/src/Settings.h b/src/Settings.h index 37c27c0..082a7fc 100644 --- a/src/Settings.h +++ b/src/Settings.h @@ -14,6 +14,8 @@ #define DEFAULT_SETUP_CODE "46637726" // changed during network setup or with 'S' command #define DEFAULT_CONTROL_PIN 21 // change with homeSpan.setControlPin(pin) #define DEFAULT_STATUS_PIN LED_BUILTIN // change with homeSpan.setStatusPin(pin) +#define DEFAULT_AP_PASSWORD "homespan" // change with homeSpan.setApPassword(pwd) +#define DEFAULT_AP_TIMEOUT 120 // change with homeSpan.setApTimeout(nSeconds) ////////////////////////////////////////////////////// // Maximum number of simultaenous IP connections // diff --git a/src/src.ino b/src/src.ino index c9de91a..542dd5d 100644 --- a/src/src.ino +++ b/src/src.ino @@ -7,7 +7,7 @@ void setup() { Serial.begin(115200); - + homeSpan.begin(Category::Lighting,"HomeSpan Benchmark"); new SpanAccessory(); // Begin by creating a new Accessory using SpanAccessory(), which takes no arguments