Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Implement std::function variants of WiFi.onEvent similar to ESP8266 #1174

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

Closed
PhracturedBlue opened this issue Mar 4, 2018 · 10 comments
Closed
Labels
Status: Stale Issue is stale stage (outdated/stuck)

Comments

@PhracturedBlue
Copy link

Description:

Could we get equivalent functions as the ESP8266 has for WiFi events:

WiFiEventHandler onStationModeConnected(std::function<void(const WiFiEventStationModeConnected&)>);
WiFiEventHandler onStationModeDisconnected(std::function<void(const WiFiEventStationModeDisconnected&)>);
WiFiEventHandler onStationModeAuthModeChanged(std::function<void(const WiFiEventStationModeAuthModeChanged&)>);
WiFiEventHandler onStationModeGotIP(std::function<void(const WiFiEventStationModeGotIP&)>);
WiFiEventHandler onStationModeDHCPTimeout(std::function<void(void)>);
WiFiEventHandler onSoftAPModeStationConnected(std::function<void(const WiFiEventSoftAPModeStationConnected&)>);
WiFiEventHandler onSoftAPModeStationDisconnected(std::function<void(const WiFiEventSoftAPModeStationDisconnected&)>);

These functions allow using std::function, which allows handling events in class functions cleanly.

@sticilface
Copy link
Contributor

I would second this. :)

@timpur
Copy link
Contributor

timpur commented Apr 26, 2018

Any progress on this? Thinking of implementing.

@tripflex
Copy link

tripflex commented May 7, 2018

Yes I third this, not only for functionality but also for easy porting of ESP8266 projects over to ESP32 👍

@aluis-rcastro
Copy link

Any update on this ?

@timpur
Copy link
Contributor

timpur commented Sep 9, 2018

Think this now supported with #1366.

See this for example: https://github.com/timpur/arduino-esp32/blob/d72e8137b3933470bfa8292e801389064fd8d001/libraries/WiFi/examples/WiFiClientEvents/WiFiClientEvents.ino#L78

@ristomatti
Copy link

ristomatti commented Oct 12, 2018

@timpur This probably would not solve the portability of ESP8266 projects @tripflex mentioned as there's not separate functions for each event but at least I find this new approach much more versatile and clean.

@wfraga18
Copy link

wfraga18 commented Mar 7, 2019

I need too

@stale
Copy link

stale bot commented Aug 1, 2019

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the Status: Stale Issue is stale stage (outdated/stuck) label Aug 1, 2019
@stale
Copy link

stale bot commented Aug 15, 2019

This stale issue has been automatically closed. Thank you for your contributions.

@stale stale bot closed this as completed Aug 15, 2019
@alvarolb
Copy link

Think this now supported with #1366.

See this for example: https://github.com/timpur/arduino-esp32/blob/d72e8137b3933470bfa8292e801389064fd8d001/libraries/WiFi/examples/WiFiClientEvents/WiFiClientEvents.ino#L78

Still not have std::function callbacks on events.

   WiFiEventId_t eventID = WiFi.onEvent([](WiFiEvent_t event, WiFiEventInfo_t info){
        Serial.print("WiFi lost connection. Reason: ");
        Serial.println(info.disconnected.reason);
    }, WiFiEvent_t::SYSTEM_EVENT_STA_DISCONNECTED);

In this example there is a lambda without any capturing parameters, which C++ converts to a standard function pointer.

Setting the same lambda with capture by reference will not compile.

   WiFiEventId_t eventID = WiFi.onEvent([&](WiFiEvent_t event, WiFiEventInfo_t info){
        Serial.print("WiFi lost connection. Reason: ");
        Serial.println(info.disconnected.reason);
    }, WiFiEvent_t::SYSTEM_EVENT_STA_DISCONNECTED);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Stale Issue is stale stage (outdated/stuck)
Projects
None yet
Development

No branches or pull requests

8 participants