Skip to content

Commit cba2b6d

Browse files
committed
Add ConnectWithWPA2Enterprise new example
1 parent 0948021 commit cba2b6d

File tree

3 files changed

+115
-0
lines changed

3 files changed

+115
-0
lines changed

.travis.yml

+1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ script:
3131
- buildExampleSketch ConnectNoEncryption
3232
- buildExampleSketch ConnectWithWEP
3333
- buildExampleSketch ConnectWithWPA
34+
- buildExampleSketch ConnectWithWPA2Enterprise
3435
- buildExampleSketch ScanNetworks
3536
- buildExampleSketch ScanNetworksAdvanced
3637
- buildExampleSketch SimpleWebServerWiFi
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
/*
2+
This example connects to an WPA2 Enterprise WiFi network.
3+
Then it prints the MAC address of the WiFi module,
4+
the IP address obtained, and other network details.
5+
6+
Based on ConnectWithWPA.ino by dlf (Metodo2 srl) and Tom Igoe
7+
*/
8+
#include <SPI.h>
9+
#include <WiFiNINA.h>
10+
11+
#include "arduino_secrets.h"
12+
///////please enter your sensitive data in the Secret tab/arduino_secrets.h
13+
char ssid[] = SECRET_SSID; // your WPA2 enterprise network SSID (name)
14+
char user[] = SECRET_USER; // your WPA2 enterprise username
15+
char pass[] = SECRET_PASS; // your WPA2 enterprise password
16+
int status = WL_IDLE_STATUS; // the Wifi radio's status
17+
18+
void setup() {
19+
//Initialize serial and wait for port to open:
20+
Serial.begin(9600);
21+
while (!Serial) {
22+
; // wait for serial port to connect. Needed for native USB port only
23+
}
24+
25+
// check for the WiFi module:
26+
if (WiFi.status() == WL_NO_MODULE) {
27+
Serial.println("Communication with WiFi module failed!");
28+
// don't continue
29+
while (true);
30+
}
31+
32+
String fv = WiFi.firmwareVersion();
33+
if (fv < WIFI_FIRMWARE_LATEST_VERSION) {
34+
Serial.println("Please upgrade the firmware");
35+
}
36+
37+
// attempt to connect to Wifi network:
38+
while (status != WL_CONNECTED) {
39+
Serial.print("Attempting to connect to WPA SSID: ");
40+
Serial.println(ssid);
41+
// Connect to WPA2 enterprise network:
42+
// - You can optionally provide additional identity and CA cert (string) parameters:
43+
// WiFi.beginEnterprise(ssid, user, pass, identity, caCert)
44+
// . if your network requires them.
45+
status = WiFi.beginEnterprise(ssid, user, pass);
46+
47+
// wait 10 seconds for connection:
48+
delay(10000);
49+
}
50+
51+
// you're connected now, so print out the data:
52+
Serial.print("You're connected to the network");
53+
printCurrentNet();
54+
printWifiData();
55+
56+
}
57+
58+
void loop() {
59+
// check the network connection once every 10 seconds:
60+
delay(10000);
61+
printCurrentNet();
62+
}
63+
64+
void printWifiData() {
65+
// print your board's IP address:
66+
IPAddress ip = WiFi.localIP();
67+
Serial.print("IP Address: ");
68+
Serial.println(ip);
69+
70+
// print your MAC address:
71+
byte mac[6];
72+
WiFi.macAddress(mac);
73+
Serial.print("MAC address: ");
74+
printMacAddress(mac);
75+
}
76+
77+
void printCurrentNet() {
78+
// print the SSID of the network you're attached to:
79+
Serial.print("SSID: ");
80+
Serial.println(WiFi.SSID());
81+
82+
// print the MAC address of the router you're attached to:
83+
byte bssid[6];
84+
WiFi.BSSID(bssid);
85+
Serial.print("BSSID: ");
86+
printMacAddress(bssid);
87+
88+
// print the received signal strength:
89+
long rssi = WiFi.RSSI();
90+
Serial.print("signal strength (RSSI):");
91+
Serial.println(rssi);
92+
93+
// print the encryption type:
94+
byte encryption = WiFi.encryptionType();
95+
Serial.print("Encryption Type:");
96+
Serial.println(encryption, HEX);
97+
Serial.println();
98+
}
99+
100+
void printMacAddress(byte mac[]) {
101+
for (int i = 5; i >= 0; i--) {
102+
if (mac[i] < 16) {
103+
Serial.print("0");
104+
}
105+
Serial.print(mac[i], HEX);
106+
if (i > 0) {
107+
Serial.print(":");
108+
}
109+
}
110+
Serial.println();
111+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#define SECRET_SSID ""
2+
#define SECRET_USER ""
3+
#define SECRET_PASS ""

0 commit comments

Comments
 (0)