-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request wled#941 from gegu/master
Usermod: fix unreachable network services
- Loading branch information
Showing
2 changed files
with
60 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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. | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 <ping.h> | ||
|
||
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(); | ||
} | ||
} |