From ea3d427c33e048ce181ccbb5a04c5e8cd3436f0d Mon Sep 17 00:00:00 2001 From: David Kopf Date: Tue, 21 Feb 2012 11:19:25 -0500 Subject: [PATCH] Add PAGETITLE option to webserver-nano, compress status page white space. --- apps/webserver-nano/httpd-cgi.c | 36 ++++++++++++++++++++--- apps/webserver-nano/httpd-fs/status.shtml | 8 ++--- apps/webserver-nano/httpd-fsdata.c | 33 ++++++++++----------- apps/webserver-nano/httpd.h | 12 ++++++++ 4 files changed, 64 insertions(+), 25 deletions(-) diff --git a/apps/webserver-nano/httpd-cgi.c b/apps/webserver-nano/httpd-cgi.c index 4bfd9432b..8a78bee0a 100644 --- a/apps/webserver-nano/httpd-cgi.c +++ b/apps/webserver-nano/httpd-cgi.c @@ -30,7 +30,6 @@ * * */ -/* Line endings in git repository are LF instead of CR-LF ? */ /* * This file includes functions that are called by the web server * scripts. The functions takes no argument, and the return value is @@ -185,19 +184,38 @@ static unsigned short generate_header(void *arg) { unsigned short numprinted=0; + #if WEBSERVER_CONF_HEADER_W3C #define _MSS1 100 static const char httpd_cgi_headerw[] HTTPD_STRING_ATTR = ""; numprinted+=httpd_snprintf((char *)uip_appdata+numprinted, uip_mss()-numprinted, httpd_cgi_headerw); #endif + #if WEBSERVER_CONF_HEADER_ICON #define _MSS2 105 - static const char httpd_cgi_header1[] HTTPD_STRING_ATTR = "Contiki-nano"; +#ifdef WEBSERVER_CONF_PAGETITLE + static const char httpd_cgi_header1[] HTTPD_STRING_ATTR = "%s"; +#else + static const char httpd_cgi_header1[] HTTPD_STRING_ATTR = "Contiki-Nano"; +#endif #else #define _MSS2 52 - static const char httpd_cgi_header1[] HTTPD_STRING_ATTR = "Contiki-nano"; +#ifdef WEBSERVER_CONF_PAGETITLE + static const char httpd_cgi_header1[] HTTPD_STRING_ATTR = "%s"; +#else + static const char httpd_cgi_header1[] HTTPD_STRING_ATTR = "Contiki-Nano"; #endif +#endif + +#ifdef WEBSERVER_CONF_PAGETITLE +#define WAD ((struct uip_ip_hdr *)&uip_buf[UIP_LLH_LEN])->destipaddr.u8 +{ char buf[40]; + WEBSERVER_CONF_PAGETITLE; + numprinted+=httpd_snprintf((char *)uip_appdata+numprinted, uip_mss()-numprinted, httpd_cgi_header1,buf); +} +#else numprinted+=httpd_snprintf((char *)uip_appdata+numprinted, uip_mss()-numprinted, httpd_cgi_header1); +#endif #if WEBSERVER_CONF_HEADER_MENU #define _MSS3 32 @@ -538,7 +556,7 @@ generate_sensor_readings(void *arg) static const char httpd_cgi_sensor2[] HTTPD_STRING_ATTR = "Battery : %s\n"; // static const char httpd_cgi_sensr12[] HTTPD_STRING_ATTR = "Temperature: %s Battery: %s
"; static const char httpd_cgi_sensor3[] HTTPD_STRING_ATTR = "Uptime : %02d:%02d:%02d\n"; - static const char httpd_cgi_sensor3d[] HTTPD_STRING_ATTR = "Uptime : %u days %02u:%02u:%02u/n"; + static const char httpd_cgi_sensor3d[] HTTPD_STRING_ATTR = "Uptime : %u days %02u:%02u:%02u\n"; // static const char httpd_cgi_sensor4[] HTTPD_STRING_ATTR = "Sleeping time : %02d:%02d:%02d (%d%%)
"; numprinted=0; @@ -624,7 +642,17 @@ uint8_t c; numprinted =httpd_snprintf((char *)uip_appdata, uip_mss(), httpd_cgi_sensor0,(unsigned int) (seconds-last_tempupdate)); } numprinted+=httpd_snprintf((char *)uip_appdata+numprinted, uip_mss()-numprinted, httpd_cgi_sensor1, sensor_temperature); +#if CONTIKI_TARGET_REDBEE_ECONOTAG +/* Econotag at 3v55 with 10 ohms to LiFePO4 battery: 3680mv usb 3106 battery (meter 3.08). Take 3500 as breakpoint for USB connected */ + static const char httpd_cgi_sensor2u[] HTTPD_STRING_ATTR = "Vcc (USB) : %s\n"; + if(adc_reading[8]<1404) { + numprinted+=httpd_snprintf((char *)uip_appdata+numprinted, uip_mss()-numprinted, httpd_cgi_sensor2u, sensor_extvoltage); + } else { + numprinted+=httpd_snprintf((char *)uip_appdata+numprinted, uip_mss()-numprinted, httpd_cgi_sensor2, sensor_extvoltage); + } +#else numprinted+=httpd_snprintf((char *)uip_appdata+numprinted, uip_mss()-numprinted, httpd_cgi_sensor2, sensor_extvoltage); +#endif // numprinted+=httpd_snprintf((char *)uip_appdata+numprinted, uip_mss()-numprinted, httpd_cgi_sensr12, sensor_temperature,sensor_extvoltage); #if RADIOSTATS diff --git a/apps/webserver-nano/httpd-fs/status.shtml b/apps/webserver-nano/httpd-fs/status.shtml index b6574fbcb..d18b74e28 100644 --- a/apps/webserver-nano/httpd-fs/status.shtml +++ b/apps/webserver-nano/httpd-fs/status.shtml @@ -1,10 +1,10 @@ %! header -

Addresses

+

Addresses
%! addresses -

Neighbors

+

Neighbors
%! neighbors -

Routes

+

Routes
%! routes -

Sensors

+

Sensors
%! sensors %! file-stats . diff --git a/apps/webserver-nano/httpd-fsdata.c b/apps/webserver-nano/httpd-fsdata.c index 486bbdc3d..b0c514a5a 100644 --- a/apps/webserver-nano/httpd-fsdata.c +++ b/apps/webserver-nano/httpd-fsdata.c @@ -1,4 +1,4 @@ -/*********Generated by contiki/tools/makefsdata on 2011-09-10*********/ +/*********Generated by contiki/tools/makefsdata on 2012-02-21*********/ const char data_404_html[86] HTTPD_STRING_ATTR = { @@ -48,24 +48,23 @@ const char data_index_shtml[120] HTTPD_STRING_ATTR = { 0x21, 0x0a, 0x25, 0x21, 0x20, 0x66, 0x69, 0x6c, 0x65, 0x2d, 0x73, 0x74, 0x61, 0x74, 0x73, 0x20, 0x2e}; -const char data_status_shtml[158] HTTPD_STRING_ATTR = { +const char data_status_shtml[150] HTTPD_STRING_ATTR = { /* /status.shtml */ 0x2f, 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, 0x2e, 0x73, 0x68, 0x74, 0x6d, 0x6c, 0x00, 0x25, 0x21, 0x20, 0x68, 0x65, 0x61, 0x64, 0x65, 0x72, 0x0a, - 0x3c, 0x68, 0x34, 0x3e, 0x41, 0x64, 0x64, 0x72, 0x65, 0x73, - 0x73, 0x65, 0x73, 0x3c, 0x2f, 0x68, 0x34, 0x3e, 0x0a, 0x25, - 0x21, 0x20, 0x61, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x65, - 0x73, 0x0a, 0x3c, 0x68, 0x34, 0x3e, 0x4e, 0x65, 0x69, 0x67, - 0x68, 0x62, 0x6f, 0x72, 0x73, 0x3c, 0x2f, 0x68, 0x34, 0x3e, - 0x0a, 0x25, 0x21, 0x20, 0x6e, 0x65, 0x69, 0x67, 0x68, 0x62, - 0x6f, 0x72, 0x73, 0x0a, 0x3c, 0x68, 0x34, 0x3e, 0x52, 0x6f, - 0x75, 0x74, 0x65, 0x73, 0x3c, 0x2f, 0x68, 0x34, 0x3e, 0x0a, - 0x25, 0x21, 0x20, 0x72, 0x6f, 0x75, 0x74, 0x65, 0x73, 0x0a, - 0x3c, 0x68, 0x34, 0x3e, 0x53, 0x65, 0x6e, 0x73, 0x6f, 0x72, - 0x73, 0x3c, 0x2f, 0x68, 0x34, 0x3e, 0x0a, 0x25, 0x21, 0x20, - 0x73, 0x65, 0x6e, 0x73, 0x6f, 0x72, 0x73, 0x0a, 0x25, 0x21, - 0x20, 0x66, 0x69, 0x6c, 0x65, 0x2d, 0x73, 0x74, 0x61, 0x74, - 0x73, 0x20, 0x2e, 0x0a}; + 0x3c, 0x70, 0x3e, 0x41, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, + 0x65, 0x73, 0x3c, 0x62, 0x72, 0x3e, 0x0a, 0x25, 0x21, 0x20, + 0x61, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x65, 0x73, 0x0a, + 0x3c, 0x70, 0x3e, 0x4e, 0x65, 0x69, 0x67, 0x68, 0x62, 0x6f, + 0x72, 0x73, 0x3c, 0x62, 0x72, 0x3e, 0x0a, 0x25, 0x21, 0x20, + 0x6e, 0x65, 0x69, 0x67, 0x68, 0x62, 0x6f, 0x72, 0x73, 0x0a, + 0x3c, 0x70, 0x3e, 0x52, 0x6f, 0x75, 0x74, 0x65, 0x73, 0x3c, + 0x62, 0x72, 0x3e, 0x0a, 0x25, 0x21, 0x20, 0x72, 0x6f, 0x75, + 0x74, 0x65, 0x73, 0x0a, 0x3c, 0x70, 0x3e, 0x53, 0x65, 0x6e, + 0x73, 0x6f, 0x72, 0x73, 0x3c, 0x62, 0x72, 0x3e, 0x0a, 0x25, + 0x21, 0x20, 0x73, 0x65, 0x6e, 0x73, 0x6f, 0x72, 0x73, 0x0a, + 0x25, 0x21, 0x20, 0x66, 0x69, 0x6c, 0x65, 0x2d, 0x73, 0x74, + 0x61, 0x74, 0x73, 0x20, 0x2e, 0x0a}; const char data_tcp_shtml[227] HTTPD_STRING_ATTR = { /* /tcp.shtml */ @@ -113,4 +112,4 @@ const struct httpd_fsdata_file file_tcp_shtml[] HTTPD_STRING_ATTR ={{ fi #define HTTPD_FS_ROOT file_tcp_shtml #define HTTPD_FS_NUMFILES 5 -#define HTTPD_FS_SIZE 759 +#define HTTPD_FS_SIZE 751 diff --git a/apps/webserver-nano/httpd.h b/apps/webserver-nano/httpd.h index 6233edf81..7e9ab900a 100644 --- a/apps/webserver-nano/httpd.h +++ b/apps/webserver-nano/httpd.h @@ -49,6 +49,18 @@ * The advertised MSS is easily seen in wireshark. * Some example set a small MSS by default. rpl-border-router for example uses a receive window of 60. */ + + /* Titles of web pages served with the !header cgi can be configured to show characteristics of the node. + * For example "CD1A:3456" to show the node id and clock time of last access. + * Change this line and rebuild to make indentifiable instances. + * Undefine to reduce program size, giving "Contiki-Nano" title on all pages. + * WAD indexes into the uip destaddr field, which contains the address that we responded to. + */ +#define WEBSERVER_CONF_PAGETITLE sprintf(buf,"[%02x%02x]",WAD[14],WAD[15]); +//#define WEBSERVER_CONF_PAGETITLE sprintf(buf,"Nano[%02x%02x%02x]",WAD[13],WAD[14],WAD[15]); +//#define WEBSERVER_CONF_PAGETITLE sprintf(buf,"Nano[%02x%02x...%02x%02x]",WAD[0],WAD[1],WAD[14],WAD[15]); +//#define WEBSERVER_CONF_PAGETITLE sprintf(buf,"%2x%02x...%2x%02x [%lu]",WAD[0],WAD[1],WAD[14],WAD[15],clock_seconds()); + #ifndef WEBSERVER_CONF_NANO #if CONTIKI_TARGET_SKY || CONTIKI_TARGET_STK500 #define WEBSERVER_CONF_NANO 1