Tank Journal Archive

mcclown

Member
Mar 12, 2017
55
23
Reverse Engineering A Hydra 26 Hd
Well I haven't updated in a while...so here's a quick one. Skip to below the photo's, for the main reason for this thread.

I've added two clowns, who proceeded to decimate my pod population and seem to be pretty happy now. I've also added a few turbos and a peppermint shrimp (we've two more to pick up tomorrow). I've also added a Tunze Nanonstream 6040, for some extra flow. Now for the obligatory photo's

ai.imgur.com_iddzyNGl.jpg


As you can see I ended up buying a Hydra 26 HD...it's not off center any more.

ai.imgur.com_WUcRsbpl.jpg


The clownbabies (Madam Mim & Merlin....I blame my girlfriend for those names)

ai.imgur.com_mPvNu5Wl.jpg


Slightly blurry but here is that fungia, that was in the middle of my live rock. I've extracted him

Now, onto the main event. As you can see, I caved...I was finding it hard to build out what I wanted on a small scale, for lighting...if I was building a bigger rig, I could make it work but for this it ended up working better for me, to buy off the shelf....but that won't stop me trying to tinker around with it :)

WARNING: Now, before we got any further....there be dragons...anything I'm messing with below, is for my own entertainment. You may be violating the warranty, by messing with these APIs below.

My Problem:

I've grabbed some aip files, with some sample programs, for the lights but they don't quite match what I want...I could write a script to change them to timeshift them to run earlier in the day and reduce the intensity (they're too strong from my tank, sometimes) but the problem is that there's a checksum in the file, which fails if I edit the file before uploading it.

My Goals:

Let's see if we can figure out how the checksum is being calculated.

The Analysis:

I did a bit of digging through the code, for the web ui, for my Hydra 26 HD and it lead me to notice a check for a cookie called "web_goblins" if it was true then it would add new elements to the page...turns out there's an API that I can query. A quick change in Chrome developers tools...

View attachment ai.imgur.com_43Ah2XIl.png

Tada...API functions. This is only some of the ones available. If you look at the javascript file ai-prime-conn.js, you can see other functions that drive the UI, like /api/devices, which allows you to change the device name. These are the dangerous functions though, as they make changes and could cause problems.

A little more digging, into ui-support.js shows how the upload dialog is being triggered

Code:
$("#upload").on("click", function() {
        $("#share_options").hide();
        $("#importRamp").trigger("click")
    });
...and another search leads me to the functions that are processing the aip files, in the following function

Code:
$("#importRamp").change
Now the important part....how is the checksum calculated...Well a bit more digging and I found the where the checksum was calculated. Using that for inspiration, I wrote this powershell script to calculate the correct checksum, for a given AIP file.

Code:
param(
    [Parameter(Mandatory=$true)]
    [String]$inputAIPFile
    )

function Create-ScriptEngine()
{
  param([string]$language = $null, [string]$code = $null);
  if ( $language )
  {
    $sc = New-Object -ComObject ScriptControl;
    $sc.Language = $language;
    if ( $code )
    {
      $sc.AddCode($code);
    }
    $sc.CodeObject;
  }
}

$jsCode =
@"
function getChecksum(l) {
        var k = 0;
        if (l.length == 0) {
            return k
        }
        for (var j = 0; j < l.length; j++) {
            var h = l.charCodeAt(j);
            k = ((k << 5) - k) + h;
            k = k & 4294967295
        }
        if (k < 0) {
            k = ~k
        }
        return k
    };
"@

$js = Create-ScriptEngine "JScript" $jsCode

[xml]$xml = Get-Content -Path $inputAIPFile
$colorsStr = [string]$xml.ramp.colors.OuterXml

$js.getChecksum($colorsStr)
(If anyone wants to run this they must run it in an x86 instance of Powershell. It's to do with how I'm running the javascript code.)

Next step is to build out some functions, that will allow you to increase or decrease the intensity, of the lights. I'll probably add something to timeshift a give AIP as well. Has anyone else played around with this before? Any other functions people would want?
 

mcclown

Member
Mar 12, 2017
55
23
I really should get around to putting out an update on this...I've managed to reverse engineer a lot more of the Hydra APIs. I've built out an API gateway, to allow me to control the lights, as I need to and I'm going to extend it to control all the other functions of my tank...with an eventual goal of adding Google Home integration for the tank (I guess I needed a project).

Watch this space though, I picked up Cade HL 1200, second hand, at the weekend and I'll be shutting down the nano tank and moving over to something bigger, over the next few weeks!
 

mcclown

Member
Mar 12, 2017
55
23
Just to add some closure here, here is a first pass on building some of this as a python library. I've a few minor things to do before making it available from pypi...so hopefully that will happen in the next few weeks. There's only a development branch available right now (for those who know what that means) but it's only a few unit tests away from being a full release.

https://github.com/mcclown/AquaIPy/tree/develop
 

Jacques Pels

Member
Feb 4, 2017
287
112
Gold Coast, QLD
mcclown - looks like you have too much time on your hands, and the brain to get away with it ... :cum
While you are digging into the guts of the Hydras, o tweak it even more, we poor mortals are just happy to be able to get the buggers to communicate with one another. !!
I got 6 of the Hydra 52, and my poor wife, being the family Tech Guru, spent many hours just trying to get them to link on WiFi, let alone on the cloud. We gave up after 3 weeks, when we reached the point that we had 1 Master and 5 slaves.
I love the lights themselves, but what a bummer that they dont refine/improve on the connectivity to make them more user-friendly. The blogs are crammer daily with new buyers asking the same help and experiencing the same problems.
With your knowledge, you should offer AI to write a new program, and use the fee to go buy some more lights :dead

Interested to follow your progress

Jac
 

Chris Whong

Member
May 22, 2019
1
0
@mcclown, I wanted to say thanks for sharing the code snippet above for calculating the checksum in the Hydra26 aip files. I wrote a node.js script today to shift the schedules in my aip files and it's working like a charm!

I published the code on github if anyone is interested, and provided links back to this forum post:

github-dot-com/chriswhong/ai-hydra-time-offset

Thanks again!