Home » NodeMCU » Creating a Simple NodeMCU Web Server
nodemcu-webserver

Creating a Simple NodeMCU Web Server

We're done with basics of the NodeMCU in my last post. Now it's time to use the NodeMCU like how it's meant to be use: as an IoT device. Here I will show you how to create a simple NodeMCU web server which will control a LED attached to one of the NodeMCU's pins. Sounds interesting? Read on!

For this to work, you must have already installed the ESP8266 board development toolkit as shown in my last tutorial. Here's the code for our simple nodemcu web server:

nodemcuwebserver.ino

Notice that I used three headers on the top. These libraries are already installed after adding the ESP8266 toolkit via the board manager. Some notes on the code:

  • Use your own WiFi SSID and password for lines 6 and 7.
  • The string page contains the HTML of our web server.
  • The LED is connected to D7 as it was on the last tutorial.

Upload the code to your NodeMCU. After that, open the serial monitor on the Arduino IDE. You should see something like this:

nodemcu web server 1

This means  you are successfully connected to the WiFi network! You can also see the IP address assigned to the NodeMCU (192.168.1.7 in this example). Open your preferred web browser and type that IP address on the address bar.

nodemcu web server 2

Click the "On" button and watch as your LED turns on. Click the "Off" button to turn it off.

Easy! Next, we will display data coming from a sensor to a webpage.

Leave a Reply

Your email address will not be published. Required fields are marked *