From 877db433a471757dec8b2ac2445886cd4ef9bb5a Mon Sep 17 00:00:00 2001 From: Harald Barth Date: Sat, 6 Nov 2021 02:59:57 +0100 Subject: [PATCH] make task startup nicer --- WifiESP32.cpp | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/WifiESP32.cpp b/WifiESP32.cpp index 0aaacd3..49b2116 100644 --- a/WifiESP32.cpp +++ b/WifiESP32.cpp @@ -143,17 +143,25 @@ bool WifiESP::setup(const char *SSid, } server = new WiFiServer(port); // start listening on tcp port server->begin(); - DIAG(F("Server up port %d"),port); + // server started here - xTaskCreatePinnedToCore(wifiLoop, /* Task function. */ - "wifiLoop",/* name of task. */ - 10000, /* Stack size of task */ - NULL, /* parameter of the task */ - 1, /* priority of the task */ - NULL, /* Task handle to keep track of created task */ - 0); /* pin task to core 0 */ + //start loop task + if (pdPASS != xTaskCreatePinnedToCore( + wifiLoop, /* Task function. */ + "wifiLoop",/* name of task. */ + 10000, /* Stack size of task */ + NULL, /* parameter of the task */ + 1, /* priority of the task */ + NULL, /* Task handle to keep track of created task */ + 0)) { /* pin task to core 0 */ + DIAG(F("Could not create wifiLoop task")); + return false; + } + + // report server started after wifiLoop creation + // when everything looks good + DIAG(F("Server up port %d"),port); return true; - return false; } void WifiESP::loop() {