Skip to content

Commit

Permalink
Merge pull request wled#941 from gegu/master
Browse files Browse the repository at this point in the history
Usermod: fix unreachable network services
  • Loading branch information
Aircoookie authored May 24, 2020
2 parents 0fc0999 + 2398657 commit a4e0931
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 0 deletions.
17 changes: 17 additions & 0 deletions usermods/Fix_unreachable_webserver/readme.md
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.


43 changes: 43 additions & 0 deletions usermods/Fix_unreachable_webserver/usermod.cpp
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();
}
}

0 comments on commit a4e0931

Please sign in to comment.