Smarpt-Power 3 Data Analysis

Post Reply
rpgfun
Posts: 20
Joined: Wed Dec 29, 2021 4:10 am
languages_spoken: english
ODROIDs: HC1, HC2, C1, SP3
Has thanked: 4 times
Been thanked: 10 times
Contact:

Smarpt-Power 3 Data Analysis

Post by rpgfun »

Hi all,

I just want to share some thoughts about analyzing the data from a
smart-power 3.

The first step is to collect the data. I'm using the following script
with firmware from 21/12/21:

Code: Select all

#!/bin/bash

PREFIX="${1:-sp3}"

netcat -u -l 6000 | \
  tr -d '\015\000' | \
    sed -ne '/^\([^,]*,\)\{8\}1\|^\([^,]*,\)\{13\}1/p' | \
      tee "$PREFIX-$(date +'%Y%m%d-%H%M%S').csv"
The tr-command removes some unwanted characters. The sed command
will only process lines with at least one active channel. The advantage
is that you can start the script and then take your time to go to the
sp3 and push the buttons to start the outputs.

The final tee-command will save the data to a file and you can also see
them on the screen. Note that due to the buffering of the various
commands in the pipeline the output is not continuous.

So once the data is available, I use a python-script with "Pandas" to
summerize the data. The best thing is to install pandas using pip. You
will find many tutorials about pandas in the net.

Code: Select all

#!/usr/bin/env python

import sys, pathlib
import pandas as pd

# read data from csv
infile = sys.argv[1]
data = pd.read_csv(infile,header=None,sep=',')

# add column labels
data.columns = ['ts','I_V','I_C','I_P','I_on',
                'CH0_V','CH0_C','CH0_P','CH0_on','CH0_Int',
                'CH1_V','CH1_C','CH1_P','CH1_on','CH1_Int','cs1','cs2']

# normalize and scale data
data['ts']    -= data['ts'][0]
data['ts']    *= 0.001
data['CH0_V'] *= 0.001
data['CH1_V'] *= 0.001
data['CH0_P'] *= 0.001
data['CH1_P'] *= 0.001

# shortcut to ts-column
t = data['ts']

# calculate cumulative sum of power-consumption
psum0 = (t.diff()*data['CH0_P']).cumsum()
psum1 = (t.diff()*data['CH1_P']).cumsum()

# print basic statistics (assume sampling is constant for avg)
print("\nmeasurement-duration: %5.1f sec" % t.max())

print("\n------- channel 0 ----------")
print("  min current %6.3f mA" % data['CH0_C'].min())
print("  avg current %6.3f mA" % data[data.CH0_on!=0].CH0_C.mean())
print("  max current %6.3f mA" % data['CH0_C'].max())

print("\n  min voltage %6.3f V" % data['CH0_V'].min())
print("  avg voltage %6.3f V" % data[data.CH0_on!=0].CH0_V.mean())
print("  max voltage %6.3f V" % data['CH0_V'].max())

print("\n  min power %6.3f W" % data['CH0_P'].min())
print("  avg power %6.3f W" % data[data.CH0_on!=0].CH0_P.mean())
print("  max power %6.3f W" % data['CH0_P'].max())

total = psum0.max()/3600
print("  tot power %6.3f Wh" % total)
print("----------------------------\n")

print("------- channel 1 ----------")
print("  min current %6.3f mA" % data['CH1_C'].min())
print("  avg current %6.3f mA" % data[data.CH1_on!=0].CH1_C.mean())
print("  max current %6.3f mA" % data['CH1_C'].max())

print("\n  min voltage %6.3f V" % data['CH1_V'].min())
print("  avg voltage %6.3f V" % data[data.CH1_on!=0].CH1_V.mean())
print("  max voltage %6.3f V" % data['CH1_V'].max())

print("\n  min power %6.3f W" % data['CH1_P'].min())
print("  avg power %6.3f W" % data[data.CH1_on!=0].CH1_P.mean())
print("  max power %6.3f W" % data['CH1_P'].max())

total = psum1.max()/3600
print("  tot power %6.3f Wh" % total)
print("----------------------------\n")
The first few lines read the input-file and add column names for
easier access. The the time-scale is normalized (moved to zero)
and time, voltage and power is scaled from ms,mV,mW to s,V,W. Since
pandas operates on columns, there is no need to program loops.

Most of the rest should be self-explanatory. "t.diff()" is the difference
to the previous value, in this case it is the interval-length and
should be almost constant. Interval*Power gives you the consumption
and "cumsum()" will calculate the cumulate-sum.

The only other tweak is the calculation of the averages. Here the
script filters only data while the channel is on.

An additional idea would be to remove data with voltage near zero. This
happens during power on and distorts the calculation of the minimum.
These users thanked the author rpgfun for the post (total 2):
mctom (Sun Jan 23, 2022 7:54 pm) • odroid (Mon Jan 24, 2022 10:18 am)

User avatar
mctom
Posts: 1987
Joined: Wed Nov 11, 2020 4:44 am
languages_spoken: english, polish
ODROIDs: OGA, XU4, C2, M1
Location: Gdansk, Poland
Has thanked: 230 times
Been thanked: 289 times
Contact:

Re: Smarpt-Power 3 Data Analysis

Post by mctom »

Hi!

Thanks for sharing your thoughts. Here are mine, if you don't mind:
rpgfun wrote:
Sun Jan 23, 2022 5:12 pm
The sed command
will only process lines with at least one active channel. The advantage
is that you can start the script and then take your time to go to the
sp3 and push the buttons to start the outputs.
Personally I found it useful to observe output voltage after the channel is turned off. SP3 does not have a capacitor discharge circuitry, so there is still some voltage hanging around at the output.
In other words, I think ideally I'd detect "both channels off" as a state where both channels have "0" status AND output voltage below 0.1V. Adding that condition to your sed should be doable, I think?
That would also record illegal states, such as when someone pumps voltage into SP3 output. It's worth logging such incidents.
rpgfun wrote:
Sun Jan 23, 2022 5:12 pm
print(" tot power %6.3f Wh" % total)
That is energy, not power. :) 1Wh = 3600J.
Perhaps displaying mWh could be suitable for results under 1Wh? I imagine this may happen a lot with low power targets.
On the other hand I can see you strongly prefer unified display convention, which is also fine.

I think some users could be interested in charge estimation for typical 3.7V or 12.4V battery. You know, to put the result into perspective.
For example, how many AA batteries would it drain, or how many % of 12V 60Ah car battery. That's just a fun idea that perhaps belongs to --verbose option of your script. ;)
energy [Wh] / battery voltage [V] = charge [Ah].
Charge is often incorrectly called "battery capacity" :roll:
rpgfun wrote:
Sun Jan 23, 2022 5:12 pm
An additional idea would be to remove data with voltage near zero. This
happens during power on and distorts the calculation of the minimum.
Agreed. Ignore the first 200ms and anything after the channel gets turned off, and you should get quite decent quality data.

In overall, I love it! If you polished it a little bit, I think it should land on SP3 Wiki for others to use it, don't you think?
Punk ain't no religious cult, punk means thinking for yourself!

Maintainer of PiStackMon

rpgfun
Posts: 20
Joined: Wed Dec 29, 2021 4:10 am
languages_spoken: english
ODROIDs: HC1, HC2, C1, SP3
Has thanked: 4 times
Been thanked: 10 times
Contact:

Re: Smarpt-Power 3 Data Analysis

Post by rpgfun »

mctom wrote:
Sun Jan 23, 2022 7:54 pm
Personally I found it useful to observe output voltage after the channel is turned off. SP3 does not have a capacitor discharge circuitry, so there is still some voltage hanging around at the output.
I don't agree here. I am measuring the device powered by the SP3, not the SP3 itself. So when I turn off the channel I explicitly end the measurement and then I don't want anymore data, even if there is still some residual voltage. (alternative reasoning: the sed command is already complicated enough, I won't understand it myself in a few weeks anymore :roll: )
mctom wrote:
Sun Jan 23, 2022 7:54 pm
rpgfun wrote:
Sun Jan 23, 2022 5:12 pm
print(" tot power %6.3f Wh" % total)
That is energy, not power. :) 1Wh = 3600J.
Oh, yes of course. Thanks!

rpgfun
Posts: 20
Joined: Wed Dec 29, 2021 4:10 am
languages_spoken: english
ODROIDs: HC1, HC2, C1, SP3
Has thanked: 4 times
Been thanked: 10 times
Contact:

Re: Smarpt-Power 3 Data Analysis

Post by rpgfun »

I added a pull request against the smartpower3-repo with my scripts: https://github.com/hardkernel/smartpower3/pull/11

lsc1117
Posts: 289
Joined: Thu Aug 22, 2013 12:46 am
languages_spoken: english
Location: South Korea
Has thanked: 10 times
Been thanked: 42 times
Contact:

Re: Smarpt-Power 3 Data Analysis

Post by lsc1117 »

@rpgfun,

Thank you for the PR.

I have tested your analyzer tool on my Linux. It's very useful to analyze power consumption. And very simple to use.
But, the scripts are only compatible with the old protocol.
https://wiki.odroid.com/accessory/power ... d_protocol

Could you update your scripts for the new logging protocol?
https://wiki.odroid.com/accessory/power ... g_protocol

rpgfun
Posts: 20
Joined: Wed Dec 29, 2021 4:10 am
languages_spoken: english
ODROIDs: HC1, HC2, C1, SP3
Has thanked: 4 times
Been thanked: 10 times
Contact:

Re: Smarpt-Power 3 Data Analysis

Post by rpgfun »

Hi,

I just checked the protocols and if I see it correctly, the new protocol adds some additional columns at the end. Since my script does not use the checksum-columms at all (it does read them though), it actually should be work with both protocols (ignoring checksum-errors of course).

Did you encounter any script-errors with the new protocol? Or wrong results? If so, could you provide a python-trace and some test-data?

BTW: I never tested the old protocol, because the first thing I did when I received my SP3 was to upgrade to the new Dec14 firmware.

Post Reply

Return to “Smart Power”

Who is online

Users browsing this forum: No registered users and 0 guests