A Dreamer's Lair

eQ-3 Max Cube message protocol decrypted (Part 1)

In my quest to write a gateway for the eQ-3 Max Cube I came across several sources of information. For those who are interested and for myself to keep a future reference at one place, I will try to write the info for as many messages as I can find on this blog. Perhaps needless to say that the messages also apply to the ELV version of the Cube (since the devices are equal, besides the accompanying software).

I shall start with how we get to know which Cube devices are available on the network and at what IP-Address (or addresses since there can be more than one Cube present).

When a certain UDP broadcast ‘Hello’ message is sent on port 23272, any cube in the network will respond to this message with an answer. On receiving this answer, we can check the originators IP-Address and thus know at what IP-Address the Cube is available. In the received message we can find the Cube’s serial number and firmware version. The latter of which is of importance because the TCP port at which to communicate with the Cube differs depending on the firmware version.

To send the broadcast message we can use the following code.

private const int CubeBroadcastPort = 23272;
private static byte[] _helloMessage = new byte[] { 0x65, 0x51, 0x33, 0x4d, 0x61, 0x78, 0x2a, 0x00, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x49 };

// Broadcast hello message to find available cubes.
UdpClient sender = new UdpClient();
IPEndPoint ip = new IPEndPoint(IPAddress.Broadcast, CubeBroadcastPort);
sender.Send(_helloMessage, _helloMessage.Length, ip);

ip = new IPEndPoint(IPAddress.Parse(""), CubeBroadcastPort);
sender.Send(_helloMessage, _helloMessage.Length, ip);

This will broadcast the ‘Hello’ message on the network. The Hello message looks like this:

00: 65 51 33 4d 61 78 2a 00    eQ3Max..
08: 2a 2a 2a 2a 2a 2a 2a 2a    ........
10: 2a 2a 49                   ..I

I don’t know the meaning of all bytes in the message. Suffice it to say that it works 🙂

When the above message is broadcasted, the Max! Cube device will respond with the following answer (of 26 bytes):

00: 65 51 33 4d 61 78 41 70    eQ3MaxAp
08: 4a 45 51 30 35 34 34 39    JEQ05449
10: 32 33 3e 49 00 03 f2 5d    23.I....
18: 01 13                      ..

Important in this are the following fields:

Description        Startpos    Length      Example Value
Response           00          8           eQ3MaxAp
Serial Number      08          10          JEQ0544923
Unknown            12          3           3e 49 00
Address            15          3           03 f2 5d
Firmware Version   18          2           01 13

The response is always eQ3MaxAp. You can check for the presence of this code to validate that it is indeed a hello broadcast response message.

The Serial number is a string of 10 characters containing the serial number of the Cube (which in this case would be JEQ0544923).

The address field is the 3 byte address of the Cube. In the Cube software itself all addresses seem to be displayed in decimal notation so the address for this cube would be 258653.

The last bit of info is the firmware version. This info is BCD encoded. So the firmware in this case, in decimal, would be 113. The firmware version is important for us to know at which port the Cube device listens. Prior to firmware version 109, the Cube listens at TCP port 80. Starting from firmware version 109, the TCP port will be 62910.

Next time, we will connect to the Cube device and deal with the hello message to and from the device (the so called h: and H: messages).

Compile Mono on a Raspberry PI (for hard float support)

You could say I am a .NET man. So the first thing I investigated after deciding to develop software on the Raspberry PI for my Home Automation, was how to develop in .NET on Linux 🙂

Fortunately there is Mono. A multi platform implementation of the Microsoft .NET runtime and C# compiler. Yeah 🙂

However unfortunate, the default Raspbian distribution (I installed Debian Wheezy through the NOOBS image) still ships with the more or less ancient 2.10 version of Mono which doesn’t support the so called hard float operating systems. And guess what… the Raspberry PI uses a coprocessor so it’s hard float alright 🙁

After some searching on the internet I read that I wasn’t the only developer who wanted .NET on the Raspberry 🙂 There were some branches of the main Mono branch (in GitHub) that supported the hard float Raspberry.

I searched the internet some more to find packages which I could use to install this modified version of Mono. To no avail I must confess.

Ah well, why not compile Mono myself then? That turned out to be easier said than done. Most posts concerning making Mono were a bit too steep on my Linux learning curve. Being a Windows man myself, Linux is quite a different cup of tea where almost everything is handled in obscure command line scripts.

But after more searching, and some asking around in forums, I finally compiled together what to do build Mono on the Raspberry PI.

And for those of you, who as I struggle with the same challenge, here is what I did to build the latest Master branch of Mono (as present on Github). I performed this build on a fairly fresh Raspberry PI (with debian wheezy) so it could be that some components are already installed on your Raspberry. Well here comes.

First I needed to install some components:

sudo apt-get install autoconf
sudo apt-get install libtool
sudo apt-get install gettext

Also, because Mono itself is build with Mono (a bit of a paradox..) you need to have some sort of Mono compiler installed. I used monolite-fast for this. So

sudo make get-monolite-latest

Because we are building Mono from the master branch we have to clone this on the PI (to get a local version of it).

sudo git clone https://github.com/mono/mono.git

After this has been done the following command take care of initialisation and building.

cd mono
sudo git submodule init
sudo git submodule update
sudo ./autogen.sh --prefix=/usr/local
sudo make
sudo make install

After the last command has finished, and be advised that the whole build process takes a couple of hours(!) on the small Raspberry PI, the latest master branch of Mono is available on your system.

You can test the version which is now available on your system

mono --version

which should result in something like this

Mono Runtime Engine version 3.2.7 (master/bb44c68 Sat Dec  7 20:08:30 CET 2013)
Copyright (C) 2002-2013 Novell, Inc, Xamarin Inc and Contributors. <a href="http://www.mono-project.com">www.mono-project.com</a>
TLS:           __thread
SIGSEGV:       normal
Notifications: epoll
Architecture:  armel,vfp+hard
Disabled:      none
Misc:          softdebug
LLVM:          supported, not enabled.
GC:            sgen

Now we can finally develop .NET on the Raspberry!