fix AP+DHCP mode

This commit is contained in:
Kevin Matz 2020-12-16 15:58:57 -05:00
parent 685c266e9d
commit 7b5807fba8

View File

@ -50,6 +50,7 @@ struct config_ {
String pwd;
wifi_mode_t mode;
bool dhcp;
String ip;
String subnet;
String gateway;
@ -138,6 +139,7 @@ bool loadConfig() {
config.mode = (wifi_mode_t)prefs.getChar("wifi_mode", WIFI_AP);
config.hostname = prefs.getString("hostname", "WiFlash");
config.dhcp = prefs.getBool("dhcp", true);
config.ip = prefs.getString("ip", "192.168.1.1");
config.subnet = prefs.getString("subnet", "255.255.255.0");
config.gateway = prefs.getString("gateway", "");
@ -215,14 +217,24 @@ void setup() {
//// start WiFi:
// set IPv4
Serial.println("Starting WiFi.");
WiFi.mode(WIFI_STA);
WiFi.setHostname(config.hostname.c_str());
WiFi.mode(config.mode);
if (!config.dhcp) {
IPAddress ip_, gateway_, subnet_;
ip_.fromString(config.ip);
gateway_.fromString(config.gateway);
subnet_.fromString(config.subnet);
WiFi.config(ip_, gateway_, subnet_);
}
switch (config.mode) {
case WIFI_AP:
WiFi.softAP(config.ssid.c_str(), config.pwd.c_str());
break;
case WIFI_STA:
WiFi.begin(config.ssid.c_str(), config.pwd.c_str());
break;
}
Serial.println("Disabling Bluetooth.");
btStop();
@ -233,7 +245,6 @@ void setup() {
Serial.println("Starting HTTP interface.");
startHTTPD();
//// start fixtures hardware:
// battery monitor
pinMode(battery_sense, INPUT);
@ -278,7 +289,8 @@ void setup() {
Arduino process loop
*/
void loop() {
if (WiFi.status() != WL_CONNECTED) {
if (config.mode == WIFI_STA &&
WiFi.status() != WL_CONNECTED) {
Serial.println("Waiting for WiFi...");
delay(1000);
return;