orion context broker exercises
TRANSCRIPT
Orion Context Broker Exercises(Basic)
Contact twitter
@fermingalan
@LeandroJGuillen
Contact email
Outline
•CB-1. Deploy your own Orion instance
•CB-2. Create entities using standard ops
•CB-3. Query entities using standard ops
•CB-4. Update entity using standard ops
•CB-5. Update two entities using standard ops
•CB-6. Update two attributes same entities
using standard ops
•CB-7. Create entities using conv ops
•CB-8. Query entities using conv ops
•CB-9. Update entity using conv ops
•CB-10. Browsing entity types
•CB-11. Basic subscription/notifications
•CB-12. Advanced subscription/notification
•CB-13. Expert subscription/notification
•CB-14. Get X-Auth-Token
•CB-15. Browse types at Orion Global instance
•CB-16. Query entities at Orion Global instance
•CB-17. Subscribe to public information
2
CB-1. Deploy your own Orion instance
•Prerequisite–To have a FIWARE Lab account
•Steps–Go to Orion catalogue page–Follow the steps in “Deploying a dedicated GE instance based on an image” in the “Creating Instances tab”–Check Orion is working using the “/version” operation from your local computer
•Hints–Image should be orion-psb-image-R4.2, installed in all FIWARE Lab regions. If you don’t find it ask us–Minimum recommended size: m1.small–Remember to set the security group properly (typically to port 1026)
Easy
CB-1(b). Deploy your own Orion instance
•Alternative in the case you already have a VM in FIWARE Lab and don’t want to deployanother one•Prerequisite
–CentOS 6.x VM
•Steps–Set FIWARE yum repository–Install Context Broker and MongoDB using yum
•Hints–See Orion Admin Guide
–Remember to set the security group properly(typically to port 1026)
Medium
CB-1(c). Deploy your own Orion instance
•Alternative, you can install in your local computer using a pre-created VirtualBoximage•Prerequisite
–VirtualBox installed in your computer
•Steps–Download from bit.ly/fiware-orion-vbox–Install the image in your VirtualBox
Easy
CB-1(d). Deploy your own Orion instance
•You can also deploy using Docker•Prerequisite
–Docker installed in your computer–(Optional) Docker-compose
•Steps–Follow the instructions provided in this link.
Medium
CB-2. Create entities using standard ops
•Prerequisites–Exercise CB-1
•Steps–Create the following entities in your Orion instance
•See table in next slide
•Hints–Orion User Manual section Entity Creation
Easy
CB-2. Create entities using standard ops Easy
Entity Entity Type
Bedroom1 Room
Bedroom2 Room
Kitchen Room
Frontdoor Door
Backdoor Door
Entity Type Attr. Name Attr. Type Example value
Room Temperature float 27.8
Presence boolean true
Status string OK
Door Locked boolean false
Closed boolean false
CB-3. Query entities using standard ops
•Prerequisites–Exercise CB-2
•Steps–Write a program (or web/mobile application) that does the following queries and prints the result
•Obtain all attributes of Bedroom1 entity•Obtain only the Temperature attribute of Kitchen entity
•Obtain all attributes of Kitchen and Bedroom2 entities in one query
•Obtain all attributes of entities that match the pattern Bedroom.*
•Find out whether the doors are closed using the pattern .*door and the Closed attribute
–Run and test your program/application
•Hints–Orion User Manual section Query Context.
Easy
CB-4. Update entity using standard ops
•Prerequisites–Exercise CB-2
•Steps–Write a program (or web/mobile application) that
•Asks for user input (one value)
•Updates Locked attribute of Frontdoor entity using that input•Queries the entity and check the result
–Run and test your program/application
•Hints–Orion User Manual section Update Context.
Easy
CB-5. Update two entities using standard ops
•Prerequisites–Exercise CB-2
•Steps–Write a program (or web/mobile application) that
•Asks for user input (two values)
•Updates the Temperature attribute of Beedroom1 and Bedroom2 entities using that input with a single update operation•Queries the entities and check the result
–Run and test your program/application
•Hints–Orion User Manual sections Query Context and Update Context
Medium
CB-6. Update two attributes same entities using
standard ops
•Prerequisites–Exercise CB-2
•Steps–Write a program (or web/mobile application) that
•Asks for user input (two values)
•Updates the Locked and Closed attributes of Frontdoorentity using that input with a single update operation•Queries the entities and check the result
–Run and test your program/application
•Hints–Orion User Manual sections Query Context and Update Context
Medium
CB-7. Create entities using conv ops
•Prerequisites–Exercise CB-1
•Steps–Create the following entities in your Orion instance
•See table in next slide
•Hints–Similar to exercise CB-2 in the standard ops set–Orion User Manual section Convenience Entity Creation.
Easy
CB-7. Create entities using conv ops Easy
Entity Entity Type
Garage Room
Bathroom Room
Light1 Light
Light2 Light
Light3 Light
Entity Type Attr. Name Attr. Type Example value
Room Temperature float 27.8
Presence boolean true
Status string OK
Light Intensity Percent 0.25
CB-8. Query entities using conv ops
•Prerequisites–Exercise CB-7
•Steps–Write a program that does the following queries using convenience operations and print the result
•Obtain all attributes of the Garage entity•Find out whether there is anyone in the Bathroom entity•Obtain all entities created so far•Obtain all entities of type Room
•Obtain the temperature attribute of all entities of type Room
–Run and test your program/application
•Hints–Similar to exercise CB-3 in the standard ops set
–Orion User Manual section Convenience Query Context–To get all entities of a given type, you can use the “contextEntityType” resource
Easy
CB-9. Update entity using conv ops
•Prerequisites–Exercise CB-7
•Steps–Write a program (or web/mobile application) that
•Asks for user input (one value)
•Updates Intensity attribute of Light1 entity using that input using a convenience operation•Queries the entity and check the result
–Run and test your program/application
•Hints–Similar to exercise CB-4 in the std ops set–Orion User Manual sections Convenience Query Contextand Getting all entities.
Easy
CB-10. Browsing entity types
•Prerequisites–Exercise CB-7
•Steps–Write a program (or web/mobile application) that
•Lists all entity types•Provides detailed information of type Door
–Run and test your program/application
•Hints–Orion User Manual section Browsing all types and detailed information on a type.
Easy
CB-11. Basic subscription/notifications
•Prerequisites–Exercise CB-2
•Steps–Write a program that
•Starts a REST server to receive notifications from Orion
•Prints the value of the Temperature attribute of Bedroom1 entity each time a notification is received
–Subscribe your program to changes in the Temperatureattribute of Bedroom1 entity–Update the Temperature attribute of Bedroom1 entity and check that your program prints the updated value
•Hints–Orion User Manual section Context Subscriptions (especially subsection on ONCHANGE)
–Your program has to run in a machine with network access to Orion’s to be able to send notifications
Medium
CB-12. Advanced subscription/notification
•Prerequisites–Exercise CB-11
•Steps–Write a program that
•Starts a REST server to receive notifications from Orion
•If the Temperature attribute of Kitchen entity is equal or greater than 30 then update the Status attribute of Kitchen entity with string TEMP_ALARM•If the Temperature attribute of Kitchen entity is lower than 30 then update the Status attribute of Kitchen entity with string OK
–Subscribe your program to changes in the Temperature attribute of Kitchen entity
–Update the Temperature attribute of Kitchen entity with 20, 30, 32, 25, etc. and checks that the Status attribute is modified accordingly
•Hints–This exercises combines subscriptions/notifications with updates–Modify the program already developed in Exercise CB-11–Check exercise CB-4 and/or CB-9 about updating entities
Hard
CB-13. Expert subscription/notification
•Prerequisites–Exercise CB-11
•Steps–Write a program that
•Starts a REST server to receive notifications from Orion•If the Temperature attribute of Kitchen entity is greater than 30 then update the Intensity attribute of Ligth3 entity with the current value of Intensity plus 0.10 (with a maximum value of 1.0)
–Subscribe your program to changes in the Temperature attribute of Kitchenentity–Update the Temperature attribute of Kitchen entity with 20, 30, 32, 25, etc. and checks that the Intensity attribute of Ligth3 is modified accordingly
•Hints–This exercises combines subscriptions/notifications with queries and updates–Modify the program already developed in Exercise CB-11–To get the current value of Intensity attribute of Light3 your program has to do a query operation. Check exercise CB-3 or CB-8 about querying entities–Check exercise CB-4 and/or CB-9 about updating entities
Hard
CB-14. Get X-Auth-Token
•Prerequisites: –To have a FIWARE Lab account
•Steps–Use your login/password to get the token
•Hints–Use the script described and available at Orion Quick Start.
Easy
CB-15. Browse types at Orion Global instance
•Prerequisites: –Auth token obtained in exercise CB-14
•Steps–Write a program (or web/mobile application) that
•Lists all entity types•Provides detailed information of type Taxi
–Run and test your program/application
•Hints–Orion global instance runs at orion.lab.fiware.org port 1026
–Similar to exercise CB-10 but adding the “X-Auth-Token” HTTP header (set with the auth token)
Easy
CB-16. Query entities at Orion Global instance
•Prerequisites: –Auth token obtained in exercise CB-14
•Steps–Write a program (or web/mobile application) that does the following queries and print the result
•All the attribute of entity MeteoLo (type MeteoLo)•All the entities of type Node
•Attribute batteryCharge of entity OUTSMART.NODE_3506 (type Node)•All the entities of type Taxi which id ends in 7
–Run and test your program/application•Hints
–Orion global instance runs at orion.lab.fiware.org port 1026
–Similar to exercise CB-3 and/or CB-8 but adding the “X-Auth-Token” HTTP header (set with the auth token)
Easy
CB-17. Subscribe to public information
•Prerequisites–Auth token obtained in exercise CB-14
•Steps–Write a program that
•Starts a REST server to receive notifications from Orion•Prints all the attributes of entities of type santander:device each time a notification is received
–Subscribe your program to all attributes of every entity of type santander:device each time TimeInstant attribute changes using throttling of 10 seconds–Check that entities information arrives each 10 seconds and you program prints it
•Hints–Orion global instance runs at orion.lab.fiware.org port 1026–Orion User Manual section Context Subscriptions–Your program has to run in a VM/machine reachable from orion.lab.fiware.org. The port you use in the reference field in the subscription has to be open in your security group–Differently from exercises CB-11/12/13, you don’t need to update the subscribed entities, as santander:devices entities are automatically update by IoT devices interacting with the Orion global instance
Hard
Orion Context Broker Exercises(Advanced)
Contact twitter
@fermingalanContact email
Outline
•CB-18. Pagination
•CB-19. Geolocation (factory)
•CB-20. Geolocation (cities)
•CB-21. Compound attributes
•CB-22. Query entities with compound attributes
•CB-23. Update entities with compound attributes
•CB-24. Custom metadata
•CB-25. Dynamic attributes addition/deletion
•CB-26. Multitenancy
•CB-27. Service Paths (create)
•CB-28. Service Paths (query)
•CB-29. Service Paths (update)
26
CB-18. Pagination
•Prerequisites–Access to Orion instance running in 130.206.81.86 port 1026
•Steps–Check how many entities of type Sensor are stored in that Orion instance–Write a program (or web/mobile application) that
•Asks for a limit and a page number
•Returns the name IDs the entities of type Sensor in the corresponding page
–Run and test your program/application
•Hints–Orion User Manual section Pagination
Medium
CB-19. Geolocation (factory)
•Prerequisites–Access to Orion instance running in 130.206.81.86 port 1026
•Steps–Write a program (or web/mobile application) that
•Gets all existing types
•Gets all entities of each type in areas Red, Green and Blue (see next slide), printing entity IDs and their attributes which their values
–Run and test your program/application
•Hints–Orion User Manual section Geolocation
Medium
29
-33.596620, -70.666825
-33.607682, -70.670730
-33.6100089, -70.643231
-33.599194, -70.640200
CB-19. Geolocation (factory)Medium
30
-33.596620, -70.666825
-33.607682, -70.670730
-33.6100089, -70.643231
-33.599194, -70.640200
-33.603458, -70.652788
-33.606123, -70.653790
-33.604231, -70.646032
-33.607108, -70.646781
-33.602391, -70.661781
x
200m
CB-19. Geolocation (factory)Medium
CB-20. Geolocation (cities)
•Prerequisites–Exercise CB-1
•Steps–Chose 2 European countries (let’s name them A and B)–Chose 3 cities in each country–Create one entity for each city, in the following way
•Entity ID: the name of the city•Entity type: “City”•The attribute “location” represent the city location (coordinates)
–Write a program (or web/mobile application) that•Does a query to get all cities•Does a query to get all cities in country A•Does a query to get all cities in country B
–Run and test your program/application
•Hints–Orion User Manual section Geolocation
–This page may help to get city coordinates: http://www.gps-coordinates.net/
–Use polygons to model countries (the model doesn’t need to be very precise). Google Maps may help (http://maps.google.com/)
Medium
CB-21. Compound attributes
•Prerequisites–Exercise CB-1
•Steps–Create the following entities in your Orion instance
•See table in next slide
•Hints–Orion User Manual section Structure Attribute Values
Medium
CB-21. Compound attributes
Entity Type Attr. Name Attr. Type Example value
Character Name string Fooy
Hitpoints integer 110
Class string Barbarian
Abilities compound {"STR": "2","DEX": "4","CON": "3","INT": "1","WIS": "1","CHA": "2"
}
Inventory compound {"weapons": [ "sword", "dagger" ],"potions": { "life": "1", "mana": "0" },"other": ["shield"]
}
Entity name Entity Type
Gandalf Character
Aragorn Character
Frodo Character
Medium
CB-22. Query entities with compound attributes
•Prerequisites–Exercise CB-21
•Steps–Write a program (or web/mobile application) that does the following queries and print the result
•Obtain all attributes of Aragorn entity•Obtain only the Abilities attribute of Frodo entity
–Run and test your program/application
•Hints–Orion User Manual section Structure Attribute Values
Medium
CB-23. Update entities with compound attributes
•Prerequisites–Exercise CB-21
•Steps–Write a program (or web/mobile application) that
•Asks for an object name (e.g. “staff”, “hat”, etc.)
•Updates Gandalf's Inventory attribute to reflect that he now has a that object test your program
–Run and test your program/application•Query the Gandalf's Inventory after that, in order to check that the object has been successfully added
•Hints–Orion User Manual section Structure Attribute Values
Medium
CB-24. Custom metadataMedium
•Prerequisites–Exercise CB-21
•Steps–Update the Gandalf entity so that the inventoryattribute has two new metadatas:
•name="Weight", type="float", value="1.2"•name="MaxWeight", type="float", value="20"
–Query Gandalf again to see the new metadata atached to the corresponding attribute
•Hints–Orion User Manual section Attribute metadata
CB-25. Dynamic attributes addition/deletion
•Prerequisites–Exercise CB-1
•Steps–Create the following initial entity
•Entity ID: Car1•Entity Type: Car•Initial attribute: name=Speed, type=integer, value=70
–Write a program (or web/mobile application) that•Asks for an operation type (ADD or DELETE)•If user chose ADD
–Ask for an attribute name, type and value
–Do a query to Orion to check that no other attributes with the same name exists in the entity (in positive case, exit informing the user about the problem)–Create the new attribute at the entity
•If user chose DELETE–Ask for an attribute name
–Do a query to Orion to check that an attributes with that name exists in the entity (in negative case, exit informing the user about the problem)–Delete the attribute at the entity
–Run and test your program/application•Query your entity to check that the attributes are added and deleted as expected
•Hints–Orion User Manual section Adding and removing attributes and entities
Hard
CB-26. Multitenancy
•Prerequisites–Exercise CB-1
•Steps–Write a program (or web/mobile application) that
•Creates the following entities in your Orion instance at tenant "Customer1"
–See table in next slide
•Creates the following entities in your Orion instance at tenant "Customer2"
–See table in next slide
–Query for the Hammer entity using Customer1 and Customer2 as Fiware-Service alternatively, checking that the result is the right one for the given tenant
•Hints–Orion User Manual section Multitenancy–Orion has to be configured to run with multitenancy enabled
•BROKER_EXTRA_OPS="-multiservice" at /etc/sysconfig/contextBroker
Medium
CB-26. Multitenancy
Entity Type Attr. Name Attr. Type Example value
Tool stock integer 1234
Tenant Entity Name Stock attribute value
Customer1 Hammer 40
Screwdriver 23
Pliers 12
Ducktape 13
Customer2 HeatGun 109
Pliers 832
Hammer 646
Screwdriver 301
Hard
CB-27. Service Paths (create)
•Prerequisites–Exercise CB-1
•Steps–Create the following entities
•See table in next page
•Keep in mind that they have to use Service Paths according to the figure
•Hints–Orion User Manual section Entity Service Paths
Hard
CB-27. Service Paths (create)
Entity Type Attr. Name Attr. Type Example value
Laptop owner string Bob
MobilePhone owner string Alice
Company
Sales Dept.
phone1owner: Dave
phone2owner: Alice
laptop1owner: Alice
TechSupport Dept.
laptop2owner: Charlie
laptop3owner: Bob
phone3owner: Bob
Service Path ¨Fiware-ServicePath¨ header value
Company /company
Sales Department /company/sales
Tech Support Department /company/tech
Hard
CB-28. Service Paths (query)
•Prerequisites–Exercise CB-27
•Steps–Write a program (or web/mobile application) that does the following queries and prints the result
•Query all phones in the company•Query all laptops in the Tech Support department
–Run and test your program/application
•Hints–Orion User Manual section Entity Service Paths
Medium
CB-29. Service Paths (update)
•Prerequisites–Exercise CB-27
•Steps–Write a program (or web/mobile application) that does the following
•Since Charlie left the Company he has to give back his laptop. Update entity laptop2's owner attribute and set it to "nobody".
•Create a new entity phone3 of type MobilePhone in the sales department and set the owner attribute to "Alice" (she needs two phones, she works a lot). Notice that as a result of this there will be two entities with the same id in different Service Paths.
–Run and test your program/application•Query entity phone3 and see which one you get when querying with the following service paths
–The Sales department–the Tech Support department–All the company
•Hints–Orion User Manual section Entity Service Paths
Hard
Thanks!Thanks!
(Number to manuals sections in this presentation are valid at time of writing this –March 9th 2015-, but they may
change along time)