<b>Calibration</b>
Each plugwise plug has some calibration information. This information can be found in the plugwise access database (PlugwiseData.mdb)
The values containing calibration information are the following:
- OffRuis
- OffTot
- GainA
- GainB
You can also query the information from the plug itself using the stick.
Let's analyze a calibration request:
Code: Select all
<ENQ><ENQ><ETX><ETX>002600A1100003111AB7071<CR><LF>
The next characters represent the mac address of the plug, in this case "00A1100003111AB"
The last 4 characters are the CRC16 code, for an explanation of this see my earlier post.
Let's analyze the calibration response:
Code: Select all
<ENQ><ENQ><ETX><ETX>0027 00A1100003111AB 3F78BD69 B6FF0876 3CA99962 00000000 EE6D<CR><LF>
The first 4 characters represent the function code, in this case calibration response.
The next string is the mac address.
Now for the interesting part:
- 3F78BD69 represents the GainA value hexadecimal.
- B6FF0876 represents the GainB value hexadecimal.
- 3CA99962 represents the OffTot value hexadecimal.
- 00000000 represents the OffRuis value hexadecimal.
- The last code is (i think) a CRC16 code again, not sure about this one.
I use a function like this in python to convert the hexadecimal values to a "human readable" float or double:
Code: Select all
def hexToFloat(self, hexstr):
intval = int(hexstr, 16)
bits = struct.pack('L', intval)
return struct.unpack('f', bits)[0]
<b>Power information</b>
Power information is read by using the following command:
Code: Select all
<ENQ><ENQ><ETX><ETX>0012 00A1100003111AB AB43<CR><LF>
The powerinfo response looks like this:
Code: Select all
<ENQ><ENQ><ETX><ETX>0013 00A1100003111AB 0030 0030 0001D62A 9863<CR><LF>
The following explains the codes followed by that:
- 0030 pulse information of 8 seconds reading.
- 0030 pulse information of 1 second reading.
- 0001D62A yet unknown, still trying to figure out.
The pulse information is again hexadecimal. To convert it to a integer I use the following python code:
Code: Select all
def hexToInt(self, hexstr):
return int(hexstr, 16)
First the pulse information has to be corrected based on the calibration information of the plug, that's done using the following formula:
1.0 * (((pow(value + offruis, 2.0) * gain_b) + ((value + offruis) * gain_a)) + offtot)
Where value is the number of pulses in integer format. pow() is a python for the mathematical power.
If the pulse information has been corrected based upon the calibration information you can go to KWH using the following formula:
(pulses / 1) / 468.9385193
Where pulses is the number of pulses offcourse.
To go to watt you'll simply have to do multiply by 1000.
Long story, I hope it's clear enough.
About the source code:
I will release this as soon as I have some time to cleanup the code a bit (it's a really big mess right now)
--
Maarten Damen
www.maartendamen.com