From c806e32ce916779c2b600455a32f3dcc94df462b Mon Sep 17 00:00:00 2001
From: Luc <8822552+luc-github@users.noreply.github.com>
Date: Tue, 7 Jan 2020 16:52:20 +0100
Subject: [PATCH] rearrange code
use generic ESP3D define instead of Marlin ones
move configuration define in esp3dconfiglib
move output to espcom
remove ARDUINO_ARCH_ESP32 as not necessary
make constistent initialization messages
---
src/esp3dlib.cpp | 8 +-
src/esp3dlibconfig.cpp | 24 ++++
src/esp3dlibconfig.h | 84 ++++++++++++
src/{esplibconfig.h => espcom.cpp} | 26 ++--
src/espcom.h | 29 ++++
src/sd_ESP32.cpp | 9 +-
src/serial2socket.cpp | 10 +-
src/web_server.cpp | 210 ++++++++++-------------------
src/web_server.h | 10 +-
src/wificonfig.cpp | 34 +++--
src/wificonfig.h | 36 +----
src/wifiservices.cpp | 86 ++++++------
12 files changed, 301 insertions(+), 265 deletions(-)
create mode 100644 src/esp3dlibconfig.cpp
create mode 100644 src/esp3dlibconfig.h
rename src/{esplibconfig.h => espcom.cpp} (73%)
create mode 100644 src/espcom.h
diff --git a/src/esp3dlib.cpp b/src/esp3dlib.cpp
index ca1c3cb..6b3450a 100644
--- a/src/esp3dlib.cpp
+++ b/src/esp3dlib.cpp
@@ -24,11 +24,12 @@
Main author: luc lebosse
*/
-#include "esplibconfig.h"
+#include "esp3dlibconfig.h"
-#if ENABLED(ESP3D_WIFISUPPORT)
+#if defined(ESP3D_WIFISUPPORT)
#include "esp3dlib.h"
#include "wificonfig.h"
+
#include MARLIN_PATH(core/serial.h)
Esp3DLib esp3dlib;
@@ -69,8 +70,7 @@ bool Esp3DLib::parse(char * cmd)
{
String scmd = cmd;
if (scmd.startsWith("[ESP")) {
- SERIAL_ECHO_START();
- SERIAL_ECHOLNPAIR("it is ESP command:", cmd);
+
return true;
} else {
return false;
diff --git a/src/esp3dlibconfig.cpp b/src/esp3dlibconfig.cpp
new file mode 100644
index 0000000..bf27505
--- /dev/null
+++ b/src/esp3dlibconfig.cpp
@@ -0,0 +1,24 @@
+/*
+ esp3dconfig.cpp - wifi functions class
+
+ Copyright (c) 2014 Luc Lebosse. All rights reserved.
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with this library; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+*/
+
+#include "esp3dlibconfig.h"
+#if defined(ESP3D_WIFISUPPORT)
+
+#endif // ESP3D_WIFISUPPORT
diff --git a/src/esp3dlibconfig.h b/src/esp3dlibconfig.h
new file mode 100644
index 0000000..005a6eb
--- /dev/null
+++ b/src/esp3dlibconfig.h
@@ -0,0 +1,84 @@
+/*
+ esp3dlibconfig.h - esp3dlib functions class
+
+ Copyright (c) 2014 Luc Lebosse. All rights reserved.
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with this library; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+*/
+//config reference, do not touxh
+#define XSTR_(M) #M
+#define XSTR(M) XSTR_(M)
+#define MARLIN_PATH(PATH) XSTR(../../../../../Marlin/src/PATH)
+#include MARLIN_PATH(inc/MarlinConfigPre.h)
+#undef DISABLED
+#undef _BV
+//version
+#define LIB_VERSION "1.0.0"
+
+//Editable configuration part
+
+//AUTHENTICATION_FEATURE: protect pages by login password
+//#define AUTHENTICATION_FEATURE
+
+//HTTP_FEATURE: enable Web Server
+//Rely on Configuration_adv.h
+#ifdef WEBSUPPORT
+#define HTTP_FEATURE
+#endif //WEBSUPPORT
+
+//OTA_FEATURE: this feature is arduino update over the air
+//Rely on Configuration_adv.h
+#ifdef OTASUPPORT
+#define OTA_FEATURE
+#endif //OTASUPPORT
+
+//MDNS_FEATURE: this feature allow type the name defined
+//in web browser by default: http:\\marlinesp.local and connect
+#define MDNS_FEATURE
+
+//SSDD_FEATURE: this feature is a discovery protocol, supported on Windows out of the box
+#define SSDP_FEATURE
+
+//CAPTIVE_PORTAL_FEATURE: In SoftAP redirect all unknow call to main page
+#define CAPTIVE_PORTAL_FEATURE
+
+//for Debug this can be disabled
+#define ENABLE_SERIAL2SOCKET_OUT
+#define ENABLE_SERIAL2SOCKET_IN
+
+//Preferences entries
+#define NAMESPACE "MARLIN"
+#define HOSTNAME_ENTRY "ESP_HOSTNAME"
+#define STA_SSID_ENTRY "STA_SSID"
+#define STA_PWD_ENTRY "STA_PWD"
+#define STA_IP_ENTRY "STA_IP"
+#define STA_GW_ENTRY "STA_GW"
+#define STA_MK_ENTRY "STA_MK"
+#define ESP_WIFI_MODE "WIFI_MODE"
+#define AP_SSID_ENTRY "AP_SSID"
+#define AP_PWD_ENTRY "AP_PWD"
+#define AP_IP_ENTRY "AP_IP"
+#define AP_CHANNEL_ENTRY "AP_CHANNEL"
+#define HTTP_ENABLE_ENTRY "HTTP_ON"
+#define HTTP_PORT_ENTRY "HTTP_PORT"
+#define TELNET_ENABLE_ENTRY "TELNET_ON"
+#define TELNET_PORT_ENTRY "TELNET_PORT"
+#define STA_IP_MODE_ENTRY "STA_IP_MODE"
+
+//Switch
+#define ESP_SAVE_ONLY 0
+#define ESP_APPLY_NOW 1
+
+
diff --git a/src/esplibconfig.h b/src/espcom.cpp
similarity index 73%
rename from src/esplibconfig.h
rename to src/espcom.cpp
index 45a4538..b772c05 100644
--- a/src/esplibconfig.h
+++ b/src/espcom.cpp
@@ -1,5 +1,5 @@
/*
- esp3dlibconfig.h - esp3dlib functions class
+ espcom.cpp - esp3d communication serial/tcp/etc.. class
Copyright (c) 2014 Luc Lebosse. All rights reserved.
@@ -18,13 +18,19 @@
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
-//config reference
-#define XSTR_(M) #M
-#define XSTR(M) XSTR_(M)
-#define MARLIN_PATH(PATH) XSTR(../../../../../Marlin/src/PATH)
-#include MARLIN_PATH(inc/MarlinConfigPre.h)
-#undef DISABLED
-#undef _BV
-#include MARLIN_PATH(HAL/HAL_ESP32/FlushableHardwareSerial.h)
-#define MYSERIAL0 flushableSerial
+#include "esp3dlibconfig.h"
+#if defined(ESP3D_WIFISUPPORT)
+
+#include MARLIN_PATH(HAL/HAL_ESP32/FlushableHardwareSerial.h)
+#include MARLIN_PATH(HAL/HAL_ESP32/HAL.h)
+#include "espcom.h"
+
+void Esp3DCom::echo(const char * data)
+{
+ SERIAL_ECHO_START();
+ SERIAL_ECHOLNPAIR("", data);
+}
+
+
+#endif //ESP3D_WIFISUPPORT
diff --git a/src/espcom.h b/src/espcom.h
new file mode 100644
index 0000000..aa00922
--- /dev/null
+++ b/src/espcom.h
@@ -0,0 +1,29 @@
+/*
+ espcom.h - esp3d communication serial/tcp/etc... class
+
+ Copyright (c) 2014 Luc Lebosse. All rights reserved.
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with this library; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+*/
+
+#ifndef ESPCOM_H
+#define ESPCOM_H
+
+class Esp3DCom
+{
+public:
+ static void echo(const char * data);
+};
+#endif //ESPCOM_H
diff --git a/src/sd_ESP32.cpp b/src/sd_ESP32.cpp
index 8b14cbc..f0c2792 100644
--- a/src/sd_ESP32.cpp
+++ b/src/sd_ESP32.cpp
@@ -19,10 +19,8 @@
* along with this program. If not, see .
*
*/
-
-#ifdef ARDUINO_ARCH_ESP32
-#include "esplibconfig.h"
-#if ENABLED(SDSUPPORT) && ENABLED(ESP3D_WIFISUPPORT)
+#include "esp3dlibconfig.h"
+#if defined(SDSUPPORT) && defined(ESP3D_WIFISUPPORT)
#include MARLIN_PATH(sd/cardreader.h)
#include MARLIN_PATH(sd/SdVolume.h)
#include MARLIN_PATH(sd/SdFatStructs.h)
@@ -295,6 +293,5 @@ bool SD_file_timestamp(const char * path, uint8_t flag, uint16_t year, uint8_t m
uint8_t hour, uint8_t minute, uint8_t second){
}**/
-#endif
+#endif// SDSUPPORT && ESP3D_WIFISUPPORT
-#endif
diff --git a/src/serial2socket.cpp b/src/serial2socket.cpp
index fe9ea02..9ca683a 100644
--- a/src/serial2socket.cpp
+++ b/src/serial2socket.cpp
@@ -19,11 +19,9 @@
*/
-#ifdef ARDUINO_ARCH_ESP32
+#include "esp3dlibconfig.h"
-#include "esplibconfig.h"
-
-#if ENABLED(ESP3D_WIFISUPPORT)
+#if defined(ESP3D_WIFISUPPORT)
#include "serial2socket.h"
#include "wificonfig.h"
#include
@@ -165,6 +163,4 @@ void Serial_2_Socket::flush(void){
}
}
-#endif // ENABLE_WIFI
-
-#endif // ARDUINO_ARCH_ESP32
+#endif // ESP3D_WIFISUPPORT
diff --git a/src/web_server.cpp b/src/web_server.cpp
index 614c863..e66ae65 100644
--- a/src/web_server.cpp
+++ b/src/web_server.cpp
@@ -18,16 +18,10 @@
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
-#ifdef ARDUINO_ARCH_ESP32
-
-#include "esplibconfig.h"
-
-
-#if ENABLED(ESP3D_WIFISUPPORT)
-
+#include "esp3dlibconfig.h"
+#if defined(ESP3D_WIFISUPPORT) && defined(HTTP_FEATURE)
+#include "espcom.h"
#include "wificonfig.h"
-
-#if defined (ENABLE_HTTP)
#include MARLIN_PATH(gcode/queue.h)
#include MARLIN_PATH(inc/Version.h)
#undef DISABLED
@@ -39,7 +33,7 @@
#include
#include
#include
-#if ENABLED(SDSUPPORT)
+#if defined(SDSUPPORT)
#include "sd_ESP32.h"
#endif
#include
@@ -49,17 +43,17 @@
#include
#include
#include
-#ifdef ENABLE_MDNS
+#ifdef MDNS_FEATURE
#include
-#endif
-#ifdef ENABLE_SSDP
+#endif //MDNS_FEATURE
+#ifdef SSDP_FEATURE
#include
-#endif
-#ifdef ENABLE_CAPTIVE_PORTAL
+#endif //SSDP_FEATURE
+#ifdef CAPTIVE_PORTAL_FEATURE
#include
const byte DNS_PORT = 53;
DNSServer dnsServer;
-#endif
+#endif //CAPTIVE_PORTAL_FEATURE
//embedded response file if no files on SPIFFS
#include "nofile.h"
@@ -73,7 +67,7 @@ typedef enum {
UPLOAD_STATUS_ONGOING = 4
} upload_status_type;
-#ifdef ENABLE_AUTHENTICATION
+#ifdef AUTHENTICATION_FEATURE
#define DEFAULT_ADMIN_PWD "admin"
#define DEFAULT_USER_PWD "user";
#define DEFAULT_ADMIN_LOGIN "admin"
@@ -99,7 +93,7 @@ long Web_Server::_id_connection = 0;
uint8_t Web_Server::_upload_status = UPLOAD_STATUS_NONE;
WebServer * Web_Server::_webserver = NULL;
WebSocketsServer * Web_Server::_socket_server = NULL;
-#ifdef ENABLE_AUTHENTICATION
+#ifdef AUTHENTICATION_FEATURE
auth_ip * Web_Server::_head = NULL;
uint8_t Web_Server::_nb_ip = 0;
#define MAX_AUTH_IP 10
@@ -131,7 +125,7 @@ bool Web_Server::begin(){
if (penabled == 0) return false;
//create instance
_webserver= new WebServer(_port);
-#ifdef ENABLE_AUTHENTICATION
+#ifdef AUTHENTICATION_FEATURE
//here the list of headers to be recorded
const char * headerkeys[] = {"Cookie"} ;
size_t headerkeyssize = sizeof (headerkeys) / sizeof (char*);
@@ -166,12 +160,12 @@ bool Web_Server::begin(){
//web update
_webserver->on ("/updatefw", HTTP_ANY, handleUpdate, WebUpdateUpload);
-#if ENABLED(SDSUPPORT)
+#if defined(SDSUPPORT)
//Direct SD management
_webserver->on("/upload", HTTP_ANY, handle_direct_SDFileList,SDFile_direct_upload);
#endif
-#ifdef ENABLE_CAPTIVE_PORTAL
+#ifdef CAPTIVE_PORTAL_FEATURE
if(WiFi.getMode() == WIFI_AP){
// if DNSServer is started with "*" for domain name, it will reply with
// provided IP to all DNS request
@@ -181,9 +175,9 @@ bool Web_Server::begin(){
//do not forget the / at the end
_webserver->on ("/fwlink/", HTTP_ANY, handle_root);
}
-#endif
+#endif //CAPTIVE_PORTAL_FEATURE
-#ifdef ENABLE_SSDP
+#ifdef SSDP_FEATURE
//SSDP service presentation
if(WiFi.getMode() == WIFI_STA){
_webserver->on ("/description.xml", HTTP_GET, handle_SSDP);
@@ -202,32 +196,32 @@ bool Web_Server::begin(){
*/
//Start SSDP
- MYSERIAL0.println("SSDP Started");
+ Esp3DCom::echo("SSDP service started");
SSDP.begin();
}
-#endif
- MYSERIAL0.println("HTTP Started");
+#endif //SSDP_FEATURE
+ Esp3DCom::echo("HTTP server started");
//start webserver
_webserver->begin();
-#ifdef ENABLE_MDNS
+#ifdef MDNS_FEATURE
//add mDNS
if(WiFi.getMode() == WIFI_STA){
MDNS.addService("http","tcp",_port);
}
-#endif
+#endif //MDNS_FEATURE
_setupdone = true;
return no_error;
}
void Web_Server::end(){
_setupdone = false;
-#ifdef ENABLE_SSDP
+#ifdef SSDP_FEATURE
SSDP.end();
-#endif
-#ifdef ENABLE_MDNS
+#endif //SSDP_FEATURE
+#ifdef MDNS_FEATURE
//remove mDNS
mdns_service_remove("_http", "_tcp");
-#endif
+#endif //MDNS_FEATURE
if (_socket_server) {
delete _socket_server;
_socket_server = NULL;
@@ -236,7 +230,7 @@ void Web_Server::end(){
delete _webserver;
_webserver = NULL;
}
-#ifdef ENABLE_AUTHENTICATION
+#ifdef AUTHENTICATION_FEATURE
while (_head) {
auth_ip * current = _head;
_head = _head->_next;
@@ -281,7 +275,7 @@ void Web_Server:: handle_not_found()
String contentType = getContentType(path);
String pathWithGz = path + ".gz";
-#if ENABLED(SDSUPPORT)
+#if defined(SDSUPPORT)
if ((path.substring(0,4) == "/SD/")) {
//remove /SD
path = path.substring(3);
@@ -328,7 +322,7 @@ void Web_Server:: handle_not_found()
}
if (page_not_found ) {
-#ifdef ENABLE_CAPTIVE_PORTAL
+#ifdef CAPTIVE_PORTAL_FEATURE
if (WiFi.getMode()!=WIFI_STA ) {
String content=PAGE_CAPTIVE;
String stmp = WiFi.softAPIP().toString();
@@ -345,7 +339,7 @@ void Web_Server:: handle_not_found()
_webserver->send(200,"text/html",content);
return;
}
-#endif
+#endif //CAPTIVE_PORTAL_FEATURE
path = "/404.htm";
contentType = getContentType(path);
pathWithGz = path + ".gz";
@@ -379,7 +373,7 @@ void Web_Server:: handle_not_found()
}
}
}
-#ifdef ENABLE_SSDP
+#ifdef SSDP_FEATURE
//http SSDP xml presentation
void Web_Server::handle_SSDP ()
{
@@ -426,7 +420,7 @@ void Web_Server::handle_SSDP ()
}
}
-#endif
+#endif //SSDP_FEATURE
//Handle web command query and send answer//////////////////////////////
void Web_Server::handle_web_command ()
@@ -588,7 +582,7 @@ bool Web_Server::execute_internal_command (int cmd, String cmd_params, level_aut
{
if (!espresponse) return false;
String resp = "No SD card";
-#if ENABLED(SDSUPPORT)
+#if defined(SDSUPPORT)
ESP_SD card;
int8_t state = card.card_status();
if (state == -1)resp="Busy";
@@ -606,7 +600,7 @@ bool Web_Server::execute_internal_command (int cmd, String cmd_params, level_aut
String defV;
Preferences prefs;
if (!espresponse) return false;
-#ifdef ENABLE_AUTHENTICATION
+#ifdef AUTHENTICATION_FEATURE
if (auth_type == LEVEL_GUEST) return false;
#endif
int8_t vi;
@@ -793,7 +787,7 @@ bool Web_Server::execute_internal_command (int cmd, String cmd_params, level_aut
//[ESP401]P= T= V= pwd=
case 401:
{
-#ifdef ENABLE_AUTHENTICATION
+#ifdef AUTHENTICATION_FEATURE
if (auth_type != LEVEL_ADMIN) return false;
#endif
//check validity of parameters
@@ -909,7 +903,7 @@ bool Web_Server::execute_internal_command (int cmd, String cmd_params, level_aut
//[ESP410]
case 410: {
if (!espresponse)return false;
-#ifdef ENABLE_AUTHENTICATION
+#ifdef AUTHENTICATION_FEATURE
if (auth_type == LEVEL_GUEST) return false;
#endif
espresponse->print("{\"AP_LIST\":[");
@@ -945,7 +939,7 @@ bool Web_Server::execute_internal_command (int cmd, String cmd_params, level_aut
//Get ESP current status
case 420:
{
-#ifdef ENABLE_AUTHENTICATION
+#ifdef AUTHENTICATION_FEATURE
if (auth_type == LEVEL_GUEST) return false;
#endif
if (!espresponse)return false;
@@ -1146,17 +1140,14 @@ bool Web_Server::execute_internal_command (int cmd, String cmd_params, level_aut
//[ESP444]
case 444:
parameter = get_param(cmd_params,"", true);
-#ifdef ENABLE_AUTHENTICATION
+#ifdef AUTHENTICATION_FEATURE
if (auth_type != LEVEL_ADMIN) {
response = false;
} else
#endif
{
if (parameter=="RESTART") {
- MYSERIAL0.println("Restart ongoing");
-#if NUM_SERIAL > 1
- MYSERIAL1.println("Restart ongoing");
-#endif
+ Esp3DCom::echo("Restart ongoing");
wifi_config.restart_ESP();
} else response = false;
}
@@ -1166,7 +1157,7 @@ bool Web_Server::execute_internal_command (int cmd, String cmd_params, level_aut
if (espresponse)espresponse->println ("ok");
}
break;
-#ifdef ENABLE_AUTHENTICATION
+#ifdef AUTHENTICATION_FEATURE
//Change / Reset user password
//[ESP555]
case 555: {
@@ -1205,7 +1196,7 @@ bool Web_Server::execute_internal_command (int cmd, String cmd_params, level_aut
#endif
//[ESP700]
case 700: { //read local file
-#ifdef ENABLE_AUTHENTICATION
+#ifdef AUTHENTICATION_FEATURE
if (auth_type == LEVEL_GUEST) return false;
#endif
cmd_params.trim() ;
@@ -1260,11 +1251,11 @@ bool Web_Server::execute_internal_command (int cmd, String cmd_params, level_aut
//Format SPIFFS
//[ESP710]FORMAT pwd=
case 710:
-#ifdef ENABLE_AUTHENTICATION
+#ifdef AUTHENTICATION_FEATURE
if (auth_type != LEVEL_ADMIN) return false;
#endif
parameter = get_param (cmd_params, "", true);
-#ifdef ENABLE_AUTHENTICATION
+#ifdef AUTHENTICATION_FEATURE
if (auth_type != LEVEL_ADMIN) {
espresponse->println ("error");
response = false;
@@ -1291,13 +1282,13 @@ bool Web_Server::execute_internal_command (int cmd, String cmd_params, level_aut
resp = "FW version:";
resp += SHORT_BUILD_VERSION;
resp += " # FW target:marlin-embedded # FW HW:";
- #if ENABLED(SDSUPPORT)
+ #if defined(SDSUPPORT)
resp += "Direct SD";
#else
resp += "No SD";
#endif
resp += " # primary sd:/sd # secondary sd:none # authentication:";
- #ifdef ENABLE_AUTHENTICATION
+ #ifdef AUTHENTICATION_FEATURE
resp += "yes";
#else
resp += "no";
@@ -1321,7 +1312,7 @@ bool Web_Server::execute_internal_command (int cmd, String cmd_params, level_aut
//login status check
void Web_Server::handle_login()
{
-#ifdef ENABLE_AUTHENTICATION
+#ifdef AUTHENTICATION_FEATURE
String smsg;
String sUser,sPassword;
String auths;
@@ -1683,10 +1674,7 @@ void Web_Server::SPIFFSFileupload ()
//Guest cannot upload - only admin
if (auth_level == LEVEL_GUEST) {
_upload_status = UPLOAD_STATUS_CANCELLED;
- MYSERIAL0.println("Upload rejected");
-#if NUM_SERIAL > 1
- MYSERIAL1.println("Upload rejected");
-#endif
+ Esp3DCom::echo("Upload rejected");
_webserver->client().stop();
return;
}
@@ -1721,10 +1709,7 @@ void Web_Server::SPIFFSFileupload ()
} else {
//if no set cancel flag
_upload_status=UPLOAD_STATUS_CANCELLED;
- MYSERIAL0.println("Upload error");
-#if NUM_SERIAL > 1
- MYSERIAL1.println("Upload error");
-#endif
+ Esp3DCom::echo("Upload error");
_webserver->client().stop();
}
//Upload write
@@ -1742,10 +1727,7 @@ void Web_Server::SPIFFSFileupload ()
SPIFFS.remove (filename);
}
_webserver->client().stop();
- MYSERIAL0.println("Upload error");
-#if NUM_SERIAL > 1
- MYSERIAL1.println("Upload error");
-#endif
+ Esp3DCom::echo("Upload error");
}
//Upload end
//**************
@@ -1768,10 +1750,7 @@ void Web_Server::SPIFFSFileupload ()
if (_upload_status == UPLOAD_STATUS_ONGOING) {
_upload_status = UPLOAD_STATUS_SUCCESSFUL;
} else {
- MYSERIAL0.println("Upload error");
-#if NUM_SERIAL > 1
- MYSERIAL1.println("Upload error");
-#endif
+ Esp3DCom::echo("Upload error");
}
} else {
//we have a problem set flag UPLOAD_STATUS_CANCELLED
@@ -1780,10 +1759,7 @@ void Web_Server::SPIFFSFileupload ()
if (SPIFFS.exists (filename) ) {
SPIFFS.remove (filename);
}
- MYSERIAL0.println("Upload error");
-#if NUM_SERIAL > 1
- MYSERIAL1.println("Upload error");
-#endif
+ Esp3DCom::echo("Upload error");
}
//Upload cancelled
//**************
@@ -1795,10 +1771,7 @@ void Web_Server::SPIFFSFileupload ()
if (SPIFFS.exists (filename) ) {
SPIFFS.remove (filename);
}
- MYSERIAL0.println("Upload error");
-#if NUM_SERIAL > 1
- MYSERIAL1.println("Upload error");
-#endif
+ Esp3DCom::echo("Upload error");
}
wifi_config.wait(0);
}
@@ -1835,11 +1808,8 @@ void Web_Server::WebUpdateUpload ()
//only admin can update FW
if (is_authenticated() != LEVEL_ADMIN) {
_upload_status = UPLOAD_STATUS_CANCELLED;
- _webserver->client().stop();
- MYSERIAL0.println("Upload rejected");
-#if NUM_SERIAL > 1
- MYSERIAL1.println("Upload rejected");
-#endif
+ _webserver->client().stop();
+ Esp3DCom::echo("Upload rejected");
return;
}
@@ -1848,10 +1818,7 @@ void Web_Server::WebUpdateUpload ()
//Upload start
//**************
if(upload.status == UPLOAD_FILE_START) {
- MYSERIAL0.println("Update Firmware");
-#if NUM_SERIAL > 1
- MYSERIAL1.println("Update Firmware");
-#endif
+ Esp3DCom::echo("Update Firmware");
_upload_status= UPLOAD_STATUS_ONGOING;
//Not sure can do OTA on 2Mb board
@@ -1859,17 +1826,11 @@ void Web_Server::WebUpdateUpload ()
last_upload_update = 0;
if(!Update.begin(maxSketchSpace)) { //start with max available size
_upload_status=UPLOAD_STATUS_CANCELLED;
- MYSERIAL0.println("Update cancelled");
-#if NUM_SERIAL > 1
- MYSERIAL1.println("Update cancelled");
-#endif
+ Esp3DCom::echo("Update cancelled");
_webserver->client().stop();
return;
} else {
- MYSERIAL0.println("Update 0%");
-#if NUM_SERIAL > 1
- MYSERIAL1.println("Update 0%");
-#endif
+ Esp3DCom::echo("Update 0%");
}
//Upload write
//**************
@@ -1882,10 +1843,7 @@ void Web_Server::WebUpdateUpload ()
String s = "Update ";
s+= String(last_upload_update);
s+="%";
- MYSERIAL0.println(s.c_str());
-#if NUM_SERIAL > 1
- MYSERIAL1.println(s.c_str());
-#endif
+ Esp3DCom::echo(s.c_str());
}
if(Update.write(upload.buf, upload.currentSize) != upload.currentSize) {
_upload_status=UPLOAD_STATUS_CANCELLED;
@@ -1896,17 +1854,11 @@ void Web_Server::WebUpdateUpload ()
} else if(upload.status == UPLOAD_FILE_END) {
if(Update.end(true)) { //true to set the size to the current progress
//Now Reboot
- MYSERIAL0.println("Update 100%");
-#if NUM_SERIAL > 1
- MYSERIAL1.println("Update 100%");
-#endif
+ Esp3DCom::echo("Update 100%");
_upload_status=UPLOAD_STATUS_SUCCESSFUL;
}
} else if(upload.status == UPLOAD_FILE_ABORTED) {
- MYSERIAL0.println("Update failed");
-#if NUM_SERIAL > 1
- MYSERIAL1.println("Update failed");
-#endif
+ Esp3DCom::echo("Update failed");
Update.end();
_upload_status=UPLOAD_STATUS_CANCELLED;
}
@@ -1914,7 +1866,7 @@ void Web_Server::WebUpdateUpload ()
}
-#if ENABLED(SDSUPPORT)
+#if defined(SDSUPPORT)
//direct SD files list//////////////////////////////////////////////////
void Web_Server::handle_direct_SDFileList()
@@ -2106,10 +2058,7 @@ void Web_Server::SDFile_direct_upload()
upload_filename= sdfile.makepath83(upload_filename);
if ( sdfile.card_status() != 1) {
_upload_status=UPLOAD_STATUS_CANCELLED;
- MYSERIAL0.println("Upload cancelled");
-#if NUM_SERIAL > 1
- MYSERIAL1.println("Upload cancelled");
-#endif
+ Esp3DCom::echo("Upload cancelled");
_webserver->client().stop();
return;
}
@@ -2119,10 +2068,7 @@ void Web_Server::SDFile_direct_upload()
if (sdfile.isopen())sdfile.close();
if (!sdfile.open (upload_filename.c_str(),false)) {
- MYSERIAL0.println("Upload cancelled");
-#if NUM_SERIAL > 1
- MYSERIAL1.println("Upload cancelled");
-#endif
+ Esp3DCom::echo("Upload cancelled");
_webserver->client().stop();
_upload_status = UPLOAD_STATUS_FAILED;
return ;
@@ -2135,10 +2081,7 @@ void Web_Server::SDFile_direct_upload()
//we need to check SD is inside
if ( sdfile.card_status() != 1) {
sdfile.close();
- MYSERIAL0.println("Upload failed");
- #if NUM_SERIAL > 1
- MYSERIAL1.println("Upload failed");
- #endif
+ Esp3DCom::echo("Upload failed");
if (sdfile.exists (upload_filename.c_str()) ) {
sdfile.remove (upload_filename.c_str());
}
@@ -2158,10 +2101,7 @@ void Web_Server::SDFile_direct_upload()
String sizeargname = upload.filename + "S";
if (_webserver->hasArg (sizeargname.c_str()) ) {
if (_webserver->arg (sizeargname.c_str()) != String(filesize)) {
- MYSERIAL0.println("Upload failed");
- #if NUM_SERIAL > 1
- MYSERIAL1.println("Upload failed");
- #endif
+ Esp3DCom::echo("Upload failed");
_upload_status = UPLOAD_STATUS_FAILED;
}
}
@@ -2170,11 +2110,7 @@ void Web_Server::SDFile_direct_upload()
}
} else {//Upload cancelled
_upload_status=UPLOAD_STATUS_FAILED;
-
- MYSERIAL0.println("Upload failed");
-#if NUM_SERIAL > 1
- MYSERIAL1.println("Upload failed");
-#endif
+ Esp3DCom::echo("Upload failed");
_webserver->client().stop();
sdfile.close();
if (sdfile.exists (upload_filename.c_str()) ) {
@@ -2187,11 +2123,11 @@ void Web_Server::SDFile_direct_upload()
void Web_Server::handle(){
static uint32_t timeout = millis();
-#ifdef ENABLE_CAPTIVE_PORTAL
+#ifdef CAPTIVE_PORTAL_FEATURE
if(WiFi.getMode() == WIFI_AP){
dnsServer.processNextRequest();
}
-#endif
+#endif //CAPTIVE_PORTAL_FEATURE
if (_webserver)_webserver->handleClient();
if (_socket_server && _setupdone) {
Serial2Socket.handle_flush();
@@ -2331,7 +2267,7 @@ String Web_Server::getContentType (String filename)
//check authentification
level_authenticate_type Web_Server::is_authenticated()
{
-#ifdef ENABLE_AUTHENTICATION
+#ifdef AUTHENTICATION_FEATURE
if (_webserver->hasHeader ("Cookie") ) {
String cookie = _webserver->header ("Cookie");
int pos = cookie.indexOf ("ESPSESSIONID=");
@@ -2349,7 +2285,7 @@ level_authenticate_type Web_Server::is_authenticated()
#endif
}
-#ifdef ENABLE_AUTHENTICATION
+#ifdef AUTHENTICATION_FEATURE
bool Web_Server::isLocalPasswordValid (const char * password)
{
@@ -2560,8 +2496,4 @@ void ESPResponseStream::flush(){
}
-#endif // Enable HTTP
-
-#endif // ENABLE_WIFI
-
-#endif // ARDUINO_ARCH_ESP32
+#endif // ESP3D_WIFISUPPORT && HTTP_FEATURE
diff --git a/src/web_server.h b/src/web_server.h
index d96e32e..c9ba283 100644
--- a/src/web_server.h
+++ b/src/web_server.h
@@ -34,7 +34,7 @@ typedef enum {
LEVEL_ADMIN = 2
} level_authenticate_type;
-#ifdef ENABLE_AUTHENTICATION
+#ifdef AUTHENTICATION_FEATURE
struct auth_ip {
IPAddress ip;
level_authenticate_type level;
@@ -83,7 +83,7 @@ class Web_Server {
static String getContentType (String filename);
static String get_Splited_Value(String data, char separator, int index);
static level_authenticate_type is_authenticated();
-#ifdef ENABLE_AUTHENTICATION
+#ifdef AUTHENTICATION_FEATURE
static auth_ip * _head;
static uint8_t _nb_ip;
static bool AddAuthIP (auth_ip * item);
@@ -95,9 +95,9 @@ class Web_Server {
#endif
static String get_param (String & cmd_params, const char * id, bool withspace);
static bool execute_internal_command (int cmd, String cmd_params, level_authenticate_type auth_level, ESPResponseStream *espresponse);
-#ifdef ENABLE_SSDP
+#ifdef SSDP_FEATURE
static void handle_SSDP ();
-#endif
+#endif //SSDP_FEATURE
static void handle_root();
static void handle_login();
static void handle_not_found ();
@@ -108,7 +108,7 @@ class Web_Server {
static void handleFileList ();
static void handleUpdate ();
static void WebUpdateUpload ();
-#if ENABLED(SDSUPPORT)
+#if defined(SDSUPPORT)
static void handle_direct_SDFileList();
static void SDFile_direct_upload();
#endif
diff --git a/src/wificonfig.cpp b/src/wificonfig.cpp
index 97a8238..fccfa71 100644
--- a/src/wificonfig.cpp
+++ b/src/wificonfig.cpp
@@ -18,16 +18,15 @@
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
-#ifdef ARDUINO_ARCH_ESP32
+#include "esp3dlibconfig.h"
-#include "esplibconfig.h"
-
-#if ENABLED(ESP3D_WIFISUPPORT)
+#if defined(ESP3D_WIFISUPPORT)
#include
#include
#include
#include
#include
+#include "espcom.h"
#include
#include "wificonfig.h"
#include "wifiservices.h"
@@ -190,11 +189,11 @@ void WiFiConfig::WiFiEvent(WiFiEvent_t event)
switch (event)
{
case SYSTEM_EVENT_STA_GOT_IP:
- MYSERIAL0.println ("Connected");
- MYSERIAL0.println(WiFi.localIP());
+ Esp3DCom::echo ("Connected");
+ Esp3DCom::echo(WiFi.localIP().toString().c_str());
break;
case SYSTEM_EVENT_STA_DISCONNECTED:
- MYSERIAL0.println("WiFi lost connection");
+ Esp3DCom::echo("WiFi lost connection");
break;
default:
break;
@@ -245,7 +244,7 @@ bool WiFiConfig::ConnectSTA2AP(){
dot++;
break;
}
- MYSERIAL0.println(msg.c_str());
+ Esp3DCom::echo(msg.c_str());
wait (500);
count++;
status = WiFi.status();
@@ -296,11 +295,12 @@ bool WiFiConfig::StartSTA(){
WiFi.config(ip, gateway,mask);
}
if (WiFi.begin(SSID.c_str(), (password.length() > 0)?password.c_str():NULL)){
- MYSERIAL0.print("\nClient Started\nConnecting ");
- MYSERIAL0.println(SSID.c_str());
+ Esp3DCom::echo("WiFi station started");
+ SSID = "Connecting " + SSID;
+ Esp3DCom::echo(SSID.c_str());
return ConnectSTA2AP();
} else {
- MYSERIAL0.println("\nStarting client failed");
+ Esp3DCom::echo("Starting station failed");
return false;
}
}
@@ -345,11 +345,11 @@ bool WiFiConfig::StartAP(){
WiFi.softAPConfig(ip, ip, mask);
//Start AP
if(WiFi.softAP(SSID.c_str(), (password.length() > 0)?password.c_str():NULL, channel)) {
- MYSERIAL0.print("\nAP Started ");
- MYSERIAL0.println(WiFi.softAPIP().toString());
+ Esp3DCom::echo("AP started ");
+ Esp3DCom::echo(WiFi.softAPIP().toString().c_str());
return true;
} else {
- MYSERIAL0.println("\nStarting AP failed");
+ Esp3DCom::echo("Starting AP failed");
return false;
}
}
@@ -364,7 +364,7 @@ void WiFiConfig::StopWiFi(){
if((WiFi.getMode() == WIFI_AP) || (WiFi.getMode() == WIFI_AP_STA))WiFi.softAPdisconnect(true);
wifi_services.end();
WiFi.mode(WIFI_OFF);
- MYSERIAL0.println("\nWiFi Off");
+ Esp3DCom::echo("WiFi Off");
}
/**
@@ -386,7 +386,7 @@ void WiFiConfig::begin() {
wifi_services.begin();
} else if (wifiMode == ESP_WIFI_STA){
if(!StartSTA()){
- MYSERIAL0.println("\nCannot connect to AP");
+ Esp3DCom::echo("Cannot connect to AP");
StartAP();
}
//start services
@@ -425,5 +425,3 @@ void WiFiConfig::handle() {
#endif // ENABLE_WIFI
-
-#endif // ARDUINO_ARCH_ESP32
diff --git a/src/wificonfig.h b/src/wificonfig.h
index 2ef0e7d..603e7f8 100644
--- a/src/wificonfig.h
+++ b/src/wificonfig.h
@@ -19,37 +19,7 @@
*/
//Services that need to be used
-#include "esplibconfig.h"
-
-#define ENABLE_MDNS
-#define ENABLE_OTA
-#define ENABLE_HTTP
-#define ENABLE_SSDP
-#define ENABLE_CAPTIVE_PORTAL
-//Authentication flag is now in Configuration_adv.h
-//#define ENABLE_AUTHENTICATION
-#define ENABLE_SERIAL2SOCKET_OUT
-
-#define ENABLE_SERIAL2SOCKET_IN
-
-//Preferences entries
-#define NAMESPACE "MARLIN"
-#define HOSTNAME_ENTRY "ESP_HOSTNAME"
-#define STA_SSID_ENTRY "STA_SSID"
-#define STA_PWD_ENTRY "STA_PWD"
-#define STA_IP_ENTRY "STA_IP"
-#define STA_GW_ENTRY "STA_GW"
-#define STA_MK_ENTRY "STA_MK"
-#define ESP_WIFI_MODE "WIFI_MODE"
-#define AP_SSID_ENTRY "AP_SSID"
-#define AP_PWD_ENTRY "AP_PWD"
-#define AP_IP_ENTRY "AP_IP"
-#define AP_CHANNEL_ENTRY "AP_CHANNEL"
-#define HTTP_ENABLE_ENTRY "HTTP_ON"
-#define HTTP_PORT_ENTRY "HTTP_PORT"
-#define TELNET_ENABLE_ENTRY "TELNET_ON"
-#define TELNET_PORT_ENTRY "TELNET_PORT"
-#define STA_IP_MODE_ENTRY "STA_IP_MODE"
+#include "esp3dlibconfig.h"
//Wifi Mode
#define ESP_WIFI_OFF 0
@@ -59,10 +29,6 @@
#define DHCP_MODE 0
#define STATIC_MODE 0
-//Switch
-#define ESP_SAVE_ONLY 0
-#define ESP_APPLY_NOW 1
-
//defaults values
#define DEFAULT_HOSTNAME "marlinesp"
#define DEFAULT_STA_SSID "MARLIN_ESP"
diff --git a/src/wifiservices.cpp b/src/wifiservices.cpp
index 7d72438..c067d5d 100644
--- a/src/wifiservices.cpp
+++ b/src/wifiservices.cpp
@@ -18,27 +18,25 @@
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
-#ifdef ARDUINO_ARCH_ESP32
-
-#include "esplibconfig.h"
-
-#if ENABLED(ESP3D_WIFISUPPORT)
+#include "esp3dlibconfig.h"
+#if defined(ESP3D_WIFISUPPORT)
#include
#include
#include
+#include "espcom.h"
#include
#include "wificonfig.h"
#include "wifiservices.h"
-#ifdef ENABLE_MDNS
+#ifdef MDNS_FEATURE
#include
-#endif
-#ifdef ENABLE_OTA
+#endif //MDNS_FEATURE
+#ifdef OTA_FEATURE
#include
-#endif
-#ifdef ENABLE_HTTP
+#endif //OTA_FEATURE
+#ifdef HTTP_FEATURE
#include "web_server.h"
-#endif
+#endif //HTTP_FEATURE
WiFiServices wifi_services;
@@ -62,79 +60,85 @@ bool WiFiServices::begin(){
//Start SPIFFS
SPIFFS.begin(true);
-#ifdef ENABLE_OTA
+#ifdef OTA_FEATURE
ArduinoOTA
.onStart([]() {
- String type;
+ String type = "OTA:Start OTA updating ";
if (ArduinoOTA.getCommand() == U_FLASH)
- type = "sketch";
+ type += "sketch";
else {// U_SPIFFS
// NOTE: if updating SPIFFS this would be the place to unmount SPIFFS using SPIFFS.end()
- type = "filesystem";
+ type += "filesystem";
SPIFFS.end();
}
- MYSERIAL0.printf("OTA:Start OTA updating %s]\r\n", type.c_str());
+ Esp3DCom::echo(type.c_str());
})
.onEnd([]() {
- MYSERIAL0.println("OTA:End");
+ Esp3DCom::echo("OTA:End");
})
.onProgress([](unsigned int progress, unsigned int total) {
- MYSERIAL0.printf("OTA:OTA Progress: %u%%]\r\n", (progress / (total / 100)));
+ String tmp = "OTA:OTA Progress:";
+ tmp += String(progress / (total / 100));
+ tmp +="%%";
+ Esp3DCom::echo(tmp.c_str());
})
.onError([](ota_error_t error) {
- MYSERIAL0.printf("OTA: Error(%u)\r\n", error);
- if (error == OTA_AUTH_ERROR) MYSERIAL0.println("OTA:Auth Failed]");
- else if (error == OTA_BEGIN_ERROR) MYSERIAL0.println("OTA:Begin Failed");
- else if (error == OTA_CONNECT_ERROR) MYSERIAL0.println("OTA:Connect Failed");
- else if (error == OTA_RECEIVE_ERROR) MYSERIAL0.println("OTA:Receive Failed");
- else if (error == OTA_END_ERROR) MYSERIAL0.println("OTA:End Failed]");
+ String tmp = "OTA: Error(";
+ tmp += String(error) + ")";
+ Esp3DCom::echo(tmp.c_str());
+ if (error == OTA_AUTH_ERROR) Esp3DCom::echo("OTA:Auth Failed");
+ else if (error == OTA_BEGIN_ERROR) Esp3DCom::echo("OTA:Begin Failed");
+ else if (error == OTA_CONNECT_ERROR) Esp3DCom::echo("OTA:Connect Failed");
+ else if (error == OTA_RECEIVE_ERROR) Esp3DCom::echo("OTA:Receive Failed");
+ else if (error == OTA_END_ERROR) Esp3DCom::echo("OTA:End Failed");
});
ArduinoOTA.begin();
+ Esp3DCom::echo("OTA service started");
#endif
-#ifdef ENABLE_MDNS
+#ifdef MDNS_FEATURE
//no need in AP mode
if(WiFi.getMode() == WIFI_STA){
//start mDns
if (!MDNS.begin(h.c_str())) {
- MYSERIAL0.println("Cannot start mDNS");
+ Esp3DCom::echo("Cannot start mDNS");
no_error = false;
} else {
- MYSERIAL0.printf("Start mDNS with hostname:%s\r\n",h.c_str());
+ String tmp = "mDNS service (" + h;
+ tmp+=") started";
+ Esp3DCom::echo(tmp.c_str());
}
}
-#endif
-#ifdef ENABLE_HTTP
+#endif //MDNS_FEATURE
+#ifdef HTTP_FEATURE
web_server.begin();
-#endif
+#endif //HTTP_FEATURE
return no_error;
}
void WiFiServices::end(){
-#ifdef ENABLE_HTTP
+#ifdef HTTP_FEATURE
web_server.end();
#endif
//stop OTA
-#ifdef ENABLE_OTA
+#ifdef OTA_FEATURE
ArduinoOTA.end();
-#endif
+#endif //OTA_FEATURE
//Stop SPIFFS
SPIFFS.end();
-#ifdef ENABLE_MDNS
+#ifdef MDNS_FEATURE
//Stop mDNS
//MDNS.end();
-#endif
+#endif //MDNS_FEATURE
}
void WiFiServices::handle(){
-#ifdef ENABLE_OTA
+#ifdef OTA_FEATURE
ArduinoOTA.handle();
-#endif
-#ifdef ENABLE_HTTP
+#endif //OTA_FEATURE
+#ifdef HTTP_FEATURE
web_server.handle();
-#endif
+#endif //HTTP_FEATURE
}
#endif // ENABLE_WIFI
-
-#endif // ARDUINO_ARCH_ESP32