ESP8266 Handle Not Found Pages and Redirect
ESP8266 Handle Not Found Pages and Redirect
ESP8266WebServer server(80);
//Initialize
Webserver server.on("/",handleRoot);
server.onNotFound(handleNotFound);
server.begin();
Step 3: Con igure not found page subroutine Arduino Beginners Guide: Get started with
arduino in simple steps
In this first we send header location as root to client and send a request to redirect to that
i.e. HTTP 302
void handleNotFound()
{
server.sendHeader("Location", "/",true); //Redirect to our html web
page
server.send(302, "text/plane","");
}
/*
* ESP8266 Redirect Web Request
*
*/
#include <ESP8266WiFi.h>
#include <ESP8266WebServer.h>
ESP8266WebServer server(80);
Ad
void handleNotFound(){
server.sendHeader("Location", "/",true); //Redirect to our html web
page
server.send(302, "text/plane","");
} Recent Posts
Best Online JSON Editor Tool to Edit JSON
void handleRoot() {
Online
server.send(200, "text/html", "<html><body>Hello from ESP <br><a
href='/Thispage'>Failed Link</a></body></html>"); ESP8266 IoT Based RGB LED Strip Controller
}
ESP8266 BMP180 pressure sensor interface
//Initialize AP Mode
WiFi.softAP(ssid); //Password not used Ad
IPAddress myIP = WiFi.softAPIP();
Serial.print("Web Server IP:");
Serial.println(myIP);
//Initialize Webserver
server.on("/",handleRoot);
server.onNotFound(handleNotFound);
server.begin();
}
void loop() {
server.handleClient();
}
Upload code and see how it handles not found link on the page.
This is a list of some commonly used HTTP status messages that might be returned:
2xx: Successful
MESSAGE: DESCRIPTION:
201 Created The request has been fulfilled, and a new resource is created
The request has been accepted for processing, but the processing has not
202 Accepted
been completed
203 Non-Authoritative The request has been successfully processed, but is returning information
The request has been successfully processed, but is not returning any
204 No Content
content
The request has been successfully processed, but is not returning any
205 Reset Content
content, and requires that the requester reset the document view
The server is delivering only part of the resource due to a range header sent
206 Partial Content
by the client
3xx: Redirection
MESSAGE: DESCRIPTION:
A link list. The user can select a link and go to that location. Maximum five
300 Multiple Choices
addresses
301 Moved
The requested page has moved to a new URL
Permanently
302 Found The requested page has moved temporarily to a new URL
303 See Other The requested page can be found under a di erent URL
304 Not Modified Indicates the requested page has not been modified since last requested
307 Temporary
The requested page has moved temporarily to a new URL
Redirect
308 Resume Used in the resumable requests proposal to resume aborted PUT or POST
Incomplete requests
400 Bad Request The request cannot be fulfilled due to bad syntax
The request was a legal request, but the server is refusing to respond to it. For
401 Unauthorized
use when authentication is possible but has failed or not yet been provided
404 Not Found The requested page could not be found but may be available again in the future
408 Request
The server timed out waiting for the request
Timeout
414 Request-URI The server will not accept the request, because the URL is too long. Occurs when
Too Long you convert a POST request to a GET request with a long query information
The server was acting as a gateway or proxy and did not receive a
504 Gateway Timeout
timely response from the upstream server
505 HTTP Version Not The server does not support the HTTP protocol version used in the
Supported request
Related
ESP8266 (NodeMCU) ADC ESP8266 Arduino WiFi Web ESP8266 Web Server AP (Access
analog value on dial gauge Server LED on o control Point)
February 3, 2018 February 5, 2018 December 16, 2016
In "ESP8266" In "ESP8266" In "IoT Tutorials"
Leave a Reply
You must be logged in to post a comment.
Login with: