Contiki Energest Module Usage

1,472 views
Skip to first unread message

rns...@gmail.com

unread,
Jan 31, 2015, 6:57:52 AM1/31/15
to osdeve_mirror_rtos...@googlegroups.com
This questions is related to a Skymote broadcasting simulation in cooja on contiki2.7.

I want to use "energest" module in cooja to estimate the energy consumption of a particular mote in different states (rx,tx,cpu and low power). I am using contiki broadcasting example for a "Skymote" simulation. The code is shown below :


#include "contiki.h"
#include "net/rime.h"
#include "random.h"
#include "sys/energest.h"
#include "powertrace.h"
#include "dev/button-sensor.h"
#include "dev/leds.h"
#include <stdio.h>

/*---------------------------------------------------------------------------*/
PROCESS(example_broadcast_process, "BROADCAST example");
AUTOSTART_PROCESSES(&example_broadcast_process);
/*---------------------------------------------------------------------------*/

static void broadcast_recv(struct broadcast_conn *c, const rimeaddr_t *from){
   printf("broadcast message received from %d.%d: '%s'\n",from->u8[0], from->u8[1], (char *)packetbuf_dataptr());
}

static const struct broadcast_callbacks broadcast_call = {broadcast_recv};
static struct broadcast_conn broadcast;

/*---------------------------------------------------------------------------*/

PROCESS_THREAD(example_broadcast_process, ev, data){

   static struct etimer et;
   static unsigned long rx_start_time,lpm_start_time,cpu_start_time,tx_start_time = 0;
   static unsigned long rx_new_time,lpm_new_time,cpu_new_time,tx_new_time = 0;

   PROCESS_EXITHANDLER(broadcast_close(&broadcast);)
   PROCESS_BEGIN();

   broadcast_open(&broadcast, 129, &broadcast_call);
   etimer_set(&et, 3*CLOCK_SECOND);

   while(1) {
       PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et));
       energest_flush();
       packetbuf_copyfrom("Hello", 6);
       broadcast_send(&broadcast);
       printf("broadcast message sent\n");

       rx_new_time = energest_type_time(ENERGEST_TYPE_LISTEN);
       lpm_new_time = energest_type_time(ENERGEST_TYPE_LPM);
       cpu_new_time = energest_type_time(ENERGEST_TYPE_CPU);
       tx_new_time = energest_type_time(ENERGEST_TYPE_TRANSMIT);

       printf("Time spent (micro sec) rx: %lu tx: %lu cpu: %lu lpm: %lu\n", 
                 (unsigned long)(1e6*(rx_new_time - rx_start_time) / RTIMER_SECOND),
                 (unsigned long)(1e6*(tx_new_time - tx_start_time) / RTIMER_SECOND),
                 (unsigned long)(1e6*(cpu_new_time - cpu_start_time) / RTIMER_SECOND),
                 (unsigned long)(1e6*(lpm_new_time - lpm_start_time) / RTIMER_SECOND));
    
         
    printf("Total Energy: %lu uJ\n",
                 
(unsigned long)( (21800*3*(rx_new_time - rx_start_time) / RTIMER_SECOND) +
                 
(19500*3*(tx_new_time - tx_start_time) / RTIMER_SECOND) +
                 
(1800*3 *(cpu_new_time - cpu_start_time) / RTIMER_SECOND) +
                 
(2.6*3 *(lpm_new_time - lpm_start_time) / RTIMER_SECOND) ) );

       rx_start_time = energest_type_time(ENERGEST_TYPE_LISTEN);
       lpm_start_time = energest_type_time(ENERGEST_TYPE_LPM);
       cpu_start_time = energest_type_time(ENERGEST_TYPE_CPU);
       tx_start_time = energest_type_time(ENERGEST_TYPE_TRANSMIT);

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


21800, 19500, 1800 and 2.6 are current values (in uA) at each state and  the highlighted expression calculates the total energy of the node . Channel check rate is set to 8 Hz. RTIMER_SECOND is the real time timer ticks per second (?).

However when I simulated it with different RDC drivers (nullrdc, contikimac etc), I cannot see a significant energy variation among the total energy values. So I want to confirm few things before proceeding to next step:

1. Is my energy calculation correct ?
2. Do we need to on/off energest module before taking the readings or is it done automatically by "energest_type_time()" ?
3. Here the etimer waiting time is set to 3 sec. Would that effect the energest module time stamping ?

any advice and suggestions will be much appreciated..... Thank You

vikram....@gmail.com

unread,
Nov 20, 2018, 11:49:06 PM11/20/18
to osdeve.mirror.rtos.Contiki-developers
Reply all
Reply to author
Forward
0 new messages