HOW TO HOST MUTIPLE WEBPAGES USING THE ESP8266 AS SERVER USING THE ARDUINO IDE?

by lolipop8867 in Circuits > Microcontrollers

749 Views, 4 Favorites, 0 Comments

HOW TO HOST MUTIPLE WEBPAGES USING THE ESP8266 AS SERVER USING THE ARDUINO IDE?

rest.jpg
  • It is possible to host multiple pages by using the very power full ESP8266.
  • We will be using the RESTful web services for our purpose.
  • We will be using the Arduino environment for building the code.

INTRODUCTION

51wY76Q0iCL._SX425_.jpg

Before doing this project having a prior knowledge of the following things is necessary

  • How to make a web server with the ESP-8266.
  • Basic concepts of the RESTful web services.
  • What is a station and what is an access point.

NOTE: We will be using the HTTP GET requests for this project

Starting the Web Server

FPI4DXMJJOK3N2O.LARGE.jpg

Start the server on the ESP-8266 and start listing to the clients from the port 80.

NOTE: The server can be either a soft-AP server or the normal station server. This project can be configured to work in both the configuration.


Check If the Client Is Connected or Not

server_strat2 (2).png
Screenshot (11).png
  • Once the code is uploaded, then check for the WiFi Access point by the name SSID and type the password.
  • Once you have successfully connected to the network, open your Web browser which in this case is the client, and type the IP address as shown.
  • If the ESP8266 is configured as the Station server, then use the WiFi.localIP() function to know the ip address.

  • If the ESP8266 is configured as the soft-AP server, then by default 192.168.4.1 will the IP address.This IP address will be used to access the server.

NOTE: However in this project we will configure the ESP8266 as the soft-AP server.

Host Your First Web Page

Screenshot (14).png
Screenshot (15).png

Write a simple HTML hello world code as shown.

Managing the GET REQUESTS

Screenshot (17).png
Screenshot (18).png
  • As shown in the step 4, to access the webpage, we just type the IP address of the server on the browser. Now lets do something very interesting.
  • We are now going to access the various web pages using the GET requests.
  • In this example the GET request is of the type : http:/192.168.4.1/first?first&
  • If we type the above URI in the browser, then we see a welcome webpage but if we type any other URI it will show a error webpage.

Refer the start_server.ino for the detailed view of the code

Downloads

Final Step: Switching From One Web Page to Another Webpage

Screenshot (21).png
Screenshot (22).png
Screenshot (23).png
Screenshot (24).png
Screenshot (25).png
Screenshot (26).png
Screenshot (20).png
Screenshot (27).png
  1. To first visit the Login page use the following URI: http:/192.168.4.1/login?
  2. Then the following URI is used to switch from one page to another: http:/192.168.4.1/page?value=pageNumber&.

Example :

http:/192.168.4.1/page?value=1& will go to the first page

http:/192.168.4.1/page?value=5& will go to the last page

http:/192.168.4.1/page?logout& will display the Thank you page

Refer to the Final_switch_multiple_page.ino for the detailed view of the code:

Refers