Add homeSpan.enableAutoStartAP()

Enables auto-start of AccessPoint if WiFi Credentials not found.
This commit is contained in:
Gregg 2021-06-05 10:30:21 -05:00
parent d46fd3949d
commit 1dfd66bf25
3 changed files with 13 additions and 2 deletions

View File

@ -142,8 +142,14 @@ void Span::poll() {
HAPClient::init(); // read NVS and load HAP settings
if(!strlen(network.wifiData.ssid)){
Serial.print("*** WIFI CREDENTIALS DATA NOT FOUND. YOU MAY CONFIGURE BY TYPING 'W <RETURN>'.\n\n");
Serial.print("*** WIFI CREDENTIALS DATA NOT FOUND. ");
if(autoStartAPEnabled){
Serial.print("AUTO-START OF ACCESS POINT ENABLED...\n\n");
processSerialCommand("A");
} else {
Serial.print("YOU MAY CONFIGURE BY TYPING 'W <RETURN>'.\n\n");
statusLED.start(LED_WIFI_NEEDED);
}
} else {
homeSpan.statusLED.start(LED_WIFI_CONNECTING);
}

View File

@ -123,6 +123,7 @@ struct Span{
char otaPwd[33]; // MD5 Hash of OTA password, represented as a string of hexidecimal characters
boolean otaAuth; // OTA requires password when set to true
void (*wifiCallback)()=NULL; // optional callback function to invoke once WiFi connectivity is established
boolean autoStartAPEnabled=false; // enables auto start-up of Access Point when WiFi Credentials not found
WiFiServer *hapServer; // pointer to the HAP Server connection
Blinker statusLED; // indicates HomeSpan status
@ -177,6 +178,7 @@ struct Span{
void setSketchVersion(const char *sVer){sketchVersion=sVer;} // set optional sketch version number
const char *getSketchVersion(){return sketchVersion;} // get sketch version number
void setWifiCallback(void (*f)()){wifiCallback=f;} // sets an optional user-defined function to call once WiFi connectivity is established
void enableAutoStartAP(){autoStartAPEnabled=true;} // enables auto start-up of Access Point when WiFi Credentials not found
};
///////////////////////////////

View File

@ -21,6 +21,8 @@ void setup() {
new SpanUserCommand('d',"My Description",userCom1);
new SpanUserCommand('d',"My second Description",userCom2);
// homeSpan.enableAutoStartAP();
homeSpan.begin(Category::Lighting,"HomeSpan Lamp Server","homespan");
new SpanAccessory(); // Begin by creating a new Accessory using SpanAccessory(), which takes no arguments
@ -40,6 +42,7 @@ void setup() {
new Characteristic::On();
new Characteristic::Brightness();
new Characteristic::Name("Light 1");
new Characteristic::ColorTemperature(0);
new Service::LightBulb();
new Characteristic::On(2);
(new Characteristic::Brightness(50))->setRange(10,100,5);