IoT/ESP32 B.Tech/Diploma Advanced

Control ESP32 and ESP8266 GPIOs from Anywhere in the World

Learn how to control your ESP32 or ESP8266 GPIOs from anywhere in the world. This can be very useful to control a relay, a thermostat, or any device remotely.

  • Suitable forB.Tech/Diploma IoT/ESP32 students
  • Build time1-2 weeks
  • LevelAdvanced
  • Available atAjvika Labs, Kakinada

About this project

In this project, you’ll learn how to control your ESP32 or ESP8266 GPIOs from anywhere in the world. This can be very useful to control a relay, a thermostat, or any other device remotely.
This project is also very versatile. Through your cloud dashboard, you can easily control more outputs (without uploading new code to your board) and you can even connect multiple boards to your server.
Previously, we’ve stored sensor readings into a database and we’ve used different methods to display sensor readings on a:
Table
Charts
Gauges
Now, I’ve created this new project where you can create buttons in a dashboard and assign them to a Board and GPIO number. Then, you can use the toggle switches to control the ESP32 or ESP8266 outputs from anywhere.
There are many ways of controlling outputs from anywhere, and even though this is a working solution there are other
methods that provide a two-way communication with your devices
. I also recommend that you take this project further and add more features to fit your own needs.
To build this project, you’ll use these technologies:
ESP32 or ESP8266 programmed with Arduino IDE
Hosting server and domain name
PHP scripts to store and retrieve the output states stored in a MySQL database
Table of Contents
This project is divided into the following main sections:
Hosting Your PHP Application and MySQL Database
Preparing Your MySQL Database
Creating Your Dashboard Files
PHP Script – Update and Retrieve Output States
PHP Script for Database Functions
PHP Script – Control Buttons
Setting Up the ESP32 or ESP8266
0. Download Source Code
For this project, you’ll need these files:
SQL query to create your table:
Outputs_and_Boards_Table.sql
Insert and access database:
esp-database.php
Handle HTTP requests:
esp-outputs-action.php
CSS file to style your web page:
esp-style.css
Display your control buttons:
esp-outputs.php
Arduino Sketch for ESP32 (
with HTTPS
):
ESP32_HTTPS_GET_Request_JSON.ino
Arduino Sketch for ESP8266 (
with HTTPS
):
ESP8266_HTTPS_GET_Request_JSON.ino
Arduino Sketch for ESP32 (without HTTPS):
ESP32_HTTP_GET_Request_JSON.ino
Arduino Sketch for ESP8266 (without HTTPS):
ESP8266_HTTP_GET_Request_JSON.ino
1. Hosting Your PHP Application and MySQL Database
The goal of this project is to have your own domain name and hosting account that allows you to control your ESP32 or ESP8266 GPIOs from anywhere in the world.
Here’s a high-level overview of how the project works:
You have a web page running a PHP script with some toggle buttons that allow you to control the outputs on and off;
When you press the buttons, it updates the output state and saves it in your database;
You can add more buttons or delete them from your dashboard;
Then, you can have an ESP32 or ESP8266 or even multiple boards that make HTTP GET requests every X number of seconds to your server;
Finally, according to the result of that HTTP GET request, the ESP board updates its GPIOs accordingly.
Hosting Services
I recommend using one of the following hosting services that can handle all the project requirements:
: free domain name when you sign up for the 3-year plan. I recommend choosing the unlimited websites option;
Digital Ocean
: Linux server that you manage through a command line. I only recommended this option for advanced users.
Those two services are the ones that I use and personally recommend, but you can use any other hosting service. Any hosting service that offers PHP and MySQL will work with this tutorial. If you don’t have a hosting account, I recommend
When buying a hosting account, you’ll also have to purchase a domain name. This is what makes this project interesting: you’ll be able to go your domain name (http://example.com) and control your boards.
Note:
you can also run a
LAMP (Linux, Apache, MySQL, PHP) server
on a Raspberry Pi to
control your boards in your local network
. However, the purpose of this tutorial is to control the ESP outputs with your own domain name that you can access from anywhere in the world.
2. Preparing Your MySQL Database
After signing up for a
hosting account and setting up a domain name
, you can login to your cPanel or similar dashboard. After that, follow the next steps to create your database, username, password and SQL table.
Creating a database and user
Open the “
Advanced
” tab:

Type “database” in the search bar and select “MySQL Database Wizard”.

Enter your desired Database name. In my case, the database name is
esp_data
. Then, press the “Next Step” button:
Note:
later you’ll have to use the database name with the prefix that your host gives you (my database prefix in the screenshot above is blurred). I’ll refer to it as
example_esp_data
from now on.

Type your Database username and set a password. You must save all those details, because you’ll need them later to establish a database connection with your PHP code.
That’s it! Your new database and user were created successfully. Now, save all your details because you’ll need them later:
Database name
: example_esp_data
Username
: example_esp_board
Password
: your password
Creating a SQL table
After creating your database and user, go back to cPanel dashboard and search for “phpMyAdmin”.
In the left sidebar, select your database name
example_esp_data
and open the “SQL” tab.
Important:
make sure you’ve opened the
example_esp_data
database. Then, click the SQL tab. If you don’t follow these exact steps and run the SQL query, you might create a table in the wrong database.
Copy the SQL query in the following snippet:
CREATE TABLE Outputs (
id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(64),
board INT(6),
gpio INT(6),
state INT(6)
);
INSERT INTO `Outputs`(`name`, `board`, `gpio`, `state`) VALUES ("Built-in LED", 1, 2, 0);

CREATE TABLE Boards (
id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
board INT(6),
last_request TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
);
INSERT INTO `Boards`(`board`) VALUES (1);
Paste it in the SQL query field (highlighted with a red rectangle) and press the “Go” button to create your table:
After that, you should see your newly created tables called
Boards
and
Outputs
in the
example_esp_data
database as shown in the figure below:
3. Creating Your Dashboard Files
In this section, we’re going to create the files that are responsible for creating your Dashboard. Here are the files:
Insert and access database:
esp-database.php
Handle HTTP requests:
esp-outputs-action.php
CSS file to style your web page:
esp-style.css
Display your control buttons:
esp-outputs.php
If you’re using a hosting provider with cPanel, you can search for “File Manager”:
Then, select the
public_html
option and press the “+ File” button to create a new file.
Note:
if you’re following this tutorial and you’re not familiar with PHP, I recommend creating these exact files.
Create four new files in
/public_html
with these exact names and extensions:
esp-database.php
esp-outputs-action.php
esp-outputs.php
esp-style.css
4. PHP Script – Update and Retrieve Output States
In this section, we’re going to create a PHP script that is responsible for receiving incoming requests and interacting with your MySQL database.
Edit the newly created file (
esp-outputs-action.php
) and copy the following snippet:
<?php
include_once('esp-database.php');

$action = $id = $name = $gpio = $state = "";

if ($_SERVER["REQUEST_METHOD"] == "POST") {
$action = test_input($_POST["action"]);
if ($action == "output_create") {

Technologies used

ESP32ESP8266ArduinoRaspberry PiBLERelayPHPMySQLArduino IDEHTMLCSS

Hardware components

  • ESP32
  • ESP8266
  • Arduino
  • Raspberry Pi
  • Relay

Software & tools

  • Arduino IDE

What you get

  • Working project / hardware kit, tested before delivery
  • Complete source code with explanation
  • Project demo and guidance for your viva
  • Project report, PPT and IEEE paper support (on request)
Delivery & Payment
Delivery takes a minimum of two weeks from the date your inquiry is confirmed. Payment is in two parts: • 50% advance to start the project • Remaining 50% before delivery Note: • Documentation and PPT are not included by default • If you need documentation/PPT, it can be arranged for extra time and cost We'll confirm the exact timeline and cost with you after reviewing your requirements.