Missing file from previous commit

Missing file from previous commit
This commit is contained in:
luc 2015-05-14 14:52:18 +08:00
parent a1b7cbc84e
commit e3346805ae

View File

@ -29,6 +29,8 @@ extern "C" {
#include "user_interface.h" #include "user_interface.h"
} }
#define LIMIT_BUFFER 2500
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" \ 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>" \ "<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>"\ "<link rel=\"stylesheet\" href=\"http://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css\">\n</head>\n<body>"\
@ -57,13 +59,30 @@ const char LABEL_START[] PROGMEM = "<label>";
const char LABEL_COLOR[] PROGMEM = "</label><label class=\"text-info\">"; const char LABEL_COLOR[] PROGMEM = "</label><label class=\"text-info\">";
const char LABEL_END[] PROGMEM = "</label>"; const char LABEL_END[] PROGMEM = "</label>";
const char BR[] PROGMEM = "<BR>\n"; 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; const char TABLE_START[] PROGMEM = "<div class=\"table-responsive\">\n<table class=\"table table-bordered table-striped\">";
#define LABEL_UNITS(buffer, title, value,units) buffer+= LABEL_START; buffer+=title;buffer+=LABEL_COLOR;buffer+=value;buffer+=units;buffer+=LABEL_END;buffer+=BR; const char TABLE_END [] PROGMEM = "</table></div>\n";
const char CAPTION_S [] PROGMEM = "<caption>\n";
const char THEAD_S[] PROGMEM = "<thead>\n";
const char TR_S[] PROGMEM = "<tr>\n";
const char TH_S[] PROGMEM = "<th>\n";
const char TH_R[] PROGMEM = "<th scope=\"row\">\n";
const char TD_S[] PROGMEM = "<td>\n";
const char TBODY_S[] PROGMEM = "<tbody>\n";
const char CAPTION_E [] PROGMEM = "</caption>\n";
const char THEAD_E[] PROGMEM = "</thead>\n";
const char TR_E[] PROGMEM = "</tr>\n";
const char TH_E[] PROGMEM = "</th>\n";
const char TD_E[] PROGMEM = "</td>\n";
const char TBODY_E[] PROGMEM = "</tbody>\n";
#define LABEL( title, value) web_interface.add4send(LABEL_START); web_interface.add4send(title);web_interface.add4send(LABEL_COLOR);web_interface.add4send(value);web_interface.add4send(LABEL_END);web_interface.add4send(BR);
#define LABEL_UNITS(title, value,units) web_interface.add4send(LABEL_START); web_interface.add4send(title);web_interface.add4send(LABEL_COLOR);web_interface.add4send(value);web_interface.add4send(units);web_interface.add4send(LABEL_END);web_interface.add4send(BR);
#define TH_ENTRY(entry) web_interface.add4send(TH_S);web_interface.add4send(entry);web_interface.add4send(TH_E);
#define THR_ENTRY(entry) web_interface.add4send(TH_R);web_interface.add4send(entry);web_interface.add4send(TH_E);
#define TD_ENTRY(entry) web_interface.add4send(TD_S);web_interface.add4send(entry);web_interface.add4send(TD_E);
//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()
{ {
String sbuf=PAGE_HEAD ;
String IP; String IP;
String sstatus; String sstatus;
struct softap_config apconfig; struct softap_config apconfig;
@ -72,156 +91,175 @@ void handle_web_interface_root()
uint8_t mac [WL_MAC_ADDR_LENGTH]; uint8_t mac [WL_MAC_ADDR_LENGTH];
if (wifi_get_opmode()==WIFI_STA ) IP=wifi_config.ip2str(WiFi.localIP()); if (wifi_get_opmode()==WIFI_STA ) IP=wifi_config.ip2str(WiFi.localIP());
else IP=wifi_config.ip2str(WiFi.softAPIP()); else IP=wifi_config.ip2str(WiFi.softAPIP());
web_interface.add4send(PAGE_HEAD);
//top bar //top bar
sbuf+=NAV_START ; web_interface.add4send(NAV_START);
sbuf+=NAV_LEFT_PART1 ; web_interface.add4send(NAV_LEFT_PART1) ;
sbuf+=NAV_ELEMENT_ACTIVE ; web_interface.add4send(NAV_ELEMENT_ACTIVE) ;
sbuf+=NAV_LEFT_PART2a ; web_interface.add4send(NAV_LEFT_PART2a );
sbuf+=IP; web_interface.add4send(IP.c_str());
sbuf+=NAV_LEFT_PART2b ; web_interface.add4send(NAV_LEFT_PART2b );
sbuf+=NAV_LEFT_PART3a ; web_interface.add4send(NAV_LEFT_PART3a );
sbuf+=IP; web_interface.add4send(IP.c_str());
sbuf+=NAV_LEFT_PART3b ; web_interface.add4send(NAV_LEFT_PART3b) ;
sbuf+=NAV_RIGHT_PART ; web_interface.add4send(NAV_RIGHT_PART) ;
sbuf+=NAV_END ; web_interface.add4send(NAV_END) ;
//system part //system part
sbuf+=PANEL_TOP; web_interface.add4send(PANEL_TOP);
sbuf+=F("System"); web_interface.add4send(F("System"));
sbuf+=PANEL_START; web_interface.add4send(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(F("Chip ID: "),String(system_get_chip_id()).c_str())
LABEL_UNITS(sbuf,F("Free Memory: "),String(system_get_free_heap_size()),F(" octets")) LABEL_UNITS(F("CPU Frequency: "),String(system_get_cpu_freq()).c_str(),F("Hz"))
LABEL(sbuf,F("SDK Version: "),system_get_sdk_version()) LABEL_UNITS(F("Free Memory: "),String(system_get_free_heap_size()).c_str(),F(" octets"))
LABEL(F("SDK Version: "),system_get_sdk_version())
#ifdef MDNS_FEATURE #ifdef MDNS_FEATURE
sstatus = F("http://"); sstatus = F("http://");
sstatus+=LOCAL_NAME; sstatus+=LOCAL_NAME;
LABEL_UNITS(sbuf,F("mDNS name: "),sstatus,F(".local")) LABEL_UNITS(F("mDNS name: "),sstatus.c_str(),F(".local"))
#endif #endif
istatus = wifi_get_phy_mode(); istatus = wifi_get_phy_mode();
if (istatus==PHY_MODE_11B) sstatus=F("11b"); if (istatus==PHY_MODE_11B) sstatus=F("11b");
else if (istatus==PHY_MODE_11G) sstatus=F("11g"); else if (istatus==PHY_MODE_11G) sstatus=F("11g");
else sstatus=F("11n"); else sstatus=F("11n");
LABEL(sbuf,F("Network: "),sstatus) LABEL(F("Network: "),sstatus.c_str())
istatus = wifi_get_sleep_type(); istatus = wifi_get_sleep_type();
if (istatus==NONE_SLEEP_T) sstatus=F("None"); if (istatus==NONE_SLEEP_T) sstatus=F("None");
else if (istatus==LIGHT_SLEEP_T) sstatus=F("Light"); else if (istatus==LIGHT_SLEEP_T) sstatus=F("Light");
else sstatus=F("Modem"); else sstatus=F("Modem");
LABEL(sbuf,F("Sleep mode: "),sstatus) LABEL(F("Sleep mode: "),sstatus.c_str())
//LABEL(sbuf,F("Boot mode: "),String(system_get_boot_mode())) //no meaning so far //LABEL(sbuf,F("Boot mode: "),String(system_get_boot_mode())) //no meaning so far
LABEL(sbuf,F("Boot version: "),String(system_get_boot_version())) LABEL(F("Boot version: "),String(system_get_boot_version()).c_str())
sbuf+=PANEL_END; web_interface.add4send(PANEL_END);
//split to not reach the sending size limit
web_interface.WebServer.send(200, F("text/html"), sbuf);
//access point //access point
sbuf=PANEL_TOP; web_interface.add4send(PANEL_TOP);
sbuf+=F("Access Point"); web_interface.add4send(F("Access Point"));
if(wifi_get_opmode()==WIFI_AP || wifi_get_opmode()==WIFI_AP_STA) sbuf+=F(" (enabled)"); if(wifi_get_opmode()==WIFI_AP || wifi_get_opmode()==WIFI_AP_STA) web_interface.add4send(F(" (enabled)"));
else sbuf+=F(" (disabled)"); else web_interface.add4send(F(" (disabled)"));
sbuf+=PANEL_START; web_interface.add4send(PANEL_START);
LABEL(sbuf,F("Mac address: "),wifi_config.mac2str(WiFi.softAPmacAddress(mac));) LABEL(F("Mac address: "),wifi_config.mac2str(WiFi.softAPmacAddress(mac)))
if (wifi_softap_get_config(&apconfig)) if (wifi_get_opmode()==WIFI_AP || wifi_get_opmode()==WIFI_AP_STA)
{ {
LABEL(sbuf,F("SSID: "),(char *)(apconfig.ssid)) if (wifi_softap_get_config(&apconfig))
if(apconfig.ssid_hidden==1)sstatus=F("No"); {
else sstatus=F("Yes"); LABEL(F("SSID: "),(char *)(apconfig.ssid))
LABEL(sbuf,F("Visible: "),sstatus) if(apconfig.ssid_hidden==1)sstatus=F("No");
LABEL(sbuf,F("Channel: "),String(apconfig.channel)) else sstatus=F("Yes");
if (apconfig.authmode==AUTH_OPEN)sstatus=F("None"); LABEL(F("Visible: "),sstatus.c_str())
else if (apconfig.authmode==AUTH_WEP)sstatus=F("WEP"); LABEL(F("Channel: "),String(apconfig.channel).c_str())
else if (apconfig.authmode==AUTH_WPA_PSK)sstatus=F("WPA"); if (apconfig.authmode==AUTH_OPEN)sstatus=F("None");
else if (apconfig.authmode==AUTH_WPA2_PSK)sstatus=F("WPA2"); else if (apconfig.authmode==AUTH_WEP)sstatus=F("WEP");
else if (apconfig.authmode==AUTH_WPA_WPA2_PSK)sstatus=F("WPA/WPA2"); else if (apconfig.authmode==AUTH_WPA_PSK)sstatus=F("WPA");
else sstatus=F("MAX"); //what is this one ? WPS ? Cannot find information else if (apconfig.authmode==AUTH_WPA2_PSK)sstatus=F("WPA2");
LABEL(sbuf,F("Authentification: "),sstatus) else if (apconfig.authmode==AUTH_WPA_WPA2_PSK)sstatus=F("WPA/WPA2");
LABEL(sbuf,F("Maximum connections : "),String(apconfig.max_connection)) else sstatus=F("MAX"); //what is this one ? WPS ? Cannot find information
} LABEL(F("Authentification: "),sstatus.c_str())
if (wifi_softap_dhcps_status()==DHCP_STARTED)sstatus=F("Started"); LABEL(F("Maximum connections : "),String(apconfig.max_connection).c_str())
else sstatus=F("Stopped"); }
LABEL(sbuf,F("DHCP Server: "),sstatus) if (wifi_softap_dhcps_status()==DHCP_STARTED)sstatus=F("Started");
if (wifi_get_ip_info(SOFTAP_IF,&info)) else sstatus=F("Stopped");
{ LABEL(F("DHCP Server: "),sstatus.c_str())
LABEL(sbuf,F("IP: "),wifi_config.ip2str(info.ip.addr)) if (wifi_get_ip_info(SOFTAP_IF,&info))
LABEL(sbuf,F("Gateway: "),wifi_config.ip2str(info.gw.addr)) {
LABEL(sbuf,F("Subnet: "),wifi_config.ip2str(info.netmask.addr)) LABEL(F("IP: "),wifi_config.ip2str(info.ip.addr))
} LABEL(F("Gateway: "),wifi_config.ip2str(info.gw.addr))
//List number of client LABEL(F("Subnet: "),wifi_config.ip2str(info.netmask.addr))
istatus = 0; }
sstatus=""; //List number of client
struct station_info * station = wifi_softap_get_station_info(); istatus = 0;
while(station){ sstatus="";
istatus++; struct station_info * station = wifi_softap_get_station_info();
sstatus+=F("<TR><TD>Mac:</TD><TD>"); struct station_info * stationtmp = station;
sstatus+=wifi_config.mac2str(station->bssid); //get total number of connected clients
sstatus+=F("</TD><TD>IP:</TD><TD>"); while(stationtmp)
static char ipstr [16]; {
if (0>sprintf(ipstr, IPSTR,IP2STR(&station->ip))) strcpy (ipstr, F("0.0.0.0")); istatus++;
sstatus+=ipstr; stationtmp = STAILQ_NEXT(stationtmp, next);
sstatus+=F("</TD></TR>"); }
station = STAILQ_NEXT(station, next); //start table as at least one connected
} web_interface.add4send(TABLE_START);
wifi_softap_free_station_info(); web_interface.add4send(CAPTION_S);
LABEL(sbuf,F("Clients: "),String(istatus)); web_interface.add4send(String(istatus).c_str());
sbuf+=F("<TABLE>"); web_interface.add4send(F(" connected station(s)"));
sbuf+=sstatus; web_interface.add4send(CAPTION_S);
sbuf+=F("</TABLE>"); web_interface.add4send(THEAD_S);
sbuf+=PANEL_END; web_interface.add4send(TR_S);
//split to not reach the sending size limit TH_ENTRY(F("#"))
web_interface.WebServer.client().print(sbuf); TH_ENTRY(F("Mac"))
TH_ENTRY(F("IP"))
sbuf=PANEL_TOP; web_interface.add4send(TR_E);
sbuf+=F("Station"); web_interface.add4send(THEAD_E);
if(wifi_get_opmode()==WIFI_STA || wifi_get_opmode()==WIFI_AP_STA) sbuf+=F(" (enabled)"); web_interface.add4send(TBODY_S);
else sbuf+=F(" (disabled)"); istatus=0;
sbuf+=PANEL_START; while(station)
LABEL(sbuf,F("Mac address: "),wifi_config.mac2str(WiFi.macAddress(mac));) {
LABEL(sbuf,F("Connection to: "),WiFi.SSID()) istatus++;
LABEL(sbuf,F("Channel: "),String(wifi_get_channel())) //display each client
istatus = wifi_station_get_connect_status(); web_interface.add4send(TR_S);
if (istatus==STATION_GOT_IP) sstatus=F("Connected"); THR_ENTRY(String(istatus).c_str())
else if (istatus==STATION_NO_AP_FOUND) sstatus=F("SSID not Available!"); TD_ENTRY(wifi_config.mac2str(station->bssid))
else if (istatus==STATION_CONNECT_FAIL) sstatus=F("Connecion failed!"); static char ipstr [16];
else if (istatus==STATION_WRONG_PASSWORD) sstatus=F("Connecion failed! (Wrong Password)"); if (0>sprintf(ipstr, IPSTR,IP2STR(&station->ip))) strcpy (ipstr, F("0.0.0.0"));
else if (istatus==STATION_IDLE) sstatus=F("Idle");//should not happen TD_ENTRY(ipstr)
else sstatus=F("Disconnected"); web_interface.add4send(TR_E);
LABEL(sbuf,F("Status: "),sstatus) station = STAILQ_NEXT(station, next);
if (wifi_station_dhcpc_status()==DHCP_STARTED)sstatus=F("Started"); }
else sstatus=F("Stopped"); web_interface.add4send(TBODY_E);
LABEL(sbuf,F("DHCP Client: "),sstatus) //close table
LABEL(sbuf,F("IP: "),wifi_config.ip2str(WiFi.localIP())) web_interface.add4send(TABLE_END);
LABEL(sbuf,F("Gateway: "),wifi_config.ip2str(WiFi.gatewayIP())) wifi_softap_free_station_info();
LABEL(sbuf,F("Subnet: "),wifi_config.ip2str(WiFi.subnetMask())) }
sbuf+=PANEL_END; web_interface.add4send(PANEL_END);
//split to not reach the sending size limit (2920) web_interface.add4send(PANEL_TOP);
web_interface.WebServer.client().print(sbuf); web_interface.add4send(F("Station"));
if(wifi_get_opmode()==WIFI_STA || wifi_get_opmode()==WIFI_AP_STA) web_interface.add4send(F(" (enabled)"));
else web_interface.add4send(F(" (disabled)"));
sbuf=PAGE_BOTTOM; web_interface.add4send(PANEL_START);
//split to not reach the sending size limit LABEL(F("Mac address: "),wifi_config.mac2str(WiFi.macAddress(mac)))
web_interface.WebServer.client().print(sbuf); if(wifi_get_opmode()==WIFI_STA || wifi_get_opmode()==WIFI_AP_STA)
{
LABEL(F("Connection to: "),WiFi.SSID())
LABEL(F("Channel: "),String(wifi_get_channel()).c_str())
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(F("Status: "),sstatus.c_str())
if (wifi_station_dhcpc_status()==DHCP_STARTED)sstatus=F("Started");
else sstatus=F("Stopped");
LABEL(F("DHCP Client: "),sstatus.c_str())
LABEL(F("IP: "),wifi_config.ip2str(WiFi.localIP()))
LABEL(F("Gateway: "),wifi_config.ip2str(WiFi.gatewayIP()))
LABEL(F("Subnet: "),wifi_config.ip2str(WiFi.subnetMask()))
}
web_interface.add4send(PANEL_END);
web_interface.add4send(PAGE_BOTTOM);
web_interface.flushbuffer();
} }
void handle_web_interface_config() void handle_web_interface_config()
{ {
String sbuf=PAGE_HEAD ;
String IP; String IP;
if (wifi_get_opmode()==WIFI_STA ) IP=wifi_config.ip2str(WiFi.localIP()); if (wifi_get_opmode()==WIFI_STA ) IP=wifi_config.ip2str(WiFi.localIP());
else IP=wifi_config.ip2str(WiFi.softAPIP()); else IP=wifi_config.ip2str(WiFi.softAPIP());
sbuf+=NAV_START ; web_interface.add4send(PAGE_HEAD);
sbuf+=NAV_LEFT_PART1 ; web_interface.add4send(NAV_START) ;
sbuf+=NAV_LEFT_PART2a ; web_interface.add4send(NAV_LEFT_PART1) ;
sbuf+=IP; web_interface.add4send(NAV_LEFT_PART2a) ;
sbuf+=NAV_LEFT_PART2b ; web_interface.add4send(IP.c_str());
sbuf+=NAV_ELEMENT_ACTIVE ; web_interface.add4send(NAV_LEFT_PART2b);
sbuf+=NAV_LEFT_PART3a ; web_interface.add4send(NAV_ELEMENT_ACTIVE) ;
sbuf+=IP; web_interface.add4send(NAV_LEFT_PART3a) ;
sbuf+=NAV_LEFT_PART3b ; web_interface.add4send(IP.c_str());
sbuf+=NAV_RIGHT_PART ; web_interface.add4send(NAV_LEFT_PART3b) ;
sbuf+=NAV_END ; web_interface.add4send(NAV_RIGHT_PART) ;
sbuf+="<div>Configuration</div>"; web_interface.add4send(NAV_END) ;
sbuf+=PAGE_BOTTOM; web_interface.add4send("<div>Configuration</div>");
web_interface.WebServer.send(200, F("text/html"), sbuf); web_interface.add4send(PAGE_BOTTOM);
web_interface.flushbuffer();
} }
//URI Decoding function //URI Decoding function
@ -257,12 +295,58 @@ void WEBINTERFACE_CLASS::urldecode(char *dst, const char *src)
*dst++ = '\0'; *dst++ = '\0';
} }
//send immediatly the current data
void WEBINTERFACE_CLASS::flushbuffer()
{ //empty buffer
web_interface.add4send("", true);
//reset header part
bsendingstarted=false;
}
//check size of buffer
//add to buffer if under buffer limit
//send if buffer limit is reached or will be reached
void WEBINTERFACE_CLASS::add4send(const char * data2send, bool bimmediatsend)
{
//we store as no need to send right now
if (((buffer2send.length() + strlen(data2send)) <LIMIT_BUFFER) && !bimmediatsend)
{
buffer2send = buffer2send + data2send;
}
else //or buffer is over or need immediate
{//send current buffer first
if(!bsendingstarted)
{ //no header send so first send using header 2500 limit allow to add extra without calculation
web_interface.WebServer.send(200, F("text/html"), buffer2send);
bsendingstarted=true;
}
else
{ //direct data send
web_interface.WebServer.client().print(buffer2send);
}
buffer2send=data2send;
//do we need to purge or to store ?
if (bimmediatsend)
{//if some data flush
if (buffer2send.length()>0)
{
web_interface.WebServer.client().print(buffer2send);
//reset buffer
buffer2send="";
}
//reset header
bsendingstarted=false;
}
}
}
//constructor //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(F("/"),HTTP_ANY, handle_web_interface_root); WebServer.on(F("/"),HTTP_ANY, handle_web_interface_root);
WebServer.on(F("/CONFIG"),HTTP_ANY, handle_web_interface_config); WebServer.on(F("/CONFIG"),HTTP_ANY, handle_web_interface_config);
buffer2send="";
} }
WEBINTERFACE_CLASS web_interface(80); WEBINTERFACE_CLASS web_interface(80);