Monday, April 6, 2015

Contiki OS: Using Powertrace and Energest power profile to estimate power consumption

To estimate the energy consumption. We can run on Cooja or with a real device

- Check the number of ticks per sencond for rtime (RTIMER_SECOND = 32768)
printf("Ticks per second: %u\n", RTIMER_SECOND);

- Include powertrace app in your project by adding it to your Makefile
APP += powertrace
(You also can use simpler version of powertrace at https://github.com/sonhan/contiki-sonhan/)
- Add to source file
#include "powertrace.h"
- Add to source file to print power profile every 10 seconds:
powertrace_start(CLOCK_SECOND * 10);

- Sample data
CPU         LPM            TX           RX
512803    14227588    153188    195436
531519    14535272    158359    203847
549549    14844701    163409    211794
560341    15161365    165821    216534
575755    15473409    169844    223419
599333    15777318    178173    231767
610307    16093852    180704    236651
625674    16406020    184722    243660
649197    16710040    193402    252940
660144    17026626    195811    258453
670942    17343372    198221    263249

- Energy consumption (Power - mW):

Check datasheet for current and voltage, e.g., CPU = (531519 - 512803) * 0.33 * 3 / 32768 / 10

- Duty cycle (%):


E.g., TX duty cycle = (158359 - 153188) / (531519 - 512803 + 14535272 - 14227588)

- Sample output:
- Sample data and calculation:
https://github.com/sonhan/contiki/tree/master/apps/powertrace-sonhan/sample-data

79 comments:

  1. If we do not devide with the runtime, it will be mJ, right ?

    ReplyDelete
  2. I try to print out the RTIMER_SECOND, put the number that I get is 32768 not 327680. Can you explain it for me ?

    ReplyDelete
  3. If we use Skymote with current in active mode is 600uA, sleep mode 3 uA, TX is 21 mA, RX is 23 mA and Voltage is 3.6V. Base on your proposed, The energy will be: 1233 uJ+ 101uJ+ 11930 uJ+ 21253uJ= 34517uJ = 35 mJ. 35 mJ for 10 seconds, Is this acceptable ? I really want to know it because I have a problem with this too.

    ReplyDelete
  4. This comment has been removed by the author.

    ReplyDelete
  5. Sorry it should be 32768, 327680 is that multiplied by 10 (second). I have updated it.

    ReplyDelete
  6. You can compare to my following sample data (mW) with TelosB CM5000 (3V, 330 uA, 1.1 uA, 18.8 mA, and 17.4 mA for Voltage, CPU, LPM, TX, and RX):

    CPU LPM TX RX Total
    0.029683685 0.003199695 0.162009888 0.9172229 1.112116168
    0.032194336 0.003191306 0.179851685 1.015675049 1.230912375
    0.03203421 0.003191799 0.180170288 1.03546875 1.250865048

    Hope it heps!

    ReplyDelete
    Replies
    1. This comment has been removed by the author.

      Delete
    2. Dear Son Han, I am calculating the values as given by you for CPU,LPM, Tx,Rx but i am not getting the exact output values as mentioned by you. I am doing the following calculation:
      For CPU, ((531519-512803) x 0.33 x 3)/327680 = 0.056545532
      But as per your given values, this value is 0.029683685.
      Similarly, For LPM, ((14535272-14227588) x 0.33 x 3)/327680 = 0.003098624
      which matches to your mentioned value i.e. 0.003199695.
      Similarly for Tx, ((158359-153188)) x 0.33 x 3)/327680 = 0.890028076
      But as per your given values, this value is 0.162009888.
      Similarly, for Rx, ((203847-195436) x 0.33 x 3)/327680 = 1.339887085
      But as per your given values, this value is 0.9172229.

      Can you please explain to me how have you calculated it because i am getting much higher value for the same input data.

      Delete
    3. You have the wrong current consumption. Note that the current consumption for the TX is 18.8, not 0.33. Just change the current consumption of LPM, TX, RX with the correct values.

      Delete
    4. thanks for you response. I rechecked the above calculations and i found that it is the typing error for current values here while as the output values that i mentioned are true and exact values for the correct current (I) values. I am getting the discrepancy in values with Son Han still.

      Delete
    5. please how can i get the values of current and voltage!!

      Delete
    6. how can i find the initial energy level for sky mote !!

      Delete
  7. Please we just have to use the rtimer ?

    ReplyDelete
  8. and if not !!! how can i do if a whant to evaluate power consumption with Temote sky sensor ?

    ReplyDelete
  9. Hi Son Han.
    Maybe this a sily question but I want to know why you are doing a difference between the first cpu value and the second to measure power consumption. And these CPU value is CPU (column 11) from powertrace otuput? , because the powertrace output shows all_cpu (column 5) and cpu (column 11) values.

    ReplyDelete
    Replies
    1. Hi Liz,

      All_CPU, for example, is the total (high) CPU, in the form of number of ticks. So in order to estimate the energy consumption in a duration of time, we just consider the power incurred during that time by subtracting the current ALL_CPU to the previous ALL_CPU. If you don't do the subtraction, it's ok, it then will mean the total energy consumed so far (from when you started the mote).

      Delete
    2. Hi Son Han, thanks a lot. I have a question, hope you can help me, I need to calculate power consuption in certain process of my poryect, for example for processing a request. I call powertrace_print("") after and before that process, however the vaules that I getting for: all_cpu, all_lpm, all_transmit, all_listen.

      16443 1514881 148 1531616
      17268 1514881 148 1532440

      all_lpm and al_transmit, do not change. Then the power consumption using the linear model: cp=c*1.8/tm; Where c is all_cpu - last_cpu , and tm is cpu + lpm. This give 825*1.8/825 = 1.8mW it is the current of cpu, and If I do the same for other values I am getting the current draw for transmit and listen.

      This seems not right to me.
      Do you know how to do this?. Calculate power consumption for a specific process?

      Thanks in advance.

      Delete
  10. My values are coming like these, which are taken from unicast receiver.The values for these paramters are not increasing as you showed @son Han...what seems to be the problem..then can I count on these values..if i want to subtract from a step to previous step..then the result comes as negative values.What can I do??
    CPU LPM TX RX
    3475 62054 0 445
    3295 62233 0 336
    3314 62217 0 344
    3478 62053 0 435
    3301 62232 0 352

    ReplyDelete
    Replies
    1. Sort your data as per node ID and you will get it in increasing order.

      Delete
    2. You have to collect the variable called all_cpu. You are collecting the variable called cpu. These two variables are different.

      Delete
  11. My values are coming like these, which are taken from unicast receiver.The values for these paramters are not increasing as you showed @son Han...what seems to be the problem..then can I count on these values..if i want to subtract from a step to previous step..then the result comes as negative values.What can I do??
    CPU LPM TX RX
    3475 62054 0 445
    3295 62233 0 336
    3314 62217 0 344
    3478 62053 0 435
    3301 62232 0 352

    ReplyDelete
    Replies
    1. I have no idea, all the values should increase. The TX seems correct as the receiver doesn't send anything...

      Delete
    2. Hi Unknown,
      I think that your values are from column 11,12,13,14 (CPU,LPM,TX,RX). I think that the Son Han values are from ALL_CPU, ALL_LPM,ALL_TRANSMIT,ALL_LISTEN. This values are increasing and if you subtract second value and first value from ALL_, you will get your values.
      ALL_CPU (second row)-ALL_CPU(first row)=CPU (your CPU value ex:3475)
      Son Han may correct me if I am wrong? And I want to know: Is the Runtime value real time in seconds or not (I think it is not). If it not real value how to get power consuption in real time, for example if I have Runtime=10 (powertrace_start(CLOCK_SECOND * 10);), how to get power consumption for real time of 1 minute and 1 hour. If the Runtime is in real seconds
      it will be easy. In my perception, for 1 minute I will get subtracted values from SECOND ROW-FIRST ROW (from ALL_CPU,ALL_LPM..) in one minute (60 seconds, or 6 values on 10 seconds) and with Son Han Formula for Energy consumption in mW will get the consumption in 60 seconds (SUM all 6 values for power consumption on 10 seconds). So I will get power consumption in 1 minute if Cooja Powertrace time is real time. If I use TmoteSky with 2900 mAh. How to get the batery life? (I have idea but I am not sure: Power consumption = Current*Voltage. I have Voltage (3V for Tmote). I have Power Consumption for 60 seconds (1 minute) and in this formula it must be in hour (Power Consumption for 1 minute*60=1 hour Power Consumption, is it true?) If it is from Power consumption = Current*Voltage I will get Current in Ampers (A). I can conver to mA. If I divide 2900mAh/Current (mA), will get hour (battery life). We can discuss about this. Is it true or not? I am waiting your opinion?

      Delete
    3. What Александар Велинов suggested could be the reason. If you use the original powertrace of Contiki, as far as I remember, there are several values in the form of CPU, LPM, TX, RX instead of ALL_, so be careful. Try to use my simpler version of powertrace to make sure about the output.

      Delete
    4. Indeed, this is the reason, the ALL_TX should not be 0. Zero mean ALL_TX doesn't change for the node doesn't send anything. Thanks Александар Велинов

      Delete
    5. I understand the previous Son Han equation except the value 0.33 based on Son Han calculation in the datasheet he fix the current value to 0.33? whats the current value ? from where we get ? which output from Powertrace represent the current.

      Delete
  12. @Александар Велинов: Runtime is in second, then RTIMER_SECOND * runtime will be in TICK which is cancelled with the Energest_value at numerator. Does it make sense?

    You can take a look on my calculation of battery life to see if the formula is ok:

    Based on the average capacity of an AA battery is 2500 mAh and nominal voltage is 1.5 V, we can estimate the battery life for smart objects to maintain the connectivity (using duty cycling, power = 0.37mW) as follows:

    ( 2500mAh * 1.5V * 2 ) / ( 0.37mW * 24h * 365days ) = 2.304years

    ReplyDelete
    Replies
    1. Hi Son Han, your formula for duty cycle is ENERGEST_TX+ENERGEST_RX / ENERGEST_CPU+ENERGEST_LPM. And you write that it is in percent (%). You have example only for E.g., TX duty cycle = (158359 - 153188) / (531519 - 512803 + 14535272 - 14227588).

      And now you get a value 0.37mW. Is it some average power consumption or something else? Tell me in details? And what mean value 2 in your formula? I what to get power consumption and battery life on Tmote Sky sensor (for Coap protocol example client) module with datasheet on link http://www.eecs.harvard.edu/~konrad/projects/shimmer/references/tmote-sky-datasheet.pdf. It has capacity on battery 2900mAh, Voltage 3V. Are you sure your latest formula is correct? Tell me in details about procedure?

      Delete
    2. That's right, the example is for duty cycle using second formula. You can calculate power by using the first one. 0.37mW is an example of one of my test, which is sum of four component CPU, LPM, TX, and RX.

      Regarding the battery life equation:
      - 2 is 2 battery (my mote has 2)
      - 2500mAh is an average capacity of an AA (sure you can use 2900mAh if it is your case)

      And I think you can easily judge if is correct.

      Delete
    3. @Son Han please explain for me what these it mean TX-duty cycle

      Delete
  13. Because of many questions I received regarding the calculation, I put my sample data and calculation on github for your reference

    https://github.com/sonhan/contiki/tree/master/apps/powertrace-sonhan/sample-data

    ReplyDelete
    Replies
    1. Thanks Son Han about your sharing. I made calculation for Tmote sky. Battery life is a measure of battery performance and longevity, which can be quantified in several ways: as run time on a full charge, as estimated by a manufacturer in milliampere hours, or as the number of charge cycles until the end of useful life. What is true for us? The first or the second claim?

      Delete
  14. And how to send multiple packets in second. For example in Cooja how you simulate Data rate 2 packet/s, ping6 -t 0.5. I think the default is Data rate 1 packet/s, ping6 -t 1. And normally the power consumption is higher. Logically!

    ReplyDelete
  15. @Александар Велинов....I have a question ..if I subtract ALL_LIsten ...2nd column- ALL_Listen 1st column = 1859
    so 1859/32768 = should be time for for one reception?
    and the unit for the formula is mw..is it right?

    ReplyDelete
    Replies
    1. Yes, dividing these results by the number of ticks per second (32768) for a particular hardware device gives results in seconds. The power consumption in mW you can calculate from Son Han formula *- Energy consumption (Power - mW).
      For your example: 1859 * Current * Voltage / 32768 * Runtime
      where you can see current (current for Listen) and voltage in your mote datasheet and Runtime value is from: powertrace_start(CLOCK_SECOND * 10); where Runtime is 10.

      Delete
  16. This comment has been removed by the author.

    ReplyDelete
  17. Thanx...Александар Велинов...But the thing is I am doing a practical project with TelosB..from oscilloscope for one reception current 22mA*voltage 240mV=5.28 mw but from this formula 0.39mw...how is this possible..i am putting from datasheet 1859*0.022*3/32768*runtime..I know power_trace is 94% accurate with respect to real value..also the time for one reception is from oscilloscope 6ms but here: 1859/32768=56 ms!!!..can u explain this..??

    ReplyDelete
  18. Hi thank you so much for the help..
    I have a couple of questions tho..
    What are exactly the values that the powertrace generates?
    For example CPU LPM TX RX
    512803 14227588 153188 195436
    is all this data Rticks? or time in us that the node spends energy?
    ---------------------------
    Furthermore about the power consumption algorithm is there any documentation about it or it is your calculation?
    Is there any references from you in order to understand how everything works?

    thank you for the help.

    ReplyDelete
    Replies
    1. Hi,

      The values are Rticks I believe

      References come from Contiki OS architecture, for example:

      A. Dunkels, “The contikimac radio duty cycling protocol,” Swedish Institute of Computer Science report, 2011.

      A. Dunkels, F. Osterlind, N. Tsiftes, and Z. He, “Software-based on-line energy estimation for sensor nodes,” in Proceedings of the 4th workshop on Embedded networked sensors. ACM, 2007, pp. 28–32.

      Delete
  19. I would like to know, Based on what the lifetime in the excel sheet was calculated. I do not understand what the values 2500,1.5 and 2 are.
    Thank you in advance

    ReplyDelete
  20. Hi,
    what is the value of rtimer (ticks per second) please. I am using Cooja, and I noticed you have used 32768. Do I use the same number to calculate the energy consumption in Cooja, or do I have to check the value of rtimer. Thank you for your help.

    ReplyDelete
    Replies
    1. In Cooja or real motes you have to find out the value by printing it:

      printf("Ticks per second: %u\n", RTIMER_SECOND);

      Delete
  21. Hey guys, I have developed an extended version of Powertrace that uses original Powertrace code to provide the remaining energy in the battery. More info and source code: https://github.com/KineticBattery/Powertrace

    ReplyDelete
    Replies
    1. Great work bro,
      will help a lot
      what the capacity of Kinetic Battery ?
      is it the default skymote in cooja ?
      Thank you

      Delete
    2. Thank you!

      The capacity of the Kinetic Battery can be set according to your needs. The default capacity is 1000000 microAh or 1000 mAh.

      The default node is Wismote, but it can also be easily changed.

      I will make a tutorial showing how to change the battery and the node settings.

      Any more questions, please contact me.

      Delete
    3. Thank you bro
      I want to know the default capacity for skymote in cooja ?
      and how we can change it?

      Delete
    4. Hello,

      Skymote is designed to use 2 AA batteries. The AA batteries may have different capacities, but you can consider each one to 2000 mAh, which will result in 4000 mAh (it is a lot of energy!).

      I have post some information showing how to set the battery capacity other than the default (1000 mAh).

      Delete
    5. Thank you
      it was helpful.
      I am waiting for your post

      Delete
    6. The information about Skymote and how to set 2 AA batteries is online on https://github.com/KineticBattery/Powertrace

      Thanks

      Delete
    7. Thank you Bro
      May I have your email
      I I wan to contact you

      Delete
  22. This comment has been removed by the author.

    ReplyDelete

  23. datasheet for current and voltage,
    e.g., CPU = (531519 - 512803) * 0.33 * 3 / 32768 / 10

    why current is fixed to 0.33

    ReplyDelete
    Replies
    1. You should specify these number because I don't understand what you are trying to do.

      Delete
    2. I understand the previous Son Han equation except the value 0.33 based on Son Han calculation in the datasheet he fix the current value to 0.33? whats the current value ? from where we get ? which output from Powertrace represent the current.

      Delete
  24. Hi Son Han, I also can't get it where does the value 0.33 for current in the above formulas come from. Can you explain it please? Thanks.

    ReplyDelete
  25. Hey Artur, can you share us the screenshot of the datasheet that shows the current value?

    ReplyDelete
    Replies
    1. Image and explanation here: https://github.com/sonhan/contiki/issues/1#issuecomment-327651350

      Delete
  26. How can I use these values to get my remaining energy ??
    in mA ?
    and how can I write them into a txt file
    I am new to COOJA
    Sorry

    ReplyDelete
  27. Hi,
    what are the precise values for Voltage, and current (CPU, LPM TX, RX) for OpenMote-cc2538dk?

    ReplyDelete
    Replies
    1. Its in the datasheet of the Motes. you can google and read it. Hope its help

      Delete
  28. Hello sir,
    I am using rpl,upd-client code with sha2.
    I want to calculate the powerconsumption of that.
    How can I proceed? Please guide.

    ReplyDelete
  29. Energy consumption (Power - mW)!
    energy or power consumption?

    ReplyDelete
  30. Hi All
    These are the values for
    All_cpu all_lpm all_transmit all_listen
    206083 2410553 13070 2607733
    216524 2563536 13070 2771573
    226990 2716495 13070 2935414
    237437 2869470 13070 3099253
    247878 3022453 13070 3263093

    but when I print cpu, lpm, transmit and listen i get
    12049 151428 0 163838
    9749 153724 0 163839
    9722 153751 0 163837
    9711 153763 0 163838
    9734 153738 0 163839

    why Tx value remains 0?Please find the answer at the earliest. Thank you.

    ReplyDelete
  31. Salut à tous,
    j'ai lis les commentaires mais je n'arrives pas à comprendre dans quel ligne je peux intégrer ces impressions?

    ReplyDelete
  32. HELLO GREETINGS, Kindly please can you tell me how to calculate overall power consumption of a Network not of single mote but all network power consumption when we simulate a network for 60mins and through power trace app for example I have 6 motes network one sink and 5 normal motes after ONE HOUR simulation i get these values

    1:00:03.039 ID:2 230504 P 2.0 29 2159225 56823705 681312 395699 0 210464 72940 1893138 22874 12434 0 6210 (radio 1.-64% / 1.79% tx 1.-58% / 1.16% listen 0.67% / 0.63%)
    1:00:03.054 ID:6 230504 P 6.0 29 2166652 56816278 739542 384043 0 177277 72606 1893472 24582 13033 0 5669 (radio 1.-56% / 1.91% tx 1.-48% / 1.25% listen 0.65% / 0.66%)
    1:00:03.151 ID:4 230504 P 4.0 29 2173547 56809383 721199 397244 0 190198 70063 1896015 22882 11560 0 5913 (radio 1.-57% / 1.75% tx 1.-51% / 1.16% listen 0.67% / 0.58%)
    1:00:03.518 ID:5 230504 P 5.0 29 2128640 56854290 682645 377692 0 203342 69957 1896121 22800 11863 0 6219 (radio 1.-66% / 1.76% tx 1.-58% / 1.15% listen 0.64% / 0.60%)
    1:00:03.766 ID:3 230508 P 3.0 29 2179093 56804880 719233 398113 0 195546 74887 1892233 24744 11853 0 6223 (radio 1.-57% / 1.86% tx 1.-51% / 1.25% listen 0.67% / 0.60%)

    now can you tell me how I can take out overall power consumption of network using Z1 mote in simulation

    ReplyDelete
  33. please help me

    HELLO GREETINGS, Kindly please can you tell me how to calculate overall power consumption of a Network not of single mote but all network power consumption when we simulate a network for 60mins and through power trace app for example I have 6 motes network one sink and 5 normal motes after ONE HOUR simulation i get these values

    1:00:03.039 ID:2 230504 P 2.0 29 2159225 56823705 681312 395699 0 210464 72940 1893138 22874 12434 0 6210 (radio 1.-64% / 1.79% tx 1.-58% / 1.16% listen 0.67% / 0.63%)
    1:00:03.054 ID:6 230504 P 6.0 29 2166652 56816278 739542 384043 0 177277 72606 1893472 24582 13033 0 5669 (radio 1.-56% / 1.91% tx 1.-48% / 1.25% listen 0.65% / 0.66%)
    1:00:03.151 ID:4 230504 P 4.0 29 2173547 56809383 721199 397244 0 190198 70063 1896015 22882 11560 0 5913 (radio 1.-57% / 1.75% tx 1.-51% / 1.16% listen 0.67% / 0.58%)
    1:00:03.518 ID:5 230504 P 5.0 29 2128640 56854290 682645 377692 0 203342 69957 1896121 22800 11863 0 6219 (radio 1.-66% / 1.76% tx 1.-58% / 1.15% listen 0.64% / 0.60%)
    1:00:03.766 ID:3 230508 P 3.0 29 2179093 56804880 719233 398113 0 195546 74887 1892233 24744 11853 0 6223 (radio 1.-57% / 1.86% tx 1.-51% / 1.25% listen 0.67% / 0.60%)

    now can you tell me how I can take out overall power consumption of network using Z1 mote in simulation

    ReplyDelete
  34. can anybody tell me how to calculate CPU resource utilization of my sky mote after introduction particular network attack on that mote ?

    ReplyDelete
  35. Hi all,
    Could anyone tell me the current consumption values of Z1 Mote(Zolertia) in each of CPU, LPM, TX and RX modes?

    ReplyDelete
  36. hello. How to create table "sample data" from data output contiki ?

    ReplyDelete
  37. Hi all,
    Can anybody tell me how to draw graph " sample output" from contiki cooja ?

    ReplyDelete
  38. How do I know which one is cpu value, LPM value, rx,tx , listen from powertrace output in contiki

    ReplyDelete
  39. I have a question regarding battery life calculation for the node. In the 'data-real-power.xlsx' solution provided by Mr. Son Han, the following formula was used:

    =2500*1.5*2/(B3* 24 * 365)

    In this formula the value of B3 cell was 1.212 (for 1packet/s). However, what I do not understand is the Numerator part of the equation.
    Can someone please explain what (2500), (1.5), and (2) are for?

    I assume 2500 is the capacity (mAH) of the battery in these calculations, however, I could not understand (1.5)*(2).

    Any help is highly appreciated.

    Cheers

    ReplyDelete