From f3b1de2f6b9ff3ea8b9e0a025a12223f3b5e8e43 Mon Sep 17 00:00:00 2001 From: Gregg Date: Mon, 12 Oct 2020 07:55:07 -0500 Subject: [PATCH] Changed apConfig() to use fixed SSID of "HomeSpan-Configuration" --- src/HomeSpan.cpp | 2 +- src/HomeSpan.h | 1 + src/Network.cpp | 6 +++--- src/Network.h | 3 ++- src/Settings.h | 3 ++- 5 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/HomeSpan.cpp b/src/HomeSpan.cpp index 61d9706..7d1fed2 100644 --- a/src/HomeSpan.cpp +++ b/src/HomeSpan.cpp @@ -515,7 +515,7 @@ void Span::processSerialCommand(char *c){ WiFi.disconnect(); } - network.apConfigure(hostName); + network.apConfigure(); nvs_set_blob(HAPClient::wifiNVS,"WIFIDATA",&network.wifiData,sizeof(network.wifiData)); // update data nvs_commit(HAPClient::wifiNVS); // commit to NVS Serial.print("\n*** Credentials saved!\n\n"); diff --git a/src/HomeSpan.h b/src/HomeSpan.h index a92b44e..b80956e 100644 --- a/src/HomeSpan.h +++ b/src/HomeSpan.h @@ -100,6 +100,7 @@ struct Span{ void setControlPin(uint8_t pin){controlPin=pin;} // sets Control Pin void setStatusPin(uint8_t pin){statusPin=pin;} // sets 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 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) diff --git a/src/Network.cpp b/src/Network.cpp index cb944e4..6225161 100644 --- a/src/Network.cpp +++ b/src/Network.cpp @@ -82,10 +82,10 @@ boolean Network::allowedCode(char *s){ /////////////////////////////// -void Network::apConfigure(char *apName){ +void Network::apConfigure(){ Serial.print("*** Starting Access Point: "); - Serial.print(apName); + Serial.print(apSSID); Serial.print(" / "); Serial.print(apPassword); Serial.print("\n"); @@ -114,7 +114,7 @@ void Network::apConfigure(char *apName){ IPAddress apIP(192, 168, 4, 1); WiFi.mode(WIFI_AP); - WiFi.softAP(apName,apPassword); // start access point + WiFi.softAP(apSSID,apPassword); // start access point dnsServer.start(DNS_PORT, "*", apIP); // start DNS server that resolves every request to the address of this device apServer.begin(); diff --git a/src/Network.h b/src/Network.h index c6481a0..5968d15 100644 --- a/src/Network.h +++ b/src/Network.h @@ -16,6 +16,7 @@ struct Network { const int MAX_HTTP=4095; // max number of bytes in HTTP message + char *apSSID=DEFAULT_AP_SSID; // Access Point SSID 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 @@ -38,7 +39,7 @@ struct Network { void scan(); // scan for WiFi networks and save only those with unique SSIDs void serialConfigure(); // configure homeSpan WiFi from serial monitor boolean allowedCode(char *s); // checks if Setup Code is allowed (HAP defines a list of disallowed codes) - void apConfigure(char *hostName); // configure homeSpan WiFi and Setup Code using temporary Captive Access Point 'hostName'; only returns if sucessful, else ESP restarts + void apConfigure(); // configure homeSpan WiFi and Setup Code using temporary Captive Access Point; only returns if sucessful, else ESP restarts void processRequest(char *body, char *formData); // process the HTTP request int getFormValue(char *formData, char *tag, char *value, int maxSize); // search for 'tag' in 'formData' and copy result into 'value' up to 'maxSize' characters; returns number of characters, else -1 if 'tag' not found int badRequestError(); // return 400 error diff --git a/src/Settings.h b/src/Settings.h index 0dce60b..213b649 100644 --- a/src/Settings.h +++ b/src/Settings.h @@ -21,7 +21,8 @@ #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_SSID "HomeSpan-Configuration" // change with homeSpan.setApSSID(pwd) +#define DEFAULT_AP_PASSWORD "homespan" // change with homeSpan.setApPassword(pwd) #define DEFAULT_AP_TIMEOUT 300 // change with homeSpan.setApTimeout(nSeconds) #define DEFAULT_COMMAND_TIMEOUT 120 // change with homeSpan.setCommandTimeout(nSeconds)