diff --git a/Grbl_Esp32/src/Config.h b/Grbl_Esp32/src/Config.h index c0496f1b..fde95aab 100644 --- a/Grbl_Esp32/src/Config.h +++ b/Grbl_Esp32/src/Config.h @@ -70,28 +70,9 @@ const int BAUD_RATE = 115200; //#define CONNECT_TO_SSID "your SSID" //#define SSID_PASSWORD "your SSID password" //CONFIGURE_EYECATCH_BEGIN (DO NOT MODIFY THIS LINE) -#define ENABLE_BLUETOOTH // enable bluetooth -#define ENABLE_WIFI //enable wifi - -#define WIFI_OR_BLUETOOTH - -#define ENABLE_HTTP //enable HTTP and all related services -#define ENABLE_OTA //enable OTA -#define ENABLE_TELNET //enable telnet -#define ENABLE_TELNET_WELCOME_MSG //display welcome string when connect to telnet -#define ENABLE_MDNS //enable mDNS discovery -#define ENABLE_SSDP //enable UPNP discovery -#define ENABLE_NOTIFICATIONS //enable notifications - -#define ENABLE_SERIAL2SOCKET_IN -#define ENABLE_SERIAL2SOCKET_OUT - -// Captive portal is used when WiFi is in access point mode. It lets the -// WebUI come up automatically in the browser, instead of requiring the user -// to browse manually to a default URL. It works like airport and hotel -// WiFi that takes you a special page as soon as you connect to that AP. -#define ENABLE_CAPTIVE_PORTAL +// #define ENABLE_BLUETOOTH // enable bluetooth -- platformio: pio run -e bt +// #define ENABLE_WIFI // enable wifi -- platformio: pio run -e wifi // Warning! The current authentication implementation is too weak to provide // security against an attacker, since passwords are stored and transmitted @@ -99,7 +80,7 @@ const int BAUD_RATE = 115200; // "friendly suggestion" to prevent unwitting dangerous actions, rather than // as effective security against malice. // #define ENABLE_AUTHENTICATION -//CONFIGURE_EYECATCH_END (DO NOT MODIFY THIS LINE) +// CONFIGURE_EYECATCH_END (DO NOT MODIFY THIS LINE) #ifdef ENABLE_AUTHENTICATION const char* const DEFAULT_ADMIN_PWD = "admin"; @@ -122,7 +103,6 @@ const int DEFAULT_RADIO_MODE = ESP_WIFI_STA; const int DEFAULT_RADIO_MODE = ESP_WIFI_AP; # endif //CONNECT_TO_SSID #else -# undef ENABLE_NOTIFICATIONS // TODO FIXME! # ifdef ENABLE_BLUETOOTH diff --git a/Grbl_Esp32/src/Grbl.cpp b/Grbl_Esp32/src/Grbl.cpp index 7eac50c3..cabcc738 100644 --- a/Grbl_Esp32/src/Grbl.cpp +++ b/Grbl_Esp32/src/Grbl.cpp @@ -103,12 +103,13 @@ void grbl_init() { info_serial("Initializing WiFi..."); WebUI::wifi_config.begin(); #endif - +#ifdef ENABLE_BLUETOOTH if (hasBluetooth()) { info_serial("Initializing Bluetooth..."); config->_comms->_bluetoothConfig->begin(); } +#endif WebUI::inputBuffer.begin(); } catch (const AssertionFailed& ex) { // This means something is terribly broken: diff --git a/Grbl_Esp32/src/Grbl.h b/Grbl_Esp32/src/Grbl.h index 42eed37a..03f753e3 100644 --- a/Grbl_Esp32/src/Grbl.h +++ b/Grbl_Esp32/src/Grbl.h @@ -72,15 +72,9 @@ const char* const GRBL_VERSION_BUILD = "20210326"; #ifdef ENABLE_WIFI # include "WebUI/WifiConfig.h" -# ifdef ENABLE_HTTP -# include "WebUI/Serial2Socket.h" -# endif -# ifdef ENABLE_TELNET -# include "WebUI/TelnetServer.h" -# endif -# ifdef ENABLE_NOTIFICATIONS -# include "WebUI/NotificationsService.h" -# endif +# include "WebUI/Serial2Socket.h" +# include "WebUI/TelnetServer.h" +# include "WebUI/NotificationsService.h" #endif #include "I2SOut.h" diff --git a/Grbl_Esp32/src/MachineConfig.cpp b/Grbl_Esp32/src/MachineConfig.cpp index d1eb861f..a955bf19 100644 --- a/Grbl_Esp32/src/MachineConfig.cpp +++ b/Grbl_Esp32/src/MachineConfig.cpp @@ -464,15 +464,20 @@ void MachineConfig::afterParse() { if (_comms == nullptr) { log_info("Comms config missing; building default comms"); - _comms = new Communications(); + _comms = new Communications(); +#ifdef ENABLE_WIFI _comms->_apConfig = new WifiAPConfig(); +#endif } + +#ifdef ENABLE_WIFI // This is very helpful for testing YAML config files. If things // screw up, you can still connect and upload a new config.yaml // TODO - Consider whether we want this for the long term if (!_comms->_apConfig) { _comms->_apConfig = new WifiAPConfig(); } +#endif } size_t MachineConfig::readFile(const char* filename, char*& buffer) { diff --git a/Grbl_Esp32/src/MachineConfig.h b/Grbl_Esp32/src/MachineConfig.h index 7bac399f..c8e592fb 100644 --- a/Grbl_Esp32/src/MachineConfig.h +++ b/Grbl_Esp32/src/MachineConfig.h @@ -31,6 +31,7 @@ #include "EnumItem.h" #include "Stepper.h" #include "Logging.h" +#include "Config.h" // TODO FIXME: Split this file up into several files, perhaps put it in some folder and namespace Machine? @@ -291,14 +292,19 @@ public: String _hostname = "grblesp"; +#ifdef ENABLE_BLUETOOTH WebUI::BTConfig* _bluetoothConfig = nullptr; - WifiAPConfig* _apConfig = nullptr; - WifiSTAConfig* _staConfig = nullptr; +#endif +#ifdef ENABLE_WIFI + WifiAPConfig* _apConfig = nullptr; + WifiSTAConfig* _staConfig = nullptr; +#endif void group(Configuration::HandlerBase& handler) override { // handler.item("user_password", _userPassword); // handler.item("admin_password", _adminPassword); +#ifdef ENABLE_WIFI handler.item("telnet_enable", _telnetEnable); handler.item("telnet_port", _telnetPort); @@ -306,16 +312,25 @@ public: handler.item("http_port", _httpPort); handler.item("hostname", _hostname); +#endif +#ifdef ENABLE_BLUETOOTH handler.section("bluetooth", _bluetoothConfig); +#endif +#ifdef ENABLE_WIFI handler.section("wifi_ap", _apConfig); handler.section("wifi_sta", _staConfig); +#endif } ~Communications() { +#ifdef ENABLE_BLUETOOTH delete _bluetoothConfig; +#endif +#ifdef ENABLE_WIFI delete _apConfig; delete _staConfig; +#endif } }; @@ -369,8 +384,16 @@ public: extern MachineConfig* config; inline bool hasWiFi() { +#ifdef ENABLE_WIFI return config && config->_comms && (config->_comms->_staConfig != nullptr || config->_comms->_apConfig != nullptr); +#else + return false; +#endif } inline bool hasBluetooth() { +#ifdef ENABLE_BLUETOOTH return !hasWiFi() && (config && config->_comms && config->_comms->_bluetoothConfig != nullptr); +#else + return false; +#endif } diff --git a/Grbl_Esp32/src/ProcessSettings.cpp b/Grbl_Esp32/src/ProcessSettings.cpp index 00247e27..6e8ac94a 100644 --- a/Grbl_Esp32/src/ProcessSettings.cpp +++ b/Grbl_Esp32/src/ProcessSettings.cpp @@ -39,13 +39,12 @@ void show_setting(const char* name, const char* value, const char* description, } void settings_restore(uint8_t restore_flag) { -#ifdef WIFI_OR_BLUETOOTH +#ifdef ENABLE_WIFI if (restore_flag & SettingsRestore::Wifi) { -# ifdef ENABLE_WIFI WebUI::wifi_config.reset_settings(); -# endif } #endif + if (restore_flag & SettingsRestore::Defaults) { bool restore_startup = restore_flag & SettingsRestore::StartupLines; for (Setting* s = Setting::List; s; s = s->next()) { diff --git a/Grbl_Esp32/src/Report.cpp b/Grbl_Esp32/src/Report.cpp index d8ecd100..9fb56d5b 100644 --- a/Grbl_Esp32/src/Report.cpp +++ b/Grbl_Esp32/src/Report.cpp @@ -149,7 +149,7 @@ void error_serial(const char* format, ...) { //function to notify void grbl_notify(const char* title, const char* msg) { -#ifdef ENABLE_NOTIFICATIONS +#ifdef ENABLE_WIFI WebUI::notificationsservice.sendMSG(title, msg); #endif } @@ -554,7 +554,7 @@ void report_build_info(const char* line, uint8_t client) { #ifdef ENABLE_PARKING_OVERRIDE_CONTROL grbl_send(client, "R"); #endif -#if defined(ENABLE_WIFI) +#ifdef ENABLE_WIFI grbl_send(client, "W"); #endif #ifndef ENABLE_RESTORE_WIPE_ALL // NOTE: Shown when disabled. @@ -576,12 +576,14 @@ void report_build_info(const char* line, uint8_t client) { // These will likely have a comma delimiter to separate them. grbl_send(client, "]\r\n"); report_machine_type(client); -#if defined(ENABLE_WIFI) +#ifdef ENABLE_WIFI grbl_send(client, (char*)WebUI::wifi_config.info()); #endif +#ifdef ENABLE_BLUETOOTH if (hasBluetooth()) { grbl_send(client, config->_comms->_bluetoothConfig->info().c_str()); } +#endif } // Prints the character string line Grbl has received from the user, which has been pre-parsed, @@ -627,15 +629,17 @@ void report_realtime_status(uint8_t client) { // Returns planner and serial read buffer states. if (bit_istrue(status_mask->get(), RtStatus::Buffer)) { int bufsize = DEFAULTBUFFERSIZE; -#if defined(ENABLE_WIFI) && defined(ENABLE_TELNET) +#ifdef ENABLE_WIFI if (client == CLIENT_TELNET) { bufsize = WebUI::telnet_server.get_rx_buffer_available(); } -#endif //ENABLE_WIFI && ENABLE_TELNET +#endif +#ifdef ENABLE_BLUETOOTH if (hasBluetooth() && client == CLIENT_BT) { //TODO FIXME bufsize = 512 - WebUI::SerialBT.available(); } +#endif if (client == CLIENT_SERIAL) { bufsize = client_get_rx_buffer_available(CLIENT_SERIAL); } diff --git a/Grbl_Esp32/src/Serial.cpp b/Grbl_Esp32/src/Serial.cpp index 9f006e40..f6ee44e0 100644 --- a/Grbl_Esp32/src/Serial.cpp +++ b/Grbl_Esp32/src/Serial.cpp @@ -124,6 +124,8 @@ static uint8_t getClientChar(uint8_t* data) { *data = WebUI::inputBuffer.read(); return CLIENT_INPUT; } + +#ifdef ENABLE_BLUETOOTH //currently is wifi or BT but better to prepare both can be live if (hasBluetooth()) { if (WebUI::SerialBT.hasClient()) { @@ -133,13 +135,12 @@ static uint8_t getClientChar(uint8_t* data) { } } } -#if defined(ENABLE_WIFI) && defined(ENABLE_HTTP) && defined(ENABLE_SERIAL2SOCKET_IN) +#endif +#ifdef ENABLE_WIFI if (WebUI::Serial2Socket.available()) { *data = WebUI::Serial2Socket.read(); return CLIENT_WEBUI; } -#endif -#if defined(ENABLE_WIFI) && defined(ENABLE_TELNET) if (WebUI::telnet_server.available()) { *data = WebUI::telnet_server.read(); return CLIENT_TELNET; @@ -174,15 +175,17 @@ void clientCheckTask(void* pvParameters) { } } // if something available WebUI::COMMANDS::handle(); -#ifdef ENABLE_WIFI - WebUI::wifi_config.handle(); -#endif + +#ifdef ENABLE_BLUETOOTH if (hasBluetooth()) { config->_comms->_bluetoothConfig->handle(); } -#if defined(ENABLE_WIFI) && defined(ENABLE_HTTP) && defined(ENABLE_SERIAL2SOCKET_IN) +#endif +#ifdef ENABLE_WIFI + WebUI::wifi_config.handle(); WebUI::Serial2Socket.handle_flush(); #endif + vTaskDelay(1 / portTICK_RATE_MS); // Yield to other tasks #ifdef DEBUG_TASK_STACK @@ -328,6 +331,8 @@ void client_write(uint8_t client, const char* text) { if (client == CLIENT_INPUT) { return; } + +#ifdef ENABLE_BLUETOOTH if (hasBluetooth()) { if (WebUI::SerialBT.hasClient() && (client == CLIENT_BT || client == CLIENT_ALL)) { // TODO: This can be .print() for consistency with other clients, @@ -337,16 +342,16 @@ void client_write(uint8_t client, const char* text) { //delay(10); // possible fix for dropped characters } } -#if defined(ENABLE_WIFI) && defined(ENABLE_HTTP) && defined(ENABLE_SERIAL2SOCKET_OUT) +#endif +#ifdef ENABLE_WIFI if (client == CLIENT_WEBUI || client == CLIENT_ALL) { WebUI::Serial2Socket.write((const uint8_t*)text, strlen(text)); } -#endif -#if defined(ENABLE_WIFI) && defined(ENABLE_TELNET) if (client == CLIENT_TELNET || client == CLIENT_ALL) { WebUI::telnet_server.write((const uint8_t*)text, strlen(text)); } #endif + if (client == CLIENT_SERIAL || client == CLIENT_ALL) { #ifdef REVERT_TO_ARDUINO_SERIAL Serial.write(text); diff --git a/Grbl_Esp32/src/WebUI/BTConfig.cpp b/Grbl_Esp32/src/WebUI/BTConfig.cpp index 936cb2c6..7f786d43 100644 --- a/Grbl_Esp32/src/WebUI/BTConfig.cpp +++ b/Grbl_Esp32/src/WebUI/BTConfig.cpp @@ -21,6 +21,8 @@ #include "../Grbl.h" #include "../MachineConfig.h" +#ifdef ENABLE_BLUETOOTH + #include "BTConfig.h" extern "C" { @@ -158,3 +160,5 @@ namespace WebUI { BTConfig::~BTConfig() { end(); } } + +#endif diff --git a/Grbl_Esp32/src/WebUI/BTConfig.h b/Grbl_Esp32/src/WebUI/BTConfig.h index a79ce1e3..94724e3c 100644 --- a/Grbl_Esp32/src/WebUI/BTConfig.h +++ b/Grbl_Esp32/src/WebUI/BTConfig.h @@ -22,9 +22,12 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ -#include #include "../Configuration/Configurable.h" +#ifdef ENABLE_BLUETOOTH + +# include + namespace WebUI { extern BluetoothSerial SerialBT; @@ -68,3 +71,5 @@ namespace WebUI { ~BTConfig(); }; } + +#endif diff --git a/Grbl_Esp32/src/WebUI/ESPResponse.cpp b/Grbl_Esp32/src/WebUI/ESPResponse.cpp index 29f49d2d..6b809106 100644 --- a/Grbl_Esp32/src/WebUI/ESPResponse.cpp +++ b/Grbl_Esp32/src/WebUI/ESPResponse.cpp @@ -19,13 +19,14 @@ */ #include "../Grbl.h" #include "ESPResponse.h" -#if defined(ENABLE_HTTP) && defined(ENABLE_WIFI) + +#ifdef ENABLE_WIFI # include "WebServer.h" # include #endif namespace WebUI { -#if defined(ENABLE_HTTP) && defined(ENABLE_WIFI) +#ifdef ENABLE_WIFI ESPResponseStream::ESPResponseStream(WebServer* webserver) { _header_sent = false; _webserver = webserver; @@ -35,7 +36,7 @@ namespace WebUI { ESPResponseStream::ESPResponseStream() { _client = CLIENT_INPUT; -#if defined(ENABLE_HTTP) && defined(ENABLE_WIFI) +#ifdef ENABLE_WIFI _header_sent = false; _webserver = NULL; #endif @@ -44,7 +45,7 @@ namespace WebUI { ESPResponseStream::ESPResponseStream(uint8_t client, bool byid) { (void)byid; //fake parameter to avoid confusion with pointer one (NULL == 0) _client = client; -#if defined(ENABLE_HTTP) && defined(ENABLE_WIFI) +#ifdef ENABLE_WIFI _header_sent = false; _webserver = NULL; #endif @@ -76,7 +77,7 @@ namespace WebUI { if (_client == CLIENT_INPUT) { return; } -#if defined(ENABLE_HTTP) && defined(ENABLE_WIFI) +#ifdef ENABLE_WIFI if (_webserver) { if (!_header_sent) { _webserver->setContentLength(CONTENT_LENGTH_UNKNOWN); @@ -107,7 +108,7 @@ namespace WebUI { } void ESPResponseStream::flush() { -#if defined(ENABLE_HTTP) && defined(ENABLE_WIFI) +#ifdef ENABLE_WIFI if (_webserver) { if (_header_sent) { //send data diff --git a/Grbl_Esp32/src/WebUI/ESPResponse.h b/Grbl_Esp32/src/WebUI/ESPResponse.h index 4c07d97f..c66c0c9c 100644 --- a/Grbl_Esp32/src/WebUI/ESPResponse.h +++ b/Grbl_Esp32/src/WebUI/ESPResponse.h @@ -20,16 +20,17 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ -#if defined(ENABLE_HTTP) && defined(ENABLE_WIFI) +#ifdef ENABLE_WIFI class WebServer; #endif namespace WebUI { class ESPResponseStream { public: -#if defined(ENABLE_HTTP) && defined(ENABLE_WIFI) +#ifdef ENABLE_WIFI ESPResponseStream(WebServer* webserver); #endif + ESPResponseStream(uint8_t client, bool byid = true); ESPResponseStream(); @@ -45,7 +46,7 @@ namespace WebUI { uint8_t _client; bool _header_sent; -#if defined(ENABLE_HTTP) && defined(ENABLE_WIFI) +#ifdef ENABLE_WIFI WebServer* _webserver; String _buffer; #endif diff --git a/Grbl_Esp32/src/WebUI/NotificationsService.cpp b/Grbl_Esp32/src/WebUI/NotificationsService.cpp index 69bfd7e5..561fc2de 100644 --- a/Grbl_Esp32/src/WebUI/NotificationsService.cpp +++ b/Grbl_Esp32/src/WebUI/NotificationsService.cpp @@ -31,7 +31,8 @@ #include "../Grbl.h" #include "../MachineConfig.h" -#ifdef ENABLE_NOTIFICATIONS +#ifdef ENABLE_WIFI + # include "NotificationsService.h" # include # include @@ -370,4 +371,4 @@ namespace WebUI { NotificationsService::~NotificationsService() { end(); } } -#endif //ENABLE_NOTIFICATIONS +#endif diff --git a/Grbl_Esp32/src/WebUI/NotificationsService.h b/Grbl_Esp32/src/WebUI/NotificationsService.h index 578b84f5..e385184a 100644 --- a/Grbl_Esp32/src/WebUI/NotificationsService.h +++ b/Grbl_Esp32/src/WebUI/NotificationsService.h @@ -20,6 +20,11 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ +#ifdef ENABLE_WIFI + +# include +# include + namespace WebUI { class NotificationsService { public: @@ -53,3 +58,5 @@ namespace WebUI { extern NotificationsService notificationsservice; } + +#endif diff --git a/Grbl_Esp32/src/WebUI/Serial2Socket.cpp b/Grbl_Esp32/src/WebUI/Serial2Socket.cpp index 08810910..459f4192 100644 --- a/Grbl_Esp32/src/WebUI/Serial2Socket.cpp +++ b/Grbl_Esp32/src/WebUI/Serial2Socket.cpp @@ -20,7 +20,7 @@ #include "../Grbl.h" -#if defined(ENABLE_WIFI) && defined(ENABLE_HTTP) +#ifdef ENABLE_WIFI # include "Serial2Socket.h" # include "WebServer.h" @@ -88,7 +88,6 @@ namespace WebUI { return 0; } -# if defined(ENABLE_SERIAL2SOCKET_OUT) if (_TXbufferSize == 0) { _lastflush = millis(); } @@ -105,7 +104,6 @@ namespace WebUI { } log_i("[SOCKET]buffer size %d", _TXbufferSize); handle_flush(); -# endif return size; } @@ -118,7 +116,6 @@ namespace WebUI { } bool Serial_2_Socket::push(const char* data) { -# if defined(ENABLE_SERIAL2SOCKET_IN) int data_size = strlen(data); if ((data_size + _RXbufferSize) <= RXBUFFERSIZE) { int current = _RXbufferpos + _RXbufferSize; @@ -138,9 +135,6 @@ namespace WebUI { return true; } return false; -# else - return true; -# endif } int Serial_2_Socket::read(void) { @@ -186,4 +180,5 @@ namespace WebUI { _RXbufferpos = 0; } } -#endif // ENABLE_WIFI + +#endif diff --git a/Grbl_Esp32/src/WebUI/Serial2Socket.h b/Grbl_Esp32/src/WebUI/Serial2Socket.h index 9babdf95..b96f05f8 100644 --- a/Grbl_Esp32/src/WebUI/Serial2Socket.h +++ b/Grbl_Esp32/src/WebUI/Serial2Socket.h @@ -20,8 +20,11 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ +#ifdef ENABLE_WIFI + #include #include +#include class WebSocketsServer; @@ -73,3 +76,5 @@ namespace WebUI { extern Serial_2_Socket Serial2Socket; } + +#endif diff --git a/Grbl_Esp32/src/WebUI/TelnetServer.cpp b/Grbl_Esp32/src/WebUI/TelnetServer.cpp index a3bf9e84..cb73eaed 100644 --- a/Grbl_Esp32/src/WebUI/TelnetServer.cpp +++ b/Grbl_Esp32/src/WebUI/TelnetServer.cpp @@ -21,7 +21,7 @@ #include "../Grbl.h" #include "../MachineConfig.h" -#if defined(ENABLE_WIFI) && defined(ENABLE_TELNET) +#ifdef ENABLE_WIFI # include "WifiServices.h" @@ -36,9 +36,7 @@ namespace WebUI { WiFiServer* Telnet_Server::_telnetserver = NULL; WiFiClient Telnet_Server::_telnetClients[MAX_TLNT_CLIENTS]; -# ifdef ENABLE_TELNET_WELCOME_MSG IPAddress Telnet_Server::_telnetClientsIP[MAX_TLNT_CLIENTS]; -# endif Telnet_Server::Telnet_Server() { _RXbufferSize = 0; @@ -84,9 +82,7 @@ namespace WebUI { for (i = 0; i < MAX_TLNT_CLIENTS; i++) { //find free/disconnected spot if (!_telnetClients[i] || !_telnetClients[i].connected()) { -# ifdef ENABLE_TELNET_WELCOME_MSG _telnetClientsIP[i] = IPAddress(0, 0, 0, 0); -# endif if (_telnetClients[i]) { _telnetClients[i].stop(); } @@ -133,12 +129,10 @@ namespace WebUI { //uint8_t c; for (uint8_t i = 0; i < MAX_TLNT_CLIENTS; i++) { if (_telnetClients[i] && _telnetClients[i].connected()) { -# ifdef ENABLE_TELNET_WELCOME_MSG if (_telnetClientsIP[i] != _telnetClients[i].remoteIP()) { report_init_message(CLIENT_TELNET); _telnetClientsIP[i] = _telnetClients[i].remoteIP(); } -# endif if (_telnetClients[i].available()) { uint8_t buf[1024]; COMMANDS::wait(0); @@ -158,9 +152,7 @@ namespace WebUI { } } else { if (_telnetClients[i]) { -# ifdef ENABLE_TELNET_WELCOME_MSG _telnetClientsIP[i] = IPAddress(0, 0, 0, 0); -# endif _telnetClients[i].stop(); } } @@ -240,4 +232,4 @@ namespace WebUI { Telnet_Server::~Telnet_Server() { end(); } } -#endif // Enable TELNET && ENABLE_WIFI +#endif diff --git a/Grbl_Esp32/src/WebUI/TelnetServer.h b/Grbl_Esp32/src/WebUI/TelnetServer.h index 83af4e89..80b2df53 100644 --- a/Grbl_Esp32/src/WebUI/TelnetServer.h +++ b/Grbl_Esp32/src/WebUI/TelnetServer.h @@ -22,6 +22,8 @@ #include "../Config.h" +#ifdef ENABLE_WIFI + class WiFiServer; class WiFiClient; @@ -55,9 +57,7 @@ namespace WebUI { static bool _setupdone; static WiFiServer* _telnetserver; static WiFiClient _telnetClients[MAX_TLNT_CLIENTS]; -#ifdef ENABLE_TELNET_WELCOME_MSG static IPAddress _telnetClientsIP[MAX_TLNT_CLIENTS]; -#endif static uint16_t _port; void clearClients(); @@ -70,3 +70,5 @@ namespace WebUI { extern Telnet_Server telnet_server; } + +#endif diff --git a/Grbl_Esp32/src/WebUI/WebServer.cpp b/Grbl_Esp32/src/WebUI/WebServer.cpp index 60937bd9..67d990fc 100644 --- a/Grbl_Esp32/src/WebUI/WebServer.cpp +++ b/Grbl_Esp32/src/WebUI/WebServer.cpp @@ -21,7 +21,7 @@ #include "../Grbl.h" #include "../MachineConfig.h" -#if defined(ENABLE_WIFI) && defined(ENABLE_HTTP) +#ifdef ENABLE_WIFI # include "WifiServices.h" @@ -39,21 +39,15 @@ # include # include # include -# ifdef ENABLE_MDNS -# include -# endif -# ifdef ENABLE_SSDP -# include -# endif -# ifdef ENABLE_CAPTIVE_PORTAL -# include +# include +# include +# include namespace WebUI { const byte DNS_PORT = 53; DNSServer dnsServer; } -# endif # include //embedded response file if no files on SPIFFS @@ -159,7 +153,6 @@ namespace WebUI { _webserver->on("/upload", HTTP_ANY, handle_direct_SDFileList, SDFile_direct_upload); //_webserver->on("/SD", HTTP_ANY, handle_SDCARD); -# ifdef ENABLE_CAPTIVE_PORTAL if (WiFi.getMode() == WIFI_AP) { // if DNSServer is started with "*" for domain name, it will reply with // provided IP to all DNS request @@ -170,9 +163,7 @@ namespace WebUI { //do not forget the / at the end _webserver->on("/fwlink/", HTTP_ANY, handle_root); } -# endif -# ifdef ENABLE_SSDP //SSDP service presentation if (WiFi.getMode() == WIFI_STA) { _webserver->on("/description.xml", HTTP_GET, handle_SSDP); @@ -194,29 +185,28 @@ namespace WebUI { info_all("SSDP Started"); SSDP.begin(); } -# endif + info_all("HTTP Started"); //start webserver _webserver->begin(); -# ifdef ENABLE_MDNS + //add mDNS if (WiFi.getMode() == WIFI_STA) { MDNS.addService("http", "tcp", _port); } -# endif + _setupdone = true; return no_error; } void Web_Server::end() { _setupdone = false; -# ifdef ENABLE_SSDP + SSDP.end(); -# endif //ENABLE_SSDP -# ifdef ENABLE_MDNS + //remove mDNS mdns_service_remove("_http", "_tcp"); -# endif + if (_socket_server) { delete _socket_server; _socket_server = NULL; @@ -325,8 +315,7 @@ namespace WebUI { content += path; _webserver->send(404, "text/plain", content); return; - } else - if (SPIFFS.exists(pathWithGz) || SPIFFS.exists(path)) { + } else if (SPIFFS.exists(pathWithGz) || SPIFFS.exists(path)) { if (SPIFFS.exists(pathWithGz)) { path = pathWithGz; } @@ -339,7 +328,6 @@ namespace WebUI { } if (page_not_found) { -# ifdef ENABLE_CAPTIVE_PORTAL if (WiFi.getMode() == WIFI_AP) { String contentType = PAGE_CAPTIVE; String stmp = WiFi.softAPIP().toString(); @@ -358,7 +346,7 @@ namespace WebUI { //_webserver->client().stop(); return; } -# endif + path = "/404.htm"; contentType = getContentType(path); pathWithGz = path + ".gz"; @@ -393,7 +381,6 @@ namespace WebUI { } } -# ifdef ENABLE_SSDP //http SSDP xml presentation void Web_Server::handle_SSDP() { StreamString sschema; @@ -434,7 +421,6 @@ namespace WebUI { _webserver->send(500); } } -# endif void Web_Server::_handle_web_command(bool silent) { //to save time if already disconnected @@ -1547,11 +1533,9 @@ namespace WebUI { void Web_Server::handle() { static uint32_t timeout = millis(); COMMANDS::wait(0); -# ifdef ENABLE_CAPTIVE_PORTAL if (WiFi.getMode() == WIFI_AP) { dnsServer.processNextRequest(); } -# endif if (_webserver) { _webserver->handleClient(); } @@ -1799,4 +1783,4 @@ namespace WebUI { } # endif } -#endif // Enable HTTP && ENABLE_WIFI +#endif diff --git a/Grbl_Esp32/src/WebUI/WebServer.h b/Grbl_Esp32/src/WebUI/WebServer.h index 16851390..a114dac2 100644 --- a/Grbl_Esp32/src/WebUI/WebServer.h +++ b/Grbl_Esp32/src/WebUI/WebServer.h @@ -21,6 +21,9 @@ */ #include "../Config.h" + +#ifdef ENABLE_WIFI + #include "Commands.h" class WebSocketsServer; @@ -73,9 +76,7 @@ namespace WebUI { static AuthenticationIP* GetAuth(IPAddress ip, const char* sessionID); static AuthenticationLevel ResetAuthIP(IPAddress ip, const char* sessionID); #endif -#ifdef ENABLE_SSDP static void handle_SSDP(); -#endif static void handle_root(); static void handle_login(); static void handle_not_found(); @@ -96,3 +97,5 @@ namespace WebUI { extern Web_Server web_server; } + +#endif diff --git a/Grbl_Esp32/src/WebUI/WebSettings.cpp b/Grbl_Esp32/src/WebUI/WebSettings.cpp index 708209f9..a1359157 100644 --- a/Grbl_Esp32/src/WebUI/WebSettings.cpp +++ b/Grbl_Esp32/src/WebUI/WebSettings.cpp @@ -44,7 +44,7 @@ namespace WebUI { StringSetting* wifi_ap_password; #endif -#ifdef ENABLE_NOTIFICATIONS +#ifdef ENABLE_WIFI enum_opt_t notificationOptions = { { "NONE", 0 }, { "LINE", 3 }, @@ -204,8 +204,7 @@ namespace WebUI { #else webPrint("no"); #endif -#if defined(ENABLE_WIFI) -# if defined(ENABLE_HTTP) +#ifdef ENABLE_WIFI webPrint(" # webcommunication: Sync: ", String(web_server.port() + 1)); webPrint(":"); switch (WiFi.getMode()) { @@ -222,7 +221,6 @@ namespace WebUI { webPrint("0.0.0.0"); break; } -# endif webPrint(" # hostname:", wifi_config.Hostname()); if (WiFi.getMode() == WIFI_AP) { webPrint("(AP mode)"); @@ -315,7 +313,7 @@ namespace WebUI { return Error::Ok; } -#ifdef ENABLE_NOTIFICATIONS +#ifdef ENABLE_WIFI static Error showSetNotification(char* parameter, AuthenticationLevel auth_level) { // ESP610 if (*parameter == '\0') { webPrint("", notification_type->getStringValue()); @@ -406,12 +404,8 @@ namespace WebUI { webPrintln("Available Size for update: ", ESPResponseStream::formatBytes(flashsize)); webPrintln("Available Size for SPIFFS: ", ESPResponseStream::formatBytes(SPIFFS.totalBytes())); -# if defined(ENABLE_HTTP) webPrintln("Web port: ", String(web_server.port())); -# endif -# if defined(ENABLE_TELNET) webPrintln("Data port: ", String(telnet_server.port())); -# endif webPrintln("Hostname: ", wifi_config.Hostname()); } @@ -520,7 +514,18 @@ namespace WebUI { webPrintln("Off"); break; } -#endif // ENABLE_WIFI + + webPrint("Notifications: "); + webPrint(notificationsservice.started() ? "Enabled" : "Disabled"); + if (notificationsservice.started()) { + webPrint("("); + webPrint(notificationsservice.getTypeString()); + webPrint(")"); + } + webPrintln(""); +#endif + +#ifdef ENABLE_BLUETOOTH if (hasBluetooth()) { auto bt_config = config->_comms->_bluetoothConfig; webPrint("Current BT Mode: "); @@ -543,15 +548,6 @@ namespace WebUI { webPrintln("Off"); } } -#ifdef ENABLE_NOTIFICATIONS - webPrint("Notifications: "); - webPrint(notificationsservice.started() ? "Enabled" : "Disabled"); - if (notificationsservice.started()) { - webPrint("("); - webPrint(notificationsservice.getTypeString()); - webPrint(")"); - } - webPrintln(""); #endif webPrint("FW version: "); webPrint(GRBL_VERSION); @@ -869,15 +865,17 @@ namespace WebUI { if (*parameter == '\0') { // Display the radio state bool on = false; -#if defined(ENABLE_WIFI) +#ifdef ENABLE_WIFI if (WiFi.getMode() != WIFI_MODE_NULL) { on = true; } #endif +#ifdef ENABLE_BLUETOOTH if (hasBluetooth() && config->_comms->_bluetoothConfig->Is_BT_on()) { on = true; } +#endif webPrintln(on ? "ON" : "OFF"); return Error::Ok; @@ -894,16 +892,18 @@ namespace WebUI { } //Stop everything -#if defined(ENABLE_WIFI) +#ifdef ENABLE_WIFI if (WiFi.getMode() != WIFI_MODE_NULL) { wifi_config.StopWiFi(); } #endif +#ifdef ENABLE_BLUETOOTH if (hasBluetooth()) { if (config->_comms->_bluetoothConfig->Is_BT_on()) { config->_comms->_bluetoothConfig->end(); } } +#endif //if On start proper service if (!on) { @@ -912,17 +912,15 @@ namespace WebUI { } //On -#ifdef WIFI_OR_BLUETOOTH +#ifdef ENABLE_WIFI if (hasWiFi()) { -# if !defined(ENABLE_WIFI) - webPrintln("WiFi is not enabled!"); - return Error::WifiFailBegin; - -# else wifi_config.begin(); return Error::Ok; -# endif - } else if (hasBluetooth()) { + } +#endif + +#ifdef ENABLE_BLUETOOTH + if (hasBluetooth()) { if (hasBluetooth()) { webPrintln("Bluetooth is not enabled!"); return Error::BtFailBegin; @@ -930,11 +928,10 @@ namespace WebUI { config->_comms->_bluetoothConfig->begin(); return Error::Ok; } - } else { - webPrintln("[MSG: Radio is Off]"); - return Error::Ok; } #endif + + webPrintln("[MSG: Radio is Off]"); return Error::Ok; } @@ -1038,7 +1035,7 @@ namespace WebUI { new WebCommand("path", WEBCMD, WU, NULL, "LocalFS/ListJSON", listLocalFilesJSON); new WebCommand("path", WEBCMD, WU, NULL, "LocalFS/Delete", deleteLocalFile); #endif -#ifdef ENABLE_NOTIFICATIONS +#ifdef ENABLE_WIFI new WebCommand( "TYPE=NONE|PUSHOVER|EMAIL|LINE T1=token1 T2=token2 TS=settings", WEBCMD, WA, "ESP610", "Notification/Setup", showSetNotification); new WebCommand("message", WEBCMD, WU, "ESP600", "Notification/Send", sendMessage); @@ -1075,7 +1072,7 @@ namespace WebUI { #endif // WebUI Settings // Standard WEBUI authentication is user+ to get, admin to set unless otherwise specified -#ifdef ENABLE_NOTIFICATIONS +#ifdef ENABLE_WIFI notification_ts = new StringSetting( "Notification Settings", WEBSET, WA, NULL, "Notification/TS", DEFAULT_TOKEN, 0, MAX_NOTIFICATION_SETTING_LENGTH, NULL); notification_t2 = new StringSetting("Notification Token 2", @@ -1119,7 +1116,7 @@ namespace WebUI { MAX_LOCAL_PASSWORD_LENGTH, &COMMANDS::isLocalPasswordValid); #endif - +#ifdef ENABLE_WIFI // no get, admin to set wifi_ap_password = new StringSetting("AP Password", WEBSET, @@ -1140,5 +1137,6 @@ namespace WebUI { MIN_PASSWORD_LENGTH, MAX_PASSWORD_LENGTH, (bool (*)(char*))WiFiConfig::isPasswordValid); +#endif } } diff --git a/Grbl_Esp32/src/WebUI/WebSettings.h b/Grbl_Esp32/src/WebUI/WebSettings.h index 719f42c3..3ab36926 100644 --- a/Grbl_Esp32/src/WebUI/WebSettings.h +++ b/Grbl_Esp32/src/WebUI/WebSettings.h @@ -29,7 +29,7 @@ namespace WebUI { extern StringSetting* admin_password; #endif -#ifdef ENABLE_NOTIFICATIONS +#ifdef ENABLE_WIFI extern EnumSetting* notification_type; extern StringSetting* notification_t1; extern StringSetting* notification_t2; diff --git a/Grbl_Esp32/src/WebUI/WifiConfig.cpp b/Grbl_Esp32/src/WebUI/WifiConfig.cpp index eb9ee488..38527c38 100644 --- a/Grbl_Esp32/src/WebUI/WifiConfig.cpp +++ b/Grbl_Esp32/src/WebUI/WifiConfig.cpp @@ -467,4 +467,4 @@ namespace WebUI { WiFiConfig::~WiFiConfig() { end(); } } -#endif // ENABLE_WIFI +#endif diff --git a/Grbl_Esp32/src/WebUI/WifiConfig.h b/Grbl_Esp32/src/WebUI/WifiConfig.h index 5c81c551..c1fe4526 100644 --- a/Grbl_Esp32/src/WebUI/WifiConfig.h +++ b/Grbl_Esp32/src/WebUI/WifiConfig.h @@ -40,14 +40,9 @@ namespace WebUI { static const int ESP_APPLY_NOW = 1; //defaults values - static const char* DEFAULT_HOSTNAME = "grblesp"; -#ifdef CONNECT_TO_SSID - static const char* DEFAULT_STA_SSID = CONNECT_TO_SSID; - static const char* DEFAULT_STA_PWD = SSID_PASSWORD; -#else //!CONNECT_TO_SSID - static const char* DEFAULT_STA_SSID = "GRBL_ESP"; - static const char* DEFAULT_STA_PWD = "12345678"; -#endif //CONNECT_TO_SSID + static const char* DEFAULT_HOSTNAME = "grblesp"; + static const char* DEFAULT_STA_SSID = "GRBL_ESP"; + static const char* DEFAULT_STA_PWD = "12345678"; static const char* DEFAULT_STA_IP = "0.0.0.0"; static const char* DEFAULT_STA_GW = "0.0.0.0"; static const char* DEFAULT_STA_MK = "0.0.0.0"; diff --git a/Grbl_Esp32/src/WebUI/WifiServices.cpp b/Grbl_Esp32/src/WebUI/WifiServices.cpp index 86ac5cb7..4abb2608 100644 --- a/Grbl_Esp32/src/WebUI/WifiServices.cpp +++ b/Grbl_Esp32/src/WebUI/WifiServices.cpp @@ -27,21 +27,11 @@ # include # include # include "WifiServices.h" -# ifdef ENABLE_MDNS -# include -# endif -# ifdef ENABLE_OTA -# include -# endif -# ifdef ENABLE_HTTP -# include "WebServer.h" -# endif -# ifdef ENABLE_TELNET -# include "TelnetServer.h" -# endif -# ifdef ENABLE_NOTIFICATIONS -# include "NotificationsService.h" -# endif +# include +# include +# include "WebServer.h" +# include "TelnetServer.h" +# include "NotificationsService.h" # include "Commands.h" namespace WebUI { @@ -59,7 +49,6 @@ namespace WebUI { String& h = config->_comms->_hostname; -# ifdef ENABLE_OTA ArduinoOTA .onStart([]() { String type; @@ -95,8 +84,6 @@ namespace WebUI { } }); ArduinoOTA.begin(); -# endif -# ifdef ENABLE_MDNS //no need in AP mode if (WiFi.getMode() == WIFI_STA) { //start mDns @@ -107,38 +94,24 @@ namespace WebUI { info_all("Start mDNS with hostname:http://%s.local/", h.c_str()); } } -# endif -# ifdef ENABLE_HTTP web_server.begin(); -# endif -# ifdef ENABLE_TELNET telnet_server.begin(); -# endif -# ifdef ENABLE_NOTIFICATIONS notificationsservice.begin(); -# endif + //be sure we are not is mixed mode in setup WiFi.scanNetworks(true); return no_error; } void WiFiServices::end() { -# ifdef ENABLE_NOTIFICATIONS notificationsservice.end(); -# endif -# ifdef ENABLE_TELNET telnet_server.end(); -# endif -# ifdef ENABLE_HTTP web_server.end(); -# endif + //stop OTA -# ifdef ENABLE_OTA ArduinoOTA.end(); -# endif -# ifdef ENABLE_MDNS + //Stop mDNS MDNS.end(); -# endif } void WiFiServices::handle() { @@ -152,15 +125,9 @@ namespace WebUI { WiFi.enableSTA(false); } } -# ifdef ENABLE_OTA ArduinoOTA.handle(); -# endif -# ifdef ENABLE_HTTP web_server.handle(); -# endif -# ifdef ENABLE_TELNET telnet_server.handle(); -# endif } } -#endif // ENABLE_WIFI +#endif diff --git a/platformio.ini b/platformio.ini index b69dc087..2cc87a2b 100644 --- a/platformio.ini +++ b/platformio.ini @@ -18,20 +18,12 @@ default_envs = release [common_env_data] lib_deps_builtin = - ArduinoOTA - BluetoothSerial - DNSServer EEPROM - ESPmDNS FS Preferences SD SPI SPIFFS - Update - WebServer - WiFi - WiFiClientSecure [common] build_flags = @@ -72,3 +64,25 @@ build_type = debug lib_deps = TMCStepper@>=0.7.0,<1.0.0 ESP8266 and ESP32 OLED driver for SSD1306 displays@^4.2.0 + +[env:wifi] +lib_deps = + TMCStepper@>=0.7.0,<1.0.0 + ESP8266 and ESP32 OLED driver for SSD1306 displays@^4.2.0 + ArduinoOTA + DNSServer + ESPmDNS + Update + WebServer + WiFi + WiFiClientSecure + +build_flags = ${common.build_flags} -DENABLE_WIFI + +[env:bt] +lib_deps = + TMCStepper@>=0.7.0,<1.0.0 + ESP8266 and ESP32 OLED driver for SSD1306 displays@^4.2.0 + BluetoothSerial + +build_flags = ${common.build_flags} -DENABLE_BLUETOOTH