Created HomeSpan::setApPassword() and setAPTimeout()

Moved default values into Settings.h
This commit is contained in:
Gregg 2020-09-27 22:31:11 -05:00
parent 7d8a91f13b
commit 2d8f36e735
6 changed files with 15 additions and 13 deletions

View File

@ -4,7 +4,6 @@
#include <sodium.h> #include <sodium.h>
#include "HAP.h" #include "HAP.h"
#include "Network.h"
using namespace Utils; using namespace Utils;
@ -159,12 +158,11 @@ void Span::poll() {
statusLED.start(500); statusLED.start(500);
} }
if(controlButton.triggered(3000,10000)){ if(controlButton.triggered(5000,10000)){
if(controlButton.longPress()){ if(controlButton.longPress()){
statusLED.start(200); statusLED.start(200);
delay(2000); delay(2000);
statusLED.off(); statusLED.off();
ESP.restart();
processSerialCommand("W"); // DELETE WiFi Data and Restart processSerialCommand("W"); // DELETE WiFi Data and Restart
} else { } else {
statusLED.off(); statusLED.off();
@ -191,7 +189,7 @@ int Span::getFreeSlot(){
void Span::initWifi(){ 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 char id[18]; // create string version of Accessory ID for MDNS broadcast
memcpy(id,HAPClient::accessory.ID,17); // copy ID bytes memcpy(id,HAPClient::accessory.ID,17); // copy ID bytes
@ -424,7 +422,7 @@ void Span::processSerialCommand(char *c){
case 'S': { case 'S': {
Network network; // Network network;
char buf[128]; char buf[128];
char setupCode[10]; char setupCode[10];

View File

@ -8,6 +8,7 @@
#include "Settings.h" #include "Settings.h"
#include "Utils.h" #include "Utils.h"
#include "Network.h"
using std::vector; using std::vector;
using std::unordered_map; using std::unordered_map;
@ -55,6 +56,7 @@ struct Span{
Blinker statusLED; // indicates HomeSpan status Blinker statusLED; // indicates HomeSpan status
PushButton controlButton; // controls HomeSpan configuration and resets 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 SpanConfig hapConfig; // track configuration changes to the HAP Accessory database; used to increment the configuration number (c#) when changes found
vector<SpanAccessory *> Accessories; // vector of pointers to all Accessories vector<SpanAccessory *> Accessories; // vector of pointers to all Accessories
@ -87,7 +89,8 @@ struct Span{
void setControlPin(uint8_t pin){controlPin=pin;} // sets Control Pin void setControlPin(uint8_t pin){controlPin=pin;} // sets Control Pin
void setStatusPin(uint8_t pin){statusPin=pin;} // sets Status 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)
}; };
/////////////////////////////// ///////////////////////////////

View File

@ -1,8 +1,7 @@
#include <DNSServer.h> #include <DNSServer.h>
#include "Network.h" #include "HomeSpan.h"
#include "HAP.h"
using namespace Utils; using namespace Utils;
@ -242,7 +241,7 @@ void Network::apConfigure(char *apName){
LOG2("\n"); LOG2("\n");
} // process HAP Client } // process Client
if(client){ if(client){
Serial.print("*** Stopping Client ***\n"); Serial.print("*** Stopping Client ***\n");

View File

@ -9,9 +9,9 @@ using std::unordered_set;
struct Network { struct Network {
const int MAX_HTTP=4095; // max number of bytes in HTTP message 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) char *apPassword=DEFAULT_AP_PASSWORD; // 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 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; char **ssidList=NULL;
int numSSID; int numSSID;

View File

@ -14,6 +14,8 @@
#define DEFAULT_SETUP_CODE "46637726" // changed during network setup or with 'S' command #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_CONTROL_PIN 21 // change with homeSpan.setControlPin(pin)
#define DEFAULT_STATUS_PIN LED_BUILTIN // change with homeSpan.setStatusPin(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 // // Maximum number of simultaenous IP connections //

View File

@ -7,7 +7,7 @@
void setup() { void setup() {
Serial.begin(115200); Serial.begin(115200);
homeSpan.begin(Category::Lighting,"HomeSpan Benchmark"); homeSpan.begin(Category::Lighting,"HomeSpan Benchmark");
new SpanAccessory(); // Begin by creating a new Accessory using SpanAccessory(), which takes no arguments new SpanAccessory(); // Begin by creating a new Accessory using SpanAccessory(), which takes no arguments