Integrated changed for new wifimgr
This commit is contained in:
112
src/wifi.cpp
112
src/wifi.cpp
@ -21,73 +21,54 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
#include <wifi.hpp>
|
||||
#include <ArduinoJson.hpp>
|
||||
#include <ESP8266HTTPClient.h>
|
||||
#include <ESP8266httpUpdate.h>
|
||||
//#include <ESP8266mDNS.h>
|
||||
#include <LittleFS.h>
|
||||
#include <incbin.h>
|
||||
|
||||
#include <ArduinoJson.hpp>
|
||||
#include <calc.hpp>
|
||||
#include <config.hpp>
|
||||
#include <gyro.hpp>
|
||||
#include <helper.hpp>
|
||||
#include <tempsensor.hpp>
|
||||
|
||||
/*
|
||||
// Configuration settings for WifiManager_Lite
|
||||
#define ESP_WM_LITE_DEBUG_OUTPUT Serial
|
||||
#define _ESP_WM_LITE_LOGLEVEL_ 3
|
||||
#define MULTIRESETDETECTOR_DEBUG true
|
||||
#define USE_DYNAMIC_PARAMETERS false
|
||||
#define CONFIG_TIMEOUT 120*1000
|
||||
#define USING_MRD false // We use DRD instead
|
||||
#define REQUIRE_ONE_SET_SSID_PW true
|
||||
#include <ESP_WiFiManager_Lite.h>
|
||||
bool LOAD_DEFAULT_CONFIG_DATA = false;
|
||||
ESP_WiFiManager_Lite* wifiManager = 0;
|
||||
ESP_WM_LITE_Configuration defaultConfig;
|
||||
*/
|
||||
#include <wifi.hpp>
|
||||
|
||||
// Settings for DRD
|
||||
#define ESP_DRD_USE_LITTLEFS true
|
||||
#define ESP_DRD_USE_SPIFFS false
|
||||
#define ESP_DRD_USE_EEPROM false
|
||||
#define DOUBLERESETDETECTOR_DEBUG true
|
||||
#include <ESP_DoubleResetDetector.h>
|
||||
#define ESP_DRD_USE_LITTLEFS true
|
||||
#define ESP_DRD_USE_SPIFFS false
|
||||
#define ESP_DRD_USE_EEPROM false
|
||||
#include <ESP_DoubleResetDetector.h>
|
||||
#define DRD_TIMEOUT 3
|
||||
#define DRD_ADDRESS 0
|
||||
|
||||
// Settings for WIFI Manager
|
||||
/*#define USING_AFRICA false
|
||||
#define USING_AMERICA true
|
||||
#define USING_ANTARCTICA false
|
||||
#define USING_ASIA false
|
||||
#define USING_ATLANTIC false
|
||||
#define USING_AUSTRALIA false
|
||||
#define USING_EUROPE true
|
||||
#define USING_INDIAN false
|
||||
#define USING_PACIFIC false
|
||||
#define USING_ETC_GMT false
|
||||
#define USE_CLOUDFLARE_NTP false
|
||||
#define CONFIG_FILENAME F("/wifi_cred.dat")*/
|
||||
#define USE_ESP_WIFIMANAGER_NTP false
|
||||
#define USE_CLOUDFLARE_NTP false
|
||||
#define USING_CORS_FEATURE false
|
||||
#define NUM_WIFI_CREDENTIALS 1
|
||||
#define USE_CLOUDFLARE_NTP false
|
||||
#define USING_CORS_FEATURE false
|
||||
#define NUM_WIFI_CREDENTIALS 1
|
||||
#define USE_STATIC_IP_CONFIG_IN_CP false
|
||||
#include <ESP_WiFiManager.h>
|
||||
const char WM_HTTP_FORM_START[] PROGMEM = "<form method='get' action='wifisave'><fieldset><div><label>SSID</label><input id='s' name='s' length=32 placeholder='SSID'><div></div></div><div><label>Password</label><input id='p' name='p' length=64 placeholder='password'><div></div></div><div hidden><label>SSID1</label><input id='s1' name='s1' length=32 placeholder='SSID1'><div></div></div><div hidden><label>Password</label><input id='p1' name='p1' length=64 placeholder='password1'><div></div></div></fieldset>";
|
||||
// Override the look and feel of the standard ui (hide secondary forms)
|
||||
const char WM_HTTP_FORM_START[] PROGMEM =
|
||||
"<form method='get' "
|
||||
"action='wifisave'><fieldset><div><label>SSID</label><input id='s' "
|
||||
"name='s' length=32 "
|
||||
"placeholder='SSID'><div></div></div><div><label>Password</label><input "
|
||||
"id='p' name='p' length=64 placeholder='password'><div></div></div><div "
|
||||
"hidden><label>SSID1</label><input id='s1' name='s1' length=32 "
|
||||
"placeholder='SSID1'><div></div></div><div "
|
||||
"hidden><label>Password</label><input id='p1' name='p1' length=64 "
|
||||
"placeholder='password1'><div></div></div></fieldset>";
|
||||
#include <ESP_WiFiManager-Impl.h>
|
||||
ESP_WiFiManager* myWifiManager;
|
||||
DoubleResetDetector* myDRD;
|
||||
ESP_WiFiManager *myWifiManager;
|
||||
DoubleResetDetector *myDRD;
|
||||
|
||||
WifiConnection myWifi;
|
||||
const char *userSSID = USER_SSID;
|
||||
const char *userPWD = USER_SSID_PWD;
|
||||
const char *userPWD = USER_SSID_PWD;
|
||||
|
||||
const int PIN_LED = 2;
|
||||
const int PIN_LED = 2;
|
||||
|
||||
//
|
||||
// Constructor
|
||||
@ -100,42 +81,30 @@ WifiConnection::WifiConnection() {
|
||||
// Check if we have a valid wifi configuration
|
||||
//
|
||||
bool WifiConnection::hasConfig() {
|
||||
if (strlen(myConfig.getWifiSSID()) ) return true;
|
||||
if (strlen(userSSID) ) return true;
|
||||
if (strlen(myConfig.getWifiSSID())) return true;
|
||||
if (strlen(userSSID)) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
//
|
||||
// Check if the wifi is connected
|
||||
//
|
||||
bool WifiConnection::isConnected() {
|
||||
return WiFi.status() == WL_CONNECTED;
|
||||
}
|
||||
bool WifiConnection::isConnected() { return WiFi.status() == WL_CONNECTED; }
|
||||
|
||||
//
|
||||
// Get the IP adress
|
||||
//
|
||||
String WifiConnection::getIPAddress() {
|
||||
return WiFi.localIP().toString();
|
||||
}
|
||||
String WifiConnection::getIPAddress() { return WiFi.localIP().toString(); }
|
||||
|
||||
//
|
||||
// Additional method to detect double reset.
|
||||
// Additional method to detect double reset.
|
||||
//
|
||||
bool WifiConnection::isDoubleResetDetected() {
|
||||
if (myDRD->detectDoubleReset()) {
|
||||
Log.notice(F("WIFI: Double reset has been detected." CR));
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
bool WifiConnection::isDoubleResetDetected() { return myDRD->detectDoubleReset(); }
|
||||
|
||||
//
|
||||
// Stop double reset detection
|
||||
//
|
||||
void WifiConnection::stopDoubleReset() {
|
||||
myDRD->stop();
|
||||
}
|
||||
void WifiConnection::stopDoubleReset() { myDRD->stop(); }
|
||||
|
||||
//
|
||||
// Start the wifi manager
|
||||
@ -144,21 +113,21 @@ void WifiConnection::startPortal() {
|
||||
Log.notice(F("WIFI: Starting Wifi config portal." CR));
|
||||
|
||||
pinMode(PIN_LED, OUTPUT);
|
||||
digitalWrite(PIN_LED, LOW);
|
||||
digitalWrite(PIN_LED, LOW);
|
||||
|
||||
myWifiManager = new ESP_WiFiManager(WIFI_MDNS);
|
||||
myWifiManager->setMinimumSignalQuality(-1);
|
||||
myWifiManager->setConfigPortalChannel(0);
|
||||
myWifiManager->setConfigPortalTimeout(120);
|
||||
|
||||
if (myWifiManager->startConfigPortal(WIFI_DEFAULT_SSID, WIFI_DEFAULT_PWD)) {
|
||||
Log.notice(F("WIFI: Exited portal, connected to wifi." CR));
|
||||
if (myWifiManager->startConfigPortal(WIFI_DEFAULT_SSID, WIFI_DEFAULT_PWD)) {
|
||||
Log.notice(F("WIFI: Exited portal, connected to wifi. Rebooting..." CR));
|
||||
myConfig.setWifiSSID(myWifiManager->getSSID());
|
||||
myConfig.setWifiPass(myWifiManager->getPW());
|
||||
myConfig.saveFile();
|
||||
}
|
||||
else {
|
||||
Log.notice(F("WIFI: Exited portal, no connection to wifi." CR)); Serial.println(F("Not connected to WiFi"));
|
||||
} else {
|
||||
Log.notice(
|
||||
F("WIFI: Exited portal, no connection to wifi. Rebooting..." CR));
|
||||
}
|
||||
|
||||
stopDoubleReset();
|
||||
@ -169,9 +138,7 @@ void WifiConnection::startPortal() {
|
||||
//
|
||||
// Call the wifi manager in loop
|
||||
//
|
||||
void WifiConnection::loop() {
|
||||
myDRD->loop();
|
||||
}
|
||||
void WifiConnection::loop() { myDRD->loop(); }
|
||||
|
||||
//
|
||||
// Connect to last known access point or create one if connection is not
|
||||
@ -372,7 +339,8 @@ bool WifiConnection::checkFirmwareVersion() {
|
||||
//
|
||||
// Parse a version string in the format M.m.p (eg. 1.2.10)
|
||||
//
|
||||
bool WifiConnection::parseFirmwareVersionString(int (&num)[3], const char *version) {
|
||||
bool WifiConnection::parseFirmwareVersionString(int (&num)[3],
|
||||
const char *version) {
|
||||
#if LOG_LEVEL == 6
|
||||
Log.verbose(F("WIFI: Parsing version number string %s." CR), version);
|
||||
#endif
|
||||
|
Reference in New Issue
Block a user