1
0
mirror of https://github.com/s00500/ESPUI.git synced 2024-11-22 04:00:55 +00:00

Add Port Option

Signed-off-by: Lukas Bachschwell <lukas@lbsfilm.at>
This commit is contained in:
Lukas Bachschwell 2021-10-29 19:20:20 +02:00
parent 6b3056ab31
commit aa03c1683d
Signed by: lbsadmin
GPG Key ID: CCC6AA87CC8DF425
2 changed files with 58 additions and 64 deletions

View File

@ -32,7 +32,6 @@ void listDir(const char* dirname, uint8_t levels)
File root = LittleFS.open(dirname); File root = LittleFS.open(dirname);
#endif #endif
if (!root) if (!root)
{ {
#if defined(DEBUG_ESPUI) #if defined(DEBUG_ESPUI)
@ -122,7 +121,7 @@ void ESPUIClass::list()
return; return;
} }
#else #else
if (!LittleFS.begin()) if (!LittleFS.begin())
{ {
Serial.println(F("LittleFS Mount Failed")); Serial.println(F("LittleFS Mount Failed"));
return; return;
@ -147,7 +146,7 @@ if (!LittleFS.begin())
void deleteFile(const char* path) void deleteFile(const char* path)
{ {
#if defined(ESP32) #if defined(ESP32)
bool exists = SPIFFS.exists(path); bool exists = SPIFFS.exists(path);
#else #else
bool exists = LittleFS.exists(path); bool exists = LittleFS.exists(path);
@ -381,8 +380,7 @@ void onWsEvent(
{ {
switch (type) switch (type)
{ {
case WS_EVT_DISCONNECT: case WS_EVT_DISCONNECT: {
{
#if defined(DEBUG_ESPUI) #if defined(DEBUG_ESPUI)
if (ESPUI.verbosity) if (ESPUI.verbosity)
{ {
@ -393,8 +391,7 @@ void onWsEvent(
break; break;
} }
case WS_EVT_PONG: case WS_EVT_PONG: {
{
#if defined(DEBUG_ESPUI) #if defined(DEBUG_ESPUI)
if (ESPUI.verbosity) if (ESPUI.verbosity)
{ {
@ -405,8 +402,7 @@ void onWsEvent(
break; break;
} }
case WS_EVT_ERROR: case WS_EVT_ERROR: {
{
#if defined(DEBUG_ESPUI) #if defined(DEBUG_ESPUI)
if (ESPUI.verbosity) if (ESPUI.verbosity)
{ {
@ -417,8 +413,7 @@ void onWsEvent(
break; break;
} }
case WS_EVT_CONNECT: case WS_EVT_CONNECT: {
{
#if defined(DEBUG_ESPUI) #if defined(DEBUG_ESPUI)
if (ESPUI.verbosity) if (ESPUI.verbosity)
{ {
@ -438,8 +433,7 @@ void onWsEvent(
} }
break; break;
case WS_EVT_DATA: case WS_EVT_DATA: {
{
String msg = ""; String msg = "";
msg.reserve(len + 1); msg.reserve(len + 1);
@ -889,7 +883,7 @@ void ESPUIClass::updateGauge(uint16_t id, int number, int clientId)
updateControlValue(id, String(number), clientId); updateControlValue(id, String(number), clientId);
} }
void ESPUIClass::clearGraph(uint16_t id, int clientId) {} void ESPUIClass::clearGraph(uint16_t id, int clientId) { }
void ESPUIClass::addGraphPoint(uint16_t id, int nValue, int clientId) void ESPUIClass::addGraphPoint(uint16_t id, int nValue, int clientId)
{ {
@ -1037,7 +1031,7 @@ void ESPUIClass::jsonReload()
this->ws->textAll(json); this->ws->textAll(json);
} }
void ESPUIClass::beginSPIFFS(const char* _title, const char* username, const char* password) void ESPUIClass::beginSPIFFS(const char* _title, const char* username, const char* password, uint16_t port)
{ {
ui_title = _title; ui_title = _title;
this->basicAuthUsername = username; this->basicAuthUsername = username;
@ -1052,7 +1046,7 @@ void ESPUIClass::beginSPIFFS(const char* _title, const char* username, const cha
basicAuth = true; basicAuth = true;
} }
server = new AsyncWebServer(80); server = new AsyncWebServer(port);
ws = new AsyncWebSocket("/ws"); ws = new AsyncWebSocket("/ws");
#if defined(ESP32) #if defined(ESP32)
@ -1144,7 +1138,7 @@ void ESPUIClass::beginSPIFFS(const char* _title, const char* username, const cha
#endif #endif
} }
void ESPUIClass::begin(const char* _title, const char* username, const char* password) void ESPUIClass::begin(const char* _title, const char* username, const char* password, uint16_t port)
{ {
basicAuthUsername = username; basicAuthUsername = username;
basicAuthPassword = password; basicAuthPassword = password;
@ -1160,7 +1154,7 @@ void ESPUIClass::begin(const char* _title, const char* username, const char* pas
ui_title = _title; ui_title = _title;
server = new AsyncWebServer(80); server = new AsyncWebServer(port);
ws = new AsyncWebSocket("/ws"); ws = new AsyncWebSocket("/ws");
ws->onEvent(onWsEvent); ws->onEvent(onWsEvent);

View File

@ -215,10 +215,10 @@ public:
bool sliderContinuous; bool sliderContinuous;
void setVerbosity(Verbosity verbosity); void setVerbosity(Verbosity verbosity);
void begin(const char* _title, const char* username = nullptr, void begin(const char* _title, const char* username = nullptr, const char* password = nullptr,
const char* password = nullptr); // Setup server and page in Memorymode uint16_t port = 80); // Setup server and page in Memorymode
void beginSPIFFS(const char* _title, const char* username = nullptr, void beginSPIFFS(const char* _title, const char* username = nullptr, const char* password = nullptr,
const char* password = nullptr); // Setup server and page in SPIFFSmode uint16_t port = 80); // Setup server and page in SPIFFSmode
void prepareFileSystem(); // Initially preps the filesystem and loads a lot of void prepareFileSystem(); // Initially preps the filesystem and loads a lot of
// stuff into SPIFFS // stuff into SPIFFS