ConnectWithWEP

Description


In this example is shown how to connect to a WEP encrypted network using the WiFi Link library on the Arduino STAR OTTO.
In paticular the sketch allows to print on Serial Monitor also some info, like MAC address and IP address of board.

Note:
If you use a 40-bit WEP, you need a key of 10 hexadecimal characters long, instead for 128-bit, you need a string of 26 characters long.


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:

You can use directly the WiFi Link examples present into IDE but remember you to 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 WEP-encrypted Wifi network.
Then it prints the MAC address of the Wifi module,
the IP address obtained, and other network details.

If you use 40-bit WEP, you need a key that is 10 characters long,
and the characters must be hexadecimal (0-9 or A-F).
e.g. for 40-bit, ABBADEAF01 will work, but ABBADEAF won't work
(too short) and ABBAISDEAF won't work (I and S are not
hexadecimal characters).

For 128-bit, you need a string that is 26 characters long.
D0D0DEADF00DABBADEAFBEADED will work because it's 26 characters,
all in the 0-9, A-F range.

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
modified 10 March 2017
by Sergio Tomasello and Andrea Cannistrá
*/

#include <WiFiLink.h>

char ssid[] = "yourNetwork"; // your network SSID (name)
char key[] = "D0D0DEADF00DABBADEAFBEADED"; // your network key
int keyIndex = 0; // your network key Index number
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 WEP network, SSID: ");
SerialUSB.println(ssid);
status = WiFi.begin(ssid, keyIndex, key);

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

// once you are connected :
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.

ConnectWithWEP output