forked from jqrbp/wemos-mpu9250-gps
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwifiUtils.cpp
executable file
·79 lines (66 loc) · 2.2 KB
/
wifiUtils.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
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
#include <ESP8266WiFi.h>
#include <ESP8266WiFiMulti.h>
#include <WiFiClient.h>
#include <ESP8266mDNS.h>
#include "webUtils.h"
#include "fileUtils.h"
ESP8266WiFiMulti wifiMulti;
const uint8_t ssidNum = 1;
const char* ssid[] = { "iptimean", "wifirouter2"};
const char* ssid_passwd[] = { "anpass5013954", "wifirouter2pass" };
const char* ap_ssid = "myAccessPoint";
const char* ap_password = "myAPPassword";
// wifi status info
String wifiInfoTxt = "";
uint32_t wifiInfoTxtTime = 0;
const uint32_t wifiInfoTxtTimeOut = 5000;
void wifi_setup() {
Serial.print("\r\nConfiguring access point...");
/* You can remove the password parameter if you want the AP to be open. */
WiFi.softAP(ap_ssid, ap_password);
IPAddress myIP = WiFi.softAPIP();
Serial.print("AP IP address: ");
Serial.println(myIP);
for (uint8_t i =0; i < ssidNum; i++) {
wifiMulti.addAP(ssid[i], ssid_passwd[i]);
}
if (wifiMulti.run() == WL_CONNECTED) {
Serial.println("");
Serial.println("WiFi connected");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
}
configTime(3 * 3600, 0, "pool.ntp.org", "time.nist.gov");
if (MDNS.begin("imasgps")) {
Serial.println("MDNS responder started");
}
}
void wifi_loop() {
static bool wl_connected_info_log_flag = true;
if (ssidNum > 0) {
if (wifiMulti.run() == WL_CONNECTED) {
if (millis() - wifiInfoTxtTime > wifiInfoTxtTimeOut) {
wifiInfoTxt = "{\"ip\":\"" + WiFi.localIP().toString() + "\"}\r\n";
SSEBroadcastTxt(wifiInfoTxt);
wifiInfoTxtTime = millis();
if (wl_connected_info_log_flag) {
appendFile("log.txt", wifiInfoTxt.c_str());
wl_connected_info_log_flag = false;
}
}
} else {
wl_connected_info_log_flag = true;
}
}
MDNS.update();
}
void print_ip_address(void) {
if (wifiMulti.run() == WL_CONNECTED) {
Serial.println("");
Serial.println("WiFi connected");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
} else {
Serial.println("wifi is not connected");
}
}