Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/Aircoookie/WLED
Browse files Browse the repository at this point in the history
  • Loading branch information
Aircoookie committed Dec 10, 2020
2 parents 03516e1 + 455a17c commit aefd812
Show file tree
Hide file tree
Showing 11 changed files with 575 additions and 387 deletions.
5 changes: 5 additions & 0 deletions images/Readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
### Additional Logos

Additional awesome logos for WLED can be found here [Aircoookie/Akemi](https://github.com/Aircoookie/Akemi).

<img src="https://github.com/Aircoookie/Akemi/blob/master/akemi/001_cheerful.png">
19 changes: 17 additions & 2 deletions usermods/Fix_unreachable_netservices_v2/readme.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,32 @@
# Fix unreachable net services V2

**Attention: This usermod compiles only for ESP8266**

This usermod-v2 modification performs a ping request to the local IP address every 60 seconds. By this procedure the net services of WLED remains accessible in some problematic WLAN environments.

The modification works with static or DHCP IP address configuration.

**Webinterface**: The number of pings and reconnects is displayed on the info page in the web interface.

_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.

## Webinterface

The number of pings and reconnects is displayed on the info page in the web interface.
The ping delay can be changed. Changes persist after a reboot.

## JSON API

The usermod supports the following state changes:

| JSON key | Value range | Description |
|-------------|------------------|---------------------------------|
| PingDelayMs | 5000 to 18000000 | Deactivdate/activate the sensor |

Changes also persist after a reboot.

## Installation

1. Copy the file `usermod_Fix_unreachable_netservices.h` to the `wled00` directory.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
#pragma once

#include "wled.h"
#if defined(ESP32)
#warning "Usermod FixUnreachableNetServices works only with ESP8266 builds"
class FixUnreachableNetServices : public Usermod
{
};
#endif

#if defined(ESP8266)
#include <ping.h>

/*
Expand All @@ -23,116 +31,138 @@
* 2. Register the usermod by adding #include "usermod_filename.h" in the top and registerUsermod(new MyUsermodClass()) in the bottom of usermods_list.cpp
*/

class FixUnreachableNetServices : public Usermod {
private:
//Private class members. You can declare variables and functions only accessible to your usermod here
unsigned long m_lastTime = 0;

// desclare required variables
const unsigned int PingDelayMs = 60000;
unsigned long m_connectedWiFi = 0;
ping_option m_pingOpt;
unsigned int m_pingCount = 0;

public:
//Functions called by WLED

/*
* setup() is called once at boot. WiFi is not yet connected at this point.
* You can use it to initialize variables, sensors or similar.
*/
void setup() {
//Serial.println("Hello from my usermod!");
}


/*
* connected() is called every time the WiFi is (re)connected
* Use it to initialize network interfaces
*/
void connected() {
//Serial.println("Connected to WiFi!");

++m_connectedWiFi;

// initialize ping_options structure
memset(&m_pingOpt, 0, sizeof(struct ping_option));
m_pingOpt.count = 1;
m_pingOpt.ip = WiFi.localIP();

}


/*
* loop() is called continuously. Here you can check for events, read sensors, etc.
*
* Tips:
* 1. You can use "if (WLED_CONNECTED)" to check for a successful network connection.
* Additionally, "if (WLED_MQTT_CONNECTED)" is available to check for a connection to an MQTT broker.
*
* 2. Try to avoid using the delay() function. NEVER use delays longer than 10 milliseconds.
* Instead, use a timer check as shown here.
*/
void loop() {
if (m_connectedWiFi > 0 && millis()-m_lastTime > PingDelayMs)
{
ping_start(&m_pingOpt);
m_lastTime = millis();
++m_pingCount;
}
}


/*
* addToJsonInfo() can be used to add custom entries to the /json/info part of the JSON API.
* Creating an "u" object allows you to add custom key/value pairs to the Info section of the WLED web UI.
* Below it is shown how this could be used for e.g. a light sensor
*/
void addToJsonInfo(JsonObject& root)
class FixUnreachableNetServices : public Usermod
{
private:
//Private class members. You can declare variables and functions only accessible to your usermod here
unsigned long m_lastTime = 0;

// declare required variables
unsigned long m_pingDelayMs = 60000;
unsigned long m_connectedWiFi = 0;
ping_option m_pingOpt;
unsigned int m_pingCount = 0;
bool m_updateConfig = false;

public:
//Functions called by WLED

/**
* setup() is called once at boot. WiFi is not yet connected at this point.
* You can use it to initialize variables, sensors or similar.
*/
void setup()
{
//Serial.println("Hello from my usermod!");
}

/**
* connected() is called every time the WiFi is (re)connected
* Use it to initialize network interfaces
*/
void connected()
{
//Serial.println("Connected to WiFi!");

++m_connectedWiFi;

// initialize ping_options structure
memset(&m_pingOpt, 0, sizeof(struct ping_option));
m_pingOpt.count = 1;
m_pingOpt.ip = WiFi.localIP();
}

/**
* loop
*/
void loop()
{
if (m_connectedWiFi > 0 && millis() - m_lastTime > m_pingDelayMs)
{
//this code adds "u":{"&#x26A1; Ping fix pings": m_pingCount} to the info object
JsonObject user = root["u"];
if (user.isNull()) user = root.createNestedObject("u");

JsonArray infoArr = user.createNestedArray("&#x26A1; Ping fix pings"); //name
infoArr.add(m_pingCount); //value

//this code adds "u":{"&#x26A1; Reconnects": m_connectedWiFi - 1} to the info object
infoArr = user.createNestedArray("&#x26A1; Reconnects"); //name
infoArr.add(m_connectedWiFi - 1); //value
ping_start(&m_pingOpt);
m_lastTime = millis();
++m_pingCount;
}


/*
* addToJsonState() can be used to add custom entries to the /json/state part of the JSON API (state object).
* Values in the state object may be modified by connected clients
*/
void addToJsonState(JsonObject& root)
if (m_updateConfig)
{
//root["user0"] = userVar0;
serializeConfig();
m_updateConfig = false;
}


/*
* readFromJsonState() can be used to receive data clients send to the /json/state part of the JSON API (state object).
* Values in the state object may be modified by connected clients
*/
void readFromJsonState(JsonObject& root)
}

/**
* addToJsonInfo() can be used to add custom entries to the /json/info part of the JSON API.
* Creating an "u" object allows you to add custom key/value pairs to the Info section of the WLED web UI.
* Below it is shown how this could be used for e.g. a light sensor
*/
void addToJsonInfo(JsonObject &root)
{
//this code adds "u":{"&#x26A1; Ping fix pings": m_pingCount} to the info object
JsonObject user = root["u"];
if (user.isNull())
user = root.createNestedObject("u");

String uiDomString = "&#x26A1; Ping fix pings<span style=\"display:block;padding-left:25px;\">\
Delay <input type=\"number\" min=\"5\" max=\"300\" value=\"";
uiDomString += (unsigned long)(m_pingDelayMs / 1000);
uiDomString += "\" onchange=\"requestJson({PingDelay:parseInt(this.value)});\">sec</span>";

JsonArray infoArr = user.createNestedArray(uiDomString); //name
infoArr.add(m_pingCount); //value

//this code adds "u":{"&#x26A1; Reconnects": m_connectedWiFi - 1} to the info object
infoArr = user.createNestedArray("&#x26A1; Reconnects"); //name
infoArr.add(m_connectedWiFi - 1); //value
}

/**
* addToJsonState() can be used to add custom entries to the /json/state part of the JSON API (state object).
* Values in the state object may be modified by connected clients
*/
void addToJsonState(JsonObject &root)
{
root["PingDelay"] = (m_pingDelayMs/1000);
}

/**
* readFromJsonState() can be used to receive data clients send to the /json/state part of the JSON API (state object).
* Values in the state object may be modified by connected clients
*/
void readFromJsonState(JsonObject &root)
{
if (root["PingDelay"] != nullptr)
{
//userVar0 = root["user0"] | userVar0; //if "user0" key exists in JSON, update, else keep old value
//if (root["bri"] == 255) Serial.println(F("Don't burn down your garage!"));
m_pingDelayMs = (1000 * max(1UL, min(300UL, root["PingDelay"].as<unsigned long>())));
m_updateConfig = true;
}


/*
* getId() allows you to optionally give your V2 usermod an unique ID (please define it in const.h!).
* This could be used in the future for the system to determine whether your usermod is installed.
*/
uint16_t getId()
{
return USERMOD_ID_FIXNETSERVICES;
}

//More methods can be added in the future, this example will then be extended.
//Your usermod will remain compatible as it does not need to implement all methods from the Usermod base class!
}

/**
* provide the changeable values
*/
void addToConfig(JsonObject &root)
{
JsonObject top = root.createNestedObject("FixUnreachableNetServices");
top["PingDelayMs"] = m_pingDelayMs;
}

/**
* restore the changeable values
*/
void readFromConfig(JsonObject &root)
{
JsonObject top = root["FixUnreachableNetServices"];
m_pingDelayMs = top["PingDelayMs"] | m_pingDelayMs;
m_pingDelayMs = max(5000UL, min(18000000UL, m_pingDelayMs));
}

/**
* getId() allows you to optionally give your V2 usermod an unique ID (please define it in const.h!).
* This could be used in the future for the system to determine whether your usermod is installed.
*/
uint16_t getId()
{
return USERMOD_ID_FIXNETSERVICES;
}
};
#endif
17 changes: 0 additions & 17 deletions usermods/Fix_unreachable_webserver/readme.md

This file was deleted.

43 changes: 0 additions & 43 deletions usermods/Fix_unreachable_webserver/usermod.cpp

This file was deleted.

Loading

0 comments on commit aefd812

Please sign in to comment.