Here to learn how to make an IOT based WiFi signal strength monitor with OLED and highcharts to create reliable and secure data visualizations and on build java script.
Nowadays for most of our daily tasks we often rely on WiFi router to connect to the internet be it home or workplace. If WiFi router is placed far from us, we will face connectivity issues due to weak signal strength. As a solution to this I have designed a WiFi strength indicator that can measure WiFi signal strength and display that to us in real time.
Circuit Diagram
Components Required
0.96 OLED 4wire Module - 1no
Node MCU ESP8266 12E Dev Module- 1 no
WiFi RSSI
To get the signal strength data we will use WiFi function. In this code you need to change only the SSID and PASSWORD of your router and hit upload. Once you upload the code to ESP8266, open up the serial monitor and you will see the signal strength in dBm.
highcharts
The Highcharts library comes with all the tools you need to create reliable and secure data visualizations. Built on JavaScript and TypeScript, all our charting libraries work with any back-end database or server stack.
Installing Library
To install the library navigate to the Sketch > Include Library > Manage Libraries… Wait for Library Manager to download libraries index and update list of installed libraries.
you need to Download and install the ESPAsyncWebServer library.
Download and install the ESPAsyncTCP library.
Download and install the SSD1306 library.
After installing the required libraries, copy the following code to your Arduino IDE.
Finally, to build the web server we need two different files. One is The Arduino sketch and the other is an HTML file. So, the HTML file should be saved inside a folder called data. It resides inside the Arduino sketch folder, as shown below:
Creating the HTML File
Create an index.html file with the following content.
The index.html file will contain web pages that will be displayed by the server along with JavaScript that will process the formation of graphics. While all server programs and sensor readings are in the .ino file.
The code explains that a new Highcharts object was formed to be rendered to the <div> tag with the chart-distance id in the HTML code. Then, the X-axis is defined as the time of reading the data, and the Y-axis is the value of the reading which is the distance in centimeters (cm). Then, the set Interval function will send data from the server every 0.5 seconds by accessing the “/ Decibelmwatt”endpoint provided by the server and sending the data to the chart object earlier.
arduino code
#include <ESP8266WiFi.h>
#include <ESPAsyncTCP.h>
#include <ESPAsyncWebServer.h>
#include <FS.h>
#include <Wire.h>
#include <SPI.h>
#include "SSD1306.h"
//display(Address of Display, SDA_PIN, SCL_PIN)
SSD1306 display(0x3C, D2, D1);
// Enter the WiFi credentials
//char wifissid[] = "TP-Link_3200";
//char wifipass[] = "95001121379884265554";
// The following values are from https://www.intuitibits.com/2016/03/23/dbm-to-percent-conversion/
int signal_dBM[] = { -100, -99, -98, -97, -96, -95, -94, -93, -92, -91, -90, -89, -88, -87, -86, -85, -84, -83, -82, -81, -80, -79, -78, -77, -76, -75, -74, -73, -72, -71, -70, -69, -68, -67, -66, -65, -64, -63, -62, -61, -60, -59, -58, -57, -56, -55, -54, -53, -52, -51, -50, -49, -48, -47, -46, -45, -44, -43, -42, -41, -40, -39, -38, -37, -36, -35, -34, -33, -32, -31, -30, -29, -28, -27, -26, -25, -24, -23, -22, -21, -20, -19, -18, -17, -16, -15, -14, -13, -12, -11, -10, -9, -8, -7, -6, -5, -4, -3, -2, -1};
int signal_percent[] = {0, 0, 0, 0, 0, 0, 4, 6, 8, 11, 13, 15, 17, 19, 21, 23, 26, 28, 30, 32, 34, 35, 37, 39, 41, 43, 45, 46, 48, 50, 52, 53, 55, 56, 58, 59, 61, 62, 64, 65, 67, 68, 69, 71, 72, 73, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 90, 91, 92, 93, 93, 94, 95, 95, 96, 96, 97, 97, 98, 98, 99, 99, 99, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100};
int strength = 0;
int percentage = 0;
// Replace with your network credentials
const char* ssid = "TP-Link_3200"; // your SSID
const char* password = "95001121379884265554"; // Your Wifi password
// Create AsyncWebServer object on port 80
AsyncWebServer server(80);
String getDecibelmwatt() {
if (WiFi.status() != WL_CONNECTED) {
delay(1000);
}
// Get signal strength if ESP is connected to WiFi
else if (WiFi.status() == WL_CONNECTED) {
// Get the signal percentage value
for (int x = 0; x < 100; x = x + 1) {
if (signal_dBM[x] == strength) {
// Print the received signal strength in percentage
percentage = signal_percent[x];
return String(strength);
// return String(percentage);
break;
}
}
delay(1000);
}
}
void setup () {
// Initialize display
display.init();
// Choose to flip the screen depending upon the display orientation
display.flipScreenVertically();
// Font for the text
display.setFont(ArialMT_Plain_10);
// Setting the text allignment to Center
display.setTextAlignment(TEXT_ALIGN_CENTER);
display.clear();
// Serial port for debugging purposes
Serial.begin (115200);
if (! SPIFFS.begin ()) {
Serial.println ("An Error has occurred while mounting SPIFFS");
return;
}
// Connect to Wi-Fi
WiFi.begin(ssid, password);
display.drawString(64, 15, "Connecting to WiFi...");
display.display();
while (WiFi.status() != WL_CONNECTED) {
delay(1000);
Serial.println("Connecting to WiFi..");
}
// Print connection information
display.clear();
display.drawString(64, 15, "Connected to " + String(ssid));
display.display();
Serial.print("\nConnected to: ");
Serial.println(ssid);
Serial.print("IP address: ");
Serial.println(WiFi.localIP());
Serial.println("");
// Print ESP32 Local IP Address
Serial.println(WiFi.localIP());
// Route for web page
server.on ("/", HTTP_GET, [] (AsyncWebServerRequest * request) {
request-> send (SPIFFS, "/index.html");
});
server.on ("/Decibelmwatt", HTTP_GET, [] (AsyncWebServerRequest * request) {
request-> send_P (200, "text / plain", getDecibelmwatt(). c_str ());
});
// start server
server.begin ();
}
void loop() {
// While checking for signal strength, check if ESP got disconnected
{
if (WiFi.status() != WL_CONNECTED) {
display.clear();
display.drawString(64, 15, "Connection lost");
display.display();
delay(1000);
}
// Get signal strength if ESP is connected to WiFi
else if (WiFi.status() == WL_CONNECTED) {
display.clear();
Serial.println(" ");
Serial.print("WiFi Signal Strength - ");
// Print the received signal strength in dBm
Serial.print("RSSI: ");
strength = WiFi.RSSI();
Serial.print(strength);
Serial.print("dBm");
Serial.print(" ");
// Get the signal percentage value
for (int x = 0; x < 100; x = x + 1) {
if (signal_dBM[x] == strength) {
// Print the received signal strength in percentage
Serial.print("Percentage: ");
percentage = signal_percent[x];
Serial.print(percentage);
Serial.println("%");
break;
}
}
drawProgressBar();
display.display();
delay(1000);
}
}
}
// Using a progress bar for visual strength indication
void drawProgressBar() {
display.drawProgressBar(10, 32, 100, 10, percentage);
display.drawString(64, 0, "WiFi Signal Strength");
display.drawString(64, 15, String(strength) + "dBm" + " | " + String(percentage) + "%");
if (percentage == 0) {
display.drawString(64, 45, "No Signal");
}
else if (percentage == 100) {
display.drawString(64, 45, "Maximum Signal");
}
}
Then, upload the code to your NodeMCU board. Make sure you have selected the right board and COM port. Also, make sure you’ve inserted your WiFi Credentials in the code.
After a successful upload, open the Serial Monitor at a baud rate of 115200. Press the “EN/RST” button on the ESP8266 board. Now it should print its IP address
Now open IP address in the Web page and see the result.
Demo
Comments