-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathNetworkManager.h
More file actions
46 lines (36 loc) · 1.29 KB
/
Copy pathNetworkManager.h
File metadata and controls
46 lines (36 loc) · 1.29 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
#ifndef NETWORK_MANAGER_H
#define NETWORK_MANAGER_H
#include <ArduinoJson.h>
#include "WiFiManager.h"
#include "EthernetManager.h"
#include "ServerConfig.h" // Added for ServerConfig declaration
class NetworkMgr {
private:
static NetworkMgr* instance;
WiFiManager* wifiManager;
EthernetManager* ethernetManager;
String primaryMode; // Configured primary mode (e.g., "ETH", "WIFI")
String activeMode; // Currently active mode
bool networkAvailable; // Overall network availability
TaskHandle_t failoverTaskHandle;
static void failoverTask(void* parameter);
void failoverLoop();
WiFiClient _wifiClient; // Internal WiFiClient for MQTT/HTTP
EthernetClient _ethernetClient; // Internal EthernetClient for MQTT/HTTP
NetworkMgr();
bool initWiFi(const JsonObject& wifiConfig);
bool initEthernet(bool useDhcp, IPAddress staticIp, IPAddress gateway, IPAddress subnet);
void startFailoverTask();
void switchMode(const String& newMode);
public:
static NetworkMgr* getInstance();
bool init(ServerConfig* serverConfig); // Changed parameter type
bool isAvailable();
IPAddress getLocalIP();
String getCurrentMode();
Client* getActiveClient(); // New method to get active client
void cleanup();
void getStatus(JsonObject& status);
~NetworkMgr();
};
#endif