Author Topic: How to Calculate Mod256 Checksum for Home Pro  (Read 4436 times)

matommy

  • Newbie
  • *
  • Posts: 7
  • Karma: +0/-0
How to Calculate Mod256 Checksum for Home Pro
« on: March 26, 2015, 02:12:50 PM »
Hello,

Noob question. I have searched around and maybe the answer is right in front of me, but I  can't see it.

I am writing code to talk to me Ted Home Pro in raw (export.raw) format.

Everything is great, except I do not understand how the Mod 256 Checksum is calculated.

If anyone would be so kind as to post an example, whether in p-code or real code, I would be grateful. I am using Ruby but it is the algorithm I am unclear on.

Here is an example string I am trying this on:

pIzCEFXLAQAABgAAALwE1APA

Thanks in advance!

pfletch101

  • Sr. Member
  • ****
  • Posts: 427
  • Karma: +0/-0
    • My home page
Re: How to Calculate Mod256 Checksum for Home Pro
« Reply #1 on: March 26, 2015, 06:36:48 PM »
Hello,

Noob question. I have searched around and maybe the answer is right in front of me, but I  can't see it.

I am writing code to talk to me Ted Home Pro in raw (export.raw) format.

Everything is great, except I do not understand how the Mod 256 Checksum is calculated.

If anyone would be so kind as to post an example, whether in p-code or real code, I would be grateful. I am using Ruby but it is the algorithm I am unclear on.

Here is an example string I am trying this on:

pIzCEFXLAQAABgAAALwE1APA

Thanks in advance!


What Mod 256 Checksum?

AFAIK (I program in VB.Net, which has a system function to handle base-64 decoding) there is no checksum in the Raw data; each line simply consists of the encoded data for the relevant device, index, interval, and time, terminated by a line feed.
Peter R. Fletcher
TED Pro Home - main MTUs monitoring utility and PV Solar feeds; 2 Spyders monitoring selected individual circuits

matommy

  • Newbie
  • *
  • Posts: 7
  • Karma: +0/-0
Re: How to Calculate Mod256 Checksum for Home Pro
« Reply #2 on: March 27, 2015, 12:43:40 AM »
For all of the raw records that I get with export.raw, the last field is described as follows:

Checksum 1 Unsigned Char    Checksum (Mod 256 sum of all previous bytes)

I was unable to get the result I was looking for. I had several unknowns, such as whether to include the last byte in the checksum also or ignore it..

I was able to get it to work. The missing piece for me was that I was adding up the Base64 encoded string, not the unencoded one. Once I used the decoded string, it was easy to get.

For anyone interested, here is a code sample that does it:

  def checksum?(enc)
    sum = 0
    enc.each_byte { |c|
      sum = (sum + (c.ord))
    }
    sum -= enc[-1,1][0].ord # don't include the last byte!
    return (sum % 256) == enc[enc.length-1].ord
  end

I hope maybe this helps someone who did't get it on their own too!
« Last Edit: April 01, 2015, 03:57:42 AM by matommy »

pfletch101

  • Sr. Member
  • ****
  • Posts: 427
  • Karma: +0/-0
    • My home page
Re: How to Calculate Mod256 Checksum for Home Pro
« Reply #3 on: March 30, 2015, 06:56:45 PM »
Interesting!

Base 64 encoding is a very loose standard which can  use checksums, but usually doesn't. One of the inputs to the VB.Net decode function is the type(s) of the binary data that you are expecting to get back, so the function presumably never actually looks at anything beyond the characters which encode the data you are asking it to return.
Peter R. Fletcher
TED Pro Home - main MTUs monitoring utility and PV Solar feeds; 2 Spyders monitoring selected individual circuits