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
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.
- For each of these two picos, create an event channel labeled "location notification"
- Use your Foursquare Ruleset from the Foursquare Exercise:
- 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
- Write a dispatcher rule that uses
foreach
to loop over the subscription map (foreach
) and theevent:send()
action to send alocation:notification
even to each subscriber.
- Create and register a ruleset that does the following:
- Write a
location_catch
rule that listens forlocation:notification
events - Store the latest location data in an entity variable
- Write a
location_show rule
that shows the location in SquareTag (see (Classic) Quickstart for SquareTag).
- Write a
- You'll need to install the ruleset created in the preceding step into each of the picos you created in step 1.
- 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.
- Create another ruleset that
- contains the same
location_catch
rule from above - puts the result in a Google spreadsheet
- contains the same
- Activate this ruleset in one of the subscriber picos and deactivate the original ruleset in the same pico.
- 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.