Connect API v2 -- Understanding Responses from the API

I’ve been doing some experimentation with the v2 Connect API with the aim of updating some of projects including a module I built for NodeJS previously for V1, a Node server which could be used to expose a Web API to the Connect API (partially built for V1 but now migrating to V2) and also an iOS app that is in the idea phase right now.

Experimenting from Node and Swift I can connect, send a command, and get something back but am struggling with interpreting the response. In the docs, there is an example of fetching the strobe lights state with command 635 for the Cessna 172. I can send 635 followed by false – that works and I get back a series of data which is in hex as follows when my strobes are on:

7B 02 00 00 04 00 00 00 00 00 E0 41 00 00 00 00 04 00 00 00 20 00 00 00

I am struggling with completely understanding what this represents. As I understand the documentation for the v2 API, I should get back something like this example from the docs:

635,1,1

I interpret the 635 as echoing back the command, the first 1 as length of the data being returned (in this case, 1 byte I guess) and the second 1 as being the actual state data. I’m not clear if I should expect the commas in the data or actually three items of data back-to-back (or separate by some hex or other delimiter). I’m guessing there is no comma or delimiter in the actual data returned from the formatting of the documentation (the commas in the docs aren’t code-formatted).

From that point I get lost trying to correlate the data I get back to that example, however. I believe the first two bytes map to the 635 command since 7B 02 swapped to 027B is 635 in decimal. But after that I get confused. I can’t see anything there that would indicate two values of 1 and 1 or anything else logical to me.

I have looked at the v2 demo .Net code – but having zero .Net experience isn’t helping me navigate the code. What I can get out of it is that the stream should be:

  1. An integer for the command code (the first two bytes, presumably)

  2. An integer for the length (the next two bytes, I assume) – which above means a length of 0? Surely that doesn’t make sense (or, does it).

  3. The data itself – which, if it should be an integer per the docs/example, would mean the next two bytes? That would be a value of ‘0004’? So – that’s 4 in decimal which I don’t know what it would mean here.

And then I’m left wondering what the rest of that data I got back in the stream actually means when I didn’t send any other commands.

Am I missing something fundamental here? Any advice appreciated.

Arman

I think I’ve made some progress myself on this:

  1. Numeric values are encoded as 32-bit integers (i.e. four bytes) in big endian format,
  2. String values are, I think, UTF8

Based on this I have successfully queried and received back many states from the API – although I still don’t fully understand the data returned in my example in my original post.

Can anyone confirm my basic understanding here and shed any further insight on interpreting the results returned from the v2 API?

Thanks.

Yes, integer values are Int32s.

Also correct.

Have you managed to decode the response you’ve been getting, and get a response like 635,1,1?

Basically, yes – I can now breakdown the responses and appear to be making sense of them. I’ll post an update later when I release a simple Swift library for interacting with v2 API which might be useful for iOS devs out there.

I’m not a strong iOS/Swift dev – I live more in node, PHP and Perl – but I figure if this little library lets me build a simple iOS app, others might find it useful too.