diff --git a/apps/webserver-nano/httpd-cgi.c b/apps/webserver-nano/httpd-cgi.c index ba36461e1..7d73adcbc 100644 --- a/apps/webserver-nano/httpd-cgi.c +++ b/apps/webserver-nano/httpd-cgi.c @@ -555,6 +555,11 @@ PT_THREAD(neighbors(struct httpd_state *s, char *ptr)) #if WEBSERVER_CONF_ROUTES extern uip_ds6_route_t uip_ds6_routing_table[]; +#if WEBSERVER_CONF_ROUTE_LINKS +static const char httpd_cgi_rtesl1[] HTTPD_STRING_ATTR = " (uip_mss() - 200)) { s->savei=i;s->savej=j; return numprinted; @@ -607,7 +609,40 @@ static const char httpd_cgi_rtesl3[] HTTPD_STRING_ATTR = ""; numprinted += httpd_snprintf((char *)uip_appdata+numprinted, uip_mss()-numprinted, httpd_cgi_addrf); } #endif +{ + static const char httpd_cgi_defr1[] HTTPD_STRING_ATTR = "\nRPL Parent\n"; + static const char httpd_cgi_defr2[] HTTPD_STRING_ATTR = " (%u sec)\n"; +#if 0 + uip_ip6addr_t *nexthop = uip_ds6_defrt_choose(); + if (nexthop) { + numprinted += httpd_snprintf((char *)uip_appdata+numprinted, uip_mss()-numprinted, httpd_cgi_defr1); + numprinted += httpd_cgi_sprint_ip6(*nexthop, uip_appdata + numprinted); + numprinted += httpd_snprintf((char *)uip_appdata+numprinted, uip_mss()-numprinted, httpd_cgi_defr2,nexthop->lifetime.start+nexthop->lifetime.interval-clock_seconds()); + } +#else +uip_ds6_defrt_t *locdefrt; +extern uip_ds6_defrt_t uip_ds6_defrt_list[UIP_DS6_DEFRT_NB]; + for(locdefrt = uip_ds6_defrt_list; + locdefrt < uip_ds6_defrt_list + UIP_DS6_DEFRT_NB; locdefrt++) { + if(locdefrt->isused) { + numprinted += httpd_snprintf((char *)uip_appdata+numprinted, uip_mss()-numprinted, httpd_cgi_defr1); +#if WEBSERVER_CONF_ROUTE_LINKS && 0 + numprinted += httpd_snprintf((char *)uip_appdata+numprinted, uip_mss()-numprinted, httpd_cgi_rtesl1); + numprinted += httpd_cgi_sprint_ip6(locdefrt->ipaddr, uip_appdata + numprinted); + numprinted += httpd_snprintf((char *)uip_appdata+numprinted, uip_mss()-numprinted, httpd_cgi_rtesl2); + numprinted += httpd_cgi_sprint_ip6(locdefrt->ipaddr, uip_appdata + numprinted); + numprinted += httpd_snprintf((char *)uip_appdata+numprinted, uip_mss()-numprinted, httpd_cgi_rtesl3); +#else + numprinted += httpd_cgi_sprint_ip6(locdefrt->ipaddr, uip_appdata + numprinted); +#endif + numprinted += httpd_snprintf((char *)uip_appdata+numprinted, uip_mss()-numprinted, httpd_cgi_defr2,locdefrt->lifetime.start+locdefrt->lifetime.interval-clock_seconds()); + // break; + } + } + +#endif +} /* Signal that this was the last segment */ s->savei = 0; return numprinted; @@ -717,8 +752,6 @@ uint8_t c; adc_disable(); #endif - snprintf(sensor_extvoltage, sizeof(sensor_extvoltage),"%u mV",1200*0xfff/adc_reading[8]); - static const char httpd_cgi_sensorv[] HTTPD_STRING_ATTR = "ADC chans : %u %u %u %u %u %u %u %u \n"; numprinted+=httpd_snprintf((char *)uip_appdata+numprinted, uip_mss()-numprinted, httpd_cgi_sensorv, adc_reading[0],adc_reading[1],adc_reading[2],adc_reading[3],adc_reading[4],adc_reading[5],adc_reading[6],adc_reading[7]); @@ -770,7 +803,7 @@ generate_stats(void *arg) uint32_t seconds=clock_seconds(); static const char httpd_cgi_stats[] HTTPD_STRING_ATTR = "\nStatistics\n"; - numprinted=httpd_snprintf((char *)uip_appdata + numprinted, uip_mss() - numprinted, httpd_cgi_stats); + numprinted=httpd_snprintf((char *)uip_appdata, uip_mss(), httpd_cgi_stats); #if ENERGEST_CONF_ON {uint8_t p1,p2; @@ -1024,10 +1057,27 @@ PT_THREAD(ajax_call(struct httpd_state *s, char *ptr)) static int iter; static char buf[128]; static uint8_t numprinted; - + uint16_t dt; PSOCK_BEGIN(&s->sout); -/*TODO:pick up time from ? parameter */ - timer_set(&t, 2*CLOCK_SECOND); + +#if WEBSERVER_CONF_PASSQUERY +/* Get update time from ? string, if present */ +{ + uint8_t i;uint16_t dt=0; + for (i=0;i '9') break; + dt = dt*10 + httpd_query[i]-'0'; + } + if (dt < 1) dt = 1; + // printf("dt %u\n",dt); + timer_set(&t, dt*CLOCK_SECOND); + httpd_query[i]=0; //necessary? + if (dt > WEBSERVER_CONF_TIMEOUT/2) s->ajax_timeout = 2*dt; else s->ajax_timeout = WEBSERVER_CONF_TIMEOUT; +} +#else + timer_set(&t, 2*CLOCK_SECOND); +#endif + iter = 0; while(1) { @@ -1064,7 +1114,8 @@ PT_THREAD(ajax_call(struct httpd_state *s, char *ptr)) adc_disable(); #endif -#if 0 + +#if 1 numprinted = snprintf(buf, sizeof(buf),"b(%u);adc(%u,%u,%u,%u,%u,%u,%u,%u);", 1200*0xfff/adc_reading[8],adc_reading[0],adc_reading[1],adc_reading[2],adc_reading[3],adc_reading[4],adc_reading[5],adc_reading[6],adc_reading[7]); #else @@ -1074,14 +1125,14 @@ PT_THREAD(ajax_call(struct httpd_state *s, char *ptr)) } if (iter<3) { static const char httpd_cgi_ajax11[] HTTPD_STRING_ATTR = "wt('Econtag ["; - static const char httpd_cgi_ajax12[] HTTPD_STRING_ATTR = "]');"; + static const char httpd_cgi_ajax12[] HTTPD_STRING_ATTR = "]');"; numprinted += httpd_snprintf(buf+numprinted, sizeof(buf)-numprinted,httpd_cgi_ajax11); #if WEBSERVER_CONF_PRINTADDR /* Note address table is filled from the end down */ {int i; for (i=0; isout, buf); + /* Can do fixed intervals or fixed starting points */ +#if FIXED_INTERVALS timer_restart(&t); - PSOCK_WAIT_UNTIL(&s->sout, timer_expired(&t)); + PSOCK_WAIT_UNTIL(&s->sout, timer_expired(&t)); +#else + PSOCK_WAIT_UNTIL(&s->sout, timer_expired(&t)); + timer_reset(&t); +#endif } PSOCK_END(&s->sout); } diff --git a/apps/webserver-nano/httpd-fs/makefsdata.ignore/ajax.js b/apps/webserver-nano/httpd-fs/makefsdata.ignore/ajax.js index eb487ac5a..cdd7cebc7 100644 --- a/apps/webserver-nano/httpd-fs/makefsdata.ignore/ajax.js +++ b/apps/webserver-nano/httpd-fs/makefsdata.ignore/ajax.js @@ -3,6 +3,7 @@ function e(el){return document.getElementById(el);} function ls(){try{r=new XMLHttpRequest();}catch(e){alert("Browswer does not support Ajax");return false;}r.open("GET","/ajaxdata.shtml",true); x=0;r.onreadystatechange=function(){e('date').innerHTML=(new Date()).toTimeString();if(r.readyState>0){j=r.responseText.substr(x);x+=j.length;eval(j);}};r.send(null);} +function tb(x){var t=e('ss');if(x||t.value=="RUN"){t.value="STOP";ls();}else{t.value="RUN";r.abort();}} function s(el,n,max,text){e(el).innerHTML=''+''+''+''+'
'+text+'  
';} function wt(m){document.title=m;e('v').innerHTML=m;} function dc(n,d){return n.toFixed(d);} @@ -12,7 +13,7 @@ function ax(m){s('ax',m+2000,4000,'Acceleration (X-axis) '+m+'mg');} function ay(m){s('ay',m+2000,4000,'Acceleration (Y-axis) '+m+'mg');} function az(m){s('az',m+2000,4000,'Acceleration (Z-axis) '+m+'mg');} function rs(m){s('rs',n,100,'RSSI '+n);} -function p(c,l,t,r){cp=0.136*c;lt=0.478*t;lr=0.412*r;n=cp+lt+lr;//128rfa1@3v3 +function p(c,l,t,r){cp=0.00109*c;lt=0.00848*t;lr=0.00617*r;n=cp+lt+lr;//mc1322x s('p',n,200,'Power consumption '+dc(n,2)+' mW'); s('pc',cp,100,'CPU power '+dc(cp,2)+' mW'); s('pr',lr,200,'Radio RX power '+dc(lr,2)+' mW'); diff --git a/apps/webserver-nano/httpd-fs/makefsdata.ignore/ajax.shtml b/apps/webserver-nano/httpd-fs/makefsdata.ignore/ajax.shtml index ed119783c..455ba3c5e 100644 --- a/apps/webserver-nano/httpd-fs/makefsdata.ignore/ajax.shtml +++ b/apps/webserver-nano/httpd-fs/makefsdata.ignore/ajax.shtml @@ -1,6 +1,8 @@ %! header %!: /ajax.js -
+ +Interval seconds
+

Sensors

diff --git a/apps/webserver-nano/httpd-fs/makefsdata.ignore/status.shtml b/apps/webserver-nano/httpd-fs/makefsdata.ignore/status.shtml index b6574fbcb..501203f0f 100644 --- a/apps/webserver-nano/httpd-fs/makefsdata.ignore/status.shtml +++ b/apps/webserver-nano/httpd-fs/makefsdata.ignore/status.shtml @@ -1,10 +1,14 @@ %! header -

Addresses

+
Addresses
 %! addresses
-

Neighbors

+ +Neighbors %! neighbors -

Routes

+ +Routes %! routes -

Sensors

+ +Sensors %! sensors -%! file-stats . +
+%! file-stats . \ No newline at end of file diff --git a/apps/webserver-nano/httpd-fs/status.shtml b/apps/webserver-nano/httpd-fs/status.shtml index d18b74e28..501203f0f 100644 --- a/apps/webserver-nano/httpd-fs/status.shtml +++ b/apps/webserver-nano/httpd-fs/status.shtml @@ -1,10 +1,14 @@ %! header -

Addresses
+

Addresses
 %! addresses
-

Neighbors
+ +Neighbors %! neighbors -

Routes
+ +Routes %! routes -

Sensors
+ +Sensors %! sensors -%! file-stats . +

+%! file-stats . \ No newline at end of file diff --git a/apps/webserver-nano/httpd.c b/apps/webserver-nano/httpd.c index 7971832b8..234b76bb3 100644 --- a/apps/webserver-nano/httpd.c +++ b/apps/webserver-nano/httpd.c @@ -94,7 +94,6 @@ static PT_THREAD(send_file(struct httpd_state *s)) { PSOCK_BEGIN(&s->sout); - do { PSOCK_GENERATOR_SEND(&s->sout, generate, s); s->file.len -= s->len; @@ -488,11 +487,18 @@ httpd_appcall(void *state) PT_INIT(&s->outputpt); s->state = STATE_WAITING; s->timer = 0; +#if WEBSERVER_CONF_AJAX + s->ajax_timeout = WEBSERVER_CONF_TIMEOUT; +#endif handle_connection(s); } else if(s != NULL) { if(uip_poll()) { ++s->timer; - if(s->timer >= 20) { +#if WEBSERVER_CONF_AJAX + if(s->timer >= s->ajax_timeout) { +#else + if(s->timer >= WEBSERVER_CONF_TIMEOUT) { +#endif uip_abort(); memb_free(&conns, s); } diff --git a/apps/webserver-nano/httpd.h b/apps/webserver-nano/httpd.h index 3226a79b4..d10d389ef 100644 --- a/apps/webserver-nano/httpd.h +++ b/apps/webserver-nano/httpd.h @@ -76,6 +76,8 @@ #define WEBSERVER_CONF_CONNS 2 #define WEBSERVER_CONF_NAMESIZE 16 #define WEBSERVER_CONF_BUFSIZE 40 +/* Short tcp timeouts allow new connections sooner */ +#define WEBSERVER_CONF_TIMEOUT 20 /* Allow include in .shtml pages, e.g. %!: /header.html */ #define WEBSERVER_CONF_INCLUDE 1 /* Allow cgi in .shtml pages, e.g. %! file-stats . */ @@ -116,13 +118,13 @@ extern char httpd_query[WEBSERVER_CONF_PASSQUERY]; #define WEBSERVER_CONF_LOG 0 /* Include referrer in log */ #define WEBSERVER_CONF_REFERER 0 - /*-----------------------------------------------------------------------------*/ #elif WEBSERVER_CONF_NANO==2 /* webserver-mini having more content */ #define WEBSERVER_CONF_CONNS 2 #define WEBSERVER_CONF_NAMESIZE 20 #define WEBSERVER_CONF_BUFSIZE 40 +#define WEBSERVER_CONF_TIMEOUT 20 /* Allow include in .shtml pages, e.g. %!: /header.html */ #define WEBSERVER_CONF_INCLUDE 1 /* Allow cgi in .shtml pages, e.g. %! file-stats . */ @@ -148,7 +150,7 @@ extern char httpd_query[WEBSERVER_CONF_PASSQUERY]; //#define WEBSERVER_CONF_TICTACTOE 1 //Needs passquery of at least 10 chars #define WEBSERVER_CONF_AJAX 1 #define WEBSERVER_CONF_SHOW_ROOM 0 -//#define WEBSERVER_CONF_PASSQUERY 10 +#define WEBSERVER_CONF_PASSQUERY 10 #if WEBSERVER_CONF_PASSQUERY extern char httpd_query[WEBSERVER_CONF_PASSQUERY]; #endif @@ -171,6 +173,7 @@ extern char httpd_query[WEBSERVER_CONF_PASSQUERY]; #define WEBSERVER_CONF_CONNS 6 #define WEBSERVER_CONF_NAMESIZE 20 #define WEBSERVER_CONF_BUFSIZE 40 +#define WEBSERVER_CONF_TIMEOUT 20 /* Allow include in .shtml pages, e.g. %!: /header.html */ #define WEBSERVER_CONF_INCLUDE 1 /* Allow cgi in .shtml pages, e.g. %! file-stats . */ @@ -285,6 +288,9 @@ struct httpd_state { #if WEBSERVER_CONF_LOADTIME clock_time_t pagetime; #endif +#if WEBSERVER_CONF_AJAX + uint16_t ajax_timeout; +#endif #if WEBSERVER_CONF_NEIGHBORS || WEBSERVER_CONF_ROUTES uint8_t starti,savei,startj,savej; #endif