-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathNetworkManager.h
More file actions
51 lines (39 loc) · 1.44 KB
/
Copy pathNetworkManager.h
File metadata and controls
51 lines (39 loc) · 1.44 KB
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
#pragma once
// Renamed to avoid a name clash with the ESP32 Core v3.x NetworkManager.
#include <Arduino.h>
#include <time.h>
class WifiTimeManager {
public:
void begin();
void update();
bool configure(const String& ssid, const String& password);
bool isWifiConnected() const;
bool isTimeSynced() const { return timeSynced_; }
time_t nowUtc() const;
bool resyncTime();
// Returns false if the NTP resync fails.
bool setTimezone(long gmtOffsetSec, int daylightOffsetSec);
long gmtOffsetSec() const { return gmtOffsetSec_; }
int daylightOffsetSec() const { return daylightOffsetSec_; }
// Current Wi-Fi connection state.
String currentSsid() const;
String currentIp() const;
int32_t currentRssi() const;
// Defers NTP resync during batch imports.
void setImportActive(bool active) { importActive_ = active; }
private:
bool timeSynced_ = false;
bool importActive_ = false;
uint32_t lastSyncAttemptMs_ = 0;
long gmtOffsetSec_ = 0;
int daylightOffsetSec_ = 0;
bool connectBlocking_(const String& ssid,
const String& password,
uint32_t timeoutMs);
bool syncTimeBlocking_(uint32_t timeoutMs);
void loadCredentials_(String& ssidOut, String& passOut);
void saveCredentials_(const String& ssid, const String& password);
// Loads the persisted timezone (or Config.h defaults).
void loadTimezone_();
void saveTimezone_(long gmtOffsetSec, int daylightOffsetSec);
};