Clean ups, and more features

This commit is contained in:
2026-02-18 16:28:52 +01:00
parent 9e6cf2bd72
commit d1294914ce
22 changed files with 228 additions and 1138 deletions

View File

@@ -44,7 +44,7 @@ void TFT_eSPI::pushBlock(uint16_t color, uint32_t len) {
SPI_BUSY_CHECK;
uint32_t i = 0;
if (rem) { // len was not multiple of 32
if(rem) { // len was not multiple of 32
for (i = 0; i < rem; i += 2) *spi_w++ = color32;
*_spi_mosi_dlen = (rem << 4) - 1; // << 4 = * 16
*_spi_cmd = SPI_USR;
@@ -343,11 +343,11 @@ void TFT_eSPI::init() {
gpio_set_level((gpio_num_t)TFT_RST, 1);
delay(3);
gpio_set_level((gpio_num_t)TFT_RST, 0);
delay(12);
delay(10);
gpio_set_level((gpio_num_t)TFT_RST, 1);
}
delay(34); // Wait for reset to complete
delay(25); // Wait for reset to complete
begin_tft_write();

View File

@@ -1,16 +1,5 @@
/*!
* @file WC_AP_HTML.h
*
* HTML snippets to build the Access Point portal and the Parameters Portal.
*
* Written by Stuart Blair
*
* GNU General Public License v3.0 licence, all text here must be included in any redistribution and you should receive a copy of the license file.
*
*/
#pragma once
#ifndef WC_AP_HTML
#define WC_AP_HTML ///< Define to stop re-inclusion
/*! \def char AP_HTTP_HEAD[] PROGMEM
Start of HTML output
*/
@@ -72,6 +61,4 @@ const char AP_HTTP_END[] PROGMEM = "</div></body></html>";
/** HTML snippet for our custom parameters portal form */
const char AP_HTTP_PORTAL_PARAM_OPTIONS[] PROGMEM = "<form action=\"/params\" method=\"get\"><button>Configure Parameters</button></form><br/><form action=\"/i\" method=\"get\"><button>Info</button></form><br/>";
/** HTML snippet for our custom parameters save */
const char AP_HTTP_FORM_PARAM_START[] PROGMEM ="<form method=\"get\" action=\"wifisave\">";
#endif
const char AP_HTTP_FORM_PARAM_START[] PROGMEM ="<form method=\"get\" action=\"wifisave\">";

File diff suppressed because it is too large Load Diff

View File

@@ -1,85 +1,28 @@
/*!
@file WiFiConnect.h
This is the documentation for WiFiConnect for the Arduino platform.
It is a WiFi connection manager for use with the popular ESP8266 and ESP32 chips.
It contains a captive portal to allow easy connection and changing of WiFi netwoks
via a web based interface and allows for additional user parameters.
You can view the project at <a href="https://github.com/smurf0969/WiFiConnect">https://github.com/smurf0969/WiFiConnect</a>.
Further information is also available in the project <a href="https://github.com/smurf0969/WiFiConnect/wiki">Wiki</a>.
This is a heavily customised version from the origional <a href="https://github.com/tzapu/WiFiManager">WiFiManager</a>
developed by https://github.com/tzapu .
This library depends on <a href="https://github.com/esp8266/Arduino">
ESP8266 Arduino Core</a> and <a href="https://github.com/espressif/arduino-esp32">ESP32 Arduino Core</a> being present on your system.
Please make sure you have installed the latest version before using this library.
Written by Stuart Blair.
GNU General Public License v3.0 licence, all text here must be included in any redistribution and you should receive a copy of the license file.
*/
#ifndef WiFiConnect_h
#define WiFiConnect_h
#pragma once
#include <Arduino.h>
#if defined(ESP8266)
#include <ESP8266WiFi.h>
#include <ESP8266WebServer.h>
#else
#include <WiFi.h>
#include <FS.h>
using fs::FS;
#include <WebServer.h>
#endif
#include <DNSServer.h>
#include <memory>
#if defined(ESP8266)
extern "C" {
#include "user_interface.h"
}
#define ESP_getChipId() (ESP.getChipId()) ///< Gets an ID from the chip
#else
#include <esp_wifi.h>
#define ESP_getChipId() ((uint32_t)ESP.getEfuseMac())///< Gets an ID from the chip
#endif
#include "WC_AP_HTML.h"
#include "WiFiConnectParam.h"
/** Options for how a access point should continue if no WiFi connected */
enum AP_Continue {
AP_NONE, ///< No action, continues to run code
AP_LOOP, ///< Stalls execution with an infinate loop
AP_RESTART, ///< Restarts the chip, allowing it to try to setup again. Handy for sensors when wifi is lost.
AP_RESET, ///< Same as AP_RESTART
AP_WAIT // Keep the AP and webserver running, sit quietly and be patient.
};
/**************************************************************************/
/*!
@brief Class that helps to connect to WiFi networks, that also has
captive portal web interface for configuration.
This is the base class for WiFiConntectOLED which displays
information on a OLED display.
*/
/**************************************************************************/
class WiFiConnect {
public:
/// Create WiFiConnect class
WiFiConnect();
boolean startConfigurationPortal();
boolean startConfigurationPortal(AP_Continue apcontinue);
boolean startConfigurationPortal(AP_Continue apcontinue, const char* apName, const char* apPassword = NULL, bool paramsMode = false);
boolean startParamsPortal();
boolean startParamsPortal(AP_Continue apcontinue);
boolean startParamsPortal(AP_Continue apcontinue, const char* apName, const char* apPassword = NULL);
boolean startConfigurationPortal(const char* apName, const char* apPassword = NULL, bool paramsMode = false);
void addParameter(WiFiConnectParam *p);
void setAPName(const char* apName);
void setAPName(const char* apName);
const char* getAPName();
void resetSettings();
@@ -87,83 +30,46 @@ class WiFiConnect {
boolean autoConnect();
boolean autoConnect(const char* ssidName, const char* ssidPassword = NULL, WiFiMode_t acWiFiMode = WIFI_STA);
//sets a custom ip /gateway /subnet configuration
void setAPStaticIPConfig(IPAddress ip, IPAddress gw, IPAddress sn);
//sets config for a static IP
void setSTAStaticIPConfig(IPAddress ip, IPAddress gw, IPAddress sn);
//called when AP mode and config portal is started
void setAPCallback( void (*func)(WiFiConnect*) );
//called when settings have been changed and connection was successful
void setSaveConfigCallback( void (*func)() );
void setDebug(boolean isDebug);
void setAPStaticIPConfig(IPAddress ip, IPAddress gw, IPAddress sn);
void setSTAStaticIPConfig(IPAddress ip, IPAddress gw, IPAddress sn);
void setRetryAttempts(int attempts);
void setConnectionTimeoutSecs(int timeout);
void setAPModeTimeoutMins(int mins);
boolean captivePortal();
boolean captivePortal();
//helpers
const char* statusToString(int state);
int getRSSIasQuality(int RSSI);
boolean isIp(String str);
String toStringIp(IPAddress ip);
virtual void displayTurnOFF(int ms = 5000); ///< Virtual method overriden in WiFiConnectOLED
virtual void displayLoop(); ///< Virtual method overriden in WiFiConnectOLED
virtual void displayON(); ///< Virtual method overriden in WiFiConnectOLED
protected:
boolean _debug = false; ///< Flag to determine wheter to output mesages or not
template <typename Generic>
void DEBUG_WC(Generic text);
virtual void displayConnecting(int attempt, int totalAttempts); ///< Virtual method overriden in WiFiConnectOLED
virtual void displayConnected(); ///< Virtual method overriden in WiFiConnectOLED
virtual void displayAP(); ///< Virtual method overriden in WiFiConnectOLED
virtual void displayParams(); ///< Virtual method overriden in WiFiConnectOLED
virtual void displayManualReset(); ///< Virtual method overriden in WiFiConnectOLED
int getRSSIasQuality(int RSSI);
boolean isIp(String str);
String toStringIp(IPAddress ip);
private:
int _retryAttempts = 3; ///< Number of attempts when trying to connect to WiFi network
int _connectionTimeoutSecs = 10; ///< How log to wait for the connection to succeed or fail
int _apTimeoutMins = 3; ///< The amount of minutes of inactivity before the access point exits it routine
// DNS server
const byte DNS_PORT = 53; ///< Standard DNS Port number
long _lastAPPage = 0; ///< The last time a page was accessed in the portal. Used for the inactivity timeout.
boolean _removeDuplicateAPs = true; ///< Flag to remove duplicate networks from scan results.
int _minimumQuality = 8; ///< The minimum netqork quality to be included in scan results.
int _paramsCount = 0; ///< The amount of custom parameters added via addParameter
boolean _readyToConnect = false; ///< Flag used in access point to determine if it should try to connect to the network.
String _ssid = " "; ///< Tempory holder for the network ssid
String _password = " "; ///< Tempory holder for the network password
long _lastAPPage = 0;
int _minimumQuality = 8;
int _paramsCount = 0;
boolean _readyToConnect = false;
String _ssid = " ";
String _password = " ";
WiFiConnectParam* _params[WiFiConnect_MAX_PARAMS]; ///< Array to hold custom parameters
std::unique_ptr<DNSServer> dnsServer; ///< DNS Server for captive portal to redirect to Access Point
#ifdef ESP8266
std::unique_ptr<ESP8266WebServer> server; ///< Web server for serving access point pages
#else
std::unique_ptr<WebServer> server; ///< Web server for serving access point pages
#endif
std::unique_ptr<DNSServer> dnsServer;
std::unique_ptr<WebServer> server;
char _apName[33] ; ///< Holder for the access point name
char _apPassword[65] ; ///< Holder for the access point password
char _apName[33];
char _apPassword[65];
IPAddress _ap_static_ip; ///< Variable for holding Static IP Address for the access point
IPAddress _ap_static_gw; ///< Variable for holding Static Gateway IP Address for the access point
IPAddress _ap_static_sn; ///< Variable for holding Static Subnet Mask IP Address for the access point
IPAddress _sta_static_ip; ///< Variable for holding Static IP Address for the network connection
IPAddress _sta_static_gw; ///< Variable for holding Static Gateway IP Address for the network connection
IPAddress _sta_static_sn; ///< Variable for holding Static Subnet Mask IP Address for the network connection
void (*_apcallback)(WiFiConnect*) = NULL;
void (*_savecallback)() = NULL;
IPAddress _ap_static_ip; ///< Variable for holding Static IP Address for the access point
IPAddress _ap_static_gw; ///< Variable for holding Static Gateway IP Address for the access point
IPAddress _ap_static_sn; ///< Variable for holding Static Subnet Mask IP Address for the access point
IPAddress _sta_static_ip; ///< Variable for holding Static IP Address for the network connection
IPAddress _sta_static_gw; ///< Variable for holding Static Gateway IP Address for the network connection
IPAddress _sta_static_sn; ///< Variable for holding Static Subnet Mask IP Address for the network connection
void handleRoot();
void handleParamRoot();
@@ -176,14 +82,6 @@ class WiFiConnect {
void handleNotFound();
template <class T>
auto optionalIPFromString(T *obj, const char *s) -> decltype( obj->fromString(s) ) {
return obj->fromString(s);
}
auto optionalIPFromString(...) -> bool {
DEBUG_WC("NO fromString METHOD ON IPAddress, you need ESP8266 core 2.1.0 or newer for Custom IP configuration to work.");
return false;
}
auto optionalIPFromString(T *obj, const char *s) -> decltype(obj->fromString(s)) { return obj->fromString(s); }
bool optionalIPFromString(...) {return false;}
};
#endif

View File

@@ -1,41 +1,5 @@
/*!
@file WiFiConnectParam.cpp
WiFi Connection Manager with Captive Portal
Introduction
This is the documentation for WiFiConnect for the Arduino platform.
It is a WiFi connection manager for use with the popular ESP8266 and ESP32 chips.
It contains a captive portal to allow easy connection and changing of WiFi netwoks
via a web based interface and allows for additional user parameters.
It can also display messages via a OLED screen see WiFiConnectOLED class.
This is a heavily customised version from the original <a href="https://github.com/tzapu/WiFiManager">WiFiManager</a>
developed by https://github.com/tzapu .
Dependencies
This library depends on <a href="https://github.com/esp8266/Arduino">
ESP8266 Arduino Core</a> and <a href="https://github.com/espressif/arduino-esp32">ESP32 Arduino Core</a> being present on your system.
Please make sure you have installed the latest version before using this library.
Written by Stuart Blair.
License
GNU General Public License v3.0 licence, all text here must be included in any redistribution and you should receive a copy of the license file.
*/
#include "WiFiConnectParam.h"
/**************************************************************************/
/*!
@brief Class object initialiser
@param custom
Custom HTML to be displayed in the access point for this item.
*/
/**************************************************************************/
WiFiConnectParam::WiFiConnectParam(const char *custom) {
_id = NULL;
_placeholder = NULL;
@@ -44,55 +8,14 @@ WiFiConnectParam::WiFiConnectParam(const char *custom) {
_customHTML = custom;
}
/**************************************************************************/
/*!
@brief Class object initialiser
@param id
The unique ID for the html input box markup for this item
@param placeholder
Text to be displayed as the input box placeholder for this item
@param defaultValue
Default text to be displayed in the input box for this item
@param length
The maximum input text length for this item
*/
/**************************************************************************/
WiFiConnectParam::WiFiConnectParam(const char *id, const char *placeholder, const char *defaultValue, int length) {
init(id, placeholder, defaultValue, length, "");
}
/**************************************************************************/
/*!
@brief Class object initialiser
@param id
The unique ID for the html input box markup for this item
@param placeholder
Text to be displayed as the input box placeholder for this item
@param defaultValue
Default text to be displayed in the input box for this item
@param length
The maximum input text length for this item
@param custom
Custom HTML to be displayed in the access point for this item.
*/
/**************************************************************************/
WiFiConnectParam::WiFiConnectParam(const char *id, const char *placeholder, const char *defaultValue, int length, const char *custom) {
init(id, placeholder, defaultValue, length, custom);
}
/**************************************************************************/
/*!
@brief Initialiser method
@param id
The unique ID for the html input box markup for this item
@param placeholder
Text to be displayed as the input box placeholder for this item
@param defaultValue
Default text to be displayed in the input box for this item
@param length
The maximum input text length for this item
@param custom
Custom HTML to be displayed in the access point for this item.
*/
/**************************************************************************/
void WiFiConnectParam::init(const char *id, const char *placeholder, const char *defaultValue, int length, const char *custom) {
_id = id;
_placeholder = placeholder;
@@ -101,66 +24,32 @@ void WiFiConnectParam::init(const char *id, const char *placeholder, const char
_customHTML = custom;
}
/**************************************************************************/
/*!
@brief Method to change the current value of the item
@param newValue
The new string value for the item
*/
/**************************************************************************/
void WiFiConnectParam::setValue(const char *newValue){
if(_length>0){
_value = new char[_length + 1];
for (int i = 0; i < _length; i++) {
_value[i] = 0;
}
if (newValue != NULL) {
strncpy(_value, newValue, _length);
}
if(_length > 0) {
// you know what was here in upstream
_value = new char[_length + 1];
for (int i = 0; i < _length; i++) _value[i] = 0;
if (newValue != NULL) strncpy(_value, newValue, _length);
}
}
/**************************************************************************/
/*!
@brief Function to get the current value of the item
@return The current value
*/
/**************************************************************************/
const char* WiFiConnectParam::getValue() {
return _value;
}
/**************************************************************************/
/*!
@brief Function to get the current id of the item
@return The current id
*/
/**************************************************************************/
const char* WiFiConnectParam::getID() {
return _id;
}
/**************************************************************************/
/*!
@brief Function to get the current placeholder text of the item
@return The current placeholder text
*/
/**************************************************************************/
const char* WiFiConnectParam::getPlaceholder() {
return _placeholder;
}
/**************************************************************************/
/*!
@brief Function to get the maximum length allowed for the value of the item
@return The current maximum value length
*/
/**************************************************************************/
int WiFiConnectParam::getValueLength() {
return _length;
}
/**************************************************************************/
/*!
@brief Function to get the current custom html markup of the item
@return The current custom html markup
*/
/**************************************************************************/
const char* WiFiConnectParam::getCustomHTML() {
return _customHTML;
}

View File

@@ -1,46 +1,11 @@
/*!
@file WiFiConnectParam.h
WiFi Connection Manager with Captive Portal
Introduction
This is the documentation for WiFiConnect for the Arduino platform.
It is a WiFi connection manager for use with the popular ESP8266 and ESP32 chips.
It contains a captive portal to allow easy connection and changing of WiFi netwoks
via a web based interface and allows for additional user parameters.
It can also display messages via a OLED screen see WiFiConnectOLED class.
This is a heavily customised version from the original <a href="https://github.com/tzapu/WiFiManager">WiFiManager</a>
developed by https://github.com/tzapu .
Dependencies
This library depends on <a href="https://github.com/esp8266/Arduino">
ESP8266 Arduino Core</a> and <a href="https://github.com/espressif/arduino-esp32">ESP32 Arduino Core</a> being present on your system.
Please make sure you have installed the latest version before using this library.
Written by Stuart Blair.
License
GNU General Public License v3.0 licence, all text here must be included in any redistribution and you should receive a copy of the license file.
*/
#ifndef WIFI_CONNECT_PARAM
#define WIFI_CONNECT_PARAM
#pragma once
#ifndef WiFiConnect_MAX_PARAMS
#define WiFiConnect_MAX_PARAMS 10 ///< The maximum size of the param array and how many custom parameters we may have
#endif
#include <Arduino.h>
/**************************************************************************/
/*!
@brief Class that stores a custom parameter
*/
/**************************************************************************/
class WiFiConnectParam {
public:
WiFiConnectParam(const char *custom);
@@ -50,19 +15,17 @@ class WiFiConnectParam {
const char *getID();
const char *getValue();
const char *getPlaceholder();
int getValueLength();
int getValueLength();
const char *getCustomHTML();
void setValue(const char *newValue);
private:
const char *_id;
const char *_placeholder;
char *_value;
int _length;
char *_value;
int _length;
const char *_customHTML;
void init(const char *id, const char *placeholder, const char *defaultValue, int length, const char *custom);
friend class WiFiConnect; ///< Declarion for WiFiConnect class
};
#endif