Plugwise and Linux

Plugwise Forum about Plugwise devices and the Source software.
Mdamen
Forum Moderator
Forum Moderator
Posts: 390
Joined: Sat Nov 22, 2008 6:58 pm
Location: Netherlands
Contact:

Plugwise and Linux

Post by Mdamen »

As promised, the stuff required for the power measurement.

<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 first 4 characters represent the function code, in this case it's the "0026" command for the calibration request.
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>
Note: the spaces have been included for readability.

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]
The calibration information is used for a correct reading of the watt usage.

<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>
It needs no explanation that the function code is "0012" the mac adress is the next string etc.

The powerinfo response looks like this:

Code: Select all

<ENQ><ENQ><ETX><ETX>0013 00A1100003111AB 0030 0030 0001D62A 9863<CR><LF>
The first two parts of this need no explanation.
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)
How to get the watt I hear you asking?
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
Digit
Global Moderator
Global Moderator
Posts: 3388
Joined: Sat Mar 25, 2006 10:23 am
Location: Netherlands
Contact:

Plugwise and Linux

Post by Digit »

This is really really great!
I'll make a hardcopy of this topic and use it as wallpaper for my office :-))
Bwired
Administrator
Administrator
Posts: 4704
Joined: Sat Mar 25, 2006 1:07 am
Location: Netherlands
Contact:

Plugwise and Linux

Post by Bwired »

Hi Maarten,
I think this is for me the trigger to contact Plugwise and ask them for cooperation.
It's better for Plugwise to give a subset of the specifications now, this way we can make a very nice Linux driver and a real Homeseer plugin etc.
The only thing we want is to get information from the circles, give On and Off commands and be able to upload timers etc.
I saw the information you retrieved from the dongle some months ago with the use of Serial port monitor. http://www.serial-port-monitor.com/
I was not able to quickly translate the CRC etc, so great job on that!
I'll get back on this!
Mdamen
Forum Moderator
Forum Moderator
Posts: 390
Joined: Sat Nov 22, 2008 6:58 pm
Location: Netherlands
Contact:

Plugwise and Linux

Post by Mdamen »

I agree, it would always be nicer to have a full implementation of the specification rather then the "hacking" I do now.
Since it's always wild guessing and trial on error right now.

Would be nice if they are wanting to co-operate so I can release a fully working linux code.

--
Maarten Damen

www.maartendamen.com
User avatar
Snelvuur
Forum Moderator
Forum Moderator
Posts: 3156
Joined: Fri Apr 06, 2007 11:01 pm
Location: Netherlands
Contact:

Plugwise and Linux

Post by Snelvuur »

mdamen: it seems your pretty good at it all..

you dont happen to be good at solving the issue at http://www.domoticaforum.eu/topic.asp?TOPIC_ID=578 ? dont know if i'am asking to much though :)
its about scales, and it seems your good at reverse engineering part.

// Erik (binkey.nl)
Esteban
Forum Moderator
Forum Moderator
Posts: 677
Joined: Sun Jan 13, 2008 6:39 pm
Location: Netherlands

Plugwise and Linux

Post by Esteban »

Congratulations Maarten, that is some really awesome work you've done here! I don't have any Plugwise but I know for sure you're making a lot of people here very happy. *Thumbs Up*
User avatar
RDNZL
Forum Moderator
Forum Moderator
Posts: 1008
Joined: Sun Sep 24, 2006 1:45 pm
Location: Dordrecht, The Netherlands
Contact:

Plugwise and Linux

Post by RDNZL »

Trying to write a routine to do the special crc16 calculations.
Pff, not easy...

I have the 'standard' crc16-ccitt working, but that's not the correct one yet.
Anyone had better results? Or a working vb routine?

Regards,
Ron.
Mdamen
Forum Moderator
Forum Moderator
Posts: 390
Joined: Sat Nov 22, 2008 6:58 pm
Location: Netherlands
Contact:

Plugwise and Linux

Post by Mdamen »

Ron,
Have a look at the e-mail I send you [:)]

--
Maarten Damen

www.maartendamen.com
Mdamen
Forum Moderator
Forum Moderator
Posts: 390
Joined: Sat Nov 22, 2008 6:58 pm
Location: Netherlands
Contact:

Plugwise and Linux

Post by Mdamen »

<blockquote id="quote"><font size="1" face="Verdana, Arial, Helvetica" id="quote">quote:<hr height="1" noshade id="quote"><i>Originally posted by snelvuur</i>
<br />mdamen: it seems your pretty good at it all..

you dont happen to be good at solving the issue at http://www.domoticaforum.eu/topic.asp?TOPIC_ID=578 ? dont know if i'am asking to much though :)
its about scales, and it seems your good at reverse engineering part.

// Erik (binkey.nl)
<hr height="1" noshade id="quote"></font id="quote"></blockquote id="quote">Erik,

I'll look into it, it's hard though without seeing what happens realtime but I'll try...

--
Maarten Damen

www.maartendamen.com
Woeka
Starting Member
Starting Member
Posts: 41
Joined: Tue Dec 09, 2008 12:50 am
Location: Netherlands

Plugwise and Linux

Post by Woeka »

Good work, I was really looking for this. Thinking of getting me some of those plugs too. I hesitated because it was windows only and I've got myself a Linux computer for controlling. Really a great job, hopefully there will be more support from Plugwise in developing this further.
Mdamen
Forum Moderator
Forum Moderator
Posts: 390
Joined: Sat Nov 22, 2008 6:58 pm
Location: Netherlands
Contact:

Plugwise and Linux

Post by Mdamen »

<b>Release update:
</b>
I have released version 0.2 on my website.
The new version supports watt reading. This is also the first version released with a source [:)]

Enough reasons to check out the project page:
http://www.maartendamen.com/node/35

p.s: bwired if you are reading this, can you remove the "code" block posted by t006 it makes this post very wiiiiiiiiiiiiiiiiiiddddddddeeeeeeeee on my screen, making it hard to read. Thanks!

--
Maarten Damen

www.maartendamen.com
t006
Starting Member
Starting Member
Posts: 26
Joined: Wed Oct 08, 2008 8:09 pm
Location: Netherlands

Plugwise and Linux

Post by t006 »

I already edited my own post Maarten [:)]
Mdamen
Forum Moderator
Forum Moderator
Posts: 390
Joined: Sat Nov 22, 2008 6:58 pm
Location: Netherlands
Contact:

Plugwise and Linux

Post by Mdamen »

Thanks, much better to read now ! [:)]

--
Maarten Damen

www.maartendamen.com
Kroonen
Member
Member
Posts: 302
Joined: Mon Oct 01, 2007 6:38 pm
Location: Netherlands

Plugwise and Linux

Post by Kroonen »

Great job Maarten!!

Soon order home start pakket, for measuring the watts, within linux

regards Richard
fwahl
Starting Member
Starting Member
Posts: 2
Joined: Fri Dec 05, 2008 2:38 pm
Location: Sweden

Plugwise and Linux

Post by fwahl »

I received my package yesterday and have started to play around with POL. It works and the fun begins! I know what to do this weekend :)

It seems like the Circle+ returns the total usage if checkd by POL, but what I remember from using Source it did return the usage of the connected equipment. Any info on this?
Post Reply

Return to “Plugwise Forum”