-
Notifications
You must be signed in to change notification settings - Fork 1
/
AccessPoint.cpp
45 lines (38 loc) · 1.02 KB
/
AccessPoint.cpp
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
#include "AccessPoint.h"
#include "Tools.h"
AccessPoint::AccessPoint(IPAddress ip, IPAddress gateway, IPAddress subnet, String ssidPrefix) {
m_ip = ip;
m_gateway = gateway;
m_subnet = subnet;
m_ssidPrefix = ssidPrefix;
m_running = false;
}
void AccessPoint::Begin(int autoClose) {
Serial.println("Starting access point ...");
WiFi.enableSTA(false);
WiFi.enableAP(true);
String ssid = m_ssidPrefix + "-" + Tools::GetChipId();
WiFi.softAPConfig(m_ip, m_ip, m_subnet);
WiFi.softAP(ssid.c_str());
Serial.println("running, SSID=" + ssid);
Serial.println("IP=" + WiFi.softAPIP().toString());
m_autoClose = autoClose;
m_startMillis = millis();
m_running = true;
}
void AccessPoint::End() {
Serial.println("Closing access point");
m_running = false;
m_autoClose = 0;
WiFi.enableAP(false);
}
void AccessPoint::Handle() {
if(m_autoClose > 0 && m_running) {
if(millis() - m_startMillis > (uint)m_autoClose * 1000) {
End();
}
}
}
bool AccessPoint::IsRunning() {
return m_running;
}