ConnectWithWPA

Description


In this example is shown how to connect to a WPA encrypted network using the WiFi Link library on the Arduino STAR OTTO.

Warning:
Use the Arduino IDE 1.8.x  and import the WiFi Link library using the Library Manager.

WiFi Link library


Hardware


Circuit


Connect the board to PC.

Fronte Arduino STAR OTTO


Code


Now, modify the below sketch inserting the name and the password of your network and after upload the code using Arduino IDE.

Note:

If you use the IDE sketch then replace the Serial with SerialUSB.

Warning:

Use the Arduino IDE 1.8.x and check that you have already downloaded the corresponding platform (Arduino STM32F4 Boards) from the Board Manager

/*

This example connects to a WPA encrypted Wifi network.
Then it prints the MAC address of the Wifi module,
the IP address obtained, and other network details.

Circuit:
* Arduino Primo or STAR OTTO or Uno WiFi Developer Edition (with WiFi Link firmware running)

created 13 July 2010
by dlf (Metodo2 srl)
modified 31 May 2012
by Tom Igoe
*/

#include <WiFiLink.h>

char ssid[] = "yournetwork"; // your network SSID (name)
char pass[] = "secretpassword"; // your network password
int status = WL_IDLE_STATUS; // the Wifi radio's status

void setup() {
//Initialize SerialUSB and wait for port to open:
SerialUSB.begin(115200);
while (!SerialUSB) {
; // wait for SerialUSB port to connect. Needed for native USB port only
}

//Check if communication with the wifi module has been established
if (WiFi.status() == WL_NO_WIFI_MODULE_COMM) {
SerialUSB.println("Communication with WiFi module not established.");
while (true);// don't continue:
}

// attempt to connect to Wifi network:
while ( status != WL_CONNECTED) {
SerialUSB.print("Attempting to connect to WPA SSID: ");
SerialUSB.println(ssid);
// Connect to WPA/WPA2 network:
status = WiFi.begin(ssid, pass);

// wait 10 seconds for connection:
delay(10000);
}

// you're connected now, so print out the data:
SerialUSB.print("You're connected to the network");
printCurrentNet();
printWifiData();

}

void loop() {
// check the network connection once every 10 seconds:
delay(10000);
printCurrentNet();
}

void printWifiData() {
// print your WiFi shield's IP address:
IPAddress ip = WiFi.localIP();
SerialUSB.print("IP Address: ");
SerialUSB.println(ip);
SerialUSB.println(ip);

// print your MAC address:
byte mac[6];
WiFi.macAddress(mac);
SerialUSB.print("MAC address: ");
SerialUSB.print(mac[5], HEX);
SerialUSB.print(":");
SerialUSB.print(mac[4], HEX);
SerialUSB.print(":");
SerialUSB.print(mac[3], HEX);
SerialUSB.print(":");
SerialUSB.print(mac[2], HEX);
SerialUSB.print(":");
SerialUSB.print(mac[1], HEX);
SerialUSB.print(":");
SerialUSB.println(mac[0], HEX);

}

void printCurrentNet() {
// print the SSID of the network you're attached to:
SerialUSB.print("SSID: ");
SerialUSB.println(WiFi.SSID());

// print the MAC address of the router you're attached to:
byte bssid[6];
WiFi.BSSID(bssid);
SerialUSB.print("BSSID: ");
SerialUSB.print(bssid[5], HEX);
SerialUSB.print(":");
SerialUSB.print(bssid[4], HEX);
SerialUSB.print(":");
SerialUSB.print(bssid[3], HEX);
SerialUSB.print(":");
SerialUSB.print(bssid[2], HEX);
SerialUSB.print(":");
SerialUSB.print(bssid[1], HEX);
SerialUSB.print(":");
SerialUSB.println(bssid[0], HEX);

// print the received signal strength:
long rssi = WiFi.RSSI();
SerialUSB.print("signal strength (RSSI):");
SerialUSB.println(rssi);

// print the encryption type:
byte encryption = WiFi.encryptionType();
SerialUSB.print("Encryption Type:");
SerialUSB.println(encryption, HEX);
SerialUSB.println();
}

Output

Open the Serial Monitor and check if the board is been connected to your network.
The monitor should show also further info, such as the MAC and IP address of the board:

ConnectWithWPA output