Updated Command Mode to include timeout and for apConfigure() to have more cancel options
This commit is contained in:
parent
7e4df498db
commit
3872d693a5
|
|
@ -213,11 +213,22 @@ void Span::commandMode(){
|
|||
boolean done=false;
|
||||
statusLED.start(500,0.3,mode,1000);
|
||||
|
||||
unsigned long alarmTime=millis()+comModeLife;
|
||||
|
||||
while(!done){
|
||||
if(millis()>alarmTime){
|
||||
Serial.print("*** Command Mode: Timed Out (");
|
||||
Serial.print(comModeLife/1000);
|
||||
Serial.print(" seconds).\n\n");
|
||||
mode=1;
|
||||
done=true;
|
||||
statusLED.start(LED_ALERT);
|
||||
delay(1000);
|
||||
} else
|
||||
if(controlButton.triggered(10,3000)){
|
||||
if(!controlButton.longPress()){
|
||||
mode++;
|
||||
if(mode==4)
|
||||
if(mode==5)
|
||||
mode=1;
|
||||
statusLED.start(500,0.3,mode,1000);
|
||||
} else {
|
||||
|
|
@ -250,6 +261,10 @@ void Span::commandMode(){
|
|||
processSerialCommand("U");
|
||||
break;
|
||||
|
||||
case 4:
|
||||
processSerialCommand("X");
|
||||
break;
|
||||
|
||||
} // switch
|
||||
|
||||
Serial.print("*** EXITING COMMAND MODE ***\n\n");
|
||||
|
|
@ -291,6 +306,8 @@ void Span::initWifi(){
|
|||
while(millis()-sTime<delayTime){
|
||||
if(controlButton.triggered(9999,3000) || (Serial.available() && readSerial(buf,1) && (buf[0]=='X'))){
|
||||
Serial.print(" TERMINATED!\n");
|
||||
statusLED.start(LED_ALERT);
|
||||
delay(1000);
|
||||
processSerialCommand("X"); // DELETE WiFi Data
|
||||
return;
|
||||
}
|
||||
|
|
@ -475,7 +492,10 @@ void Span::processSerialCommand(char *c){
|
|||
network.serialConfigure();
|
||||
nvs_set_blob(HAPClient::wifiNVS,"WIFIDATA",&network.wifiData,sizeof(network.wifiData)); // update data
|
||||
nvs_commit(HAPClient::wifiNVS); // commit to NVS
|
||||
Serial.print("\n*** WiFi Credentials saved!\n\n");
|
||||
Serial.print("\n*** WiFi Credentials erased! Re-starting ***\n\n");
|
||||
delay(500);
|
||||
statusLED.off();
|
||||
ESP.restart();
|
||||
}
|
||||
break;
|
||||
|
||||
|
|
@ -601,14 +621,19 @@ void Span::processSerialCommand(char *c){
|
|||
Serial.print(" s - print connection status\n");
|
||||
Serial.print(" d - print attributes database\n");
|
||||
Serial.print(" i - print detailed info about configuration\n");
|
||||
Serial.print(" U - unpair device by deleting all Controller data\n");
|
||||
Serial.print(" X - delete WiFi credentials and restart\n");
|
||||
Serial.print(" W - configure WiFi credentials and connect\n");
|
||||
Serial.print("\n");
|
||||
Serial.print(" W - configure WiFi credentials and restart\n");
|
||||
Serial.print(" A - start Access Point\n");
|
||||
Serial.print(" H - delete stored HomeKit Pairing data and restart\n");
|
||||
Serial.print(" X - delete WiFi credentials and restart\n");
|
||||
Serial.print("\n");
|
||||
Serial.print(" U - unpair device by deleting all Controller data\n");
|
||||
Serial.print(" H - delete HomeKit Device ID & Pairing data and restart\n");
|
||||
Serial.print("\n");
|
||||
Serial.print(" F - factory reset and restart\n");
|
||||
Serial.print(" E - delete all stored data and restart\n");
|
||||
Serial.print("\n");
|
||||
Serial.print(" ? - print this list of commands\n");
|
||||
Serial.print("\n");
|
||||
Serial.print(" L <level> - change Log Level to <level>\n");
|
||||
Serial.print(" S <code> - change Setup Code to 8-digit <code>\n");
|
||||
Serial.print("\n*** End Commands ***\n\n");
|
||||
|
|
|
|||
|
|
@ -62,6 +62,7 @@ struct Span{
|
|||
uint8_t controlPin=DEFAULT_CONTROL_PIN; // pin for Control Pushbutton
|
||||
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
|
||||
|
||||
Blinker statusLED; // indicates HomeSpan status
|
||||
PushButton controlButton; // controls HomeSpan configuration and resets
|
||||
|
|
@ -101,6 +102,7 @@ struct Span{
|
|||
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)
|
||||
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)
|
||||
};
|
||||
|
|
|
|||
|
|
@ -123,6 +123,15 @@ void Network::apConfigure(char *apName){
|
|||
|
||||
while(1){ // loop until we get timed out (which will be accelerated if save/cancel selected)
|
||||
|
||||
if(homeSpan.controlButton.triggered(9999,3000)){
|
||||
Serial.print("\n*** Access Point Terminated.");
|
||||
homeSpan.statusLED.start(LED_ALERT);
|
||||
homeSpan.controlButton.wait();
|
||||
Serial.print(" Restarting... \n\n");
|
||||
homeSpan.statusLED.off();
|
||||
ESP.restart();
|
||||
}
|
||||
|
||||
if(millis()>alarmTimeOut){
|
||||
WiFi.softAPdisconnect(true); // terminate connections and shut down captive access point
|
||||
delay(100);
|
||||
|
|
@ -134,9 +143,13 @@ void Network::apConfigure(char *apName){
|
|||
Serial.print("\n*** Access Point: Timed Out (");
|
||||
Serial.print(lifetime/1000);
|
||||
Serial.print(" seconds).");
|
||||
} else
|
||||
} else {
|
||||
Serial.print("\n*** Access Point: Configuration Canceled.");
|
||||
}
|
||||
Serial.print(" Restarting...\n\n");
|
||||
homeSpan.statusLED.start(LED_ALERT);
|
||||
delay(1000);
|
||||
homeSpan.statusLED.off();
|
||||
ESP.restart();
|
||||
}
|
||||
}
|
||||
|
|
@ -317,6 +330,9 @@ void Network::processRequest(char *body, char *formData){
|
|||
|
||||
responseBody+="<center><input style=\"font-size:300%\" type=\"submit\" value=\"SUBMIT\"></center>"
|
||||
"</form>";
|
||||
|
||||
responseBody+="<center><button style=\"font-size:300%\" onclick=\"document.location='/cancel'\">CANCEL Configuration</button></center>";
|
||||
|
||||
} else
|
||||
|
||||
if(!landingPage)
|
||||
|
|
|
|||
|
|
@ -24,6 +24,7 @@
|
|||
#define DEFAULT_AP_PASSWORD "homespan" // change with homeSpan.setApPassword(pwd)
|
||||
|
||||
#define DEFAULT_AP_TIMEOUT 120 // change with homeSpan.setApTimeout(nSeconds)
|
||||
#define DEFAULT_COMMAND_TIMEOUT 30 // change with homeSpan.setCommandTimeout(nSeconds)
|
||||
|
||||
#define DEFAULT_LOG_LEVEL 0 // change with homeSpan.setLogLevel(level)
|
||||
|
||||
|
|
@ -37,7 +38,6 @@
|
|||
#define LED_PAIRING_NEEDED 300,0.5,2,2550 // slow double-blink
|
||||
#define LED_ALERT 100 // rapid flashing
|
||||
#define LED_WIFI_CONNECTING 2000 // slow flashing
|
||||
#define LED_INPUT_NEEDED 500 // medium flashing
|
||||
#define LED_AP_STARTED 100,0.5,2,500 // rapid double-blink
|
||||
#define LED_AP_CONNECTED 500,0.3,2,1000 // slow double-blink
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue