Home > Domotica > Plugwise Protocol Analysis, Part 5 (Date/Time)

Plugwise Protocol Analysis, Part 5 (Date/Time)

More and more details become clear in the plugwise protocol. In Plugwise Unleased Maarten made this post, that describes a timesync between the modules and the computer. There is also a second DateTime format in use.

I also found a third field, that is also represent a time format. This is in the 003F response and the 0016 command.

In this post I describe what I found for future reference. I use color to make references to the same type of timestamp more clear. To make the messages fit, I removed the MAC-addresses ((…) in those commands.

Date-time format – Packed for archive

This date-time format is used when storing data in the buffers for data logging. It only registers down to the minute level. This is sufficient, as the data is archived on an hourly base, i.e. the power consumption of a device is measured for one hour and the accumulated power usage for that hour is archived. Commands that use this format are 0016/0000 and 0023/0024.

SEND    0016 ... 0B0540DB FFFFFFFF FFFF 0C2B13 04    [2011-05-12 12:43 UTC]
RECV    0000 ...

SEND    0023 ...
RECV    0024 ... 0B0540DB 00045278 01 85 653907014023 4CCEC0C2 02    [2011-05-12 12:43 UTC]

The Archive DateTime ‘stamp’ is used in the read-buffer sequence 0048/0049

SEND    0048 ... 00045140
RECV    0049 ... 0B05378C 00002564 0B0537C8 00002574 0B053804 0000259E 0B053840 00002592 00045140

Codesample in VBscript to decode this (e.g: 0B05378C)

Function DecodePWpackeddate(ByVal strPWdate) 
Dim intYear, intMonth, lngMinutesMonth 
Dim intDay, intHour, intMinute 
If strPWdate <> "FFFFFFFF" Then 
intYear = CInt("&H" & Mid(strPWdate,1,2)) + 2000 
intMonth = CInt("&H" & Mid(strPWdate,3,2)) 
lngMinutesMonth = CLng("&H" & Mid(strPWdate,5,4)) 
intDay = CInt(lngMinutesMonth \ (60*24) ) +1 
intMinute = CInt(lngMinutesMonth Mod (60*24) ) 
intHour = CInt(intMinute \ 60) 
intMinute = CInt(intMinute Mod 60) 
DecodePWpackeddate = (intYear) & "-" & Right(("00" & intMonth),2) &_ 
"-" & Right(("00" & intDay),2) & " " & Right(("00" & intHour),2) &_ 
":" & Right(("00" & intMinute),2) & " UTC" 
Else 
DecodePWpackeddate = "0000-00-00 00:00 UTC" '* no date 
End If 
End Function

DateTime format – ASCII-format

This format is used where more real-time clock data is needed. You also have seconds resolution. The  04 is a weekday indicator (already documented my Maarten, who documented this earlier. I did read that, but forgot when writing this entry).

SEND    0028 ... 194312 04 120511    [2011-05-12 12:43:19 UTC]
RECV    0000 ...

SEND    0029 ...
RECV    003A ... 204312 04 120511    [2011-05-12 12:43:20 UTC]

DateTime format – HEX-format

Below the command and reply (to a different command), 0016 / 003F that also has time information, but this time a different notation. Now there are three groups of hex-numbers that (after conversion to decimal) are hh, mm ss values. I have marked them in pink. The 04 value here is again a Day of Week value.

SEND    0016 … 0B0540DB FFFFFFFF FFFF 0C2B13 04

RECV    0000 ...

SEND    003E ...
RECV    003F ... 0C2B15 04 01457A

Codesample in VBscript

Function DecodeHexTime(ByVal strHexDoW, Byval strHexTime)
Dim intDoW
Dim intHour, intMinute, intSecond
intDoW = Cint("&H" & strHexDoW)
intHour = Cint("&H" & MID(strHexTime,1,2))
intMinute = Cint("&H" & MID(strHexTime,3,2))
intSecond = Cint("&H" & MID(strHexTime,5,2))
DecodeHexTime = Right(("00" & intHour),2) & ":" & Right(("00" &_
intMinute),2) & ":" & Right(("00" & intSecond),2) &_
" UTC (" & DayOfWeek(intDoW) & ")"
End Function

The other unknown value of the 003F response does not change much. I did see different values in 003F responses when setting a ‘schema’, but it’s meaning  is still a mystery for me.

So that concludes this post.

Advertisements
Categories: Domotica Tags: ,
  1. titioft
    29 July 2011 at 01:00

    03F is a answer to the 03E request (timeinfo)

    The request:
    elsif ($command eq ‘timeinfo’) {
    $packet = “003E” . “000D6F0000” . uc($circle);

    The answer is as follow:
    elsif ($function_code == 0x3F) { # Message is response to time info request
    $xplmsg{‘body’}{‘command’} = ‘timeinfo’;
    $xplmsg{‘body’}{‘device’} = substr($result, 18, 6); # Macaddress
    $xplmsg{‘body’}{‘time’} = sprintf(“%02d%02d%02d”,hex2int(substr($result, 24, 2)),hex2int(substr($result, 26, 2)),hex2int(substr($result, 28, 2))); # Hour + Minutes + Seconds
    $xplmsg{‘body’}{‘dayofweek’} = substr($result, 30, 2); # Day of the week

  2. 7 October 2012 at 10:57

    Anyone has seen the following as a response to a power buffer request (0049)?

    000D6F000098E9B8622D656D3235302D656D3235302D6465763034353500000000000000F814FD7400880020

    chopped up this would be

    000D6F000098E9B8 : MAC
    622D656D : Date? what format? because converting it according to Year-Month-Minutes yields impossible values (year=2098, month = 45, ….)

    Assuming it is a unix epoch, so, converting to long integer ,then x 1000 to go milliseconds = impossbile date value as well

    anyone any idea?

    • 7 October 2012 at 15:56

      The 0049 reply contains 4 parts of date/value: Im my analysis script I decode it like this:


      Case "0049" '* Read LogBuffer, Reply
      strSequence = Mid(strOption,1,4)
      strMACsrc = Mid(strOption,5,16)
      strPackedTime1 = Mid(strOption,21,8)
      strPackedData1 = Mid(strOption,29,8)
      strPackedTime2 = Mid(strOption,37,8)
      strPackedData2 = Mid(strOption,45,8)
      strPackedTime3 = Mid(strOption,53,8)
      strPackedData3 = Mid(strOption,61,8)
      strPackedTime4 = Mid(strOption,69,8)
      strPackedData4 = Mid(strOption,77,8)
      strLogBuffer = Mid(strOption,85,8)

      DecodeCommand = ..(weg).. "[" & DecodePWpackeddate(strPackedTime1) & "]" ..(weg)...

      The first 4 byte of ascii code hex-data (8 hex-characters) contains a timestamp in the format I called “Archive timestamp”. It is NOT a unix timestamp, but just bunch of 8-bit and 16-bit values, packed in 4 bytes. See the decoding function DecodePWpackeddate above.

      The first byte is the year, just add offset “2000”.
      The second byte is the month.
      The second 16 bit is a “minutes from the start of the month” value. Use it to calculate the day of the month, hour and minute.

  3. 8 October 2012 at 09:09

    Aha. I found the problem. I had a bug in my code that miscalculated the logAdress offset. Everything else was Ok. The interesting point here is that it *seems* to be possible to feed the 0048 function any “address” and get back any data. It this by design? I would be fun to do a complete “memory dump” of the Circles to see what is in there. If there would be a memory protection built in the Circle, then at least what it shows is that the memory structure in the Circle is simple, and that it is not built around a preset “data structure” representing stamp/pulse pairs

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: