Merge pull request #941 from gegu/master
Usermod: fix unreachable network services
This commit is contained in:
commit
a4e093159e
17
usermods/Fix_unreachable_webserver/readme.md
Normal file
17
usermods/Fix_unreachable_webserver/readme.md
Normal file
@ -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.
|
||||||
|
|
||||||
|
|
43
usermods/Fix_unreachable_webserver/usermod.cpp
Normal file
43
usermods/Fix_unreachable_webserver/usermod.cpp
Normal file
@ -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();
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user