Automatic Curtain  MVP
Software repository for an automatic curtain using stepper motor, TMC2209 and ESP32
connectivity.h
Go to the documentation of this file.
1 
13 #ifndef _CONNECTIVITY_INCLUDE_GUARD
14 #define _CONNECTIVITY_INCLUDE_GUARD
15 
16 #include <ArduinoOTA.h>
17 #include <AsyncTCP.h>
18 #include <ESPAsyncWebServer.h>
19 
20 #include <memory>
21 #include <thread>
22 #include <tuple>
23 
24 #include "../config/config.h"
25 #include "../logging/logging.h"
26 #include "WiFi.h"
27 #include "webpage.h"
28 
29 class Connectivity {
30  public:
36  Connectivity(std::shared_ptr<Logging>& logging, CONFIG_SET::DEVICE_CRED* device_cred);
37 
42  ~Connectivity();
43 
48  void StartOTA();
49 
54  void StartEnsureConnectivity(const CONFIG_SET::DEVICE_CRED device_cred);
55 
61 
66  void HandleOTA();
67 
72  void StopOTA();
73 
80  bool IsConnected();
81 
86  void StartWebpage();
87 
92  void StopWebpage();
93 
98  void StopWiFi();
99 
106  std::tuple<bool, CONFIG_SET::DEVICE_CRED> GetWebpageSubmission();
107 
108  private:
109  std::shared_ptr<Logging> logger_;
110  std::unique_ptr<AsyncWebServer> webpage_server_{nullptr};
111 
112  // boolean vars to store the status of functionalities
113  bool ota_enabled_ = false;
114  bool webpage_enabled_ = false;
115  bool hotspot_enabled_ = false;
116  bool keep_handler_running_ = false;
120  std::unique_ptr<std::thread> ensure_conn_thread_{nullptr};
122 
127  void StartHotspot();
128 
133  void StopHotspot();
134 
142  void EnsureConnectivity();
143 
152 };
153 
154 #endif
void StartEnsureConnectivity(const CONFIG_SET::DEVICE_CRED device_cred)
Start ensuring connectivity.
Definition: connectivity.cpp:41
std::chrono::time_point< std::chrono::system_clock > time_var
Definition: config.h:176
void StartHotspot()
Starts wifi hotspot, basically start wifi in soft access point mode.
Definition: connectivity.cpp:152
bool IsConnected()
Checks if the device is connected to the WiFi.
Definition: connectivity.cpp:148
void EnsureConnectivity()
Check if the device is connected, if not, try to connect it.
Definition: connectivity.cpp:56
Connectivity(std::shared_ptr< Logging > &logging, CONFIG_SET::DEVICE_CRED *device_cred)
Fetches the LED pin from config, setups pin mode, setup WS2812 RGBLED, initializes logger...
Definition: connectivity.cpp:27
void StartOTA()
Set the up Arduino OTA.
Definition: connectivity.cpp:87
bool ota_enabled_
Definition: connectivity.h:113
void StartWebpage()
Creates a server and starts hosting webpage.
Definition: connectivity.cpp:172
bool is_new_submission_available_
Definition: connectivity.h:117
bool keep_handler_running_
Definition: connectivity.h:116
bool webpage_enabled_
Definition: connectivity.h:114
std::mutex webpage_submission_mutex_
Definition: connectivity.h:121
void StopOTA()
Disable OTA.
Definition: connectivity.cpp:139
void StopEnsuringConnectivity()
Check if the device is connected, if not, try to connect it.
Definition: connectivity.cpp:49
std::tuple< bool, CONFIG_SET::DEVICE_CRED > GetWebpageSubmission()
Get the latest submission.
Definition: connectivity.cpp:222
Contains resources related to webpage for eg. html code.
void StopHotspot()
Stops wifi hotspot.
Definition: connectivity.cpp:164
CONFIG_SET::time_var time_last_connected_
Definition: connectivity.h:118
void StopWebpage()
Stops webpage server.
Definition: connectivity.cpp:212
~Connectivity()
Destroy the Connectivity object.
Definition: connectivity.cpp:32
void StopWiFi()
disconnects WiFi
Definition: connectivity.cpp:82
std::shared_ptr< Logging > logger_
Definition: connectivity.h:109
std::unique_ptr< AsyncWebServer > webpage_server_
Definition: connectivity.h:110
std::unique_ptr< std::thread > ensure_conn_thread_
Definition: connectivity.h:120
int GetSecLostConnection()
Return number of seconds of lost connection.
Definition: connectivity.cpp:77
Definition: config.h:164
CONFIG_SET::DEVICE_CRED device_cred_
Definition: connectivity.h:119
CONFIG_SET::DEVICE_CRED webpage_submitted_device_cred_
Definition: connectivity.h:119
void HandleOTA()
Regular call function for syncing OTA requests.
Definition: connectivity.cpp:133
bool hotspot_enabled_
Definition: connectivity.h:115
Definition: connectivity.h:29