Doxygen with github
Loading...
Searching...
No Matches
ksWifiConnector.h
1/*
2 * Copyright (c) 2021-2025, Krzysztof Strehlau
3 *
4 * This file is a part of the ksIotFramework library.
5 * All licensing information can be found inside LICENSE.md file.
6 *
7 * https://github.com/cziter15/ksIotFrameworkLib/blob/master/LICENSE
8 */
9
10#pragma once
11
12#include "../evt/ksEvent.h"
13#include "../ksComponent.h"
14#include "../misc/ksSimpleTimer.h"
15
16namespace ksf::comps
17{
30 {
31 KSF_RTTI_DECLARATIONS(ksWifiConnector, ksComponent)
32
33 protected:
37
38 struct
39 {
40 bool wasConnected : 1;
41 bool savePower : 1;
42 bool gotIpAddress : 1;
43 } bitflags = {false, true, false};
44
51 void setupMacAddress();
52
53 public:
54 DECLARE_KS_EVENT(onConnected) // onConnected event that user can bind to.
55 DECLARE_KS_EVENT(onDisconnected) // onDisconnected event that user can bind to.
56
57
62 ksWifiConnector(const char* hostname, bool savePower = true);
63
67 virtual ~ksWifiConnector();
68
74 bool init(ksApplication* app) override;
75
81 bool loop(ksApplication* app) override;
82
87 bool isConnected() const;
88 };
89}
A component that manages the WiFi connection.
Definition ksWifiConnector.h:30
misc::ksSimpleTimer wifiIpCheckTimer
Wifi timer - IP check interval.
Definition ksWifiConnector.h:36
bool isConnected() const
Returns whether WiFi is connected or not.
Definition ksWifiConnector.cpp:139
bool gotIpAddress
True if IP address is set.
Definition ksWifiConnector.h:42
bool wasConnected
True if connected in previous loop.
Definition ksWifiConnector.h:40
ksWifiConnector(const char *hostname, bool savePower=true)
Constructs WiFi connector component.
Definition ksWifiConnector.cpp:30
misc::ksSimpleTimer wifiTimeoutTimer
Wifi timer - long timeout in case of issues.
Definition ksWifiConnector.h:34
bool init(ksApplication *app) override
Initializes WiFi connector component.
Definition ksWifiConnector.cpp:79
bool loop(ksApplication *app) override
Handles WiFi connector component loop logic.
Definition ksWifiConnector.cpp:95
void setupMacAddress()
Internal method that generates MAC address for the device.
Definition ksWifiConnector.cpp:53
bool savePower
True to save power.
Definition ksWifiConnector.h:41
virtual ~ksWifiConnector()
Destructos WiFi connector component.
Definition ksWifiConnector.cpp:48
misc::ksSimpleTimer wifiReconnectTimer
Wifi timer - reconnection timeout.
Definition ksWifiConnector.h:35
A class that serves as the base for user-defined applications.
Definition ksApplication.h:44
Base component class.
Definition ksComponent.h:36
A simple timer class that does not rely on component architecture.
Definition ksSimpleTimer.h:27