The New AirStore in Sun SPOT SDK

Many of you may not know this, or may not have noticed, since ... well, we haven't made much noise about it, and it's only available in the Developer Releases so far, but it's just too cool not to say something about.


AirStore. What is AirStore? It's pretty much just what it sounds like. Storing stuff "in the air." And that's pretty much how it works. From one SPOT I can take some information and put it into the AirStore. Then from any other SPOT on in the area, I can just get values out of that AirStore. No writing the tiring code of connecting the radios, of making sure you're connecting to the right SPOT, etc. Just get some values.


And it really is that easy. A few steps:



  1. Add these lines to your project's build.properties file:


    user.classpath=${sunspot.home}/Demos/AirStore/lib/AirStore_common.jar:${sunspot.home}/Demos/AirStore/lib/AirStore_device.jar
    utility.jars=${sunspot.home}/Demos/AirStore/lib/AirStore_common.jar:${sunspot.home}/Demos/AirStore/lib/AirStore_device.jar

  2. Next, in your 'sending' project, just add an AirStore and put values in it:


    int x = 49;
    int y = 47;
    int z = 97;
    Record r = new Record();
    r.set("X", x);
    r.set("Y", y);
    r.set("Z", z);
    AirStore.put(r);

  3. In your 'receiving' project, add an AirStore and get the values from it:


    RecordTemplate rt = new RecordTemplate();
    rt.add("X");
    rt.add("Y");
    rt.add("Z");
    Record r = AirStore.getMatch(rt);
    int x = r.getInt("X");
    int y = r.getInt("Y");
    int z = r.getInt("Z");

  4. That's it!

Seriously. That's all there is to it.

By using the built-in (in the Demos directory) AirStore Inspector Application you can see the values being stored in the AirStore:

org.sunspotworld.airstore.inspector.AirStoreInspector001.png

If you deploy code containing step 2 to one SPOT, and code containing step 3 to another SPOT, the value of X from SPOT 1 will be sent to SPOT 2 (or, rather, any number of SPOTs running the code in step 3!). You'll see those values 'stored' in the air, and 'retrieved' from the air as well.

Now, there's something in there that needs a bit more explaining. The RecordTemplate part. This is a nifty bit of work that allows you to only retrieve records from the AirStore that match a particular pattern. In the code-example above, only a record in the AirStore that has X, Y and Z Keys will 'match' the template, and will be retrieved. So if I have another SPOT storing values into the AirStore as "A", "B" and "C", they won't get mixed up and mis-read here.

You can run the AirStore Inspector Application by running 'ant host-run' in the Demos/AirStore/AirStore_Inspector directory that comes with your SDK (starting with Red). With the AirStore Inspector running (see above) you can see the values you are writing to the AirStore.

This is a simple example of making a simple program to transmit values from one SPOT to another. Notice how much easier this is than the old way of establishing radio connections, etc. AirStore handles all of those details for you 'under the covers' so all you have to do is deal with your application code.

It is possible to 'remove' records from the AirStore rather than just getting them, and I'll cover that in a subsequent blog post.

Comments:

So I assume this uses broadcast radiograms behind the scenes? Host applications use RecordTemplate and getMatch the same way?

Even if the storage of collected data isn't the critical part, this doesn't look like a bad way to transfer it. Very clean.

Posted by Jason on April 27, 2010 at 01:27 AM EDT #

Post a Comment:
Comments are closed for this entry.
About

user9157252

Search

Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today