Plugwise protocol question

Plugwise Forum about Plugwise devices and the Source software.
Post Reply
guldan
Starting Member
Starting Member
Posts: 6
Joined: Mon Dec 21, 2009 6:09 pm

Plugwise protocol question

Post by guldan »

I'm currently in the process of developing a .Net library that can communicate with plugwise devices. I'm using the protocol description maarten made which can be found here:

http://www.domotiga.nl/projects/domotig ... otocol.txt
The only problem i need to solve is to read the history of power usage. I get some data back from the device, and i need to get a date from it. Here's how it's explained in maarten's code:

Code: Select all

275 The abshour format
276	Let's pick the first buffer address as example: 000036B1
277	The decimal value of this abshour value is 14001
278	
279	This value was a real brain cracker, after comparing the values I figured out the following.
280	For illustration let's convert the next abshour value (000036B2) to decimal: 14002
281	
282	Aha! It increases by one all the time, so there must be a constant in these values. Then I substracted this value as hours from the current date (as it states abshour I was figuring it had something to do with hoours) this brought me to the following date:
283	
284	1-6-2007
285	
286	So if you add the number of hours to that date you'll get the datetime of that buffer.
287	Example in python:
288	
289	>>> import datetime
290	>>> timestart = datetime.datetime(2007, 6, 1, 2)
291	>>> dif = datetime.timedelta(hours=14001)
292	>>> datetime = timestart + dif
293	>>> datetime
294	datetime.datetime(2009, 1, 4, 11, 0)
295	
296	
297	So the date and time of this buffer request is:
298	4-1-2009 11:00
So if i undertand correctly, i can subtract the amount of hours from the current date for example today 12/22/2009 12:00:00 AM and i substract an amount of hours (22455) after that i add the hours again and voila i'm at the date i started with. I know i'm doing something wrong maybe you guys can give me an answer.

EDIT:

Maybe i figured it out. The hour number that i got has gotten me confused. When it reads the last buffered usage information, then i get an amount of hours that has occured before this buffer (and the amount of hours that has passed before the start of the measurements). When i subtract that.. then i get a base date on which i can calculate the dates of the other request. I'n the above example.. suppose it's 12-22-2009 12:00 AM at this moment, after I substract the total amount of hours i then know when the plugwise system started measusing and after that it easy to get the date for a buffer. (i just add the amount of hours i get to the start time).
guldan
Starting Member
Starting Member
Posts: 6
Joined: Mon Dec 21, 2009 6:09 pm

Re: Plugwise protocol question

Post by guldan »

Okay, i'll answer my own question. When looking at the source I discovered some magic numbers. The so called plugwise Epoch time.. i made function to calculate the time of a history request:

Code: Select all

  public static DateTime CalculatePlugwiseDate(Int64 hours)
        {
            DateTime output = new DateTime(2007, 6, 1, 0, 0, 0, DateTimeKind.Utc);
            output = output.AddHours(hours);
            return output;
        }
Bwired
Administrator
Administrator
Posts: 4704
Joined: Sat Mar 25, 2006 1:07 am
Location: Netherlands
Contact:

Re: Plugwise protocol question

Post by Bwired »

Hi Guldan,
Thanks for posting!
Maarten is not often on the forum lately.
He was into the protocol and discovered the most.
Great idea to make a .Net driver for it. All the .Net members on this forum still use the source software.
So please keep us up te date and perhaps we can help you in the future.....
http://www.bwired.nl Online Home, Domotica, Home Automation. Weblog. http://blog.bwired.nl
User avatar
Rene
Global Moderator
Global Moderator
Posts: 1689
Joined: Wed Oct 08, 2008 3:54 pm
Location: Netherlands

Re: Plugwise protocol question

Post by Rene »

I am very curious whether Maarten's reverse engineering is still valid for the new firmware release.
Rene.
guldan
Starting Member
Starting Member
Posts: 6
Joined: Mon Dec 21, 2009 6:09 pm

Re: Plugwise protocol question

Post by guldan »

To be honest i haven't updated yet... The .Net driver I made can be found on http://plugwiselib.codeplex.com. But it's a very very very early version of the library. I'm currently also building my own Source software. So maybe i run into issues with it and need to fix some things. But for now it works as it is supposed too.

Luckily for me the plugwise source software is written in .Net and i'm a .Net programmer for a living that also helps alot.
Mdamen
Forum Moderator
Forum Moderator
Posts: 390
Joined: Sat Nov 22, 2008 6:58 pm
Location: Netherlands
Contact:

Re: Plugwise protocol question

Post by Mdamen »

Guess who's back.. good to see that there's other people picking up the development also!
Since I have time again.. I will be looking into reversing plugwise again also...
Bwired
Administrator
Administrator
Posts: 4704
Joined: Sat Mar 25, 2006 1:07 am
Location: Netherlands
Contact:

Re: Plugwise protocol question

Post by Bwired »

Hi again :D
guldan
Starting Member
Starting Member
Posts: 6
Joined: Mon Dec 21, 2009 6:09 pm

Re: Plugwise protocol question

Post by guldan »

Maarten, it's good to hear that your are reverse engineering the protocol again. I tried to contact you before but I didn't know an email address where I could reach you.
Post Reply

Return to “Plugwise Forum”