From 23986579bb02629d688448ac7326322f56f4a39d Mon Sep 17 00:00:00 2001 From: gegu Date: Sun, 24 May 2020 10:02:03 +0200 Subject: [PATCH] Usermod: fix unreachable network services --- usermods/Fix_unreachable_webserver/readme.md | 17 ++++++++ .../Fix_unreachable_webserver/usermod.cpp | 43 +++++++++++++++++++ 2 files changed, 60 insertions(+) create mode 100644 usermods/Fix_unreachable_webserver/readme.md create mode 100644 usermods/Fix_unreachable_webserver/usermod.cpp diff --git a/usermods/Fix_unreachable_webserver/readme.md b/usermods/Fix_unreachable_webserver/readme.md new file mode 100644 index 00000000..5ed17b87 --- /dev/null +++ b/usermods/Fix_unreachable_webserver/readme.md @@ -0,0 +1,17 @@ +# Fix unreachable Webserver + +This modification performs a ping request to the local IP address every 60 seconds. By this procedure the web server remains accessible in some problematic WLAN environments. + +The modification works with static or DHCP IP address configuration + +_Story:_ + +Unfortunately, with all ESP projects where a web server or other network services are running, I have the problem that after some time the web server is no longer accessible. Now I found out that the connection is at least reestablished when a ping request is executed by the device. + +With this modification, in the worst case, the network functions are not available for 60 seconds until the next ping request. + +## Installation + +Copy and replace the file `usermod.cpp` in wled00 directory. + + diff --git a/usermods/Fix_unreachable_webserver/usermod.cpp b/usermods/Fix_unreachable_webserver/usermod.cpp new file mode 100644 index 00000000..f1957da2 --- /dev/null +++ b/usermods/Fix_unreachable_webserver/usermod.cpp @@ -0,0 +1,43 @@ +#include "wled.h" +/* + * This file allows you to add own functionality to WLED more easily + * See: https://github.com/Aircoookie/WLED/wiki/Add-own-functionality + * EEPROM bytes 2750+ are reserved for your custom use case. (if you extend #define EEPSIZE in const.h) + * bytes 2400+ are currently ununsed, but might be used for future wled features + */ + +#include + +const int PingDelayMs = 60000; +long lastCheckTime = 0; +bool connectedWiFi = false; +ping_option pingOpt; + +//Use userVar0 and userVar1 (API calls &U0=,&U1=, uint16_t) + +//gets called once at boot. Do all initialization that doesn't depend on network here +void userSetup() +{ + +} + + +//gets called every time WiFi is (re-)connected. Initialize own network interfaces here +void userConnected() +{ + connectedWiFi = true; + // initialize ping_options structure + memset(&pingOpt, 0, sizeof(struct ping_option)); + pingOpt.count = 1; + pingOpt.ip = WiFi.localIP(); +} + +//loop. You can use "if (WLED_CONNECTED)" to check for successful connection +void userLoop() +{ + if (connectedWiFi && millis()-lastCheckTime > PingDelayMs) + { + ping_start(&pingOpt); + lastCheckTime = millis(); + } +}