-
Notifications
You must be signed in to change notification settings - Fork 0
/
wifi.h
95 lines (74 loc) · 2.09 KB
/
wifi.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#ifndef _wifi_h_
#define _wifi_h_
#include <DNSServer.h>
String defaultPassword = "1234";
DNSServer dnsServer;
void setup_wifi() {
// Connect to WiFi network
//if !dhcp
//wifiManager.setCORSHeader("Your Access-Control-Allow-Origin");
if (!config.enable_dhcp) {
WiFi.config(config.ip, config.gw, config.mask, config.dns1, config.dns2);
}
WiFi.begin(config.ssid, config.password);
logger.println("");
String thisBoard = ARDUINO_BOARD;
logger.println(thisBoard);
// Wait for connection
while (WiFi.status() != WL_CONNECTED) {
delay(500);
logger.print(".");
}
logger.println("");
logger.print("Connected to ");
logger.println(config.ssid);
logger.print("IP address: ");
logger.println(WiFi.localIP());
// Set up mDNS responder:
// - first argument is the domain name, in this example
// the fully-qualified domain name is "esp8266.local"
// - second argument is the IP address to advertise
// we send our IP address on the WiFi network
if (!MDNS.begin("esp8266")) {
logger.println("Error setting up MDNS responder!");
while (1) {
delay(1000);
}
}
NBNS.begin("esp8266");
// Add service to MDNS-SD
MDNS.addService("http", "tcp", 80);
logger.println("mDNS responder started");
}
#define DRD_ADDRESS 0
void setup_drd_detector() {
drd = new DoubleResetDetector(DRD_TIMEOUT, DRD_ADDRESS);
if (drd->detectDoubleReset()) {
logger.println("DRD");
// initialConfig = true;
//TODO: erase eeprom config
//TODO: reboot
}
}
void drd_loop() {
drd->loop();
}
void setup_wifi_ap() {
//bootTime = lastActivity = millis();
WiFi.mode(WIFI_AP_STA);
WiFi.softAPConfig(config.ip, config.gw, config.mask);
WiFi.softAP(String("ESP_") + ESP.getChipId());
while (WiFi.softAPIP() == IPAddress(0, 0, 0, 0)) {
yield();
delay(100);
}
dnsServer.start(53, "*", WiFi.softAPIP()); // DNS spoofing (Only HTTP)
logger.print("AP started. IP:");
logger.println(WiFi.softAPIP());
pinMode(BUILTIN_LED, OUTPUT);
digitalWrite(BUILTIN_LED, LOW);
}
void handle_wifi_ap() {
dnsServer.processNextRequest();
}
#endif