[Contiki-developers] Energy estimation

1,715 views
Skip to first unread message

Andrea Martelli

unread,
May 19, 2010, 11:09:18 AM5/19/10
to Contiki developer mailing list
Hi all,
does Contiki provide some feature to track the energy consumption on nodes?

I'm simulating a protocol in Cooja and energy is a really important aspect.

Many thanks,
Andrea

Fredrik Österlind

unread,
May 20, 2010, 3:08:25 AM5/20/10
to Contiki developer mailing list
Contiki has a built-in power profiling module that measures the uptime
of various components such as (i.e. it can be used to estimate the radio
duty cycle).
Read more here:
http://www.sics.se/~adam/dunkels07softwarebased.pdf

If you are interested in trying it, a good example can be found in:
/examples/sky-shell/sky-shell.c

If you are simulating the network, you may also want to take a look at
the Contiki project sics.se/powertracker: a COOJA plugin that measures
the average simulated radio duty cycles.
Read more here:
http://www.sics.se/contiki/news/announcing-the-contiki-projects-community.html

Best,
Fredrik

Andrea Martelli skrev:
> ------------------------------------------------------------------------
>
> ------------------------------------------------------------------------------
>
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> Contiki-developers mailing list
> Contiki-d...@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/contiki-developers
>


--
Fredrik Österlind <fr...@sics.se>, +46706641502


------------------------------------------------------------------------------

_______________________________________________
Contiki-developers mailing list
Contiki-d...@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/contiki-developers

--
You received this message because you are subscribed to the Google Groups "osdeve.mirror.rtos.Contiki-developers" group.
To post to this group, send email to osdeve_mirror_rtos...@googlegroups.com.
To unsubscribe from this group, send email to osdeve_mirror_rtos_conti...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/osdeve_mirror_rtos_contiki-developers?hl=en.

Andrea Martelli

unread,
May 20, 2010, 9:31:57 AM5/20/10
to Contiki developer mailing list
Fredrik,

thank you for the very interesting answer and for the article.
I tried the powertracker plugin and it seems to be nice ;)

Actually I'm simulating routing protocols in Cooja...is there some API in the contiki code to perform an estimation of the energy consumed by each node?

Many thanks,
Andrea


2010/5/20 Fredrik Österlind <fr...@sics.se>

Andrea Martelli

unread,
May 20, 2010, 10:25:15 AM5/20/10
to Contiki developer mailing list
I'm sorry for the previous stupid message.

I'm simulating a network in Cooja...is there a way to make energest work there?

I obtain always 0 values of consumed energy! (in which unit is expressed?)

I'd like to trace the energy consumption for every second.

My process is this:

PROCESS_THREAD(energy_monitor, ev, data)
{
static struct etimer nrg;

PROCESS_BEGIN();

static unsigned long last_rx, last_tx, last_lpm, last_cpu;

last_rx = 0;
last_tx = 0;
last_lpm = 0;
last_cpu = 0;

etimer_set(&nrg, CLOCK_SECOND);

while(1) {

PROCESS_WAIT_EVENT();
if(ev == PROCESS_EVENT_TIMER) {

PRINTF("ENERGY rx %lu tx %lu lpm %lu cpu %lu\n",
energest_type_time(ENERGEST_TYPE_LISTEN) - last_rx,
energest_type_time(ENERGEST_TYPE_TRANSMIT) - last_tx,
energest_type_time(ENERGEST_TYPE_LPM) - last_lpm,
energest_type_time(ENERGEST_TYPE_CPU) - last_cpu);

last_rx = energest_type_time(ENERGEST_TYPE_LISTEN);
last_tx = energest_type_time(ENERGEST_TYPE_TRANSMIT);
last_lpm = energest_type_time(ENERGEST_TYPE_LPM);
last_cpu = energest_type_time(ENERGEST_TYPE_CPU);

etimer_reset(&nrg);
}
}

PROCESS_END();
}

Andrea Martelli

www.andreamartelli.it
www.andreamartelli.it/blog/


2010/5/20 Andrea Martelli <andre...@gmail.com>

Marcus Lundén

unread,
May 20, 2010, 6:48:59 PM5/20/10
to contiki-d...@lists.sourceforge.net
It could be that you need to flush the energest before reading it (in any way, you'll get more accurate results that way).
For every device that has an corresponding energest (eg radio in Rx mode, CPU in LPM mode, sensors), a macro is run every time the device and mode is started, and another when stopped. For instance something like this (don't remember the exact syntax though):

// some process
ENERGEST_ON(ENERGEST_TYPE_RADIO_LISTEN);
cc2420_on();
...
...
...
...
cc2420_off();
ENERGEST_OFF(ENERGEST_TYPE_RADIO_LISTEN);

What it does is basically getting a timestamp expressed in rtimer ticks (as set by cpu/something/rtimer-arch.h: RTIMER_ARCH_SECOND, try printf("%u", RTIMER_SECOND) or checking platform/sky/contiki-conf.h if I remember correctly, presently 8192 ticks/s).

If you, between the _ON(...) and _OFF(...) check the energest, it won't give you the correct value as it doesn't update until the _OFF(...). By running energest_flush(), you force an update of every energest type.

The energest value is always incremented and never reset to zero, that's why you must subtract the previous value (there is a function for setting it to an arbitrary value should you prefer to reset it to zero each time).
The duty cycle = (energest time diff for a device)/(total time between measurements).
The average power consumption during this time = DC * (power consumption for that device when on).
The power consumption = (supply voltage) * (current consumption), but it is mostly preferred to use the DC instead as current consumption often depend on supply voltage, and supply voltage drops as batteries deplete. It also makes it easier to compare between different hardwares.

Minor detail but you could replace the PROCESS_WAIT_EVENT() and etimer_expired-check (as you're only waiting for the etimer) with
PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et));
if you'd like. I think even
PROCESS_WAIT_UNTIL(etimer_expired(&et));
will work fine but will same some bytes if space is precious.

Good files to look in: core/sys/{rtimer, energest}.{c,h}.

I hope that cleared some clouds for you, I tried to keep it more generic as I've been getting some emails about this as well that I took this opportunity to answer to here...

Best,
Marcus Lunden


On Thu, May 20, 2010 at 18:40, <contiki-devel...@lists.sourceforge.net> wrote:
Re: [Contiki-developers] Energy estimation

David Hasenfratz

unread,
May 21, 2010, 3:07:42 AM5/21/10
to Contiki developer mailing list
In version 2.4 there is already an update of the current timestamp value in the energest_type_time function. Thus there is no need to call energest_flush() before reading the values.

There is one important line missing in the 2.4 release.  Flushing energest is missing in the file cpu/msp430/clock.c:

The if statement on line 77 has to be changed from:
if(count % CLOCK_CONF_SECOND == 0) {
    ++seconds;
}

to

if(count % CLOCK_CONF_SECOND == 0) {
    ++seconds;
    energest_flush();
}

Whitout this you will most probably get an overflow in energest.c and incorrect timestamps.

Regards, David
------------------------------------------------------------------------------

Andrea Martelli

unread,
May 21, 2010, 5:16:55 AM5/21/10
to Contiki developer mailing list
Thank you all, but my code still don't work. Remember that I'm simulating motes in Cooja...maybe here there's some difference?
I added the ENERGEST_ON macros but I still have all 0 values for the energy.
I'm sure I'm doing something stupid in the code but I need your help.

PROCESS_THREAD(energy_monitor, ev, data)
{
static struct etimer nrg;

PROCESS_BEGIN();

static unsigned long last_rx, last_tx, last_lpm, last_cpu;

last_rx = 0;
last_tx = 0;
last_lpm = 0;
last_cpu = 0;

ENERGEST_ON(ENERGEST_TYPE_LISTEN);
ENERGEST_ON(ENERGEST_TYPE_TRANSMIT);
ENERGEST_ON(ENERGEST_TYPE_LPM);
ENERGEST_ON(ENERGEST_TYPE_CPU);
cc2420_on();

energest_flush();

etimer_set(&nrg, CLOCK_SECOND);


while(1) {

PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&nrg));

// energest_flush();
PRINTF("ENERGY rx %lu tx %lu lpm %lu cpu %lu\n",
energest_type_time(ENERGEST_TYPE_LISTEN) - last_rx,
energest_type_time(ENERGEST_TYPE_TRANSMIT) - last_tx,
energest_type_time(ENERGEST_TYPE_LPM) - last_lpm,
energest_type_time(ENERGEST_TYPE_CPU) - last_cpu);

last_rx = energest_type_time(ENERGEST_TYPE_LISTEN);
last_tx = energest_type_time(ENERGEST_TYPE_TRANSMIT);
last_lpm = energest_type_time(ENERGEST_TYPE_LPM);
last_cpu = energest_type_time(ENERGEST_TYPE_CPU);

etimer_reset(&nrg);
}

cc2420_off();
ENERGEST_OFF(ENERGEST_TYPE_LISTEN);
ENERGEST_OFF(ENERGEST_TYPE_TRANSMIT);
ENERGEST_OFF(ENERGEST_TYPE_LPM);
ENERGEST_OFF(ENERGEST_TYPE_CPU);

PROCESS_END();
}

Andrea Martelli

www.andreamartelli.it
www.andreamartelli.it/blog/


2010/5/21 David Hasenfratz <hda...@ee.ethz.ch>

Fredrik Österlind

unread,
May 21, 2010, 5:26:49 AM5/21/10
to Contiki developer mailing list
Simulated Contiki motes do not support energy estimation, only emulated
motes ("Sky motes").
Which mote type are you using?

Best,
Fredrik


Andrea Martelli skrev:
> www.andreamartelli.it <http://www.andreamartelli.it>
> www.andreamartelli.it/blog/ <http://www.andreamartelli.it/blog/>
>
>
> 2010/5/21 David Hasenfratz <hda...@ee.ethz.ch <mailto:hda...@ee.ethz.ch>>
>> <mailto:contiki-devel...@lists.sourceforge.net>> wrote:
>>
>> Re: [Contiki-developers] Energy estimation
>>
>>
>>
>> ------------------------------------------------------------------------------
>>
>>
>>
>>
>> _______________________________________________
>> Contiki-developers mailing list
>> Contiki-d...@lists.sourceforge.net <mailto:Contiki-d...@lists.sourceforge.net>
>> https://lists.sourceforge.net/lists/listinfo/contiki-developers
>>
>
> ------------------------------------------------------------------------------
>
>
> _______________________________________________
> Contiki-developers mailing list
> Contiki-d...@lists.sourceforge.net
> <mailto:Contiki-d...@lists.sourceforge.net>
> https://lists.sourceforge.net/lists/listinfo/contiki-developers
>
>
> ------------------------------------------------------------------------
>
> ------------------------------------------------------------------------------
>
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> Contiki-developers mailing list
> Contiki-d...@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/contiki-developers
>


--
Fredrik Österlind <fr...@sics.se>, +46706641502


------------------------------------------------------------------------------

_______________________________________________
Contiki-developers mailing list
Contiki-d...@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/contiki-developers

Andrea Martelli

unread,
May 21, 2010, 5:32:59 AM5/21/10
to Contiki developer mailing list
I'm using Contiki motes....

so the only way to have an energy estimation is to use the powertracker plugin? It's not sufficient for my needs.

Is there some way to convert a contiki mote in a sky mote?
If I choose "sky mote" in cooja, it doesn't let me choose the communication stack and the "more attributes" interface.



2010/5/21 Fredrik Österlind <fr...@sics.se>

Fredrik Österlind

unread,
May 21, 2010, 7:00:18 AM5/21/10
to Contiki developer mailing list
Ok, I see.

If you want to measure the energy consumption or radio duty cycles in
COOJA, I recommend emulating motes rather then simulating them.
For instance, measuring the radio duty cycle of Contiki motes makes no
sense without a power-saving MAC protocol. By default, Contiki motes do
not use any power-saving MAC, simply because the results would not be
very realistic (in comparison with using emulated motes).

Just add a Sky mote type, and pick the same application as for the
Contiki mote.
For most /examples, the netstack configuration is either the default or
specified in the /examples/*/Makefile.
What parts of the stack do you need to reconfigure?

Best,
Fredrik

Andrea Martelli skrev:
> I'm using Contiki motes....
>
> so the only way to have an energy estimation is to use the
> powertracker plugin? It's not sufficient for my needs.
>
> Is there some way to convert a contiki mote in a sky mote?
> If I choose "sky mote" in cooja, it doesn't let me choose the
> communication stack and the "more attributes" interface.
>
>
>
> 2010/5/21 Fredrik Österlind <fr...@sics.se <mailto:fr...@sics.se>>
> <mailto:hda...@ee.ethz.ch> <mailto:hda...@ee.ethz.ch
> >> <mailto:contiki-devel...@lists.sourceforge.net
> <mailto:contiki-devel...@lists.sourceforge.net>>> wrote:
> >>
> >> Re: [Contiki-developers] Energy estimation
> >>
> >>
> >>
> >>
> ------------------------------------------------------------------------------
> >>
> >>
> >>
> >>
> >> _______________________________________________
> >> Contiki-developers mailing list
> >> Contiki-d...@lists.sourceforge.net
> <mailto:Contiki-d...@lists.sourceforge.net>
> <mailto:Contiki-d...@lists.sourceforge.net
> <mailto:Contiki-d...@lists.sourceforge.net>>
> >> https://lists.sourceforge.net/lists/listinfo/contiki-developers
> >>
> >
> >
> ------------------------------------------------------------------------------
> >
> >
> > _______________________________________________
> > Contiki-developers mailing list
> > Contiki-d...@lists.sourceforge.net
> <mailto:Contiki-d...@lists.sourceforge.net>
> > <mailto:Contiki-d...@lists.sourceforge.net
> <mailto:Contiki-d...@lists.sourceforge.net>>
> > https://lists.sourceforge.net/lists/listinfo/contiki-developers
> >
> >
> >
> ------------------------------------------------------------------------
> >
> >
> ------------------------------------------------------------------------------
> >
> >
> >
> ------------------------------------------------------------------------
> >
> > _______________________________________________
> > Contiki-developers mailing list
> > Contiki-d...@lists.sourceforge.net
> <mailto:Contiki-d...@lists.sourceforge.net>
> > https://lists.sourceforge.net/lists/listinfo/contiki-developers
> >
>
>
> --
> Fredrik Österlind <fr...@sics.se <mailto:fr...@sics.se>>, +46706641502
>
>
> ------------------------------------------------------------------------------
>
> _______________________________________________
> Contiki-developers mailing list
> Contiki-d...@lists.sourceforge.net
> <mailto:Contiki-d...@lists.sourceforge.net>
> https://lists.sourceforge.net/lists/listinfo/contiki-developers
>
>
> ------------------------------------------------------------------------
>
> ------------------------------------------------------------------------------
>
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> Contiki-developers mailing list
> Contiki-d...@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/contiki-developers
>


--
Fredrik Österlind <fr...@sics.se>, +46706641502


------------------------------------------------------------------------------

_______________________________________________
Contiki-developers mailing list
Contiki-d...@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/contiki-developers

Andrea Martelli

unread,
May 21, 2010, 7:15:38 AM5/21/10
to Contiki developer mailing list
Uhm ok, I'll try to do what you say.

I see that the sky-ip example has the following line in the makefile:

DEFINES=MAC_DRIVER=cxmac_driver

Where can I found the other mac drivers names?
To enable the IPv6 stack, I have to put the following line in the makefile, right?

UIP_CONF_IPV6=1

Can you tell me if i'm right or write me some examples?

Many thanks,
Andrea Martelli

2010/5/21 Fredrik Österlind <fr...@sics.se>

Andrea Martelli

unread,
May 25, 2010, 9:52:17 AM5/25/10
to Contiki developer mailing list
Ok, I'm using my application with Sky nodes in Cooja and now I'm able to use the energest module.
I don't understand exactly the meaning of the output.
Calculating the differences in the energest_type_time output values every second, I obtain log entries like this:

ENERGY rx 507 tx 1122 lpm 6297 cpu 2770

What that numbers mean? What's the unit?
How can I calculate the duty cycle using these statistics?

Best regards,

Andrea Martelli


2010/5/21 Andrea Martelli <andre...@gmail.com>

David Hasenfratz

unread,
May 25, 2010, 3:04:38 PM5/25/10
to Contiki developer mailing list
These are rt-tick values. 1 second is represented as 8192 ticks on Contiki 2.4. Now you have to get a data sheet and calculate the energy consumption. You have to multiply the time with the operating current and the supply voltage. For RX on the Sky this is roughly 3V and 20mA. With this values you get an energy consumption of 507/8192*3*20 = 3.7 mJ

Regards, David
Reply all
Reply to author
Forward
0 new messages