Doxygen with github
Loading...
Searching...
No Matches
ksWifiConnector.h
1/*
2 * Copyright (c) 2021-2023, 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 "../ksSimpleTimer.h"
15
16namespace ksf::comps
17{
30 {
31 KSF_RTTI_DECLARATIONS(ksWifiConnector, ksComponent)
32
33 protected:
34 ksSimpleTimer wifiTimeoutTimer{KSF_WIFI_TIMEOUT_MS};
35 ksSimpleTimer wifiReconnectTimer{KSF_WIFI_RECONNECT_TIME_MS};
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
57
62
63 public:
64 DECLARE_KS_EVENT(onConnected) // onConnected event that user can bind to.
65 DECLARE_KS_EVENT(onDisconnected) // onDisconnected event that user can bind to.
66
67
72 ksWifiConnector(const char* hostname, bool savePower = true);
73
79 bool init(ksApplication* app) override;
80
86 bool loop(ksApplication* app) override;
87
92 bool isConnected() const;
93
97 virtual ~ksWifiConnector();
98 };
99}
A component that manages WiFi connection.
Definition ksWifiConnector.h:30
ksSimpleTimer wifiReconnectTimer
Wifi timer - reconnection timeout.
Definition ksWifiConnector.h:35
bool isConnected() const
Returns whether WiFi is connected or not.
Definition ksWifiConnector.cpp:159
ksSimpleTimer wifiIpCheckTimer
Wifi timer - IP check interval.
Definition ksWifiConnector.h:36
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:40
bool init(ksApplication *app) override
Initializes WiFi connector component.
Definition ksWifiConnector.cpp:82
bool loop(ksApplication *app) override
Handles WiFi connector component loop logic.
Definition ksWifiConnector.cpp:115
ksSimpleTimer wifiTimeoutTimer
Wifi timer - long timeout in case of issues.
Definition ksWifiConnector.h:34
void setupMacAddress()
Internal method that generates MAC address for the device.
Definition ksWifiConnector.cpp:57
void wifiDisconnectedInternal()
Internal method called on WiFi disconnection.
Definition ksWifiConnector.cpp:110
bool savePower
True to save power.
Definition ksWifiConnector.h:41
void wifiConnectedInternal()
Internal method called on WiFi connection.
Definition ksWifiConnector.cpp:98
virtual ~ksWifiConnector()
Destructos WiFi connector component.
Definition ksWifiConnector.cpp:164
A class that is a base for user-defined application.
Definition ksApplication.h:43
Base component class.
Definition ksComponent.h:51
Simple timer class, without using component architecture.
Definition ksSimpleTimer.h:27