Lab 3: Rules, Events, and Intermediaries
- Due Feb 7, 2018 by 11:59pm
- Points 100
- Submitting a text entry box, a website url, a media recording, or a file upload
Objective
After completing this lab, you will be able to:
- use multiple rules in conjunction with each other to achieve a purpose
- explain how a pico is a first-class Internet citizen
- explain channels and how to manage them
- send events and queries to a pico using a browser, the event console, and the "Testing" tab
Reading and Reference
Read the following:
You may find the following resources useful:
- KRL Manual
- Developer Tips for the Pico Engine
- The Event Intermediaries section from Live_Web_Chap_12.pdf Download Live_Web_Chap_12.pdfThe Event Intermediary section of Live_Web_Chap_11.pdf Download Live_Web_Chap_11.pdf
Prerequisites
You should have completed:
Implementation Notes
- You will be given a Wovyn temperature sensor as part of this lab. Refer to Wovyn Documentation Links to an external site. for more information about its operation.
- The best way to use the KRL documentation is to search since you may not always appreciate how it's organized (or isn't).
- You can use various methods to send events Links to an external site. to your picos for testing.
- You'll be modifying the rulesets that you create for this lessons in subsequent lessons. Be sure that the ruleset URLs you turn in for this lesson are unique from the URLs you provide later since this rulesets may not have been graded yet. You could do this by providing links to specific versions.
- To send events to your pico, you will need the IP address of the machine that the pico engine is running on (along with the port that the pico engine is listening on).
- To learn more about actions and compound actions, look at this documentation Links to an external site..
Do This
Do the following:
- Write and register a ruleset named
wovyn_base
that contains a rule calledprocess_heartbeat
that responds to awovyn:heartbeat
event. This rule should return a directive. - Using the Pico Engine UI, create a pico that represents a temperature sensor and install your
wovyn_base
ruleset in it. - Using one of the techniques in Raising Events Links to an external site., test your ruleset. Try it with various values for the sensor data to ensure it's working.
- Configure your Wovyn device to post a
wovyn:heartbeat
event to your temperature sensor pico. You'll need to format the temperature sensor's webhook URL to correspond to the Sky Event API Links to an external site. that your pico engine is expecting. You will need to create a channel for the temperature sensor to communicate with the pico. - Modify the
process_heartbeat
rule so that it will not fire unless there is a "genericThing" attribute present. See the Wovyn documentation for information on the structure of this attribute. Look at the implementation notes above for more info. - Modify the
process_heartbeat
rule to raise an event Links to an external site. with domainwovyn
and typenew_temperature_reading
. The new event should include new attributes for the temperature reading (called "temperature" and based on the content of the "genericThing" attribute) and a timestamp (called "timestamp"). Hint:event:attrs
is a map of all attributes in the current event. - In the same ruleset, write a new rule named
find_high_temps
that selects on thewovyn:new_temperature_reading
event. It should read thetemperature
attribute and, if it contains a value greater than the numeric value of the global variable namedtemperature_threshold
, raises another event with domainwovyn
, typethreshold_violation
, and any attributes passed along. Note, there are multiple ways to accomplish this. You can pick any positive value fortemperature_threshold
that you like. Thefind_high_temps
rule should issue a directive stating whether or not there was a temperature violation. - In the same ruleset, write another rule called
threshold_notification
that selects on thewovyn:threshold_violation
event. The rule should use the SMS action you created in Lab 2: APIs and Picos to send a notification of the violation to a SMS number stored in a global variable in the ruleset. Note: you will need to install your Twilio module ruleset and your key's module in the temperature sensor pico. - Use ruleset logging and debugging tools to convince yourself that your rules work.
Deliverables
Turn in the following:
- URLs for your ruleset(s)
- Short screencast (< 3 min with sound) showing the operation of your rulesets
- Answers to the following questions:
Questions
- What parsing method did you choose?
- Did you accomplish step 5 with an event expression or a rule conditional? What are the advantages and disadvantages of the method you used instead of the other?
- What was the output of the testing your ruleset before the
find_high_temps
rule was added? How many directives were returned? How many rules do you think ran? - What was the output of the test after the
find_high_temps
rule was added? How many directives were returned? How many rules do you think ran? - How do you account for the difference? Diagram the event flow within the pico (i.e. show the event flow from when the pico receives the first event to the directives being created) using a swimlane diagram Links to an external site..
- Would you say that your
find_high_temps
rule is an event intermediary? If so, what kind? Justify your answer. - How do your logs show that the
find_high_temps
rule works? Pick out specific lines and explain them.