-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWiFi.ino
65 lines (59 loc) · 1.54 KB
/
WiFi.ino
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
/*
WiFi module
*/
// ***** Configure WiFi
const char* ssid = "Pat3net";
const char* password = "xxxxx";
const char* SSID_HOME = "Pat3net";
const char* SSID_HOME_PSWD = "xxxxx";
const char* SSID_WORK = "HCP";
const char* SSID_WORK_PSWD = "xxxxx";
const char* SSID_MIFI = "MPate-Hotspot";
const char* SSID_MIFI_PSWD = "xxxxx";
/**************************************************/
void connectWiFi() {
Serial.println("\nScanning for WiFi Networks...");
int numSsid = WiFi.scanNetworks();
if (numSsid == -1) {
Serial.println("no WiFi networks found");
// ??? display message
while(true);
}
for (int thisNet = 0; thisNet < numSsid; thisNet++) {
// check to see if found home or work wifi network
if (WiFi.SSID(thisNet) == SSID_HOME) {
ssid = SSID_HOME;
password = SSID_HOME_PSWD;
break;
}
else if (WiFi.SSID(thisNet) == SSID_WORK) {
ssid = SSID_WORK;
password = SSID_WORK_PSWD;
break;
}
else if (WiFi.SSID(thisNet) == SSID_MIFI) {
ssid = SSID_MIFI;
password = SSID_MIFI_PSWD;
break;
}
// ??? no AP found
}
Serial.print("\nConnecting to ");
Serial.println(ssid);
delay(20);
WiFi.mode(WIFI_STA);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
yield();
}
Serial.println();
Serial.println("CONNECTED!");
Serial.print("IP address: ");
Serial.println(WiFi.localIP());
Serial.print("Signal = ");
Serial.print(WiFi.RSSI());
Serial.println("dBm");
Serial.println();
}