Doxygen with github
|
A component that manages the WiFi connection. More...
#include <ksWifiConnector.h>
Public Member Functions | |
virtual const std::size_t | getInstanceType () const |
Retrieves type ID of the object. | |
virtual bool | isA (const std::size_t id) const |
Checks whether object is of given type. | |
ksWifiConnector (const char *hostname, bool savePower=true) | |
Constructs WiFi connector component. | |
virtual | ~ksWifiConnector () |
Destructos WiFi connector component. | |
bool | init (ksApplication *app) override |
Initializes WiFi connector component. | |
bool | loop (ksApplication *app) override |
Handles WiFi connector component loop logic. | |
bool | isConnected () const |
Returns whether WiFi is connected or not. | |
![]() | |
virtual bool | postInit (ksApplication *app) |
Method called after component initialization, used to setup references to other components. | |
![]() | |
virtual | ~ksRtti ()=default |
Destructor. | |
template<typename TType > | |
TType * | as () |
Tries to cast object to the type provided as a template parameter. | |
template<typename TType > | |
const TType * | as () const |
Tries to cast object to the type provided as a template parameter (const version). | |
Static Public Member Functions | |
static const std::size_t | getClassType () |
![]() | |
static const std::size_t | getClassType () |
Public Attributes | |
std::shared_ptr< ksf::evt::ksEvent<> > | onConnected {std::make_shared<ksf::evt::ksEvent<>>()} |
std::shared_ptr< ksf::evt::ksEvent<> > | onDisconnected {std::make_shared<ksf::evt::ksEvent<>>()} |
Protected Member Functions | |
void | setupMacAddress () |
Internal method that generates MAC address for the device. | |
Protected Attributes | ||
misc::ksSimpleTimer | wifiTimeoutTimer | |
Wifi timer - long timeout in case of issues. | ||
misc::ksSimpleTimer | wifiReconnectTimer | |
Wifi timer - reconnection timeout. | ||
misc::ksSimpleTimer | wifiIpCheckTimer | |
Wifi timer - IP check interval. | ||
struct { | ||
bool wasConnected: 1 | ||
True if connected in previous loop. | ||
bool savePower: 1 | ||
True to save power. | ||
bool gotIpAddress: 1 | ||
True if IP address is set. | ||
} | bitflags = {false, true, false} | |
![]() | ||
ksComponentState::TYPE | componentState { ksComponentState::NotInitialized } | |
Holds current state of the component. | ||
A component that manages the WiFi connection.
This component handles WiFi connectivity and automatically reconnects in case of disconnection.
Key functionalities include:
ksf::comps::ksWifiConnector::ksWifiConnector | ( | const char * | hostname, |
bool | savePower = true ) |
Constructs WiFi connector component.
hostname | Hostname of the device, used also by mDNS service. |
savePower | If set, will put the device in modem sleep mode. This is useful to reduce power consumption, but increases reaction time. |
References savePower, and setupMacAddress().
|
inlinevirtual |
|
overridevirtual |
Initializes WiFi connector component.
app | Pointer to the parent ksApplication. |
Reimplemented from ksf::ksComponent.
|
inlinevirtual |
Checks whether object is of given type.
id | Type ID to check against. |
Reimplemented from ksf::ksComponent.
bool ksf::comps::ksWifiConnector::isConnected | ( | ) | const |
Returns whether WiFi is connected or not.
Referenced by loop().
|
overridevirtual |
Handles WiFi connector component loop logic.
app | Pointer to the parent ksApplication. |
Reimplemented from ksf::ksComponent.
References ksf::evt::ksEvent< Params >::broadcast(), ksf::misc::ksSimpleTimer::hasTimePassed(), isConnected(), ksf::misc::ksSimpleTimer::restart(), ksf::misc::ksSimpleTimer::triggered(), wifiIpCheckTimer, wifiReconnectTimer, and wifiTimeoutTimer.
|
protected |
Internal method that generates MAC address for the device.
This MAC is generated by using original ChipID / MAC, but starts with 0xFA 0xF1 and then there are four Chip ID bytes. 0xFA 0xF1 works like prefix / signature to help identyfying devices in router properties / Wireshark (debugging) etc.
Referenced by ksWifiConnector().