This is the first guide for the series of guides to replace the setup for IBM Watson IoT based projects. If you look at our old articles and GitHub repository, you will realize that we were publishing IBM Watson IoT-centric sketches for the past 4 years. A significant time and effort were spent and our innocent readers were using them. Suddenly they came to know that IBM Watson IoT platform will get closed.
That event forced us to start searching for a modern alternative to quickly get started. In the earlier article on this topic, we have pointed towards some of the ways which our users can select themselves.
How We Have Started ESP32 Arduino IoT Relay Control Project
Codes and snippets of this article are fully based on electronoobs.com’s NOOBIX project. We have forked their present version on our GitHub repository without modifying any file. If you download the version 1.0.0 from our GitHub repo, you’ll get the same files they have distributed. The future versions of the project will gradually change and will not be compatible with NOOBIX project. We will also be happy if you want to follow the guides of
electronoobs.com instead of ours. They have invested their time to create some DIY projects with the hope that some of the readers will use their affiliate links and they will get some money. If this v1.0.0 comes to your work then kindly consider donating them. The reason I have chosen their files as a base is that they are time-tested by many users and they are basic and fat-free. It is difficult to start a complex project.
The diagram is indicative only.
How to Get Started With This Project
This project can control one Relay and have one LED indicator. There is no encryption and you can not use it in the final project because of a lack of security. This is good to get started and follow our next guides for further development.
You need a few things for this project. First is an ESP32 dev board which is configured to use Arduino IDE. Second, you will need a solid-state relay connected with Pin 12.
On the server part, you will need a LAMP server. Your existing server running WordPress should work fine or you can use some cheap or free host and install a LAMP server on it. We have guides to install Apache2, Percona MySQL and PHP on any VPS. You can use any shared server like that from BlueHost or GoDaddy or HostGator.
Create a MySQL database and create a Table with the name
LED_status with number of columns 2. Name the first column as
id and second column as
status. Type of both will be
INT. Length/Values will be 11 for both.
id column will be incremental and primary. The value of
id will be 1 and
status (rows) will be 0. You can run these two SQL queries to create it:
CREATE TABLE `esp32`.`LED_status` ( `id` INT(11) NOT NULL AUTO_INCREMENT , `status` INT(11) NOT NULL , PRIMARY KEY (`id`)) ENGINE = InnoDB;
INSERT INTO `LED_status` (`id`, `status`) VALUES ('1', '0')
I am describing the project originally had. I will supply the required SQL from next versions, so you need not to fight with it if you do not know what I am talking about.
Now, go to our GitHub project. Open the
ESP32 sketch.ino file and edit these below lines:
//Add WIFI data
const char* ssid = "ElectroNoobs-Taller"; //Add your WIFI network name
const char* password = "12345678"; //Add WIFI password
/*Begin a new connection to the website. Make sure you change "https://electronoobs.com/" to
*the name of your website. So the next line should be:
http.begin("https://electronoobs.com/NOOBIX_V2/esp32_update.php"); //Indicate the destination webpage
The WIFI network name and WIFI password will be of your router or mobile hotspot.
yourwebsite.com/NOOBIX_V2/esp32_update.php must match the public URL of your file.
You can upload the files to your ESP32 via Arduino IDE. Now go to
/server_files/ directory of the GitHub project. Open the
connection.php file. I will sanitize this file in future, for now, create a MySQL database and fill up the basic details. Upload these files on the public root of your web server (and delete the index.html file):
If you open
index.php on the browser, you will be able to control the relay.
What is Next?
In near future, we will remove the LED control via the
index.php file. You will be able to control the relay via HTTP POST request via cURL command with bash scripts and developer mobile app. We will add a push button control with debounce-on code. This was the setup we started working with IBM Watson IoT. We have to secure the server so that without an access key, unknown people can not send an HTTP POST request to control our relay.