Add variable update time for Ajax display. Update status.shtml with <pre> tag now used by cgi.

This commit is contained in:
David Kopf 2012-03-10 10:43:23 -05:00
parent cf3827829d
commit ca273e28e9
7 changed files with 123 additions and 36 deletions

View File

@ -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 = "<a href=http://[";
static const char httpd_cgi_rtesl2[] HTTPD_STRING_ATTR = "]/status.shtml>";
static const char httpd_cgi_rtesl3[] HTTPD_STRING_ATTR = "</a>";
#endif
/*---------------------------------------------------------------------------*/
static unsigned short
make_routes(void *p)
@ -573,9 +578,6 @@ struct httpd_state *s=p;
j++;
#if WEBSERVER_CONF_ROUTE_LINKS
static const char httpd_cgi_rtesl1[] HTTPD_STRING_ATTR = "<a href=http://[";
static const char httpd_cgi_rtesl2[] HTTPD_STRING_ATTR = "]/status.shtml>";
static const char httpd_cgi_rtesl3[] HTTPD_STRING_ATTR = "</a>";
numprinted += httpd_snprintf((char *)uip_appdata+numprinted, uip_mss()-numprinted, httpd_cgi_rtesl1);
numprinted += httpd_cgi_sprint_ip6(uip_ds6_routing_table[i].ipaddr, uip_appdata + numprinted);
numprinted += httpd_snprintf((char *)uip_appdata+numprinted, uip_mss()-numprinted, httpd_cgi_rtesl2);
@ -592,7 +594,7 @@ static const char httpd_cgi_rtesl3[] HTTPD_STRING_ATTR = "</a>";
} else {
numprinted += httpd_snprintf((char *)uip_appdata+numprinted, uip_mss()-numprinted, httpd_cgi_rtes3);
}
/* If buffer nearly full, send it and wait for the next call. Could be a retransmission, or the next segment */
/* If buffer near full, send it and wait for the next call. Could be a retransmission, or the next segment */
if(numprinted > (uip_mss() - 200)) {
s->savei=i;s->savej=j;
return numprinted;
@ -607,7 +609,40 @@ static const char httpd_cgi_rtesl3[] HTTPD_STRING_ATTR = "</a>";
numprinted += httpd_snprintf((char *)uip_appdata+numprinted, uip_mss()-numprinted, httpd_cgi_addrf);
}
#endif
{
static const char httpd_cgi_defr1[] HTTPD_STRING_ATTR = "\n<big><b>RPL Parent</b></big>\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 = "<em>ADC chans :</em> %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 = "\n<big><b>Statistics</b></big>\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<WEBSERVER_CONF_PASSQUERY;i++) {
if (httpd_query[i] < '0' || httpd_query[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; i<UIP_DS6_ADDR_NB;i++) {
if (uip_ds6_if.addr_list[i].isused) {
numprinted += httpd_cgi_sprint_ip6(uip_ds6_if.addr_list[i].ipaddr, buf + numprinted);
numprinted += httpd_cgi_sprint_ip6(uip_ds6_if.addr_list[i].ipaddr, buf + numprinted);
break;
}
}
@ -1256,8 +1307,15 @@ static uint16_t c0=0x3ff,c1=0x3ff,c2=0x3ff,c3=0x3ff,c4=0x3ff,c5=0x3ff,c6=0x3ff,c
#if ENERGEST_CONF_ON
{
#if 1
/* Send on times in percent since last update. Handle 16 bit rtimer wraparound. */
/* Javascript must convert based on platform cpu, tx, rx power, e.g. 20ma*3v3=66mW*(% on time/100) */
/* Send on times in percent since last update. Handle 16 bit rtimer wraparound.
* Javascript must convert based on platform cpu, tx, rx power.
* e.g. for cpu drawing 1.2ma@3v3, cp = 1.2*3.3*(% on time)/100 = 0.0396*c;
* Low power mode l is essentially zero for cpus that sleep.
* function p(c,l,t,r){cp=0.013*c;lt=0.465*t;lr=0.400*r;n=cp+lt+lr;//128rfa1@3v3,3dBm
* function p(c,l,t,r){cp=0.013*c;lt=0.317*t;lr=0.400*r;n=cp+lt+lr;//128rfa1@3v3,0dBm
* function p(c,l,t,r){cp=0.109*c;lt=0.848*t;lr=0.617*r;n=cp+lt+lr;//mc1322x@3v3,0dBm
* Precision can be increased by multiplying by another 100 before sending.
*/
static rtimer_clock_t last_send;
rtimer_clock_t delta_time;
static unsigned long last_cpu, last_lpm, last_listen, last_transmit;
@ -1267,10 +1325,10 @@ static uint16_t c0=0x3ff,c1=0x3ff,c2=0x3ff,c3=0x3ff,c4=0x3ff,c5=0x3ff,c6=0x3ff,c
last_send=RTIMER_NOW();
static const char httpd_cgi_ajaxe1[] HTTPD_STRING_ATTR = "p(%lu,%lu,%lu,%lu);";
numprinted += httpd_snprintf(buf+numprinted, sizeof(buf)-numprinted,httpd_cgi_ajaxe1,
(100UL*(energest_total_time[ENERGEST_TYPE_CPU].current - last_cpu))/delta_time,
(100UL*(energest_total_time[ENERGEST_TYPE_LPM].current - last_lpm))/delta_time,
(100UL*(energest_total_time[ENERGEST_TYPE_TRANSMIT].current - last_transmit))/delta_time,
(100UL*(energest_total_time[ENERGEST_TYPE_LISTEN].current - last_listen))/delta_time);
(10000UL*(energest_total_time[ENERGEST_TYPE_CPU].current - last_cpu))/delta_time,
(10000UL*(energest_total_time[ENERGEST_TYPE_LPM].current - last_lpm))/delta_time,
(10000UL*(energest_total_time[ENERGEST_TYPE_TRANSMIT].current - last_transmit))/delta_time,
(10000UL*(energest_total_time[ENERGEST_TYPE_LISTEN].current - last_listen))/delta_time);
last_cpu = energest_total_time[ENERGEST_TYPE_CPU].current;
last_lpm = energest_total_time[ENERGEST_TYPE_LPM].current;
last_transmit = energest_total_time[ENERGEST_TYPE_TRANSMIT].current;
@ -1299,8 +1357,14 @@ static uint16_t c0=0x3ff,c1=0x3ff,c2=0x3ff,c3=0x3ff,c4=0x3ff,c5=0x3ff,c6=0x3ff,c
#endif /* ENERGEST_CONF_ON */
PSOCK_SEND_STR(&s->sout, 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);
}

View File

@ -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='<table width=504 border=0 cellpadding=1 cellspacing=0>'+'<tr><td width=200>'+text+'</td>'+'<td width='+(10+300*n/max)+' bgcolor="gray">&nbsp;</td>'+'<td width='+(310-300*n/max)+' bgcolor="lightgray">&nbsp;</td>'+'</table>';}
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');

View File

@ -1,6 +1,8 @@
%! header
%!: /ajax.js
<input type="button" value="RUN" onclick="ls()"><input type="button" value="STOP" onclick="r.abort()"><br><span id="date"></span>
<input id="ss" type="button" value="STOP" onclick="tb(0)">
Interval <input id="tc" type="text" style="width:60;text-align:right;" maxlength="5" value="10" onchange="tb(1)"> seconds<br>
<span id="date"></span>
<div id="v"></div>
<pre><span id="rims"></span><div id="ener"></div></pre>
<h2>Sensors</h2>

View File

@ -1,10 +1,14 @@
%! header
<h4>Addresses</h4>
<pre><big><b>Addresses</b></big>
%! addresses
<h4>Neighbors</h4>
<big><b>Neighbors</b></big>
%! neighbors
<h4>Routes</h4>
<big><b>Routes</b></big>
%! routes
<h4>Sensors</h4>
<big><b>Sensors</b></big>
%! sensors
%! file-stats .
</pre>
%! file-stats .

View File

@ -1,10 +1,14 @@
%! header
<p>Addresses<br>
<pre><big><b>Addresses</b></big>
%! addresses
<p>Neighbors<br>
<big><b>Neighbors</b></big>
%! neighbors
<p>Routes<br>
<big><b>Routes</b></big>
%! routes
<p>Sensors<br>
<big><b>Sensors</b></big>
%! sensors
%! file-stats .
</pre>
%! file-stats .

View File

@ -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);
}

View File

@ -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