This repository has been archived by the owner on Jan 11, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 48
/
Basecamp.hpp
110 lines (91 loc) · 2.64 KB
/
Basecamp.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
/*
Basecamp - ESP32 library to simplify the basics of IoT projects
Written by Merlin Schumacher ([email protected]) for c't magazin für computer technik (https://www.ct.de)
Licensed under GPLv3. See LICENSE for details.
*/
#ifndef Basecamp_h
#define Basecamp_h
#include "debug.hpp"
#include "Configuration.hpp"
#include <Preferences.h>
#include <rom/rtc.h>
#ifndef BASECAMP_NOWIFI
#include "WifiControl.hpp"
#endif
#ifndef BASECAMP_NOWEB
#ifdef BASECAMP_USEDNS
#include <DNSServer.h>
#endif
#include "WebServer.hpp"
#endif
#ifndef BASECAMP_NOMQTT
#include <AsyncMqttClient.h>
#include "mqttGuardInterface.hpp"
#include "freertos/timers.h"
#endif
#ifndef BASECAMP_NOOTA
#include <ArduinoOTA.h>
#endif
class Basecamp
#ifndef BASECAMP_NOMQTT
: public MqttGuardInterface
#endif
{
public:
// How to handle encryption in setup mode (AP mode)
enum class SetupModeWifiEncryption
{
none, ///< Do not use WiFi encryption (open network)
secured, ///< Use ESP32 default encryption (WPA2 at this time)
};
// When to enable the Configuration UI (setup via local webserver)
enum class ConfigurationUI
{
always, ///< Always start the configuration-ui webserver
accessPoint, ///< Only start the server if acting as an access (first setup mode)
};
explicit Basecamp(Basecamp::SetupModeWifiEncryption setupModeWifiEncryption =
Basecamp::SetupModeWifiEncryption::none,
Basecamp::ConfigurationUI configurationUi = Basecamp::ConfigurationUI::always);
~Basecamp() = default;
Configuration configuration;
Preferences preferences;
/** Initialize.
* Give a fixex ap secret here to override the one-time secret
* password generation. If a password is given, the ctor given
* SetupModeWifiEncryption will be overriden to SetupModeWifiEncryption::secure.
*/
bool begin(String fixedWiFiApEncryptionPassword = {});
void handle();
void checkResetReason();
String showSystemInfo();
bool isSetupModeWifiEncrypted();
String getSetupModeWifiName();
String getSetupModeWifiSecret();
String hostname;
#ifndef BASECAMP_NOWIFI
String mac;
WifiControl wifi;
#endif
#ifndef BASECAMP_NOMQTT
AsyncMqttClient mqtt;
static TimerHandle_t mqttReconnectTimer;
static void onMqttDisconnect(AsyncMqttClientDisconnectReason reason);
static void connectToMqtt(TimerHandle_t xTimer);
#endif
#ifndef BASECAMP_NOWEB
#ifdef BASECAMP_USEDNS
#ifdef DNSServer_h
DNSServer dnsServer;
static void DnsHandling(void *);
#endif
#endif
WebServer web;
#endif
private:
String _cleanHostname();
bool shouldEnableConfigWebserver() const;
SetupModeWifiEncryption setupModeWifiEncryption_;
ConfigurationUI configurationUi_;
};
#endif