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

All registration of callbacks for various "on connection attempt" failures #57

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions src/Arduino_ConnectionHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,10 @@ void ConnectionHandler::addCallback(NetworkConnectionEvent const event, OnNetwor
{
switch (event)
{
case NetworkConnectionEvent::CONNECTED: _on_connect_event_callback = callback; break;
case NetworkConnectionEvent::DISCONNECTED: _on_disconnect_event_callback = callback; break;
case NetworkConnectionEvent::ERROR: _on_error_event_callback = callback; break;
case NetworkConnectionEvent::CONNECTED: _on_connect_event_callback = callback; break;
case NetworkConnectionEvent::DISCONNECTED: _on_disconnect_event_callback = callback; break;
case NetworkConnectionEvent::ERROR: _on_error_event_callback = callback; break;
case NetworkConnectionEvent::CONNECTION_FAILED: _on_connection_failed_event_callback = callback; break;
}
}

Expand Down
7 changes: 6 additions & 1 deletion src/Arduino_ConnectionHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,8 @@ enum class NetworkConnectionState : unsigned int {
enum class NetworkConnectionEvent {
CONNECTED,
DISCONNECTED,
ERROR
ERROR,
CONNECTION_FAILED,
};

typedef void (*OnNetworkEventCallback)();
Expand Down Expand Up @@ -218,6 +219,10 @@ class ConnectionHandler {
virtual NetworkConnectionState update_handleDisconnecting() = 0;
virtual NetworkConnectionState update_handleDisconnected () = 0;

protected:

OnNetworkEventCallback _on_connection_failed_event_callback = NULL;


private:

Expand Down
2 changes: 2 additions & 0 deletions src/Arduino_WiFiConnectionHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ NetworkConnectionState WiFiConnectionHandler::update_handleConnecting()

if (WiFi.status() != NETWORK_CONNECTED)
{
if (_on_connection_failed_event_callback)
_on_connection_failed_event_callback();
#if !defined(__AVR__)
Debug.print(DBG_ERROR, F("Connection to \"%s\" failed"), _ssid);
Debug.print(DBG_INFO, F("Retrying in \"%d\" milliseconds"), CHECK_INTERVAL_TABLE[static_cast<unsigned int>(NetworkConnectionState::CONNECTING)]);
Expand Down