mirror of
https://git.mirrors.martin98.com/https://github.com/luc-github/ESP3D.git
synced 2025-08-14 05:05:54 +08:00
Memory optimization and Client Status Info
Diisplay all System information and Client Information AP information to be done
This commit is contained in:
parent
2f1ee7abc9
commit
700cc71ffb
@ -50,13 +50,16 @@
|
||||
|
||||
//default values
|
||||
#define DEFAULT_WIFI_MODE AP_MODE
|
||||
#define DEFAULT_SSID "ESP8266"
|
||||
#define DEFAULT_PASSWORD "12345678"
|
||||
const char DEFAULT_SSID [] PROGMEM = "ESP8266";
|
||||
const char DEFAULT_PASSWORD [] PROGMEM = "12345678";
|
||||
#define DEFAULT_IP_MODE STATIC_IP_MODE
|
||||
#define DEFAULT_IP_VALUE "192.168.0.1"
|
||||
#define DEFAULT_MASK_VALUE "255.255.255.0"
|
||||
const char DEFAULT_IP_VALUE[] PROGMEM = "192.168.0.1";
|
||||
const char DEFAULT_MASK_VALUE[] PROGMEM = "255.255.255.0";
|
||||
#define DEFAULT_GATEWAY_VALUE DEFAULT_IP_VALUE
|
||||
#define DEFAULT_BAUD_RATE "9600"
|
||||
const char DEFAULT_BAUD_RATE[] PROGMEM = "9600";
|
||||
#if MDNS_FEATURE
|
||||
const char LOCAL_NAME[] PROGMEM = "esp8266";
|
||||
#endif
|
||||
|
||||
#define EEPROM_SIZE 256 //max is 512
|
||||
#define MAX_SSID_LENGH 32
|
||||
|
@ -29,36 +29,48 @@ 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" \
|
||||
const char PAGE_HEAD[] PROGMEM = "<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"
|
||||
" <div class=\"container theme-showcase\" role=\"main\">";
|
||||
const char NAV_START[] PROGMEM = "<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"
|
||||
const char NAV_LEFT_PART1 [] PROGMEM = "<ul class=\"nav navbar-nav navbar-left\">\n<li ";
|
||||
const char NAV_ELEMENT_ACTIVE [] PROGMEM = "class=\"active\"";
|
||||
const char NAV_LEFT_PART2a[] PROGMEM = "><a href=\"http://";
|
||||
const char NAV_LEFT_PART2b[] PROGMEM = "\">Home</a></li>\n<li ";
|
||||
const char NAV_LEFT_PART3a[] PROGMEM = "><a href=\"http://";
|
||||
const char NAV_LEFT_PART3b[] PROGMEM = "/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"\
|
||||
const char NAV_RIGHT_PART[] PROGMEM = "<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"
|
||||
"<p class=\"navbar-text navbar-right\">FW: " FW_VERSION "</p>\n";
|
||||
|
||||
#define NAV_END "</div>\n</nav>"
|
||||
const char NAV_END[] PROGMEM = "</div>\n</nav>";
|
||||
|
||||
#define PAGE_BOTTOM "</body>\n</html>"
|
||||
|
||||
const char PAGE_BOTTOM[] PROGMEM = "</body>\n</html>" ;
|
||||
|
||||
const char PANEL_TOP[] PROGMEM = "<div class=\"panel panel-default\">\n<div class=\"panel-heading\">\n<h3 class=\"panel-title\">";
|
||||
const char PANEL_START[] PROGMEM ="</h3>\n</div>\n<div class=\"panel-body\">";
|
||||
const char PANEL_END[] PROGMEM = "</div>\n</div>";
|
||||
const char LABEL_START[] PROGMEM = "<label>";
|
||||
const char LABEL_COLOR[] PROGMEM = "</label><label class=\"text-info\">";
|
||||
const char LABEL_END[] PROGMEM = "</label>";
|
||||
const char BR[] PROGMEM = "<BR>\n";
|
||||
#define LABEL(buffer, title, value) buffer+= LABEL_START; buffer+=title;buffer+=LABEL_COLOR;buffer+=value;buffer+=LABEL_END;buffer+=BR;
|
||||
#define LABEL_UNITS(buffer, title, value,units) buffer+= LABEL_START; buffer+=title;buffer+=LABEL_COLOR;buffer+=value;buffer+=units;buffer+=LABEL_END;buffer+=BR;
|
||||
|
||||
//cannot put it in class then cast it as std::function<void(void)> so put outside
|
||||
void handle_web_interface_root()
|
||||
{
|
||||
String sbuf=PAGE_HEAD ;
|
||||
String IP;
|
||||
String sstatus;
|
||||
int istatus;
|
||||
uint8_t mac [WL_MAC_ADDR_LENGTH];
|
||||
if (wifi_get_opmode()==WIFI_STA ) IP=wifi_config.ip2str(WiFi.localIP());
|
||||
else IP=wifi_config.ip2str(WiFi.softAPIP());
|
||||
//top bar
|
||||
sbuf+=NAV_START ;
|
||||
sbuf+=NAV_LEFT_PART1 ;
|
||||
sbuf+=NAV_ELEMENT_ACTIVE ;
|
||||
@ -70,36 +82,77 @@ void handle_web_interface_root()
|
||||
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());
|
||||
//system part
|
||||
sbuf+=PANEL_TOP;
|
||||
sbuf+=F("System");
|
||||
sbuf+=PANEL_START;
|
||||
LABEL(sbuf,F("Chip ID: "),String(system_get_chip_id()))
|
||||
LABEL_UNITS(sbuf,F("CPU Frequency: "),system_get_cpu_freq(),F("Hz"))
|
||||
LABEL_UNITS(sbuf,F("Free Memory: "),String(system_get_free_heap_size()),F(" octets"))
|
||||
LABEL(sbuf,F("SDK Version: "),system_get_sdk_version())
|
||||
#if MDNS_FEATURE
|
||||
sstatus = F("http:\\\\");
|
||||
sstatus+=LOCAL_NAME;
|
||||
LABEL_UNITS(sbuf,F("mDNS name: "),sstatus,F(".local"))
|
||||
#endif
|
||||
istatus = wifi_get_phy_mode();
|
||||
if (istatus==PHY_MODE_11B) sstatus=F("11b");
|
||||
else if (istatus==PHY_MODE_11G) sstatus=F("11g");
|
||||
else sstatus=F("11n");
|
||||
LABEL(sbuf,F("Network: "),sstatus)
|
||||
istatus = wifi_get_sleep_type();
|
||||
if (istatus==NONE_SLEEP_T) sstatus=F("None");
|
||||
else if (istatus==LIGHT_SLEEP_T) sstatus=F("Light");
|
||||
else sstatus=F("Modem");
|
||||
LABEL(sbuf,F("Sleep mode: "),sstatus)
|
||||
//LABEL(sbuf,F("Boot mode: "),String(system_get_boot_mode())) //no meaning so far
|
||||
LABEL(sbuf,F("Boot version: "),String(system_get_boot_version()))
|
||||
sbuf+=PANEL_END;
|
||||
|
||||
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);
|
||||
web_interface.WebServer.send(200, F("text/html"), sbuf);
|
||||
|
||||
sbuf=PANEL_TOP;
|
||||
sbuf+=F("Access Point");
|
||||
if(wifi_get_opmode()==WIFI_AP || wifi_get_opmode()==WIFI_AP_STA) sbuf+=F(" (enabled)");
|
||||
else sbuf+=F(" (disabled)");
|
||||
sbuf+=PANEL_START;
|
||||
|
||||
LABEL(sbuf,F("Mac address: "),wifi_config.mac2str(WiFi.softAPmacAddress(mac));)
|
||||
softap_config apconfig;
|
||||
sbuf+=PANEL_END;
|
||||
//split to not reach the sending size limit
|
||||
web_interface.WebServer.client().print(sbuf);
|
||||
|
||||
sbuf=PANEL_TOP;
|
||||
sbuf+=F("Station");
|
||||
if(wifi_get_opmode()==WIFI_STA || wifi_get_opmode()==WIFI_AP_STA) sbuf+=F(" (enabled)");
|
||||
else sbuf+=F(" (disabled)");
|
||||
sbuf+=PANEL_START;
|
||||
LABEL(sbuf,F("Mac address: "),wifi_config.mac2str(WiFi.macAddress(mac));)
|
||||
LABEL(sbuf,F("Connection to: "),WiFi.SSID())
|
||||
LABEL(sbuf,F("Channel: "),String(wifi_get_channel()))
|
||||
istatus = wifi_station_get_connect_status();
|
||||
if (istatus==STATION_GOT_IP) sstatus=F("Connected");
|
||||
else if (istatus==STATION_NO_AP_FOUND) sstatus=F("SSID not Available!");
|
||||
else if (istatus==STATION_CONNECT_FAIL) sstatus=F("Connecion failed!");
|
||||
else if (istatus==STATION_WRONG_PASSWORD) sstatus=F("Connecion failed! (Wrong Password)");
|
||||
else if (istatus==STATION_IDLE) sstatus=F("Idle");//should not happen
|
||||
else sstatus=F("Disconnected");
|
||||
LABEL(sbuf,F("Status: "),sstatus)
|
||||
if (wifi_station_dhcpc_status()==DHCP_STARTED)sstatus=F("Started");
|
||||
else sstatus=F("Stopped");
|
||||
LABEL(sbuf,F("DHCP Client: "),sstatus)
|
||||
LABEL(sbuf,F("IP: "),wifi_config.ip2str(WiFi.localIP()))
|
||||
LABEL(sbuf,F("Gateway: "),wifi_config.ip2str(WiFi.gatewayIP()))
|
||||
LABEL(sbuf,F("Subnet: "),wifi_config.ip2str(WiFi.subnetMask()))
|
||||
sbuf+=PANEL_END;
|
||||
//split to not reach the sending size limit (2920)
|
||||
web_interface.WebServer.client().print(sbuf);
|
||||
|
||||
|
||||
sbuf=PAGE_BOTTOM;
|
||||
//split to not reach the sending size limit
|
||||
web_interface.WebServer.client().print(sbuf);
|
||||
}
|
||||
|
||||
void handle_web_interface_config()
|
||||
@ -121,7 +174,7 @@ void handle_web_interface_config()
|
||||
sbuf+=NAV_END ;
|
||||
sbuf+="<div>Configuration</div>";
|
||||
sbuf+=PAGE_BOTTOM;
|
||||
web_interface.WebServer.send(200, "text/html", sbuf);
|
||||
web_interface.WebServer.send(200, F("text/html"), sbuf);
|
||||
}
|
||||
|
||||
//URI Decoding function
|
||||
@ -161,8 +214,8 @@ void WEBINTERFACE_CLASS::urldecode(char *dst, const char *src)
|
||||
WEBINTERFACE_CLASS::WEBINTERFACE_CLASS (int port):WebServer(port)
|
||||
{
|
||||
//init what will handle "/"
|
||||
WebServer.on("/",HTTP_ANY, handle_web_interface_root);
|
||||
WebServer.on("/CONFIG",HTTP_ANY, handle_web_interface_config);
|
||||
WebServer.on(F("/"),HTTP_ANY, handle_web_interface_root);
|
||||
WebServer.on(F("/CONFIG"),HTTP_ANY, handle_web_interface_config);
|
||||
}
|
||||
|
||||
WEBINTERFACE_CLASS web_interface(80);
|
||||
|
@ -68,7 +68,7 @@ void WIFI_CONFIG::configAP(IPAddress local_ip, IPAddress gateway, IPAddress subn
|
||||
char * WIFI_CONFIG::mac2str(uint8_t mac [WL_MAC_ADDR_LENGTH])
|
||||
{
|
||||
static char macstr [18];
|
||||
if (0>sprintf(macstr, "%02X:%02X:%02X:%02X:%02X:%02X",mac[0],mac[1],mac[2],mac[3],mac[4],mac[5])) strcpy (macstr, "00:00:00:00:00:00");
|
||||
if (0>sprintf(macstr,F("%02X:%02X:%02X:%02X:%02X:%02X"),mac[0],mac[1],mac[2],mac[3],mac[4],mac[5])) strcpy (macstr, F("00:00:00:00:00:00"));
|
||||
return macstr;
|
||||
}
|
||||
|
||||
@ -76,7 +76,7 @@ char * WIFI_CONFIG::mac2str(uint8_t mac [WL_MAC_ADDR_LENGTH])
|
||||
char * WIFI_CONFIG::ip2str(IPAddress Ip )
|
||||
{
|
||||
static char ipstr [16];
|
||||
if (0>sprintf(ipstr, "%i.%i.%i.%i",Ip[0],Ip[1],Ip[2],Ip[3])) strcpy (ipstr, "0.0.0.0");
|
||||
if (0>sprintf(ipstr, F("%i.%i.%i.%i"),Ip[0],Ip[1],Ip[2],Ip[3])) strcpy (ipstr, F("0.0.0.0"));
|
||||
return ipstr;
|
||||
}
|
||||
|
||||
@ -144,8 +144,8 @@ bool WIFI_CONFIG::Setup()
|
||||
// - second argument is the IP address to advertise
|
||||
// we send our IP address on the WiFi network
|
||||
// Note: for AP mode we would use WiFi.softAPIP()!
|
||||
if (!mdns.begin("esp8266", currentIP)) {
|
||||
Serial.println("Error setting up MDNS responder!");
|
||||
if (!mdns.begin(LOCAL_NAME, currentIP)) {
|
||||
Serial.println(F("Error setting up MDNS responder!"));
|
||||
}
|
||||
#endif
|
||||
return true;
|
||||
|
Loading…
x
Reference in New Issue
Block a user