/*---------------------------------------------------------------------------*/
static void
shutdown_handler(uint8_t mode)
{
  if(mode == LPM_MODE_SHUTDOWN) {
    buzzer_stop();
    SENSORS_DEACTIVATE(bmp_280_sensor);
    SENSORS_DEACTIVATE(opt_3001_sensor);
    SENSORS_DEACTIVATE(tmp_007_sensor);
    SENSORS_DEACTIVATE(sht_21_sensor);
    mpu_9250_sensor.configure(MPU_9250_SENSOR_SHUTDOWN, 0);
  }
}
Esempio n. 2
0
PROCESS_THREAD(temp_sensor_process, ev, data)
{

PROCESS_BEGIN();

static struct etimer et;
static uint64_t temperature;
static uint64_t val;
printf("starting Sensor Example\n");

while(1)
{
	etimer_set(&et,CLOCK_SECOND*3);
     	SENSORS_ACTIVATE(temp_sensor);

	PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et));

temperature = (temp_sensor.value(TEMP_SENSOR));
printf("temperature is %lu\n",temperature);

etimer_reset(&et);
SENSORS_DEACTIVATE(temp_sensor);
}
PROCESS_END();

}
Esempio n. 3
0
PROCESS_THREAD(sniffer_process, ev, data)
{
	static struct etimer et;

	leds_off(LEDS_ALL); /* turn off LEDs */
	SENSORS_ACTIVATE(button_sensor); /* turn on button sensor */

	PROCESS_EXITHANDLER(broadcast_close(&bc));
	PROCESS_BEGIN();

	broadcast_open(&bc, SNIFFER_CHANNEL, &broadcast_call);

	process_start(&wait_process, NULL); /* Start wait process.  This will end the main process when a button sensor 						event is posted */

	while(1) /* Infinite loop */
	{
		etimer_set(&et, CLOCK_SECOND * 2 * PERIOD); /* Wait 4 seconds per loop for a receive event */

		PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et));

		#if DEBUG
			printf("Loop\n");
		#endif
	}


	SENSORS_DEACTIVATE(button_sensor); /* Deactivate sensor when we're done */
	PROCESS_END();
}
Esempio n. 4
0
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(test_remote_zonik_process, ev, data)
{
  static int16_t zonik_val;
  static uint8_t i;

  PROCESS_BEGIN();

  printf("Initial status of sensor is: 0x%04X\n",
          zonik.status(SENSORS_ACTIVE));

  while(1) {
    /* Configure Zonik and activate the internal process readings */
    SENSORS_ACTIVATE(zonik);

    printf("Initialized. Sensor status: 0x%04X\n",
            zonik.status(SENSORS_ACTIVE));

    /* Read sensor value dBA multiple times */
    for(i=0; i<MAX_VALID_READINGS; i++) {
      /* Wait a bit */
      etimer_set(&et, CLOCK_SECOND);
      PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et));

      /* Get data from sensor */
      zonik_val = zonik.value(ZONIK_DBA_LEQ_VALUE);
      leds_toggle(LEDS_GREEN);
      printf("Value (dBA): %d\n", zonik_val);
    }

    printf("Sensor status is: 0x%04X\n",
            zonik.status(SENSORS_ACTIVE));

    /* Disable Zonik sensor */
    SENSORS_DEACTIVATE(zonik);
    printf("Process Stopped: 0x%04X\n", zonik.status(SENSORS_ACTIVE));

    for(i=0; i<MAX_INVALID_READINGS; i++) {
      /* Wait a bit */
      etimer_set(&et, CLOCK_SECOND);
      PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et));

      /* Get data from sensor */
      zonik_val = zonik.value(ZONIK_DBA_LEQ_VALUE);
      leds_toggle(LEDS_GREEN);
      printf("Value (dBA): %d\n", zonik_val);
    }
    
    etimer_set(&et, CLOCK_SECOND);
    PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et));
  }

  PROCESS_END();
}
Esempio n. 5
0
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(waitTheButton_process, ev, data)
{
  PROCESS_BEGIN();

  printf("I wait you push the button !!!\n");
  SENSORS_ACTIVATE(button_sensor);
  PROCESS_WAIT_EVENT_UNTIL(ev == sensors_event && data == &button_sensor);
  SENSORS_DEACTIVATE(button_sensor);
  printf("You pushed it!!!\n");

  PROCESS_END();
}
Esempio n. 6
0
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(IWaitSomeone_process, ev, data)
{
  PROCESS_BEGIN();

  SENSORS_ACTIVATE(PIR_555_28027_sensor);
  do
  {
    PROCESS_WAIT_EVENT_UNTIL(ev == sensors_event && data == &PIR_555_28027_sensor);
  }
  while (!((struct sensors_sensor *)data)->value(0));
  SENSORS_DEACTIVATE(PIR_555_28027_sensor);

  PROCESS_END();
}
Esempio n. 7
0
/*---------------------------------------------------------------------------*/
void
test_sensor_deactivate(struct sensors_sensor sensor)
{
//  TEST_BEGIN(name);

  TEST_CODE();
  TEST_EQUALS(SENSORS_DEACTIVATE(sensor), 1);

  TEST_POST();
  //TEST_EQUALS(sensor.status(SENSORS_ACTIVE), 0);  @TODO: check
  TEST_EQUALS(sensor.status(SENSORS_READY), 1);

//  TEST_END();
}
Esempio n. 8
0
PROCESS_THREAD(wait_process, ev, data)
{
	PROCESS_BEGIN();

	SENSORS_ACTIVATE(button_sensor); /* activate button sensor */
	
	/* Wait and return control to main_process until button sensor is pressed */
	PROCESS_WAIT_EVENT_UNTIL((ev == sensors_event) && (data == &button_sensor));

	SENSORS_DEACTIVATE(button_sensor); /* Deactivate button sensor */
	process_exit(&sniffer_process); /* End main process once button sensor is pressed */

	PROCESS_END();
}
Esempio n. 9
0
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(shell_seq_data1_process, ev, data) {

	static uint16_t data_sam[NUM_SAM]; 
	uint16_t sum = 0;
	uint16_t sqsum = 0;
	static struct etimer etimer;

	PROCESS_BEGIN();


	//DEBUG CODE
	printf("cusum-seq: Gathering post-change data... ");


	// Gather NUM_SAM samples over 1 second of time
	SENSORS_ACTIVATE(light_sensor);
	for(counter = 0;counter < NUM_SAM;counter++) {
		// Get data for no change analysis.
		etimer_set(&etimer, CLOCK_SECOND / NUM_SAM);
		PROCESS_WAIT_UNTIL(etimer_expired(&etimer));
		data_sam[counter] = light_sensor.value(LIGHT_SENSOR_PHOTOSYNTHETIC);
	}
	printf("done!\n");
	SENSORS_DEACTIVATE(light_sensor);
	
	sum = 0;
	sqsum = 0;

	// Sum the change data
	for(counter = 0;counter < NUM_SAM;counter++) {
		sum = sum + data_sam[counter];
	}
	printf("cusum-seq: sum = %d\n",sum);
	mean_1 = sum/NUM_SAM;		// 542.3846
	printf("mean_1 = %d\n",mean_1);

	// Caclulate std_dev_1
	for(counter = 0;counter < NUM_SAM;counter++) {
		sqsum = sqsum + mypow2(abs_sub(data_sam[counter], mean_1));
	}
	std_dev_1 = sqsum/NUM_SAM;	// 16.8388
	std_dev_1 = mysqrt(std_dev_1);
	printf("cusum-seq: std_dev_1 = %d\n",std_dev_1);

	// DEBUG CODE
	blink_LEDs(LEDS_ALL);

	PROCESS_END();
}
Esempio n. 10
0
void sensorsPowerDown(){

	sensors_status = 0;

	if(button_sensor.status(SENSORS_READY)){
		sensors_status |= BUTTON_STATUS_ACTIVE;
	}
	if(temperature_sensor.status(SENSORS_READY)){
		sensors_status |= TEMP_STATUS_ACTIVE;
	}
	if(acc_sensor.status(SENSORS_READY)){
		sensors_status |= ACC_STATUS_ACTIVE;
		// Power down accelerometer to save power
		SENSORS_DEACTIVATE(acc_sensor);
	}
}
Esempio n. 11
0
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(test_potent_process, ev, data)
{

  PROCESS_BEGIN();

  SENSORS_ACTIVATE(potentiometer_sensor);

  while(1) {
    uint16_t value = potentiometer_sensor.value(0);

    printf("Potentiometer Value: %i\n", v);
  }

  SENSORS_DEACTIVATE(potentiometer_sensor);

  PROCESS_END();
}
Esempio n. 12
0
/*---------------------------------------------------------------------------*/
static
PT_THREAD(sensorscall(struct httpd_state *s, char *ptr))
{
  static struct timer t;
  static int i;
  static char buf[100];
  static unsigned long last_cpu, last_lpm, last_listen, last_transmit;
  
  PSOCK_BEGIN(&s->sout);

  timer_set(&t, CLOCK_SECOND);
 
  SENSORS_ACTIVATE(acc_sensor);
      
  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);

  PSOCK_SEND_STR(&s->sout, buf);


  snprintf(buf, sizeof(buf),
	     "p(%lu,%lu,%lu,%lu);v(%d);",
	     energest_type_time(ENERGEST_TYPE_CPU) - last_cpu,
	     energest_type_time(ENERGEST_TYPE_LPM) - last_lpm,
	     energest_type_time(ENERGEST_TYPE_TRANSMIT) - last_transmit,
	     energest_type_time(ENERGEST_TYPE_LISTEN) - last_listen,
	     i++);
  last_cpu = energest_type_time(ENERGEST_TYPE_CPU);
  last_lpm = energest_type_time(ENERGEST_TYPE_LPM);
  last_transmit = energest_type_time(ENERGEST_TYPE_TRANSMIT);
  last_listen = energest_type_time(ENERGEST_TYPE_LISTEN);
  PSOCK_SEND_STR(&s->sout, buf);

  PSOCK_END(&s->sout);
}
Esempio n. 13
0
PROCESS_THREAD(reading_level_process, ev, data)
{
  PROCESS_BEGIN();
  active = 0;
  SENSORS_ACTIVATE(button_sensor);

  while(1) {
    PROCESS_WAIT_EVENT_UNTIL(ev == sensors_event &&
			     data == &button_sensor);
    leds_toggle(LEDS_ALL);
    if(!active) {
      /* activate light sensor */
      SENSORS_ACTIVATE(level_sensor);
      printf("Level: %d\n", level_sensor.value(2));
    } else {
      /* deactivate light sensor */
      printf("Level: %d\n", level_sensor.value(2));
      SENSORS_DEACTIVATE(level_sensor);
    }
    active ^= 1;
    leds_toggle(LEDS_ALL);
  }
  PROCESS_END();
}
Esempio n. 14
0
/* periodic broadcast light sensor data */
PROCESS_THREAD(spam_process, ev, data) {

	PROCESS_BEGIN();
	SENSORS_ACTIVATE(light_sensor);

	// init
	leds_off(LEDS_ALL);
	int light_val = 0;

	while(1) {
		// wait a bit
		static struct etimer et;
		etimer_set(&et, 1 * CLOCK_SECOND / 2);
		PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et));

		// send packet
		light_val = light_sensor.value(LIGHT_SENSOR_PHOTOSYNTHETIC);
		packetbuf_copyfrom(&light_val, sizeof(int));
		broadcast_send(&broadcast_connection);
	}

	SENSORS_DEACTIVATE(light_sensor);
	PROCESS_END();
}
Esempio n. 15
0
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(shell_sequence_process, ev, data) {

	static struct etimer etimer;

	PROCESS_EXITHANDLER(leds_off(LEDS_ALL));

	PROCESS_BEGIN();

	static uint16_t temp3;
	temp3 = mylog(std_dev_0/std_dev_1);

	// Error probability parameters
	// alpha = 0.001 - Probability of false alarm.
	// beta = 0.001 - Probability of miss.
	static int b = 7;	// b = log((1-beta)/alpha) = 6.9068

	// Variables
	uint16_t observation;
	static int16_t S_n;
	// Make sure to actually reset S_n every time we run a sequence.
	S_n = 0;
	static int16_t suff_stat = 0;
	static int16_t min_level;
	min_level = 0;
	uint16_t temp1 = 0;
	uint16_t temp2 = 0;
	static int decision;
	// Make sure to actually reset decision every time we run a sequence.
	decision = 0;
	int a = 0;
	int c = 0;

	etimer_set(&etimer, (CLOCK_SECOND / 16));

	while(1) {

		blink_LEDs(LEDS_ALL);

		// Get reading from sensor.
		SENSORS_ACTIVATE(light_sensor);

		// Give the sensors time to activate before taking a reading.
		PROCESS_WAIT_UNTIL(etimer_expired(&etimer));
		etimer_set(&etimer, 11 * (CLOCK_SECOND / 16));
		observation = light_sensor.value(LIGHT_SENSOR_PHOTOSYNTHETIC);
		SENSORS_DEACTIVATE(light_sensor);

		printf("cusum-seq: observation = %d\n",observation);

		// Calculate new statistic based on:
		// suff_stat = log(std_dev_0/std_dev_1)
		// - ((observation - mean_1)^2) / (2*(std_dev_1^2)
		// + ((observation - mean_0)^2) / (2*(std_dev_0^2)	
		//suff_stat =  log(std_dev_0 / std_dev_1) - pow2(observation - mean_1) / (2*pow2(std_dev_1)) + pow2(observation - mean_0) / (2*pow2(std_dev_0));

		a = abs_sub(observation, mean_1);
		c = abs_sub(observation, mean_0);

		// If a or c is too large, calculating temp1 or temp2 can be tough.
		temp1 = temp3 + log_exp_term(c, std_dev_0);
		temp2 = log_exp_term(a, std_dev_1);
		suff_stat = temp1 - temp2;

		// Do appropriate overflow protection.
		if(S_n/2 + suff_stat/2 > 16384 ) {
			S_n = 32767;
		} else if( S_n/2 + suff_stat/2 < -16384) {
			S_n = -32768;
		} else {
			S_n = S_n + suff_stat;
		}

		// Reset the min_level appropriately.
		if(S_n < min_level) {
			min_level = S_n;
		}

		// DEBUG CODE
		printf("cusum-seq: min_level = %d\n",min_level);
		printf("cusum-seq: S_n = %d\n\n",S_n);

			
		// Make decision based on statistic.
		if(S_n >= b + min_level) {
			
			leds_on(LEDS_RED);

			rimeaddr_t addr;
			packetbuf_copyfrom("Change detected", strlen("Change detected"));
			addr.u8[0] = 62;
			addr.u8[1] = 41;
			mesh_send(&mesh, &addr);

			// Send out an observation of data if change detected.
			collect_data(&sequence_command);

			//PROCESS_END();
			if(STOP_MODE) {
				leds_off(LEDS_RED);
				PROCESS_EXIT();
			}
		}

		PROCESS_WAIT_UNTIL(etimer_expired(&etimer));
	}

	PROCESS_END();
}
Esempio n. 16
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);
}
Esempio n. 17
0
//FUNCTIONS TO READ VALUES ---------------------------------------
void read_temp(void* temp) {

	SENSORS_ACTIVATE(sht21);
	*(uint16_t*)(temp) = sht21.value(SHT21_READ_TEMP);
	SENSORS_DEACTIVATE(sht21);
}
Esempio n. 18
0
void read_humid(void* humid) {

	SENSORS_ACTIVATE(sht21);
	*(uint16_t*)(humid) = sht21.value(SHT21_READ_RHUM);
	SENSORS_DEACTIVATE(sht21);
}
Esempio n. 19
0
void read_light (void* light) {

	 SENSORS_ACTIVATE(max44009);
	 max44009.value(MAX44009_READ_LIGHT);
	 SENSORS_DEACTIVATE(max44009);
}
Esempio n. 20
0
PROCESS_THREAD(acc_process, ev, data)
{
    PROCESS_BEGIN();

    // just wait shortly to be sure sensor is available
    etimer_set(&timer, CLOCK_SECOND * 0.05);
    PROCESS_YIELD();

    // get pointer to sensor
    static const struct sensors_sensor *acc_sensor;
    acc_sensor = sensors_find("Acc");

    {
        // activate and check status
        uint8_t status = SENSORS_ACTIVATE(*acc_sensor);
        if (status == 0) {
            printf("Error: Failed to init accelerometer, aborting...\n");
            PROCESS_EXIT();
        }

        // configure
        acc_sensor->configure(ACC_CONF_SENSITIVITY, ACC_2G);
        acc_sensor->configure(ACC_CONF_DATA_RATE, ACC_100HZ);
    }

    static const struct sensors_sensor *gyro_sensor;
    gyro_sensor = sensors_find("Gyro");

    {
        // get pointer to sensor
        // activate and check status
        uint8_t status = SENSORS_ACTIVATE(*gyro_sensor);
        if (status == 0) {
            printf("Error: Failed to init gyroscope, aborting...\n");
            PROCESS_EXIT();
        }

        // configure
        gyro_sensor->configure(GYRO_CONF_SENSITIVITY, GYRO_250DPS);
        gyro_sensor->configure(GYRO_CONF_DATA_RATE, GYRO_100HZ);
    }

    SENSORS_ACTIVATE(button_sensor);

    etimer_set(&timer, CLOCK_SECOND * 0.01);

    static int on;
    static short accData[3], gyroData[3];
    static double pitch = 0, roll = 0;

    while (1) {

        if(ev == sensors_event && data == &button_sensor) {
            on = !on;
        } else if(ev == PROCESS_EVENT_TIMER) {

            accData[0] = acc_sensor->value(ACC_X);
            accData[1] = acc_sensor->value(ACC_Y);
            accData[2] = acc_sensor->value(ACC_Z);
            gyroData[0] = gyro_sensor->value(GYRO_X);
            gyroData[1] = gyro_sensor->value(GYRO_Y);
            gyroData[2] = gyro_sensor->value(GYRO_Z);

            ComplementaryFilter(accData, gyroData, &pitch, &roll);
            // printf("%d %d\n", (int) (pitch), (int) (accData[1]));

            // read and output values
            // printf("%d %d %d %d %d %d %d\n",
            //         acc_sensor->value(ACC_X),
            //         acc_sensor->value(ACC_Y),
            //         acc_sensor->value(ACC_Z),
            //         gyro_sensor->value(GYRO_X),
            //         gyro_sensor->value(GYRO_Y),
            //         gyro_sensor->value(GYRO_Z),
            //         on);

            etimer_reset(&timer);
        }

        PROCESS_YIELD();
        // PROCESS_PAUSE();

    }

    // deactivate (never reached here)
    SENSORS_DEACTIVATE(*acc_sensor);
    SENSORS_DEACTIVATE(*gyro_sensor);
    SENSORS_DEACTIVATE(button_sensor);

    PROCESS_END();
}