diff --git a/src/IotWebConf.cpp b/src/IotWebConf.cpp index bbf1b96..c72f8ef 100644 --- a/src/IotWebConf.cpp +++ b/src/IotWebConf.cpp @@ -258,6 +258,12 @@ void IotWebConf::setConfigSavedCallback(std::function func) this->_configSavedCallback = func; } +void IotWebConf::setStateChangedCallback(std::function func) +{ + this->_stateChangedCallback = func; +} + void IotWebConf::setFormValidator( std::function func) { @@ -629,6 +635,10 @@ void IotWebConf::changeState(NetworkState newState) NetworkState oldState = this->_state; this->_state = newState; this->stateChanged(oldState, newState); + if (this->_stateChangedCallback != nullptr) + { + this->_stateChangedCallback(oldState, newState); + } #ifdef IOTWEBCONF_DEBUG_TO_SERIAL Serial.print("State changed from: "); Serial.print(oldState); diff --git a/src/IotWebConf.h b/src/IotWebConf.h index ae7739c..002ed92 100644 --- a/src/IotWebConf.h +++ b/src/IotWebConf.h @@ -293,6 +293,13 @@ class IotWebConf */ void setConfigSavedCallback(std::function func); + /** + * Specify a callback method, that will be called when ever the state is changed. + * See NetworkState enum for possible values + */ + void setStateChangedCallback(std::function func); + /** * Specify a callback method, that will be called when form validation is required. * If the method will return false, the configuration will not be saved. @@ -600,6 +607,8 @@ class IotWebConf std::function _wifiConnectionCallback = nullptr; std::function _configSavingCallback = nullptr; std::function _configSavedCallback = nullptr; + std::function + _stateChangedCallback = nullptr; std::function _formValidator = nullptr; std::function _apConnectionHandler = &(IotWebConf::connectAp);