-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwifiUtilities.h
More file actions
98 lines (83 loc) · 2.23 KB
/
wifiUtilities.h
File metadata and controls
98 lines (83 loc) · 2.23 KB
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
96
97
98
#include <SPI.h>
#include <WiFiNINA.h>
void checkWifiStatus() {
if (WiFi.status() == WL_NO_MODULE) {
Serial.println("Communication with WiFi module failed!");
Serial.println("Restarting");
restart();
}
}
void checkFirmwareVersion() {
String wifiFirmwareVersion = WiFi.firmwareVersion();
if (wifiFirmwareVersion < WIFI_FIRMWARE_LATEST_VERSION) {
Serial.println("Please upgrade the firmware from " + wifiFirmwareVersion + " to " + (String)WIFI_FIRMWARE_LATEST_VERSION);
}
}
void printMacAddress(byte mac[]) {
for (int i = 5; i >= 0; i--) {
if (mac[i] < 16) {
Serial.print("0");
}
Serial.print(mac[i], HEX);
if (i > 0) {
Serial.print(":");
}
}
Serial.println();
}
void printWiFiData() {
// print your board's IP address:
IPAddress ip = WiFi.localIP();
Serial.print("IP address : ");
Serial.println(ip);
Serial.print("Subnet mask: ");
Serial.println((IPAddress)WiFi.subnetMask());
Serial.print("Gateway IP : ");
Serial.println((IPAddress)WiFi.gatewayIP());
// print your MAC address:
byte mac[6];
WiFi.macAddress(mac);
Serial.print("MAC address: ");
printMacAddress(mac);
}
void printCurrentNet() {
Serial.print("SSID: ");
Serial.println(WiFi.SSID());
byte bssid[6];
WiFi.BSSID(bssid);
Serial.print("BSSID: ");
printMacAddress(bssid);
long rssi = WiFi.RSSI();
Serial.print("signal strength (RSSI): ");
Serial.println(rssi);
// print the encryption type:
byte encryption = WiFi.encryptionType();
Serial.print("Encryption Type: ");
Serial.println(encryption, HEX);
Serial.println();
}
void connectToWifi(char ssid[], char pass[]) {
int status = WL_IDLE_STATUS;
Serial.println();
Serial.print("Attempting to connect to WPA SSID: ");
Serial.print(ssid);
int attepmts = 0;
while (status != WL_CONNECTED && attepmts < 10) {
attepmts++;
Serial.print(".");
status = WiFi.begin(ssid, pass);
if (status != WL_CONNECTED) {
delay(30000);
}
}
Serial.println();
Serial.println();
if (status != WL_CONNECTED) {
Serial.println("Could not connect to the WiFi network");
Serial.println("Restarting");
restart();
}
Serial.println("You're connected to the network");
printCurrentNet();
printWiFiData();
}