Final project
Wi-Fi Strength Measurement¶
Wi-Fi strength measurement refers to the process of determining the quality and reliability of a Wi-Fi signal at a particular location. This measurement is typically expressed in terms of signal strength, often represented in decibels relative to one milliwatt (dBm). It helps assess how well a Wi-Fi network can support data transmission and connectivity. Common methods to measure Wi-Fi strength include:
-
RSSI (Received Signal Strength Indicator): A metric provided by Wi-Fi adapters indicating the power level of the received signal.
-
dBm: A logarithmic measurement of signal strength; higher values (closer to 0 dBm) indicate stronger signals, while lower values (e.g., -90 dBm) indicate weaker signals.
Tools like Wi-Fi analyzers and signal strength meters on smartphones or laptops are commonly used for these measurements. Wi-Fi strength measurement is crucial for optimizing network performance, troubleshooting connectivity issues, and ensuring reliable wireless communication.
ESP32¶
Receiver Code¶
#include <WiFi.h>
// Replace with your access point credentials
const char* ssid = "ReceiverESP32";
const char* password = "receiverpassword";
// IP and port of the Transmitter ESP32
const char* transmitterIP = "192.168.1.100";
const int transmitterPort = 12345;
WiFiServer server(80);
WiFiClient client;
void setup() {
Serial.begin(115200);
// Start Wi-Fi in Access Point mode
WiFi.softAP(ssid, password);
Serial.println("Receiver ESP32 started as Access Point");
// Start UDP client
client.connect(transmitterIP, transmitterPort);
if (client.connected()) {
Serial.println("Connected to Transmitter ESP32");
} else {
Serial.println("Failed to connect to Transmitter ESP32");
}
}
void loop() {
int n = WiFi.scanNetworks(); // Scan for available networks
if (n > 0) {
for (int i = 0; i < n; i++) {
String data = "SSID: " + WiFi.SSID(i) + " | RSSI: " + String(WiFi.RSSI(i));
Serial.println(data);
if (client.connected()) {
client.println(data); // Send data to Transmitter ESP32
}
}
} else {
Serial.println("No networks found");
}
delay(z); // Delay between scans
}
Transmitter Code¶
#include <WiFi.h>
const char* ssid = "TransmitterESP32";
const char* password = "transmitterpassword";
WiFiServer server(12345);
void setup() {
Serial.begin(115200);
// Start Wi-Fi in Access Point mode
WiFi.softAP(ssid, password);
Serial.println("Transmitter ESP32 started as Access Point");
// Start the server
server.begin();
Serial.println("Server started, waiting for connection...");
}
void loop() {
WiFiClient client = server.available(); // Check for incoming clients
if (client) {
Serial.println("Client connected");
while (client.connected()) {
if (client.available()) {
String line = client.readStringUntil('\n');
Serial.println(line); // Print received data
}
}
client.stop();
Serial.println("Client disconnected");
}
}
Results¶
MKR1010 & LED¶
The code for the Arduino MKR 1010 includes two parts: one MKR 1010 configured as an access point (AP) and another as a client. The AP code sets up a Wi-Fi network with a specified SSID and password, allowing other devices to connect. The client code connects to this AP, measures the Wi-Fi signal strength (RSSI), and uses two LEDs to indicate signal strength: a red LED for strong signals and a blue LED for weak signals. The client continuously monitors the signal strength and updates the LED status accordingly, providing a visual representation of the Wi-Fi signal quality. Adjustments to the threshold values for weak and strong signals can be made based on the specific environment.
Access Point Code¶
#include <SPI.h>
#include <WiFiNINA.h>
const char* ssid = "MKR1010_AP";
const char* password = "12345678";
void setup() {
Serial.begin(9600);
// Check for the WiFi module
if (WiFi.status() == WL_NO_MODULE) {
Serial.println("Communication with WiFi module failed!");
while (true);
}
// Configure as Access Point
Serial.print("Setting up Access Point: ");
Serial.println(ssid);
int status = WiFi.beginAP(ssid, password);
if (status != WL_AP_LISTENING) {
Serial.println("Creating Access Point failed!");
while (true);
}
Serial.println("Access Point created successfully");
}
void loop() {
// AP logic can be added here
delay(1000);
}
Client Code¶
#include <SPI.h>
#include <WiFiNINA.h>
// Define LED pins
const int blueLedPin = 6;
const int redLedPin = 7;
// Wi-Fi credentials
const char* ssid = "MKR1010_AP";
const char* password = "12345678";
// Threshold for signal strength (dBm)
const int weakThreshold = -70; // Adjust as needed
const int strongThreshold = -50; // Adjust as needed
void setup() {
// Initialize serial communication
Serial.begin(9600);
// Initialize LED pins
pinMode(blueLedPin, OUTPUT);
pinMode(redLedPin, OUTPUT);
// Connect to Wi-Fi
Serial.println("Connecting to Wi-Fi...");
WiFi.begin(ssid, password);
// Wait for connection
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("Connected to Wi-Fi");
// Print the IP address
Serial.print("IP Address: ");
Serial.println(WiFi.localIP());
}
void loop() {
// Measure Wi-Fi signal strength
int32_t rssi = WiFi.RSSI();
// Print signal strength to Serial Monitor
Serial.print("Signal Strength (RSSI): ");
Serial.println(rssi);
// Control LEDs based on signal strength
if (rssi >= strongThreshold) {
// Strong signal
digitalWrite(redLedPin, HIGH); // Red LED on
digitalWrite(blueLedPin, LOW); // Blue LED off
} else if (rssi <= weakThreshold) {
// Weak signal
digitalWrite(redLedPin, LOW); // Red LED off
digitalWrite(blueLedPin, HIGH); // Blue LED on
} else {
// Intermediate signal strength
digitalWrite(redLedPin, LOW); // Red LED off
digitalWrite(blueLedPin, LOW); // Blue LED off
}
// Delay before the next measurement
delay(1000);
}
ESP32 & LED¶
Access Point Code¶
#include <WiFi.h>
const char* ssid = "ESP32_AP";
const char* password = "12345678";
void setup() {
Serial.begin(115200);
// Configure as Access Point
Serial.print("Setting up Access Point: ");
Serial.println(ssid);
WiFi.softAP(ssid, password);
Serial.println("Access Point created successfully");
Serial.print("IP Address: ");
Serial.println(WiFi.softAPIP());
}
void loop() {
// AP logic can be added here
delay(1000);
}
Client Code¶
#include <WiFi.h>
// Define LED pins
const int blueLedPin = 2; // GPIO2 for blue LED
const int redLedPin = 4; // GPIO4 for red LED
// Wi-Fi credentials
const char* ssid = "ESP32_AP";
const char* password = "12345678";
// Threshold for signal strength (dBm)
const int weakThreshold = -70; // Adjust as needed
const int strongThreshold = -50; // Adjust as needed
void setup() {
// Initialize serial communication
Serial.begin(115200);
// Initialize LED pins
pinMode(blueLedPin, OUTPUT);
pinMode(redLedPin, OUTPUT);
// Connect to Wi-Fi
Serial.println("Connecting to Wi-Fi...");
WiFi.begin(ssid, password);
// Wait for connection
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("Connected to Wi-Fi");
// Print the IP address
Serial.print("IP Address: ");
Serial.println(WiFi.localIP());
}
void loop() {
// Measure Wi-Fi signal strength
int32_t rssi = WiFi.RSSI();
// Print signal strength to Serial Monitor
Serial.print("Signal Strength (RSSI): ");
Serial.println(rssi);
// Control LEDs based on signal strength
if (rssi >= strongThreshold) {
// Strong signal
digitalWrite(redLedPin, HIGH); // Red LED on
digitalWrite(blueLedPin, LOW); // Blue LED off
} else if (rssi <= weakThreshold) {
// Weak signal
digitalWrite(redLedPin, LOW); // Red LED off
digitalWrite(blueLedPin, HIGH); // Blue LED on
} else {
// Intermediate signal strength
digitalWrite(redLedPin, LOW); // Red LED off
digitalWrite(blueLedPin, LOW); // Blue LED off
}
// Delay before the next measurement
delay(1000);
}