From 804609cc49f8e46378bce1b0c2a8a8ec882723e3 Mon Sep 17 00:00:00 2001 From: Felix Storm Date: Wed, 22 May 2019 10:47:51 +0200 Subject: [PATCH] ESP32: move wifi_init() to BOARD_INIT, wifi status messages --- Marlin/src/HAL/HAL_ESP32/HAL.cpp | 6 +++++- Marlin/src/HAL/HAL_ESP32/HAL.h | 2 ++ Marlin/src/HAL/HAL_ESP32/wifi.cpp | 15 ++++++++++++--- 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/Marlin/src/HAL/HAL_ESP32/HAL.cpp b/Marlin/src/HAL/HAL_ESP32/HAL.cpp index 9002efa81f73..166d74f98741 100644 --- a/Marlin/src/HAL/HAL_ESP32/HAL.cpp +++ b/Marlin/src/HAL/HAL_ESP32/HAL.cpp @@ -92,6 +92,11 @@ esp_adc_cal_characteristics_t characteristics; // -------------------------------------------------------------------------- void HAL_init(void) { + i2s_init(); +} + +void HAL_init_board(void) { + #if ENABLED(WIFISUPPORT) wifi_init(); #if ENABLED(OTASUPPORT) @@ -106,7 +111,6 @@ void HAL_init(void) { spiffs_init(); #endif - i2s_init(); } void HAL_idletask(void) { diff --git a/Marlin/src/HAL/HAL_ESP32/HAL.h b/Marlin/src/HAL/HAL_ESP32/HAL.h index 556a484677b6..4c831edf4fe5 100644 --- a/Marlin/src/HAL/HAL_ESP32/HAL.h +++ b/Marlin/src/HAL/HAL_ESP32/HAL.h @@ -122,5 +122,7 @@ void HAL_adc_start_conversion(uint8_t adc_pin); // Enable hooks into idle and setup for HAL #define HAL_IDLETASK 1 #define HAL_INIT 1 +#define BOARD_INIT() HAL_init_board(); void HAL_idletask(void); void HAL_init(void); +void HAL_init_board(void); diff --git a/Marlin/src/HAL/HAL_ESP32/wifi.cpp b/Marlin/src/HAL/HAL_ESP32/wifi.cpp index 9fb5459ae07a..ba81cd948cb5 100644 --- a/Marlin/src/HAL/HAL_ESP32/wifi.cpp +++ b/Marlin/src/HAL/HAL_ESP32/wifi.cpp @@ -22,6 +22,7 @@ #ifdef ARDUINO_ARCH_ESP32 +#include "../../core/serial.h" #include "../../inc/MarlinConfigPre.h" #if ENABLED(WIFISUPPORT) @@ -38,20 +39,28 @@ AsyncWebServer server(80); #endif void wifi_init() { + + SERIAL_ECHO_MSG("Starting WiFi..."); + WiFi.mode(WIFI_STA); WiFi.begin(WIFI_SSID, WIFI_PWD); while (WiFi.waitForConnectResult() != WL_CONNECTED) { + SERIAL_ERROR_MSG("Unable to connect to WiFi with SSID '" WIFI_SSID "', restarting."); delay(5000); ESP.restart(); } delay(10); - - // Loop forever (watchdog kill) on failure - if (!MDNS.begin(WIFI_HOSTNAME)) for(;;) delay(5000); + if (!MDNS.begin(WIFI_HOSTNAME)) { + SERIAL_ERROR_MSG("Unable to start mDNS with hostname '" WIFI_HOSTNAME "', restarting."); + delay(5000); + ESP.restart(); + } MDNS.addService("http", "tcp", 80); + + SERIAL_ECHOLNPAIR("Successfully connected to WiFi with SSID '" WIFI_SSID "', hostname: '" WIFI_HOSTNAME "', IP address: ", WiFi.localIP().toString().c_str()); } #endif // WIFISUPPORT