Leakage sensor
Loading...
Searching...
No Matches
wifi-connection.hpp
1#pragma once
2
3#include <ESP8266WiFi.h>
4#include <Ticker.h>
5#include <list>
6#include <vector>
7#include "wifi-dependent.hpp"
8
20{
21 WiFiEventHandler wifiConnectHandler;
22 WiFiEventHandler wifiDisconnectHandler;
23 // Ticker wifiReconnectTimer;
24
25 bool connected = false;
26 std::vector<WifiDependent *> dependents;
27
28 // Singleton "constructor"
29public:
33 static auto getInstance() -> WifiConnection &
34 {
35 static WifiConnection instance;
36 return instance;
37 }
38 // hide constructor, copy constructor and = operator
39private:
40 WifiConnection() = default; // hide default constructor
41 WifiConnection(WifiConnection const &); // Don't implement.
42 WifiConnection(WifiConnection &&) noexcept; // Don't implement.
43 void operator=(WifiConnection const &); // Don't implement.
44 void operator=(WifiConnection &&) noexcept; // Don't implement.
45 ~WifiConnection() = default; // Don't implement.
46
47 // normal methods
48public:
49 auto isConnected() -> bool;
50 void init(std::list<WifiDependent *> dependents);
51 // void addDependent
52 // void removeDependent
53
54private:
55 void init();
56 void connect();
57 void setConnected(bool connected);
58 void notifyDependentsConnected();
59 void notifyDependentsDisconnected();
60
61 static void onWifiConnect(const WiFiEventStationModeGotIP &event);
62 static void onWifiDisconnect(const WiFiEventStationModeDisconnected &event);
63};
A controller for a WiFi connection.
Definition wifi-connection.hpp:20
static auto getInstance() -> WifiConnection &
Definition wifi-connection.hpp:33
auto isConnected() -> bool
Definition wifi-connection.cpp:47
An interface defining a controller that depends on a WiFi connection.
Definition wifi-dependent.hpp:10