Doxygen with github
Loading...
Searching...
No Matches
ksf::comps::ksWifiConnector Class Reference

A component that manages the WiFi connection. More...

#include <ksWifiConnector.h>

+ Inheritance diagram for ksf::comps::ksWifiConnector:

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.
 
- Public Member Functions inherited from ksf::ksComponent
virtual bool postInit (ksApplication *app)
 Method called after component initialization, used to setup references to other components.
 
- Public Member Functions inherited from ksf::ksRtti
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 Public Member Functions inherited from ksf::ksComponent
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} 
 
- Protected Attributes inherited from ksf::ksComponent
ksComponentState::TYPE componentState { ksComponentState::NotInitialized }
 Holds current state of the component.
 

Detailed Description

A component that manages the WiFi connection.

This component handles WiFi connectivity and automatically reconnects in case of disconnection.

Key functionalities include:

  • MAC address generation for easy identification of ksIotFrameworkLib-based devices.
  • Simple power management using DTIM low-power mode.
  • IP address validation to confirm a successful WiFi connection beyond just the PHY state.
  • Timeout management to handle prolonged connection issues, triggering an application exit and switching to configuration mode if necessary.

Constructor & Destructor Documentation

◆ ksWifiConnector()

ksf::comps::ksWifiConnector::ksWifiConnector ( const char * hostname,
bool savePower = true )

Constructs WiFi connector component.

Parameters
hostnameHostname of the device, used also by mDNS service.
savePowerIf set, will put the device in modem sleep mode. This is useful to reduce power consumption, but increases reaction time.

References savePower, and setupMacAddress().

Member Function Documentation

◆ getInstanceType()

virtual const std::size_t ksf::comps::ksWifiConnector::getInstanceType ( ) const
inlinevirtual

Retrieves type ID of the object.

Returns
Object type ID.

Reimplemented from ksf::ksComponent.

◆ init()

bool ksf::comps::ksWifiConnector::init ( ksApplication * app)
overridevirtual

Initializes WiFi connector component.

Parameters
appPointer to the parent ksApplication.
Returns
True on success, false on fail.

Reimplemented from ksf::ksComponent.

◆ isA()

virtual bool ksf::comps::ksWifiConnector::isA ( const std::size_t id) const
inlinevirtual

Checks whether object is of given type.

Parameters
idType ID to check against.
Returns
True if object is of given type, otherwise false.

Reimplemented from ksf::ksComponent.

◆ isConnected()

bool ksf::comps::ksWifiConnector::isConnected ( ) const

Returns whether WiFi is connected or not.

Returns
True if connected. False otherwise.

Referenced by loop().

◆ loop()

bool ksf::comps::ksWifiConnector::loop ( ksApplication * app)
overridevirtual

Handles WiFi connector component loop logic.

Parameters
appPointer to the parent ksApplication.
Returns
True on success, false on fail.

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.

◆ setupMacAddress()

void ksf::comps::ksWifiConnector::setupMacAddress ( )
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().


The documentation for this class was generated from the following files: