Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added WDT feeds to reduce HW WDT crashes. #395

Merged
merged 10 commits into from
Oct 18, 2021
31 changes: 19 additions & 12 deletions ESPixelStick/ESPixelStick.ino
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,8 @@ void setup()
FPPDiscovery.begin ();

#ifdef ARDUINO_ARCH_ESP8266
ESP.wdtEnable (2000);
// * ((volatile uint32_t*)0x60000900) &= ~(1); // Hardware WDT OFF
ESP.wdtEnable (2000); // 2 seconds
#else
esp_task_wdt_init (5, true);
#endif
Expand Down Expand Up @@ -482,11 +483,9 @@ String serializeCore(bool pretty)
/** Arduino based main loop */
void loop()
{
#ifdef ARDUINO_ARCH_ESP32
esp_task_wdt_reset ();
#else
ESP.wdtFeed ();
#endif // def ARDUINO_ARCH_ESP32
// DEBUG_START;

FeedWDT ();

// Keep the WiFi Open
WiFiMgr.Poll ();
Expand All @@ -500,17 +499,14 @@ void loop()
WebMgr.Process ();

// need to keep the rx pipeline empty
size_t BytesToDiscard = min (1000, LOG_PORT.available ());
size_t BytesToDiscard = min (100, LOG_PORT.available ());
while (0 < BytesToDiscard)
{
FeedWDT ();

// DEBUG_V (String("BytesToDiscard: ") + String(BytesToDiscard));
BytesToDiscard--;
LOG_PORT.read();
#ifdef ARDUINO_ARCH_ESP32
esp_task_wdt_reset ();
#else
ESP.wdtFeed ();
#endif // def ARDUINO_ARCH_ESP32
} // end discard loop

// Reboot handler
Expand All @@ -523,11 +519,13 @@ void loop()

if (ConfigLoadNeeded)
{
FeedWDT ();
loadConfig ();
}

if (ConfigSaveNeeded)
{
FeedWDT ();
SaveConfig ();
}

Expand All @@ -554,3 +552,12 @@ void _logcon (String & DriverName, String Message)
LOG_PORT.println ("[" + String (Spaces) + DriverName + "] " + Message);
LOG_PORT.flush ();
} // logcon

void FeedWDT ()
{
#ifdef ARDUINO_ARCH_ESP32
esp_task_wdt_reset ();
#else
ESP.wdtFeed ();
#endif // def ARDUINO_ARCH_ESP32
}
19 changes: 19 additions & 0 deletions ESPixelStick/src/ESPixelStick.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,25 @@ extern bool reboot;
extern bool IsBooting;
extern bool ResetWiFi;
static const String ConfigFileName = "/config.json";
extern void FeedWDT ();

template <typename J, typename N>
bool setFromJSON (float & OutValue, J& Json, N Name)
{
bool HasBeenModified = false;

if (true == Json.containsKey (Name))
{
float temp = Json[Name];
if (fabs (temp - OutValue) > 0.000005F)
{
OutValue = temp;
HasBeenModified = true;
}
}

return HasBeenModified;
};

template <typename T, typename J, typename N>
bool setFromJSON (T& OutValue, J& Json, N Name)
Expand Down
115 changes: 10 additions & 105 deletions ESPixelStick/src/WebMgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ static Espalexa espalexa;
static EFUpdate efupdate; /// EFU Update Handler
static AsyncWebServer webServer (HTTP_PORT); // Web Server
static AsyncWebSocket webSocket ("/ws"); // Web Socket Plugin
static DynamicJsonDocument webJsonDoc (3 * WebSocketFrameCollectionBufferSize);

//-----------------------------------------------------------------------------
void PrettyPrint (JsonArray& jsonStuff, String Name)
Expand Down Expand Up @@ -187,31 +188,6 @@ void c_WebMgr::init ()
FPPDiscovery.ProcessFPPJson(request);
});

#ifdef USE_REST
// URL's needed for FPP Connect fseq uploading and querying
webServer.on ("/rest", HTTP_GET,
[this](AsyncWebServerRequest* request)
{
RestProcessGET (request);
});

webServer.on ("/rest", HTTP_POST | HTTP_PUT,
[this](AsyncWebServerRequest* request)
{
RestProcessPOST (request);
},

[this] (AsyncWebServerRequest* request, String filename, size_t index, uint8_t* data, size_t len, bool final)
{
RestProcessFile (request, filename, index, data, len, final);
},

[this] (AsyncWebServerRequest* request, uint8_t* data, size_t len, size_t index, size_t total)
{
RestProcessBody (request, data, len, index, total);
});
#endif // def USE_REST

// Static Handlers
webServer.serveStatic ("/UpdRecipe", LittleFS, "/UpdRecipe.json");
// webServer.serveStatic ("/static", LittleFS, "/www/static").setCacheControl ("max-age=31536000");
Expand Down Expand Up @@ -362,8 +338,7 @@ void c_WebMgr::GetConfiguration ()
extern void GetConfig (JsonObject & json);
// DEBUG_START;

DynamicJsonDocument webJsonDoc (4096);

webJsonDoc.clear ();
JsonObject JsonSystemConfig = webJsonDoc.createNestedObject (CN_system);
GetConfig (JsonSystemConfig);
// DEBUG_V ("");
Expand All @@ -388,7 +363,7 @@ void c_WebMgr::GetDeviceOptions ()
// DEBUG_START;
#ifdef SUPPORT_DEVICE_OPTION_LIST
// set up a framework to get the option data
DynamicJsonDocument webJsonDoc (2048);
webJsonDoc.clear ();

if (0 == webJsonDoc.capacity ())
{
Expand Down Expand Up @@ -482,6 +457,8 @@ void c_WebMgr::onWsEvent (AsyncWebSocket* server, AsyncWebSocketClient * client,
// DEBUG_V (WebSocketFrameCollectionBuffer);
// message is all here. Process it

FeedWDT ();

if (WebSocketFrameCollectionBuffer[0] == 'X')
{
// DEBUG_V ("");
Expand All @@ -507,7 +484,7 @@ void c_WebMgr::onWsEvent (AsyncWebSocket* server, AsyncWebSocketClient * client,

// convert the input data into a json structure (use json read only mode)
size_t docSize = strlen ((const char*)(&WebSocketFrameCollectionBuffer[0])) * 3;
DynamicJsonDocument webJsonDoc (docSize);
webJsonDoc.clear ();
DeserializationError error = deserializeJson (webJsonDoc, (const char *)(&WebSocketFrameCollectionBuffer[0]));

// DEBUG_V ("");
Expand Down Expand Up @@ -551,6 +528,8 @@ void c_WebMgr::onWsEvent (AsyncWebSocket* server, AsyncWebSocketClient * client,
}
} // end switch (type)

FeedWDT ();

// DEBUG_V (CN_Heap_colon + String (ESP.getFreeHeap ()));

// DEBUG_END;
Expand Down Expand Up @@ -626,7 +605,7 @@ void c_WebMgr::ProcessXARequest (AsyncWebSocketClient* client)
{
// DEBUG_START;

DynamicJsonDocument webJsonDoc (1024);
webJsonDoc.clear ();
JsonObject jsonAdmin = webJsonDoc.createNestedObject (F ("admin"));

jsonAdmin[CN_version] = VERSION;
Expand Down Expand Up @@ -656,7 +635,7 @@ void c_WebMgr::ProcessXJRequest (AsyncWebSocketClient* client)
{
// DEBUG_START;

DynamicJsonDocument webJsonDoc (2048);
webJsonDoc.clear ();
JsonObject status = webJsonDoc.createNestedObject (CN_status);
JsonObject system = status.createNestedObject (CN_system);

Expand Down Expand Up @@ -1183,80 +1162,6 @@ void c_WebMgr::Process ()
}
} // Process


#ifdef USE_REST
void printRequest (AsyncWebServerRequest* request)
{
// DEBUG_V (String (" version: '") + String (request->version ()) + "'");
// DEBUG_V (String (" method: '") + String (request->method ()) + "'");
// DEBUG_V (String (" url: '") + String (request->url ()) + "'");
// DEBUG_V (String (" host: '") + String (request->host ()) + "'");
// DEBUG_V (String (" contentType: '") + String (request->contentType ()) + "'");
// DEBUG_V (String ("contentLength: '") + String (request->contentLength ()) + "'");
// DEBUG_V (String (" multipart: '") + String (request->multipart ()) + "'");

//List all collected headers
int headers = request->headers ();
int i;
for (i = 0; i < headers; i++)
{
AsyncWebHeader* h = request->getHeader (i);
// DEBUG_V (String (" HEADER: '") + h->name () + "', '" + h->value () + "'");
}

} // printRequest
//-----------------------------------------------------------------------------
void c_WebMgr::RestProcessGET (AsyncWebServerRequest* request)
{
// DEBUG_START;
printRequest (request);

// request->send (200, "text/json", WebSocketFrameCollectionBuffer);


request->send (200, CN_textSLASHplain, "Hello");

// DEBUG_END;

} // RestProcessPOST

//-----------------------------------------------------------------------------
void c_WebMgr::RestProcessPOST (AsyncWebServerRequest* request)
{
// DEBUG_START;
printRequest (request);

request->send (404, CN_textSLASHplain, "Page Not found");

// DEBUG_END;

} // RestProcessGET

//-----------------------------------------------------------------------------
void c_WebMgr::RestProcessFile (AsyncWebServerRequest* request, String filename, size_t index, uint8_t* data, size_t len, bool final)
{
// DEBUG_START;
printRequest (request);

request->send (404, CN_textSLASHplain, "Page Not found");

// DEBUG_END;

} // RestProcessFile

//-----------------------------------------------------------------------------
void c_WebMgr::RestProcessBody (AsyncWebServerRequest* request, uint8_t* data, size_t len, size_t index, size_t total)
{
// DEBUG_START;
printRequest (request);

request->send (404, CN_textSLASHplain, "Page Not found");

// DEBUG_END;

} // RestProcessBody
#endif // def USE_REST

//-----------------------------------------------------------------------------
// create a global instance of the WEB UI manager
c_WebMgr WebMgr;
10 changes: 2 additions & 8 deletions ESPixelStick/src/WebMgr.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ class c_WebMgr
void handleFileUpload (AsyncWebServerRequest* request, String filename, size_t index, uint8_t* data, size_t len, bool final);
void NetworkStateChanged (bool NewNetworkState);
void GetDriverName (String & Name) { Name = "WebMgr"; }

private:

EFUpdate efupdate;
Expand All @@ -70,7 +71,7 @@ class c_WebMgr
};

void init ();
void onWsEvent (AsyncWebSocket* server, AsyncWebSocketClient* client, AwsEventType type, void* arg, uint8_t* data, size_t len);
void onWsEvent (AsyncWebSocket* server, AsyncWebSocketClient* client, AwsEventType type, void* arg, uint8_t* data, size_t len);
void ProcessVseriesRequests (AsyncWebSocketClient * client);
void ProcessGseriesRequests (AsyncWebSocketClient * client);
void ProcessReceivedJsonMessage (DynamicJsonDocument & webJsonDoc, AsyncWebSocketClient * client);
Expand All @@ -91,13 +92,6 @@ class c_WebMgr
void GetInputOptions ();
void GetOutputOptions ();

#ifdef USE_REST
void RestProcessGET (AsyncWebServerRequest* request);
void RestProcessPOST (AsyncWebServerRequest* request);
void RestProcessFile (AsyncWebServerRequest* request, String filename, size_t index, uint8_t* data, size_t len, bool final);
void RestProcessBody (AsyncWebServerRequest* request, uint8_t* data, size_t len, size_t index, size_t total);
#endif // def USE_REST

protected:

}; // c_WebMgr
Expand Down
Loading