mirror of
https://git.mirrors.martin98.com/https://github.com/luc-github/ESP3D.git
synced 2025-08-14 18:35:57 +08:00
Page Information and Page Configuration sample
backbone for Information page and configuration page
This commit is contained in:
parent
29339aee3c
commit
2f1ee7abc9
@ -26,6 +26,8 @@
|
|||||||
#define FW_VERSION "V0.1"
|
#define FW_VERSION "V0.1"
|
||||||
#define REPOSITORY "https://github.com/luc-github/ESP8266"
|
#define REPOSITORY "https://github.com/luc-github/ESP8266"
|
||||||
|
|
||||||
|
#define MDNS_FEATURE 1
|
||||||
|
|
||||||
//pin used to reset setting
|
//pin used to reset setting
|
||||||
#define RESET_CONFIG_PIN 2
|
#define RESET_CONFIG_PIN 2
|
||||||
|
|
||||||
|
@ -27,7 +27,7 @@
|
|||||||
//cannot put it in class then cast it as std::function<void(void)> so put outside
|
//cannot put it in class then cast it as std::function<void(void)> so put outside
|
||||||
void handle_data_interface_root()
|
void handle_data_interface_root()
|
||||||
{
|
{
|
||||||
data_interface.WebServer.send(200, "text/plain", "hello from esp8266 from port 8888 ");
|
data_interface.WebServer.send(200, "text/html", "hello from esp8266 from port 8888 ");
|
||||||
}
|
}
|
||||||
|
|
||||||
DATAINTERFACE_CLASS::DATAINTERFACE_CLASS (int port):WebServer(port)
|
DATAINTERFACE_CLASS::DATAINTERFACE_CLASS (int port):WebServer(port)
|
||||||
|
@ -20,20 +20,149 @@
|
|||||||
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include "webinterface.h"
|
#include "webinterface.h"
|
||||||
|
#include "wifi.h"
|
||||||
#include <WiFiClient.h>
|
#include <WiFiClient.h>
|
||||||
#include <WiFiServer.h>
|
#include <WiFiServer.h>
|
||||||
|
#include <ESP8266WiFi.h>
|
||||||
#include <ESP8266WebServer.h>
|
#include <ESP8266WebServer.h>
|
||||||
|
extern "C" {
|
||||||
|
#include "user_interface.h"
|
||||||
|
}
|
||||||
|
|
||||||
|
#define PAGE_HEAD "<html lang=\"en\">\n<head>\n<meta charset=\"utf-8\">\n<meta http-equiv=\"X-UA-Compatible\" content=\"IE=edge\">\n" \
|
||||||
|
"<meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">\n<title>Wifi Configuration</title>" \
|
||||||
|
"<link rel=\"stylesheet\" href=\"http://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css\">\n</head>\n<body>"\
|
||||||
|
" <div class=\"container theme-showcase\" role=\"main\">"
|
||||||
|
#define NAV_START "<nav class=\"navbar navbar-inverse\">\n<div class=\"container\">\n"
|
||||||
|
|
||||||
|
#define NAV_LEFT_PART1 "<ul class=\"nav navbar-nav navbar-left\">\n<li "
|
||||||
|
#define NAV_ELEMENT_ACTIVE "class=\"active\""
|
||||||
|
#define NAV_LEFT_PART2a "><a href=\"http://"
|
||||||
|
#define NAV_LEFT_PART2b "\">Home</a></li>\n<li "
|
||||||
|
#define NAV_LEFT_PART3a "><a href=\"http://"
|
||||||
|
#define NAV_LEFT_PART3b "/CONFIG\">Configuration</a></li>\n</ul>\n"
|
||||||
|
|
||||||
|
#define NAV_RIGHT_PART "<p class=\"navbar-text navbar-right\"> </p>\n<ul class=\"nav navbar-nav navbar-right\">\n"\
|
||||||
|
"<li><a href=\"" REPOSITORY "\">Github</a></li>\n</ul>\n"\
|
||||||
|
"<p class=\"navbar-text navbar-right\">FW: " FW_VERSION "</p>\n"
|
||||||
|
|
||||||
|
#define NAV_END "</div>\n</nav>"
|
||||||
|
|
||||||
|
#define PAGE_BOTTOM "</body>\n</html>"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//cannot put it in class then cast it as std::function<void(void)> so put outside
|
//cannot put it in class then cast it as std::function<void(void)> so put outside
|
||||||
void handle_web_interface_root()
|
void handle_web_interface_root()
|
||||||
{
|
{
|
||||||
web_interface.WebServer.send(200, "text/plain", "hello from esp8266 from port 80!");
|
String sbuf=PAGE_HEAD ;
|
||||||
|
String IP;
|
||||||
|
if (wifi_get_opmode()==WIFI_STA ) IP=wifi_config.ip2str(WiFi.localIP());
|
||||||
|
else IP=wifi_config.ip2str(WiFi.softAPIP());
|
||||||
|
sbuf+=NAV_START ;
|
||||||
|
sbuf+=NAV_LEFT_PART1 ;
|
||||||
|
sbuf+=NAV_ELEMENT_ACTIVE ;
|
||||||
|
sbuf+=NAV_LEFT_PART2a ;
|
||||||
|
sbuf+=IP;
|
||||||
|
sbuf+=NAV_LEFT_PART2b ;
|
||||||
|
sbuf+=NAV_LEFT_PART3a ;
|
||||||
|
sbuf+=IP;
|
||||||
|
sbuf+=NAV_LEFT_PART3b ;
|
||||||
|
sbuf+=NAV_RIGHT_PART ;
|
||||||
|
sbuf+=NAV_END ;
|
||||||
|
/* if (web_interface.WebServer.arg("myinput").length()> 0)
|
||||||
|
{
|
||||||
|
char buf[250];
|
||||||
|
char buf1[250];
|
||||||
|
web_interface.WebServer.arg("myinput").toCharArray(buf1, 249);
|
||||||
|
web_interface.urldecode(buf,buf1);
|
||||||
|
sbuf="<FORM METHOD=POST><INPUT TYPE=TEXT NAME=myinput value=\"";
|
||||||
|
sbuf+=buf;
|
||||||
|
sbuf+="\"><BUTTON TYPE=SUBMIT NAME=Submit VALUE=\"Submit\"></FORM>";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
sbuf += "No Data";
|
||||||
|
}*/
|
||||||
|
sbuf+="<div>Information<BR>";
|
||||||
|
sbuf+="<BR>CPU Freq:";
|
||||||
|
sbuf+=String(system_get_cpu_freq());
|
||||||
|
sbuf+="<BR>Mem:";
|
||||||
|
sbuf+=String(system_get_free_heap_size());
|
||||||
|
sbuf+="<BR>ID:";
|
||||||
|
sbuf+=String(system_get_chip_id());
|
||||||
|
|
||||||
|
sbuf+="<BR>SDK:";
|
||||||
|
sbuf+=system_get_sdk_version();
|
||||||
|
sbuf+="<BR>Mac:";
|
||||||
|
uint8_t mac [WL_MAC_ADDR_LENGTH];
|
||||||
|
sbuf+=wifi_config.mac2str(WiFi.macAddress(mac));
|
||||||
|
sbuf+="</div>";
|
||||||
|
sbuf+=PAGE_BOTTOM;
|
||||||
|
web_interface.WebServer.send(200, "text/html", sbuf);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void handle_web_interface_config()
|
||||||
|
{
|
||||||
|
String sbuf=PAGE_HEAD ;
|
||||||
|
String IP;
|
||||||
|
if (wifi_get_opmode()==WIFI_STA ) IP=wifi_config.ip2str(WiFi.localIP());
|
||||||
|
else IP=wifi_config.ip2str(WiFi.softAPIP());
|
||||||
|
sbuf+=NAV_START ;
|
||||||
|
sbuf+=NAV_LEFT_PART1 ;
|
||||||
|
sbuf+=NAV_LEFT_PART2a ;
|
||||||
|
sbuf+=IP;
|
||||||
|
sbuf+=NAV_LEFT_PART2b ;
|
||||||
|
sbuf+=NAV_ELEMENT_ACTIVE ;
|
||||||
|
sbuf+=NAV_LEFT_PART3a ;
|
||||||
|
sbuf+=IP;
|
||||||
|
sbuf+=NAV_LEFT_PART3b ;
|
||||||
|
sbuf+=NAV_RIGHT_PART ;
|
||||||
|
sbuf+=NAV_END ;
|
||||||
|
sbuf+="<div>Configuration</div>";
|
||||||
|
sbuf+=PAGE_BOTTOM;
|
||||||
|
web_interface.WebServer.send(200, "text/html", sbuf);
|
||||||
|
}
|
||||||
|
|
||||||
|
//URI Decoding function
|
||||||
|
//no check if dst buffer is big enough to receive string so
|
||||||
|
//use same size as src is a recommendation
|
||||||
|
void WEBINTERFACE_CLASS::urldecode(char *dst, const char *src)
|
||||||
|
{
|
||||||
|
char a, b;
|
||||||
|
if (dst==NULL) return;
|
||||||
|
while (*src) {
|
||||||
|
if ((*src == '%') &&
|
||||||
|
((a = src[1]) && (b = src[2])) &&
|
||||||
|
(isxdigit(a) && isxdigit(b))) {
|
||||||
|
if (a >= 'a')
|
||||||
|
a -= 'a'-'A';
|
||||||
|
if (a >= 'A')
|
||||||
|
a -= ('A' - 10);
|
||||||
|
else
|
||||||
|
a -= '0';
|
||||||
|
if (b >= 'a')
|
||||||
|
b -= 'a'-'A';
|
||||||
|
if (b >= 'A')
|
||||||
|
b -= ('A' - 10);
|
||||||
|
else
|
||||||
|
b -= '0';
|
||||||
|
*dst++ = 16*a+b;
|
||||||
|
src+=3;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
*dst++ = *src++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
*dst++ = '\0';
|
||||||
|
}
|
||||||
|
|
||||||
|
//constructor
|
||||||
WEBINTERFACE_CLASS::WEBINTERFACE_CLASS (int port):WebServer(port)
|
WEBINTERFACE_CLASS::WEBINTERFACE_CLASS (int port):WebServer(port)
|
||||||
{
|
{
|
||||||
//init what will handle "/"
|
//init what will handle "/"
|
||||||
WebServer.on("/",HTTP_GET, handle_web_interface_root);
|
WebServer.on("/",HTTP_ANY, handle_web_interface_root);
|
||||||
|
WebServer.on("/CONFIG",HTTP_ANY, handle_web_interface_config);
|
||||||
}
|
}
|
||||||
|
|
||||||
WEBINTERFACE_CLASS web_interface(80);
|
WEBINTERFACE_CLASS web_interface(80);
|
||||||
|
@ -30,6 +30,7 @@ class WEBINTERFACE_CLASS
|
|||||||
public:
|
public:
|
||||||
WEBINTERFACE_CLASS (int port = 82);
|
WEBINTERFACE_CLASS (int port = 82);
|
||||||
ESP8266WebServer WebServer;
|
ESP8266WebServer WebServer;
|
||||||
|
void urldecode(char *dst, const char *src);
|
||||||
private:
|
private:
|
||||||
|
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user