Dispatching Events Exercise

Objective

In this exercise you will create a dispatcher in one personal event network that sends events to subscribers. You will learn how to use the event:send() action from the event library to interact with event subscribers and how to use event channels.

Setup

  • You should have completed the Foursquare exercise. 

Initial Exercise

  1. Create two additional picos by signing up for two Kynetx accounts besides the one you used for the Foursquare exercise.

    Note: if you're using GMail, you can create aliases by appending <text> to the username. So, if you're GMail address is foo@gmail.com, you can send email to foo+hello@gmail.com or foo+45@gmail.com and the mail will get to you. This makes it convenient to create test accounts from a single email address.

  2. For each of these two picos, create an event channel labeled "location notification"
  3. Use your Foursquare Ruleset from the Foursquare Exercise:
    1. Copy the event channel identifiers (ECIs) from each of the channels you created in the preceding step into a subscription map data structure in the global block
    2. Write a dispatcher rule that uses foreach to loop over the subscription map (foreach) and the event:send() action to send a location:notification even to each subscriber.
  4. Create and register a ruleset that does the following:
    1. Write a location_catch rule that listens for location:notification events
    2. Store the latest location data in an entity variable
    3. Write a location_show rule that shows the location in SquareTag (see (Classic) Quickstart for SquareTag). 
  5. You'll need to install the ruleset created in the preceding step into each of the picos you created in step 1. 
  6. Test the result by checking in on Foursquare and then viewing the app in either (both) of the subscriber picos. 

Going Further

The purpose of going further is to see that different PENs can respond to the same event with different rules. 

  1. Create another ruleset that 
    1. contains the same location_catch rule from above
    2. puts the result in a Google spreadsheet
  2. Activate this ruleset in one of the subscriber picos and deactivate the original ruleset in the same pico. 
  3. Test the result by checking into Foursquare. You should be able to se the results in SquareTag and in the spreadsheet.  

 

Copyright Picolabs | Licensed under Creative Commons.