Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WiFi: ARP gratuitous API for wifi station mode #6889

Merged
merged 20 commits into from Apr 9, 2020
Merged

Conversation

d-a-v
Copy link
Collaborator

@d-a-v d-a-v commented Dec 7, 2019

Based on multiple reports and examples

fixes #6886
fixes #5998 (together with #6484, hopefully)

@TD-er
Copy link
Contributor

TD-er commented Dec 7, 2019

Just looking at the code and I think this is probably not optimal to use.

bool ESP8266WiFiSTAClass::stationKeepAliveEnabled ()
{
    return _keepStationAliveUs != 0;
}

void ESP8266WiFiSTAClass::stationKeepAliveStop ()
{
    _keepStationAliveUs = -1;
    // will be set to 0 at recurrent call
}

bool ESP8266WiFiSTAClass::stationKeepAliveSetupMs (int ms)
{
    if (_keepStationAliveUs != 0 || ms <= 0)
        return false;
[...]

So on other words, you can only change the value by calling stop and then wait for the next scheduled interval before you can even set a new value.
Worst case scenario is to wait for as long as the previous set interval.
It would make sense to set the interval to anything > 0 and if you want to stop it, call the stop function.
Now you just have to poll as long as you receive false to set a new interval.

Also I do miss to send (or restart the scheduler) when a wifi connection to the AP is established.
That's the most important one to send these ARP packets. If it was set to for example 10 seconds and you make a connection right after the scheduler tried sending these ARP packets, you may be unable to make a connection to another host, for about 10 seconds after successful wifi connection was established.

@d-a-v
Copy link
Collaborator Author

d-a-v commented Dec 8, 2019

@TD-er please review the API change

@d-a-v
Copy link
Collaborator Author

d-a-v commented Dec 8, 2019

@TD-er the API has changed, based on your use case. Setting the interval will:

  • cancel everything that was planned
  • immediately send a packet
  • schedule the next ones based on the new interval

@marrold
Copy link

marrold commented Dec 12, 2019

Novice question, is there a simple way I can test this branch in platformio?

@d-a-v
Copy link
Collaborator Author

d-a-v commented Dec 12, 2019

If you are using git for this repository in your platformIO setup, then yes.
You first need to checkout this PR (help with this) then rebuild using PIO.

@d-a-v d-a-v mentioned this pull request Mar 5, 2020
6 tasks
@Jason2866
Copy link
Contributor

Sorry for replying sooo late. We had no equipment until now to reproduce the issue (of not beeing reachable via http after a while) in our wifi setups. Since a few days i have a OpenWRT AP which has this issue...
@s-hadinger implemented your changes as backport in a Tasmota test version https://github.com/s-hadinger/Tasmota/tree/arp_dev
Using this version (which sends every minute Gratiuitous ARP) device keeps beeing reachable.
The issue is solved (at least for OpenWRT)

It would be great if you merge this PR that all users can benefit from this option to solve issues
of devices not reachable because ARP seems to get lost if no Gratiuitous ARP is done.

@s-hadinger
Copy link
Contributor

I confirm this feature is useful with some wifi routers. I ported this feature in Tasmota, and it would be great for it to be integrated natively in Arduino Core. Some other projects might benefit from it.

@d-a-v d-a-v added this to the 2.7.0 milestone Apr 7, 2020
@d-a-v d-a-v closed this Apr 7, 2020
@d-a-v d-a-v deleted the gratuitous branch April 7, 2020 21:14
@devyte devyte self-assigned this Apr 8, 2020
@d-a-v d-a-v restored the gratuitous branch April 8, 2020 10:21
@d-a-v d-a-v self-assigned this Apr 8, 2020
@d-a-v d-a-v reopened this Apr 8, 2020
@d-a-v
Copy link
Collaborator Author

d-a-v commented Apr 8, 2020

Per internal review comment:

  • use a Ticker, but with adding a new ticker method using recurrent scheduled function once so:
    when tick is fired, function is executed once at next yield() (instead of at next loop())
    This is needed to keep regularity the most we can in cont space.
  • move to a new experimental::ESP8266WiFiGratuitous class

@d-a-v
Copy link
Collaborator Author

d-a-v commented Apr 8, 2020

@ivankravets @platformio I need help with this issue:

Following change does not help (because in that case arduino does not compile Ticker.cpp):

-#include <Ticker.h>
+#include "../../Ticker/src/Ticker.h" // instead of <Ticker.h> (platformio can't find it otherwise)

This Ticker is ours and does not appear in https://platformio.org/lib/search?query=header:Ticker.h .
This is a case where a local library uses another local library.
This is not a problem with arduino.

@d-a-v
Copy link
Collaborator Author

d-a-v commented Apr 9, 2020

Moving #include <Ticker.h> from .cpp to .h didn't help

@valeros
Copy link
Contributor

valeros commented Apr 9, 2020

Hi @d-a-v ! Looks like these changes are going to affect a lot of PlatformIO users since Library Dependency Finder in default mode doesn't look for dependencies in source files. Probably an optimal solution would be to add depends field to the library.properties file for ESP8266WiFi library, e.g.:

name=ESP8266WiFi
version=1.0
author=Ivan Grokhotkov
maintainer=Ivan Grokhtkov <ivan@esp8266.com>
sentence=Enables network connection (local and Internet) using the ESP8266 built-in WiFi.
paragraph=With this library you can instantiate Servers, Clients and send/receive UDP packets through WiFi. The shield can connect either to open or encrypted networks (WEP, WPA). The IP address can be assigned statically or through a DHCP. The library can also manage DNS.
category=Communication
url=
architectures=esp8266
dot_a_linkage=true
depends=Ticker

@s-hadinger
Copy link
Contributor

What about just leaving the stationKeepAliveNow () function and leaving the timer on the client side? In Tasmota that's easy to add a timer for that, and it would avoid bringing yet another library to projects that don't need it.

@d-a-v
Copy link
Collaborator Author

d-a-v commented Apr 9, 2020

@valeros good idea but as @s-hadinger says, it may include Ticker for nothing if gratuitous is not used (unless it is moved in a separate directory ?).
Well, I chose to short-circuit the library and use the core api instead.

@d-a-v d-a-v merged commit bc170e6 into esp8266:master Apr 9, 2020
@d-a-v d-a-v deleted the gratuitous branch August 9, 2020 17:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ESP8266 Doesn't respond to ARP requests WiFi dropouts unless using WiFi.setSleepMode(WIFI_NONE_SLEEP)
7 participants