Data- and Service-Centric Orchestration of the Internet of Things Overview Sheet Table of Contents: Tutorial: Overview Video Walkthrough Emulated IoT device Idea of the Game Goals/Steps of the Tutorial Virtual Machine overview Installed software Folder Structure Code Structure Starting services/agents from binaries Interacting with the VSL using the console service Tutorial TLDR Tutorial: The different steps Part 1: Overlay and Services Task 1: Start a knowledge KA and observe its initial messages Task 2: Start a second KA and and see what both agents exchange. Task 3: Start the gatewayService.jar Task 4: Use the console service to check the result Task 5: Stop everything Part 2: Building a devices digital twin as context model Task 1: Complete the context model of the board Gateway service Task 2: Complete the playercontrol context model Task 3: Play the game Task 4: Stop everything Part 3: Building the game logic and mashing up services Task 1: Complete the subscriptions and VirtualNode registrations of the Gateway Task 1.1: Complete subscriptions of the Gateway Task 1.2: Complete the virtual node registrations of the Gateway Task 2 (optional): Test if your code is working
Task 3: Complete the orchestration logic Task 4: Test if your logic works! Task 5: Stop everything Part 4: Security Task 1: Check how secure the access to the secretKey currently is: Task 2: Update the model of the monitor service Task 3: Try accessing the secretKey node again Tutorial: Closing words VSL Java Cheatsheet Solution Part 3: BoardGateway.java GameControlServiceHandler.java Tutorial: Overview In this tutorial we will use the VSL to mash up different services in order to build a small game integrating an emulated IoT device. Video Walkthrough You can find a video walkthrough to follow along here: Intro: https://www.youtube.com/watch?v=wxcWGZDXfuw Walkthrough: https://www.youtube.com/watch?v=p4v8nmS0hco Emulated IoT device For that purpose we prepared an emulated IoT device offering different resources like leds and buttons. The device can be controlled (send commands, request state) using CoAP. This part is already fully implemented by us. When started, a new window is opened and the device is shown in figure 1.:
Figure 1: The user interface of the emulated device The screen is split in two sides, one side for each player: ● Each player has a button that can be pressed, which is mapped to a key on your keyboard . In the case of Player 1 this is “ D ” for Player 2 it is “ J ”. ● Next to it we have a green led . If the button/key the according player is pressed, the device turns the lamp automatically on (as shown for Player 1). Otherwise the led is off (as shown for Player 2). ● Finally towards the center each player has a red led , which is required for the game. In the image that led is currently off for both players. Finally we also have a single blue “ alarm ” led in the top center of the emulated device. Idea of the Game On its own the emulated device is rather dumb. The only thing it does is checking whether you press the D and/or J buttons and then turns on the respective players green LED. Not much of a fun game so far. What we actually want to have in the end is a little game that starts when both keys are pressed at the same time. 1. If this is the case, the blue alarm led should turn on to indicate the game is started. 2. Then, after a random amount of time, one players red LED should light up . The according player than has to take his finger of his key as fast as possible (but not before the led lights up!).
3. Another random delay later, the other players red led should light up and he has to take his finger of the key. 4. The emulated device can then be queried for the time it took both players to react after their red led turned on . 5. Based on those times we can calculate the winner (who was faster?) and display it on the device using the leds. Goals/Steps of the Tutorial The different steps of this tutorial is as follows: 1. Get familiar with the VSL and how the game works . Afterwards you are provided with a skeleton code of services and models for the game and have to complete it on your own. 2. Create a context model for the VSL that describes the capabilities of the smart device 3. Create a gateway service that connects the device to the VSL using the context model. 4. Create an orchestration service that implements the logic of the game. For this purpose it has to: a. Interact with the gateway service to get/set the current state of the emulated device b. Report the results of the game to a leaderboard service c. Report the (relevant) interactions with the VSL to a monitor service 5. Have a brief look at the access control features offered by the VSL. The leaderboard and monitor services are already finished and can be used as they are. The Gateway and orchestration services are provided as skeleton code with TODOs on the relevant parts. Virtual Machine overview Installed software The Virtual Machine runs lubuntu as lightweight ubuntu alternative. In case you need username or password (e.g. for sudo): ● Username: im ● Password: im When you start the VM, you will find all required shortcuts on the desktop: ● Eclipse : The IDE to work on the coding tasks ● Firefox : To display the leaderboard and join our irc channel for questions.
● Terminal : Open a new terminal to e.g. start service jars or Knowledge Agents (The peers that build the Vsl Overlay). You can also press ctrl+alt+t to open a new terminal ● Teamviewer : If you are stuck we can connect to your VM via teamviewer and try to help you. If you want to do this, start teamviewer and send us your ID and password over irc as private message (or contact us over IRC first). ● Tutorial files : Shortcut to the folder where all tutorial related files are stored. See next subsection for details. The folders full path is /home/im/tutorial Feel free to install any other software you like, e.g. a text editor of your choice. You can change your keyboard layout by opening the menu (bottom left) → Preferences → LXQT settings → Keyboard and Mouse Folder Structure The tutorial folder contains different subfolders: ● code : The skeleton codes for the tutorial. See next subsection for details. ● bin : The bin folder contains all compiled (working) jars for the game, so that you can try it even without/before completing the code. It also contains the console service and the knowledge agents (ka.jar) (see later section) ○ models : The models subfolder of the bin folder contains all models relevant for the tutorial. They are simple xml files structured in different subfolders and can be edited with any editor. You will need to edit some models during the tutorial . ● web : The website that display the leaderboard and activity of the services. (nothing to do here for you) ● certificates : The certificates for all services and Knowledge agents and the scripts to recreate them. For your convenience the skeleton code uses the correct certificates automatically. (nothing to do here for you) Code Structure The code is already imported in eclipse. The different packages contain different services or helpers. In this template we usually separate services in two java classes per package, using the following naming scheme: ● xxxService.java: This class contains the main method and is the entry point of the service. It sets up all necessary things for the service in order to work. E.g. it: ○ Specifies the context model used by this service in the MANIFEST ○ Loads the specified certificate ○ Creates a ServiceConnector object (connector) used to interact with the VSL ○ Creates the corresponding xxxServiceHandler.java class ○ Registers subscriptions and virtual nodes and uses xxxServiceHandler.java methods as callback So basically the xxxService.java class is responsible for wiring the service together
Recommend
More recommend