Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Reflect deprecation in title

Creating a SquareTag Application

After you have created a CloudOS Hello World App, creating a SquareTag application is quite simple. I'll be using the final result from our Hello World app as the starting point for our SquareTag app. If you have not followed the CloudOS Hello World Tutorial, go do that now.

At the end of the CloudOS tutorial, you should have a ruleset similar to:

Code Block
ruleset a41x216 {
  meta {
    name "Hello World"
    description <<
      Hello World
    >>
    author ""
    logging off
    use module a169x701 alias CloudRain
  }
  dispatch {
  }
  global {
  }
  rule HelloWorld {
    select when web cloudAppSelected
    pre {
      my_html = <<
        <h5>Hello, world!</h5>
      >>;
    }
    {
      CloudRain:createLoadPanel("Hello World!", {}, my_html);
    }
  }
}

Getting Ready for SquareTag

To get our application ready for SquareTag, we're going to 

...

We load the module just as we did the CloudRain module by adding a use statement to the meta section of the ruleset:

Code Block
languagejavascript
themeConfluencelanguagejavascript
use module a41x196 alias SquareTag

We add the styling by adding an action to the rule:

Code Block
languagejavascript
themeConfluence
languagejavascript
SquareTag:inject_styling();

When you're done, the ruleset should look like this:

Code Block
languagejavascript
themeConfluence
languagejavascript
ruleset a41x216 {
  meta {
    name "Hello World"
    description <<
      Hello World
    >>
    author ""
    logging off
    use module a169x701 alias CloudRain
    use module a41x196 alias SquareTag
  }
  dispatch {
  }
  global {
  }
  rule HelloWorld {
    select when web cloudAppSelected
    pre {
      my_html = <<
        <h5>Hello, world!</h5>
      >>;
    }
    {
      SquareTag:inject_styling();
      CloudRain:createLoadPanel("Hello World!", {}, my_html);
    }
  }
} 

...

We'll cover each of these in turn in the following sections. 

Firing on SquareTag Scans

When a tag is scanned, the SquareTag service in the cloud associated with tag raises specific events. Your HelloWorld rule must be modified so that it is listening for those events.  Looking at the documentation of the SquareTag Service, we can see that there are three different events that we can respond to if we so choose. Let's modify our select statement to fire on all three:

...

Info
titleNote

You can have more than one rule in your ruleset so that you respond to the explicit:isOwner, explicit:isNotOwner, and explicit:isAnonymous events differently. Further, more than one rule can listen to any given event.

Making the App the Default

The next step to have your SquareTag Application run is to set your application as the SquareTag default. This can be done with a combination of the SquareTag Service and a rule in your ruleset.

...

Next we need to create a rule that handles the web:cloudAppAction event when the action attribute has the value makeDefault. The rule will raise an event into the thing's (Classic) PDS to set the defaultOwnerApp and defaultNonOwnerApp. It is possible to have different apps run based on whether the scanner is the owner or if they are a non-owner of the thing. To change the default of both the owner and the non-owner, create the following rule:

...

Code Block
ruleset a41x216 {
  meta {
    name "Hello World"
    description <<
      Hello World
    >>
    author ""
    logging off
    use module a169x701 alias CloudRain
    use module a41x196 alias SquareTag
  }
  dispatch {
  }
  global {
    SquareTagRID = "a41x178";
  }
  rule appSelected {
    select when web cloudAppSelected
             or explicit isOwner
             or explicit isNotOwner
             or explicit isAnonymous
    pre {
      defaultAppHtml = SquareTag:get_default_app_html();
      my_html = <<
        #{defaultAppHtml}
        <h5>Hello, world!</h5>
      >>;
    }
    {
      SquareTag:inject_styling();
      CloudRain:createLoadPanel("Hello World!", {}, my_html);
    }
  }
  rule makeDefault {
    select when web cloudAppAction action re/makeDefault/
    {
      replace_html("#makeDefaultSquareTagApp", "");
      CloudRain:hideSpinner();
    }
    fired {
      raise pds event new_settings_attribute
        with _api = "sky"
        and setRID = SquareTagRID
        and setAttr = "defaultOwnerApp"
        and setValue = meta:rid();
      raise pds event new_settings_attribute
        with _api = "sky"
        and setRID = SquareTagRID
        and setAttr = "defaultNotOwnerApp"
        and setValue = meta:rid();
    }
  }
}

Final Steps

If you already have a tag and have already associated it with something, all that's left is installing, running, and setting the app as the default.

  1. Log in as your thing (Go to myThings, click the gear menu when hovering over one of your things, select "Login As...").
  2. Once you are logged in as your thing, go through the same steps for installing the app as you did in the CloudOS Hello World Tutorial. You need to change the cloudType from cloudTypeThing to cloudTypeDeveloper.
  3. Install your application as a devApp and save it.
  4. Go back to myApps and run the application.
  5. Select the "Make Default" button.
  6. Scan your tag! You should see "Hello World" displayed!

What's Next?

Once you've got a basic hello world app working, why not use all of the other CloudOS modules and services at your disposal to build a more complex app?