Skip to content

Commit

Permalink
ESP32: move wifi_init() to BOARD_INIT, wifi status messages
Browse files Browse the repository at this point in the history
  • Loading branch information
felixstorm-c4a8 committed May 23, 2019
1 parent cb7b994 commit 804609c
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
6 changes: 5 additions & 1 deletion Marlin/src/HAL/HAL_ESP32/HAL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -106,7 +111,6 @@ void HAL_init(void) {
spiffs_init();
#endif

i2s_init();
}

void HAL_idletask(void) {
Expand Down
2 changes: 2 additions & 0 deletions Marlin/src/HAL/HAL_ESP32/HAL.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
15 changes: 12 additions & 3 deletions Marlin/src/HAL/HAL_ESP32/wifi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

#ifdef ARDUINO_ARCH_ESP32

#include "../../core/serial.h"
#include "../../inc/MarlinConfigPre.h"

#if ENABLED(WIFISUPPORT)
Expand All @@ -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
Expand Down

0 comments on commit 804609c

Please sign in to comment.