Added user config flag to set wifi settings to static value. The flag disables the WiFiManager.
This commit is contained in:
parent
3cea359c49
commit
b2c69868f0
3 changed files with 48 additions and 5 deletions
|
@ -10,7 +10,7 @@
|
||||||
#define DELAY_LOOP_MS 50
|
#define DELAY_LOOP_MS 50
|
||||||
#define POWERSAVING_SLEEP_S 600
|
#define POWERSAVING_SLEEP_S 600
|
||||||
#define EMERGENCY_SLEEP_S 172800 // Sleep for 2 days to recover
|
#define EMERGENCY_SLEEP_S 172800 // Sleep for 2 days to recover
|
||||||
#define RESET_ESP_TIME_INTERVAL_MS (60*60*3*1000) // (60*60*6*1000) // reset every 3 hours
|
#define RESET_ESP_TIME_INTERVAL_MS (60*60*12*1000) // reset every 12 hours
|
||||||
#define WIND_SENSOR_MEAS_TIME_S 15
|
#define WIND_SENSOR_MEAS_TIME_S 15
|
||||||
#define INITIAL_WEBSERVER_TIME 20
|
#define INITIAL_WEBSERVER_TIME 20
|
||||||
|
|
||||||
|
|
|
@ -7,13 +7,16 @@
|
||||||
#include <ESP8266HTTPClient.h>
|
#include <ESP8266HTTPClient.h>
|
||||||
|
|
||||||
#include <WiFiClient.h> // WiFiClient
|
#include <WiFiClient.h> // WiFiClient
|
||||||
#include <WiFiManager.h> // WiFiManager from bib manager
|
|
||||||
|
|
||||||
// Project includes
|
// Project includes
|
||||||
#include "constants.h"
|
#include "constants.h"
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include "config_user.h"
|
#include "config_user.h"
|
||||||
|
|
||||||
|
#ifdef USE_WIFIMANAGER
|
||||||
|
#include <WiFiManager.h> // WiFiManager from bib manager
|
||||||
|
#endif
|
||||||
|
|
||||||
//*************************************************************************//
|
//*************************************************************************//
|
||||||
// check if some settings are correct
|
// check if some settings are correct
|
||||||
|
|
||||||
|
@ -36,7 +39,9 @@ uint16_t update_windspeed_exceed_cnt = 0;
|
||||||
|
|
||||||
boolean validData = false;
|
boolean validData = false;
|
||||||
|
|
||||||
|
#ifdef USE_WIFIMANAGER
|
||||||
WiFiManager wifiManager;
|
WiFiManager wifiManager;
|
||||||
|
#endif
|
||||||
|
|
||||||
//*************************************************************************//
|
//*************************************************************************//
|
||||||
|
|
||||||
|
@ -141,7 +146,7 @@ void setup()
|
||||||
|
|
||||||
#ifdef ENABLE_WATCHDOG
|
#ifdef ENABLE_WATCHDOG
|
||||||
// Enable the internal watchdog
|
// Enable the internal watchdog
|
||||||
ESP.wdtEnable(WATCHDOG_TIMEOUT_MS);
|
ESP.wdtEnable(WDTO_4S);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -150,6 +155,9 @@ void setup()
|
||||||
|
|
||||||
void wifiConnectionCheck()
|
void wifiConnectionCheck()
|
||||||
{
|
{
|
||||||
|
|
||||||
|
#ifdef USE_WIFIMANAGER
|
||||||
|
|
||||||
// Establish WiFi connection
|
// Establish WiFi connection
|
||||||
String wifiName = "oko-weather-" + DEVICE_NAME;
|
String wifiName = "oko-weather-" + DEVICE_NAME;
|
||||||
|
|
||||||
|
@ -161,6 +169,7 @@ void wifiConnectionCheck()
|
||||||
|
|
||||||
while (!wifiManager.autoConnect(wifiName.c_str(), "DEADBEEF"))
|
while (!wifiManager.autoConnect(wifiName.c_str(), "DEADBEEF"))
|
||||||
{
|
{
|
||||||
|
|
||||||
debug("WiFi connection failed, try again in 5 seconds...");
|
debug("WiFi connection failed, try again in 5 seconds...");
|
||||||
// If autoconnect to WLAN failed and no client connected, go to deep sleep
|
// If autoconnect to WLAN failed and no client connected, go to deep sleep
|
||||||
#ifdef SLEEP_IF_NO_WLAN_CONNECTION
|
#ifdef SLEEP_IF_NO_WLAN_CONNECTION
|
||||||
|
@ -173,6 +182,33 @@ void wifiConnectionCheck()
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#else // else of USE_WIFIMANAGER
|
||||||
|
|
||||||
|
if (WiFi.status() == WL_CONNECTED)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!WiFi.config(local_IP, gateway, subnet))
|
||||||
|
{
|
||||||
|
Serial.println("Failed to set IP configuration");
|
||||||
|
} else {
|
||||||
|
Serial.println("Successful set IP configuration");
|
||||||
|
}
|
||||||
|
|
||||||
|
WiFi.begin(ssid, password);
|
||||||
|
|
||||||
|
Serial.println("Connecting to WLAN");
|
||||||
|
|
||||||
|
while (WiFi.status() != WL_CONNECTED)
|
||||||
|
{
|
||||||
|
delay(100);
|
||||||
|
}
|
||||||
|
|
||||||
|
Serial.println("WLAN connection OK");
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//*************************************************************************//
|
//*************************************************************************//
|
||||||
|
|
|
@ -11,11 +11,14 @@
|
||||||
#include <ESP8266HTTPUpdateServer.h>
|
#include <ESP8266HTTPUpdateServer.h>
|
||||||
|
|
||||||
#include <WiFiClient.h>
|
#include <WiFiClient.h>
|
||||||
#include <WiFiManager.h> // WiFiManager from bib manager
|
|
||||||
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include "config_user.h"
|
#include "config_user.h"
|
||||||
|
|
||||||
|
#ifdef USE_WIFIMANAGER
|
||||||
|
#include <WiFiManager.h> // WiFiManager from bib manager
|
||||||
|
#endif
|
||||||
|
|
||||||
ESP8266WebServer httpServer(WEB_UPDATER_HTTP_PORT);
|
ESP8266WebServer httpServer(WEB_UPDATER_HTTP_PORT);
|
||||||
ESP8266HTTPUpdateServer httpUpdater;
|
ESP8266HTTPUpdateServer httpUpdater;
|
||||||
|
|
||||||
|
@ -44,7 +47,9 @@ void setupWebUpdater(String device, String ip)
|
||||||
httpUpdater.setup(&httpServer);
|
httpUpdater.setup(&httpServer);
|
||||||
|
|
||||||
httpServer.on("/", showHTMLMain);
|
httpServer.on("/", showHTMLMain);
|
||||||
|
#ifdef USE_WIFIMANAGER
|
||||||
httpServer.on("/resetWifiManager", resetWifiManager);
|
httpServer.on("/resetWifiManager", resetWifiManager);
|
||||||
|
#endif
|
||||||
#ifdef HOMEBRIDGE_WEBSTAT
|
#ifdef HOMEBRIDGE_WEBSTAT
|
||||||
httpServer.on("/hbWebstat", hb_webstat_send);
|
httpServer.on("/hbWebstat", hb_webstat_send);
|
||||||
#endif
|
#endif
|
||||||
|
@ -70,7 +75,7 @@ void setSensorData(float sensorValues[])
|
||||||
{
|
{
|
||||||
if (sensorValues[i] != 0)
|
if (sensorValues[i] != 0)
|
||||||
{
|
{
|
||||||
wuValidData = true; // at least one value is not zero, the data
|
wuValidData = true; // at least one value is not zero, the data is valid
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -129,6 +134,7 @@ void hb_webstat_send(void)
|
||||||
httpServer.send(200, "text/html", msg);
|
httpServer.send(200, "text/html", msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef USE_WIFIMANAGER
|
||||||
void resetWifiManager()
|
void resetWifiManager()
|
||||||
{
|
{
|
||||||
|
|
||||||
|
@ -150,6 +156,7 @@ void resetWifiManager()
|
||||||
// manual reset after restart is required
|
// manual reset after restart is required
|
||||||
ESP.restart();
|
ESP.restart();
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
void measureWindspeed()
|
void measureWindspeed()
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue