Exemple #1
0
void tmr0_isr(void) {
	if(bit_is_set(*TMR(0,CSCTRL),TCF1)) {
		current_clock++;
		if((current_clock % CLOCK_CONF_SECOND) == 0) {
			seconds++;

/* ADC can be serviced every tick or every second */
#if CLOCK_CONF_SAMPLEADC > 1
			adc_service();
#endif
		}
#if CLOCK_CONF_SAMPLEADC == 1
		adc_service();
#endif
		if(etimer_pending() &&
		   (etimer_next_expiration_time() - current_clock - 1) > MAX_TICKS) {
 			etimer_request_poll();
 		}


		/* clear the compare flags */
		clear_bit(*TMR(0,SCTRL),TCF);
		clear_bit(*TMR(0,CSCTRL),TCF1);
		clear_bit(*TMR(0,CSCTRL),TCF2);
		return;
	} else {
		/* this timer didn't create an interrupt condition */
		return;
	}
}
Exemple #2
0
void
clock_init()
{
	/* timer setup */
	/* CTRL */
#define COUNT_MODE 1      /* use rising edge of primary source */
#define PRIME_SRC  0xf    /* Perip. clock with 128 prescale (for 24Mhz = 187500Hz)*/
#define SEC_SRC    0      /* don't need this */
#define ONCE       0      /* keep counting */
#define LEN        1      /* count until compare then reload with value in LOAD */
#define DIR        0      /* count up */
#define CO_INIT    0      /* other counters cannot force a re-initialization of this counter */
#define OUT_MODE   0      /* OFLAG is asserted while counter is active */

	*TMR_ENBL = 0;                     /* tmrs reset to enabled */
	*TMR0_SCTRL = 0;
	*TMR0_CSCTRL =0x0040;
	*TMR0_LOAD = 0;                    /* reload to zero */
	*TMR0_COMP_UP = 1875;             /* trigger a reload at the end */
	*TMR0_CMPLD1 = 1875;              /* compare 1 triggered reload level, 10HZ maybe? */
	*TMR0_CNTR = 0;                    /* reset count register */
	*TMR0_CTRL = (COUNT_MODE<<13) | (PRIME_SRC<<9) | (SEC_SRC<<7) | (ONCE<<6) | (LEN<<5) | (DIR<<4) | (CO_INIT<<3) | (OUT_MODE);
	*TMR_ENBL = 0xf;                   /* enable all the timers --- why not? */

	enable_irq(TMR);
/* Do startup scan of the ADC */
#if CLOCK_CONF_SAMPLEADC
	adc_reading[8]=0;
	adc_init();
	while (adc_reading[8]==0) adc_service();
#endif
}
Exemple #3
0
static int poti_value(int type) 
{
	uint16_t result = 0;
	uint8_t counter = 0;

    global_irq_disable();

	while(counter < 254)
	{
      adc_service();
	  result = adc_voltage(ADC_PIN);
	  counter++;
	  clock_delay_usec( 33 );
	}

    global_irq_enable();

	return result;
}
Exemple #4
0
/*---------------------------------------------------------------------------*/
static
PT_THREAD(ajax_call(struct httpd_state *s, char *ptr))
{
  static struct timer t;
  static int iter;
  static char buf[128];
  static uint8_t numprinted;
  
  PSOCK_BEGIN(&s->sout);
/*TODO:pick up time from ? parameter */
  timer_set(&t, 2*CLOCK_SECOND);
  iter = 0;
  
  while(1) {
  	iter++;

#if CONTIKI_TARGET_SKY
    SENSORS_ACTIVATE(sht11_sensor);
    SENSORS_ACTIVATE(light_sensor);
    numprinted = snprintf(buf, sizeof(buf),
	     "t(%d);h(%d);l1(%d);l2(%d);",
	     sht11_sensor.value(SHT11_SENSOR_TEMP),
	     sht11_sensor.value(SHT11_SENSOR_HUMIDITY),
         light_sensor.value(LIGHT_SENSOR_PHOTOSYNTHETIC),
         light_sensor.value(LIGHT_SENSOR_TOTAL_SOLAR));
    SENSORS_DEACTIVATE(sht11_sensor);
    SENSORS_DEACTIVATE(light_sensor);

#elif CONTIKI_TARGET_MB851
  SENSORS_ACTIVATE(acc_sensor);    
  numprinted = snprintf(buf, sizeof(buf),"t(%d);ax(%d);ay(%d);az(%d);",
	     temperature_sensor.value(0),
	     acc_sensor.value(ACC_X_AXIS),
	     acc_sensor.value(ACC_Y_AXIS),
	     acc_sensor.value(ACC_Z_AXIS));   
  SENSORS_DEACTIVATE(acc_sensor);

#elif CONTIKI_TARGET_REDBEE_ECONOTAG
{	uint8_t c;
	adc_reading[8]=0;
	adc_init();
	while (adc_reading[8]==0) adc_service();
    adc_disable();
    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]);
}
		
#elif CONTIKI_TARGET_MINIMAL_NET
static uint16_t c0=0x3ff,c1=0x3ff,c2=0x3ff,c3=0x3ff,c4=0x3ff,c5=0x3ff,c6=0x3ff,c7=0x3ff;
    numprinted = snprintf(buf, sizeof(buf), "t(%d);b(%u);v(%u);",273+(rand()&0x3f),3300-iter/10,iter);
	numprinted += snprintf(buf+numprinted, sizeof(buf)-numprinted,"adc(%u,%u,%u,%u,%u,%u,%u,%u);",c0,c1,c2,c3,c4,c5,c6,c7);
	c0+=(rand()&0xf)-8;
	c1+=(rand()&0xf)-8;
	c2+=(rand()&0xf)-7;
	c3+=(rand()&0x1f)-15;
	c4+=(rand()&0x3)-1;
	c5+=(rand()&0xf)-8;
	c6+=(rand()&0xf)-8;
	c7+=(rand()&0xf)-8;
  if (iter==1) {
    static const char httpd_cgi_ajax11[] HTTPD_STRING_ATTR = "wt('Minimal-net ";
	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);
	    break;
	  }
    }
}
#endif
	numprinted += httpd_snprintf(buf+numprinted, sizeof(buf)-numprinted,httpd_cgi_ajax12);
  }

#elif CONTIKI_TARGET_AVR_ATMEGA128RFA1
{ uint8_t i;int16_t tmp,bat;
  BATMON = 16; //give BATMON time to stabilize at highest range and lowest voltage
/* Measure internal temperature sensor, see atmega128rfa1 datasheet */
/* This code disabled by default for safety.
   Selecting an internal reference will short it to anything connected to the AREF pin
 */
#if 1
  ADCSRB|=1<<MUX5;          //this bit buffered till ADMUX written to!
  ADMUX =0xc9;              // Select internal 1.6 volt ref, temperature sensor ADC channel
  ADCSRA=0x85;              //Enable ADC, not free running, interrupt disabled, clock divider 32 (250 KHz@ 8 MHz)
//  while ((ADCSRB&(1<<AVDDOK))==0);  //wait for AVDD ok
//  while ((ADCSRB&(1<<REFOK))==0);  //wait for ref ok 
  ADCSRA|=1<<ADSC;          //Start throwaway conversion
  while (ADCSRA&(1<<ADSC)); //Wait till done
  ADCSRA|=1<<ADSC;          //Start another conversion
  while (ADCSRA&(1<<ADSC)); //Wait till done
  tmp=ADC;                  //Read adc
  tmp=11*tmp-2728+(tmp>>2); //Convert to celcius*10 (should be 11.3*h, approximate with 11.25*h)
  ADCSRA=0;                 //disable ADC
  ADMUX=0;                  //turn off internal vref      
#endif
/* Bandgap can't be measured against supply voltage in this chip. */
/* Use BATMON register instead */
  for ( i=16; i<31; i++) {
    BATMON = i;
    if ((BATMON&(1<<BATMON_OK))==0) break;
  }
  bat=2550-75*16-75+75*i;  //-75 to take the floor of the 75 mv transition window
  static const char httpd_cgi_ajax10[] HTTPD_STRING_ATTR ="t(%u),b(%u);adc(%d,%d,%u,%u,%u,%u,%u,%lu);";
  numprinted = httpd_snprintf(buf, sizeof(buf),httpd_cgi_ajax10,tmp,bat,iter,tmp,bat,sleepcount,OCR2A,0,clock_time(),clock_seconds());
  if (iter==1) {
    static const char httpd_cgi_ajax11[] HTTPD_STRING_ATTR = "wt('128rfa1 [";
	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);
	    break;
	  }
    }
}
#endif
	numprinted += httpd_snprintf(buf+numprinted, sizeof(buf)-numprinted,httpd_cgi_ajax12);
  }
}
#elif CONTIKI_TARGET_AVR_RAVEN
{ int16_t tmp,bat;
#if 1
/* Usual way to get AVR supply voltage, measure 1.1v bandgap using Vcc as reference.
 * This connects the bandgap to the AREF pin, so enable only if there is no external AREF!
 * A capacitor may be connected to this pin to reduce reference noise.
 */
  ADMUX =0x5E;              //Select AVCC as reference, measure 1.1 volt bandgap reference.
  ADCSRA=0x87;              //Enable ADC, not free running, interrupt disabled, clock divider  128 (62 KHz@ 8 MHz)
  ADCSRA|=1<<ADSC;          //Start throwaway conversion
  while (ADCSRA&(1<<ADSC)); //Wait till done
  ADCSRA|=1<<ADSC;          //Start another conversion
  while (ADCSRA&(1<<ADSC)); //Wait till done
//bat=1126400UL/ADC;        //Get supply voltage (factor nominally 1100*1024)
  bat=1198070UL/ADC;        //My Raven
  ADCSRA=0;                 //disable ADC
  ADMUX=0;                  //turn off internal vref
#else
  bat=3300;  
#endif
   
  tmp=420;
  
  static const char httpd_cgi_ajax10[] HTTPD_STRING_ATTR ="t(%u),b(%u);adc(%d,%d,%u,%u,%u,%u,%u,%lu);";
  numprinted = httpd_snprintf(buf, sizeof(buf),httpd_cgi_ajax10,tmp,bat,iter,tmp,bat,sleepcount,OCR2A,0,clock_time(),clock_seconds());
  if (iter<3) {
    static const char httpd_cgi_ajax11[] HTTPD_STRING_ATTR = "wt('Raven [";
	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);
	    break;
	  }
    }
}
#endif
	numprinted += httpd_snprintf(buf+numprinted, sizeof(buf)-numprinted,httpd_cgi_ajax12);
  }
}

//#elif CONTIKI_TARGET_IS_SOMETHING_ELSE
#else
{
  static const char httpd_cgi_ajax10[] HTTPD_STRING_ATTR ="v(%u);";
  numprinted = httpd_snprintf(buf, sizeof(buf),httpd_cgi_ajax10,iter);
  if (iter==1) {
    static const char httpd_cgi_ajax11[] HTTPD_STRING_ATTR = "wt('Contiki Ajax ";
	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);
	    break;
	  }
    }
}
#endif
	numprinted += httpd_snprintf(buf+numprinted, sizeof(buf)-numprinted,httpd_cgi_ajax12);
  }
}
#endif
 
#if CONTIKIMAC_CONF_COMPOWER
#include "sys/compower.h"
{
//sl=compower_idle_activity.transmit/RTIMER_ARCH_SECOND;
//sl=compower_idle_activity.listen/RTIMER_ARCH_SECOND;
}
#endif

#if RIMESTATS_CONF_ON

#include "net/rime/rimestats.h"
    static const char httpd_cgi_ajaxr1[] HTTPD_STRING_ATTR ="rime(%lu,%lu,%lu,%lu);";
    numprinted += httpd_snprintf(buf+numprinted, sizeof(buf)-numprinted,httpd_cgi_ajaxr1,
		rimestats.tx,rimestats.rx,rimestats.lltx-rimestats.tx,rimestats.llrx-rimestats.rx);
#endif

#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) */
	static rtimer_clock_t last_send;
	rtimer_clock_t delta_time;
    static unsigned long last_cpu, last_lpm, last_listen, last_transmit;
    energest_flush();
	delta_time=RTIMER_NOW()-last_send;
	if (RTIMER_CLOCK_LT(RTIMER_NOW(),last_send)) delta_time+=RTIMER_ARCH_SECOND;
	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);
    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;
    last_listen = energest_total_time[ENERGEST_TYPE_LISTEN].current;
#endif
#if 1
/* Send cumulative on times in percent*100 */
	uint16_t cpp,txp,rxp;
	uint32_t sl,clockseconds=clock_seconds();
//	energest_flush();
//	sl=((10000UL*energest_total_time[ENERGEST_TYPE_CPU].current)/RTIMER_ARCH_SECOND)/clockseconds;
    sl=energest_total_time[ENERGEST_TYPE_CPU].current/RTIMER_ARCH_SECOND;
    cpp=(10000UL*sl)/clockseconds;
//    txp=((10000UL*energest_total_time[ENERGEST_TYPE_TRANSMIT].current)/RTIMER_ARCH_SECOND)/clockseconds;
    sl=energest_total_time[ENERGEST_TYPE_TRANSMIT].current/RTIMER_ARCH_SECOND;
    txp=(10000UL*sl)/clockseconds;

 //   rxp=((10000UL*energest_total_time[ENERGEST_TYPE_LISTEN].current)/RTIMER_ARCH_SECOND)/clockseconds;
    sl=energest_total_time[ENERGEST_TYPE_LISTEN].current/RTIMER_ARCH_SECOND;
    rxp=(10000UL*sl)/clockseconds;

    static const char httpd_cgi_ajaxe2[] HTTPD_STRING_ATTR = "ener(%u,%u,%u);";	
    numprinted += httpd_snprintf(buf+numprinted, sizeof(buf)-numprinted,httpd_cgi_ajaxe2,cpp,txp,rxp);
#endif
}
#endif /* ENERGEST_CONF_ON */
 
    PSOCK_SEND_STR(&s->sout, buf);
    timer_restart(&t);
	PSOCK_WAIT_UNTIL(&s->sout, timer_expired(&t));
}
  PSOCK_END(&s->sout);
}
Exemple #5
0
/*---------------------------------------------------------------------------*/
static unsigned short
generate_sensor_readings(void *arg)
{
  uint16_t numprinted;
  uint16_t days,h,m,s;
  unsigned long seconds=clock_seconds();
  static const char httpd_cgi_sensor0[] HTTPD_STRING_ATTR = "[Updated %d seconds ago]<br><br>";
  static const char httpd_cgi_sensor1[] HTTPD_STRING_ATTR = "<pre><em>Temperature:</em> %s\n";
  static const char httpd_cgi_sensor2[] HTTPD_STRING_ATTR = "<em>Battery    :</em> %s\n";
//  static const char httpd_cgi_sensr12[] HTTPD_STRING_ATTR = "<em>Temperature:</em> %s   <em>Battery:</em> %s<br>";
  static const char httpd_cgi_sensor3[] HTTPD_STRING_ATTR = "<em>Uptime     :</em> %02d:%02d:%02d\n";
  static const char httpd_cgi_sensor3d[] HTTPD_STRING_ATTR = "<em>Uptime    :</em> %u days %02u:%02u:%02u/n";
// static const char httpd_cgi_sensor4[] HTTPD_STRING_ATTR = "<em>Sleeping time :</em> %02d:%02d:%02d (%d%%)<br>";

  numprinted=0;
  /* Generate temperature and voltage strings for each platform */
#if CONTIKI_TARGET_AVR_ATMEGA128RFA1  
{uint8_t i;
  BATMON = 16; //give BATMON time to stabilize at highest range and lowest voltage

/* Measure internal temperature sensor, see atmega128rfa1 datasheet */
/* This code disabled by default for safety.
   Selecting an internal reference will short it to anything connected to the AREF pin
 */
#if 0
  ADCSRB|=1<<MUX5;          //this bit buffered till ADMUX written to!
  ADMUX =0xc9;              // Select internal 1.6 volt ref, temperature sensor ADC channel
  ADCSRA=0x85;              //Enable ADC, not free running, interrupt disabled, clock divider 32 (250 KHz@ 8 MHz)
//  while ((ADCSRB&(1<<AVDDOK))==0);  //wait for AVDD ok
//  while ((ADCSRB&(1<<REFOK))==0);  //wait for ref ok 
  ADCSRA|=1<<ADSC;          //Start throwaway conversion
  while (ADCSRA&(1<<ADSC)); //Wait till done
  ADCSRA|=1<<ADSC;          //Start another conversion
  while (ADCSRA&(1<<ADSC)); //Wait till done
  h=ADC;                    //Read adc
  h=11*h-2728+(h>>2);       //Convert to celcius*10 (should be 11.3*h, approximate with 11.25*h)
  ADCSRA=0;                 //disable ADC
  ADMUX=0;                  //turn off internal vref      
  m=h/10;s=h-10*m;
  static const char httpd_cgi_sensor1_printf[] HTTPD_STRING_ATTR = "%d.%d C";
  httpd_snprintf(sensor_temperature,sizeof(sensor_temperature),httpd_cgi_sensor1_printf,m,s);
#endif

/* Bandgap can't be measured against supply voltage in this chip. */
/* Use BATMON register instead */
  for ( i=16; i<31; i++) {
    BATMON = i;
    if ((BATMON&(1<<BATMON_OK))==0) break;
  }
  h=2550-75*16-75+75*i; //-75 to take the floor of the 75 mv transition window
  static const char httpd_cgi_sensor2_printf[] HTTPD_STRING_ATTR = "%u mv";
  httpd_snprintf(sensor_extvoltage,sizeof(sensor_extvoltage),httpd_cgi_sensor2_printf,h);
}
#elif CONTIKI_TARGET_AVR_RAVEN
{
#if 1
/* Usual way to get AVR supply voltage, measure 1.1v bandgap using Vcc as reference.
 * This connects the bandgap to the AREF pin, so enable only if there is no external AREF!
 * A capacitor may be connected to this pin to reduce reference noise.
 */
  ADMUX =0x5E;              //Select AVCC as reference, measure 1.1 volt bandgap reference.
  ADCSRA=0x87;              //Enable ADC, not free running, interrupt disabled, clock divider  128 (62 KHz@ 8 MHz)
  ADCSRA|=1<<ADSC;          //Start throwaway conversion
  while (ADCSRA&(1<<ADSC)); //Wait till done
  ADCSRA|=1<<ADSC;          //Start another conversion
  while (ADCSRA&(1<<ADSC)); //Wait till done
//h=1126400UL/ADC;          //Get supply voltage (factor nominally 1100*1024)
  h=1198070UL/ADC;          //My Raven
  ADCSRA=0;                 //disable ADC
  ADMUX=0;                  //turn off internal vref    

  static const char httpd_cgi_sensor2_printf[] HTTPD_STRING_ATTR = "%u mv";
  httpd_snprintf(sensor_extvoltage,sizeof(sensor_extvoltage),httpd_cgi_sensor2_printf,h);
#endif
}
#elif CONTIKI_TARGET_REDBEE_ECONOTAG
//#include "adc.h"
{
uint8_t c;
		adc_reading[8]=0;
		adc_init();
		while (adc_reading[8]==0) adc_service();
	//	for (c=0; c<NUM_ADC_CHAN; c++) printf("%u %04u\r\n", c, adc_reading[c]);
		adc_disable();
		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]);

}
#endif
 
  if (last_tempupdate) {
    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);
  numprinted+=httpd_snprintf((char *)uip_appdata+numprinted, uip_mss()-numprinted, httpd_cgi_sensor2, sensor_extvoltage);
//   numprinted+=httpd_snprintf((char *)uip_appdata+numprinted, uip_mss()-numprinted, httpd_cgi_sensr12, sensor_temperature,sensor_extvoltage);

#if RADIOSTATS
  /* Remember radioontime for display below - slow connection might make it report longer than cpu ontime! */
  savedradioontime = radioontime;
#endif
  h=seconds/3600;s=seconds-h*3600;m=s/60;s=s-m*60;
  days=h/24;
  if (days == 0) {
    numprinted+=httpd_snprintf((char *)uip_appdata + numprinted, uip_mss() - numprinted, httpd_cgi_sensor3, h,m,s);
  } else {
  	h=h-days*24;	
	numprinted+=httpd_snprintf((char *)uip_appdata + numprinted, uip_mss() - numprinted, httpd_cgi_sensor3d, days,h,m,s);
  }
	
#if 0
  if (sleepseconds) {
	uint8_t p1;
	p1=100UL*sleepseconds/seconds;h=sleepseconds/3600;s=sleepseconds-h*3600;m=s/60;s=s-m*60;
    numprinted+=httpd_snprintf((char *)uip_appdata + numprinted, uip_mss() - numprinted, httpd_cgi_sensor4, h,m,s,p1);
  }
#endif

#if ENERGEST_CONF_ON
{uint8_t p1,p2;
 uint32_t sl;
#if 0
/* Update all the timers to get current values */
  for (p1=1;p1<ENERGEST_TYPE_MAX;p1++) {
    if (energest_current_mode[p1]) {
      ENERGEST_OFF(p1);
      ENERGEST_ON(p1);
    }
  }
#else
  energest_flush();
#endif
  static const char httpd_cgi_sensor4[] HTTPD_STRING_ATTR =  "<em>CPU time   (ENERGEST):</em> %02u:%02u:%02u (%u.%02u%%)\n";
  static const char httpd_cgi_sensor10[] HTTPD_STRING_ATTR = "<em>Radio      (ENERGEST):</em> Tx %02u:%02u:%02u (%u.%02u%%)  ";
  static const char httpd_cgi_sensor11[] HTTPD_STRING_ATTR = "Rx %02u:%02u:%02u (%u.%02u%%)\n";
  sl=energest_total_time[ENERGEST_TYPE_CPU].current/RTIMER_ARCH_SECOND;
  h=(10000UL*sl)/seconds;p1=h/100;p2=h-p1*100;h=sl/3600;s=sl-h*3600;m=s/60;s=s-m*60;
  numprinted+=httpd_snprintf((char *)uip_appdata+numprinted, uip_mss()-numprinted, httpd_cgi_sensor4, h,m,s,p1,p2);

  sl=energest_total_time[ENERGEST_TYPE_TRANSMIT].current/RTIMER_ARCH_SECOND;
  h=(10000UL*sl)/seconds;p1=h/100;p2=h-p1*100;h=sl/3600;s=sl-h*3600;m=s/60;s=s-m*60;
  numprinted+=httpd_snprintf((char *)uip_appdata+numprinted, uip_mss()-numprinted, httpd_cgi_sensor10, h,m,s,p1,p2);

  sl=energest_total_time[ENERGEST_TYPE_LISTEN].current/RTIMER_ARCH_SECOND;
  h=(10000UL*sl)/seconds;p1=h/100;p2=h-p1*100;h=sl/3600;s=sl-h*3600;m=s/60;s=s-m*60;
  numprinted+=httpd_snprintf((char *)uip_appdata+numprinted, uip_mss()-numprinted, httpd_cgi_sensor11, h,m,s,p1,p2);
}
#endif /* ENERGEST_CONF_ON */

#if CONTIKIMAC_CONF_COMPOWER
#include "sys/compower.h"
{uint8_t p1,p2;
 // extern struct compower_activity current_packet;
  static const char httpd_cgi_sensor31[] HTTPD_STRING_ATTR = "<em>ContikiMAC (COMPOWER):</em> Tx %02u:%02u:%02u (%u.%02u%%)  ";
  static const char httpd_cgi_sensor32[] HTTPD_STRING_ATTR = "Rx %02u:%02u:%02u (%u.%02u%%)\n";

  s=compower_idle_activity.transmit/RTIMER_ARCH_SECOND;
  h=((10000UL*compower_idle_activity.transmit)/RTIMER_ARCH_SECOND)/seconds;
  p1=h/100;p2=h-p1*100;h=s/3600;s=s-h*3600;m=s/60;s=s-m*60;
  numprinted+=httpd_snprintf((char *)uip_appdata+numprinted, uip_mss()-numprinted, httpd_cgi_sensor31, h,m,s,p1,p2);

  s=compower_idle_activity.listen/RTIMER_ARCH_SECOND;
  h=((10000UL*compower_idle_activity.listen)/RTIMER_ARCH_SECOND)/seconds;
  p1=h/100;p2=h-p1*100;h=s/3600;s=s-h*3600;m=s/60;s=s-m*60;
  numprinted+=httpd_snprintf((char *)uip_appdata+numprinted, uip_mss()-numprinted, httpd_cgi_sensor32, h,m,s,p1,p2);

}
#endif

#if RIMESTATS_CONF_ON
#include "net/rime/rimestats.h"
  static const char httpd_cgi_sensor21[] HTTPD_STRING_ATTR = "<em>Packets   (RIMESTATS):</em> Tx=%5lu  Rx=%5lu   TxL=%4lu  RxL=%4lu\n";
  numprinted+=httpd_snprintf((char *)uip_appdata+numprinted, uip_mss()-numprinted, httpd_cgi_sensor21,
		rimestats.tx,rimestats.rx,rimestats.lltx-rimestats.tx,rimestats.llrx-rimestats.rx);
#endif
  static const char httpd_cgi_sensor99[] HTTPD_STRING_ATTR = "</pre>";
  numprinted+=httpd_snprintf((char *)uip_appdata+numprinted, uip_mss()-numprinted, httpd_cgi_sensor99);

  return numprinted;

}