Skip to end of metadata
Go to start of metadata

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:

Getting Ready for SquareTag

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

  1. Load the SquareTag module
  2. Add an action to the HelloWorld rule to inject SquareTag specific styling. 

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

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

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

Once your ruleset is loading the SquareTag module, there are two steps to making this action fire when a tag is scanned:

  1. Adding events to the rule that select on scans.
  2. Making this application the default app for a tag so that it sees the scan. 

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:

By adding those events to your select statement, you have made it possible for your app to run on a SquareTag Scan!

Note

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.

In the rule which gets run when the application is selected (HelloWorld in the example), add a call to the get_default_app_html() function. Then insert the returned HTML into your displayed HTML using a beesting. Your rule's prelude should now look like this:

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 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:

Raising these events into the PDS will cause your application to become the default whenever a tag associated with this cloud is scanned. We also need to set SquareTagRID in the global. Add the following code to the global section:

Your app should now look like:

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?

Labels: