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

A component that manages WiFi connection. More...

#include <ksWifiConnector.h>

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

Public Member Functions

virtual const size_t getInstanceType () const
 Retrieves type ID of the object.
 
virtual bool isA (const size_t id) const
 Checks whether object is of given type.
 
 ksWifiConnector (const char *hostname, bool savePower=true)
 Constructs 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 ~ksWifiConnector ()
 Destructos WiFi connector component.
 
- 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
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 size_t getClassType ()
 
- Static Public Member Functions inherited from ksf::ksComponent
static const 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.
 
void wifiConnectedInternal ()
 Internal method called on WiFi connection.
 
void wifiDisconnectedInternal ()
 Internal method called on WiFi disconnection.
 

Protected Attributes

ksSimpleTimer wifiTimeoutTimer { 120000UL }
 Wifi timer - long timeout in case of issues.
 
ksSimpleTimer wifiReconnectTimer { 5000UL }
 Wifi timer - reconnection timeout.
 
ksSimpleTimer wifiIpCheckTimer { 1000UL }
 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 }
 

Detailed Description

A component that manages WiFi connection.

This component handles WiFi connection, reconnecting automatically in case of disconnection.

There are many things that this component manages:

  • MAC address generation (to easily identify ksIotFrameworkLib based devices)
  • Simple power management (DTIM low-power mode)
  • IP address validation, used to determine if WiFi connection was successful (not only using WiFi PHY state)
  • Timeout management, used to break in case of longer WiFi connection issues (causing application to exit and swittch to configuration mode)

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 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 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::ksSimpleTimer::hasTimePassed(), isConnected(), ksf::ksSimpleTimer::restart(), ksf::ksSimpleTimer::triggered(), wifiConnectedInternal(), wifiDisconnectedInternal(), 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: