-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWiFiManager.h
72 lines (47 loc) · 1.82 KB
/
WiFiManager.h
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
#ifndef __WiFiManager_H
#define __WiFiManager_H
#include "application.h"
/*
Class to manage WiFi.
It always falls back to WiFi direct mode (listen).
For example if the network is not available, or if the password is wrong.
It automatically will try to reconnect of the network has been found again.
Power cycle is not implemented, don't know if this is necessary?
// https://github.com/kennethlimcp/particle-examples/blob/master/wifi-auto-reconnect/wifi-auto-reconnect.ino
*/
#define WDEBUG 1
#define WIFI_DIRECT_SSID_ATTEMPT_CALL_TIMEOUT 60000
#define CHECK_SSID_AVAILABLE_TIMEOUT 15000
#define ATTEMPT_CONNECTING_TIMEOUT 15000
#define ONE_DAY_MILLIS (24 * 60 * 60 * 1000)
class WiFiManager {
public:
boolean failedConnectionAttemptFlag = false;
boolean weakRSSIFlag = false;
WiFiManager();
virtual ~WiFiManager();
void setup();
void loop();
bool connected();
void resetWiFiRetryConnectTimer();
bool isFirstScan;
private:
// global because accessible from wifi_scan_callback and isStoredSSIDAvailable functions.
// we always set this, because maybe on the road WAPs will be added (without a reset)
WiFiAccessPoint storedWAPs[5];
int storedWAPsAmount = 0;
bool isStoredSSIDFound = false;
int foundSSID_RSSI;
enum WiFiManagerState { WIFI_DIRECT, WIFI_CONNECTED, WIFI_CHECK_SSID_AVAILABLE, WIFI_ATTEMPT_CONNECTING, WIFI_OFF };
enum WiFiManagerState state = WIFI_CONNECTED;
enum WiFiManagerState previousState = WIFI_OFF;
unsigned long currentStateStartTime;
unsigned long lastWiFiStateUpdateTime;
unsigned long lastConnectAttemptTime;
unsigned long lastRtcUpdateTime;
void updateWiFiStates();
static void handle_ap(WiFiAccessPoint* wap, WiFiManager* self);
void next(WiFiAccessPoint& ap);
bool isStoredSSIDAvailable();
};
#endif