Skip to main content

Notice: this Wiki will be going read only early in 2024 and edits will no longer be possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

Difference between revisions of "SensiNact/sensinact-full-start"

(2.1.2. Install from sources)
 
(42 intermediate revisions by 2 users not shown)
Line 1: Line 1:
= sensiNact Documentation =
+
----
 
+
<span style="color: red; font-size: large;">Please refer</span> [https://wiki.eclipse.org/SensiNact sensinact home page]
== Table of content ==
+
----
 
+
# [[#sensinact-overview|sensiNact overview]]
+
# [[#getting-started|Getting started]]
+
 
+
* [[#install-gateway|Install and start sensiNact Gateway]]
+
* [[#install-studio|Install sensiNact Studio]]
+
 
+
<ol start="3" style="list-style-type: decimal;">
+
<li>[[#core-concepts|Core concepts]]</li>
+
<li>[[#appmanager-concepts|AppManager concepts]]</li>
+
<li>[[#using-studio|Using the Studio]]</li></ol>
+
 
+
* [[#configure-studio|Configure the Studio]]
+
* [[#create-application|Create an application]]
+
* [[#deploy-application|Deploy and start an application]]
+
 
+
<ol start="6" style="list-style-type: decimal;">
+
<li>[[#legal-information|Legal information]]</li></ol>
+
 
+
 
+
-----
+
 
+
<div id="sensinact-overview">
+
 
+
 
+
 
+
</div>
+
== 1. sensiNact overview ==
+
 
+
sensiNact is a horizontal platform dedicated to IoT and in particularly used in various smart city and smart home applications. sensiNact aims at managing IoT protocols and devices heterogeneity and provides synchronous (on demand) and asynchronous (periodic or event based) access to data/actions of IoT devices, as well as access to historic data with generic and easy-to-use API. To achieve these objectives, sensiNact comes with two complementary frameworks:
+
 
+
* sensiNact Gateway interconnects IoT devices using different southbound IoT protocols such as Zigbee, EnOcean, LoRa, XBee, MQTT, XMPP, as well as platforms such as FIWARE and allows access to them with various northbound protocols such as HTTP REST, MQTT, XMPP, JSON RPC and CDMI. The gateway can also host applications and manage them using an application manager module.
+
* sensiNact Studio proposes an IDE (Integrated Development Environment) based on Eclipse to manage the existing devices, in addition to develop, deploy and manage IoT applications.
+
 
+
[[Image:./images/architecture/architecture.svg|frame|none|alt=sensiNact overview|caption sensiNact overview]]
+
 
+
 
+
-----
+
 
+
<div id="getting-started">
+
 
+
 
+
 
+
</div>
+
== 2. Getting started ==
+
 
+
<div id="install-gateway">
+
 
+
 
+
 
+
</div>
+
=== 2.1. Install and start sensiNact Gateway ===
+
 
+
This section explains how to install and start sensiNact Gateway under the Linux operating system.
+
 
+
==== 2.1.1. Requirements ====
+
 
+
sensiNact Gateway requires at least Java 6.0 but some features from third party libraries may require Java 7.0.
+
 
+
sensiNact Gateway may requires the access to USB port. To ease the recognition of the USB connector by sensiNact Gateway, it is required to install the [https://en.wikipedia.org/wiki/Udev UDEV rules].
+
 
+
==== 2.1.2. Install from sources ====
+
 
+
Clone the GIT repository
+
 
+
Check [https://projects.eclipse.org/projects/technology.sensinact/developer link Sensinact] eclipse project website.
+
 
+
Enter inside the newly created folder of sensiNact and compile it using Maven 3:
+
 
+
<source lang="bash">mvn clean install</source>
+
 
+
The sensiNact distribution has been created inside the repository ''sensinact/distribution/sensinact-distribution-generator/target/sensinact''.
+
 
+
==== 2.1.3. Launch sensiNact Gateway ====
+
 
+
Once installed, enter into the sensiNact directory. You can now configure the modules you need using the following command:
+
 
+
<source lang="bash">./sensinact -c</source>
+
Some modules require to activate others modules to run. For example, each modules using the USB require the USB module to activated. In a near future, we plan to automate the activation of dependencies modules accordingly to the modules activated by the user.
+
 
+
Once, you finished the configuration of the modules, you can start sensiNact using the following command.
+
 
+
<source lang="bash">./sensinact</source>
+
If the user is not part of the '''dialout''' Linux group, you need to launch sensiNact using '''sudo'''.
+
 
+
<div id="install-studio">
+
 
+
 
+
 
+
</div>
+
=== 2.2. Install sensiNact Studio ===
+
 
+
There are TWO ways to install sensiNact Studio on your computer, depending on what you want to do with the Studio.
+
 
+
* '''If you are a sensiNact end user''', you may be interested in the latest stable release of sensiNact Studio.
+
* '''If you are a sensiNact core developper''', you will need to install the studio from it sources. It will gives you access to the Studio development branch, with the latest features and the ability to debug the Studio using the source code.
+
 
+
==== 2.2.1. For end users: sensiNact Studio latest release ====
+
 
+
===== 2.2.1.1. Install Eclipse Mars =====
+
 
+
You MUST add sensiNact APT repository in your ''sources.list'' in order to have access to this installer, check on the [[#|download page]] how to do it.
+
 
+
Install Eclipse Mars using the installer typing the command below.
+
 
+
<source lang="bash">sudo apt-get install sensinact-studio-eclipse</source>
+
Now you can launch Eclipse Mars simply by typing <code>sensinact-studio</code>
+
 
+
===== 2.2.1.2. Install sensiNact Plugin =====
+
 
+
In eclipse add the three Update Sites below:
+
 
+
* http://p2.restlet.com/2.2/
+
* http://download.eclipse.org/technology/nebula/snapshot
+
* http://132.168.88.189/eclipse/ (this last one is private for now, please ask for the plugin in the contact form).
+
 
+
Look and install the feature named &quot;Sensinact&quot; and click in ''Install''.
+
 
+
===== 2.2.1.3. Update Sensinact Studio =====
+
 
+
Just access the Eclipse menu ''Help'' &gt; ''Check for Updates'', if there is a new version of sensiNact Studio, it will be installed.
+
 
+
==== 2.2.2. For sensiNact developpers: installation from sources ====
+
 
+
===== 2.2.2.1. Install plugin dependencies =====
+
 
+
# Eclipse download and start-up 1.1 Download [http://www.eclipse.org/downloads/packages/eclipse-ide-java-and-dsl-developers/mars2 Eclipse Mars Package “Eclipse IDE for Java and DSL developers”]; 1.2. Extract the archive to the directory of your choice; 1.3. Run the eclipse executable.
+
# EMF transaction installation 2.1. Go to ''Help'' / ''Install new software'' 2.2. Work with: http://download.eclipse.org/releases/mars (already existing); 2.3. Take a coffee ! Eclipse is getting up to date information and this takes time ; 2.4. Select ''Modeling / EMF Model Transaction SDK''; 2.5. Install.
+
# Restlet installation 3.1. Go to ''Help'' / ''Install new software'' 3.2. Work with: http://p2.restlet.com/2.2/ (to be added); 3.3. Select ''Restlet Core and inside Standards support : Restlet Extension – JSON''; 3.4. Install.
+
# Nebula installation 4.1. Go to ''Help'' / ''Install new software''; 4.2. http://download.eclipse.org/technology/nebula/snapshot; 4.3. Select ''Nebula Release Individual Widgets''. 4.4. Install.
+
 
+
===== 2.2.2.2. Clone and Import Studio project =====
+
 
+
# Clone the sensiNact Studio project from
+
 
+
<source lang="bash">git clone https://git-lialp.intra.cea.fr/sensinact/studio`</source>
+
<ol start="2" style="list-style-type: decimal;">
+
<li>Projects import in the studio 2.1. ''File'' &gt; ''Import...''; 2.2. ''General'' &gt; ''Existing Projects into Workspace''; 2.3. Select root directory --&gt; the studio repository; 2.4. Check all the projects; 2.5. Click on finish.</li>
+
<li>First Studio Execution 3.1. Run / Run configurations...; 3.2. Double click on &quot;Eclipse Application&quot; to create a new runner; 3.3. Run.</li></ol>
+
 
+
 
+
-----
+
 
+
== 3. Core concepts ==
+
 
+
The sensiNact Gateway allows interconnection of different networks to achieve access and communication with embedded devices. It is composed of six functional groups and their relative interfaces:
+
 
+
* The Device Protocol Adapter abstracts the specific connectivity technology of wireless sensor networks. It is composed of the bridges associated to protocol stacks. All the bridges comply with a generic Device Access API used to interact with northbound sensiNact’s services.
+
* The Smart Object Access and Control implements the core functionalities of sensiNact like discovering devices and resources and, securing communication among devices and consumers of their services.
+
* The Consumer API is protocol agnostic and exposes services of the Smart Object Access and Control functional to Consumers.
+
* The Consumer Protocol Adapter consists of a set of protocol bridges, translating the Consumer API interface into specific application protocols.
+
* The Platform Management functional group includes all the components needed to ease management of devices connected to sensiNact, regardless of their underlying technologies. A Device Management API is used for this purpose. This functional group also contains the components managing cache, resource directory and security services. These management features are exposed by means of the Platform Management API.
+
* And finally the Manager Protocol Adapter allows adapting the Platform Management API to the specific protocols used by different external management entities.
+
 
+
In terms of connectivity (cf. Figure 3), on the southbound side the sensiNact Gateway allows to cope both with “physical device” protocols and “virtual device” ones, allowing a uniform and transparent access to an XBee network, or an HTTP Restful web service for example. Here's pell-mell a non-exhaustive list of supported protocols:
+
 
+
* '''EnOcean''', concerting energy harvesting wireless sensor technology (ultra-low-power radio technology for free wireless sensors), and protocols in use to interact with those sensors;
+
* '''Bluetooth Low Energy''', which is a personal area network, low power protocol designed mainly for healthcare or entertainment type of applications;
+
* '''MQTT''', which is a machine-to-machine protocol, lightweight publish/subscribe messaging transport, useful for connections with remote locations where a small code footprint is required and/or network bandwidth is at a premium;
+
* '''ZigBee''' based protocols (XBee for example);
+
* '''CoAP''', which is a REST application protocol, designed to be “the HTTP for constrained networks and devices” whose concept originated from the idea that &quot;the Internet Protocol could and should be applied even to the smallest devices,&quot; and that low-power devices with limited processing capabilities should be able to participate in the Internet of Things; it is usually used on top of a 6LoWPAN network, but it may travel regular IP networks as well (it is used by the OMA LWM2M protocol, for instance).
+
 
+
On the northbound side the sensiNact Gateway provides both client/server and publish/subscribe access protocols:
+
 
+
* '''MQTT''';
+
* '''JSON-RPC (1.0 and 2.0)''';
+
* '''HTTP RESTful''';
+
* '''CDMI'''.
+
 
+
[[Image:./images/architecture/gateway_protocol_2.svg|frame|none|alt=sensiNact Paltform architecture|caption sensiNact Paltform architecture]]
+
 
+
The Smart Object Access and Control functional group described above in this section includes a large number of functionalities:
+
 
+
* It handles the communication with the Consumer Protocol Adapter (REST API, JSON RPC, etc.) and IoT (and non-IoT) devices, providing URI mapping, incoming data/messages translation in an internal format and outgoing data/messages translation in Consumer format. Whenever a Consumer tries to access a resource via Consumer API, the requested URI is forwarded to the Resource Manager in order to check if a specific resource descriptor exists or not inside the Resource Directory and to verify its accessibility status. If a resource descriptor doesn’t exist, a message response with error code is returned to the Consumer API. Otherwise, the request is forwarded to the right interface. At the same time whenever response is originated from IoT device (or abstract IoT device), it will be also forwarded to its logical counterpart in order to update the resource representation in the platform.
+
* It manages the subscription/notification phases towards the Consumer, if it is not handled by the targeted device (service) itself
+
* It supports Devices and Resource Discovery and Resource Management capabilities, to keep track of IoT Resource descriptions that reflect those resources that are reachable via the platform. These can be both IoT Resources, or resources hosted by legacy devices that are exposed as abstracted IoT Resources. Moreover, resources can be hosted on the platform itself. The Resource Management functionality enables to publish resources in sensiNact, and also for the Consumer to discover what resources are actually available from the platform; sensiNact Service and Resource model allows exposing the resources provided by an individual service. The latter, characterized by a service identifier, represents a concrete physical device or a logical entity not directly bound to any device. Each service exposes resources and could use resources provided by other services. Figure 4 depicts the Service and Resource model.
+
 
+
[[Image:./images/architecture/data_model.svg|frame|none|alt=Generic data model|caption Generic data model]]
+
 
+
The Resource Directory allows storing information, i.e. resource descriptions, about the resources provided by individual devices connected to sensiNact. It also supports looking up resource descriptions, as well as publishing, updating and removing resource descriptions to it.
+
 
+
Discovering and using resources exposed by Services is a favored approach for avoiding using static service interfaces and then increase interoperability. Therefore, sensiNact Services and their exposed resources are registered into Service/Resource repositories. The platform uses the OSGi service registry as Service/Resource repository, where resources are registered as service properties. Clients ask the Service/Resource repository for resources fulfilling a set of specified properties (defined by LDAP filters). In response, the Service/Resource repository sends clients the list of service references that expose the requested and authorized resources. Clients can then access/manipulate the resources exposed by their selected service objects (cf. Figure 5).
+
 
+
Figure 5: Service Oriented Architecture (MacKenzie, 2006). When a service provider starts, it registers/publishes itself into the service broker. When a consumer appears, it looks for the reference to the service provider into the service broker. With this reference, the consumer can interact directly with the provider.
+
 
+
Resources and services can be exposed for remote discovery and access using different communication protocols, such as HTTP REST, JSON-RPC, etc., and advanced features may also be supported (as semantic-based lookup). Resources can be classified as shown in Table , while the access methods are described in Table 2: Resource's access method.
+
 
+
{|
+
!Type
+
!Description
+
|-
+
|Sensor Data
+
|Sensory data provided by a service. This is real-time information provided, for example, by the SmartObject that measures physical quantities.
+
|-
+
|Action
+
|Functionality provided by a service. This is mostly an actuation on the physical environment via an actuator SmartObject supporting this functionality (turn on light, open door, etc.) but can also be a request to do a virtual action (play a multimedia on a TV, make a parking space reservation, etc.).
+
|-
+
|Property
+
|Information representing a SmartObject state variable of the service. This variable is most likely to be modified by an action (turn on light modifies the light state, opening door changes the door state, etc.) but also to intrinsic conditions associated to the working procedure of the service.
+
|-
+
|State Variable
+
|Property exposed by a service. This is information which is likely to be static (owner, model, vendor, static location, etc.). In some cases, this property can be allowed to be modified.
+
|}
+
 
+
Table 1: Resources types and description
+
 
+
{|
+
!Type
+
!Description
+
|-
+
|GET
+
|Get the value attribute of the resource.
+
|-
+
|SET
+
|Sets a given new value as the data value of the resource.
+
|-
+
|ACT
+
|Invokes the resource (method execution) with a set of defined parameters.
+
|-
+
|SUBSCRIBE
+
|Subscribes to the resource with optional condition and periodicity.
+
|-
+
|UNSUBSCRIBE
+
|Remove an existing subscription.
+
|}
+
 
+
Table 2: Resource's access method
+
 
+
The access methods that can be associated to a resource depend on the resource type, for example, a GET method can only be associated to resources of type Property, StateVariable and SensorData. A SET method can only be associated to StateVariable and modifiable Property resources. An ACT method can only be associated to an Action resources. SUBSCRIBE and UNSUBSCRIBE methods can be associated to any resources.
+
 
+
 
+
-----
+
 
+
<div id="appmanager-concepts">
+
 
+
 
+
 
+
</div>
+
== 4. AppManager concepts ==
+
 
+
The AppManager aims at creating higher level applications based on the resources provided by the sensiNact gateway. The AppManager provides a way to develop event driven applications, i.e., based on the Event-Condition-Actions (ECA) axiom. Thus, the application is only triggered when the required events occur. Then, if all conditions are satisfied, the actions are done. Events are created from sNa sensors and the actions are performed using the sNa actuators available in the environment.
+
 
+
=== 4.1. Data model and JSON format ===
+
 
+
The AppManager assumes that an application is a set of bound components. Each component processes a single function (e.g., addition, comparison, action). The result of this function is stored in a variable in the current instance of the application. The components using this result as input listen to the corresponding variable. When the variable changes, they are notified and can process their own function leading to a new result.
+
 
+
[[Image:./images/appmanager/component.svg|frame|none|alt=Component|caption Component]]
+
 
+
The component is the atomic element of an application, thus an application can consider a single component to perform an action. It holds the minimal requirements to create an ECA application:
+
 
+
* '''Events''': events that trigger the process of a component. Trigger can be conditioned to a specific event or a specific value of the event (e.g., when the value of the sensor reach a threshold) ;
+
* '''Function''': function wrapped in the component (e.g., addition, comparison, action). The acquisition of the parameters is realized in the transition block before the function block;
+
* '''Parameters''': parameters of the function that are not available in the event (e.g., static value, sensors values).
+
* '''Output''': result of the function that is stored in a variable and that triggers a new event.
+
* '''Properties''': nonfunctional properties of the component (e.g., register the result as a new resource in sNa).
+
 
+
The AppManager is a sNa service provider, thus it provides an '''INSTALL''' and an '''UNINSTALL''' resources, enabling a client to install/uninstall an application. These resources are accessible using the different bridges.
+
 
+
A sNa application is described using a JSON file. We developed a specific Architecture Description Language (ADL) to describe the components used in an application and the bindings between the components.
+
 
+
<img src="images/appmanager/data_model.svg" height="200"/>
+
 
+
<img src="./images/appmanager/event_model.svg" height="400"/>
+
 
+
<img src="./images/appmanager/parameter_model.svg" height="200"/>
+
 
+
The following JSON code example corresponds to the code of a single component:
+
 
+
<pre class="json">{
+
    &quot;events&quot;: [
+
        {
+
            &quot;value&quot;: &quot;resource1&quot;,
+
            &quot;type&quot;: &quot;resource&quot;,
+
            &quot;condition&quot;: {
+
                &quot;operator&quot;: &quot;&gt;=&quot;,
+
                &quot;value&quot;: 100,
+
                &quot;type&quot;: &quot;integer&quot;
+
            }
+
        }
+
    ],
+
    &quot;function&quot;: &quot;function_name&quot;,
+
    &quot;parameters&quot;: [
+
        {
+
            &quot;value&quot;: &quot;ON&quot;,
+
            &quot;type&quot;: &quot;string&quot;
+
        }
+
    ],
+
    &quot;properties&quot;: {},
+
    &quot;output&quot;: &quot;output_name&quot;
+
}</pre>
+
This component specifies that when the <code>resource1</code> is greater or equals to <code>100</code>, the <code>function_name</code> is called with the <code>string</code> parameter <code>&quot;ON&quot;</code>. The result of the function is stored in the <code>output_name</code> variable and triggers a new event that may be used by others components.
+
 
+
Supported types are:
+
 
+
* '''Primitives types''': <code>integer</code>, <code>boolean</code>, <code>long</code>, <code>double</code>, <code>float</code>, <code>string</code>. This is used to described a static variable;
+
* '''Resource type''': <code>resource</code>. This is used to refer to a resource. If this is set in the JSON Event section of the JSON, a SUBSCRIBE is done on the resource. If this is done in any JSON Parameters section, a GET is done on the resource and returns the current value;
+
* '''Variable type''': <code>variable</code>. This is used to refer to the output of a previously processed component;
+
* '''Event type''': <code>event</code>. This is used to refer to the value of the event that triggers the function. This type is never used in the condition of the JSON Event section.
+
 
+
Here after is a synthesis of the type that can be used in the different parts of the JSON file.
+
 
+
{|
+
!
+
!Primitive types
+
!Resource type
+
!Variable type
+
!Event type
+
|-
+
|In event type
+
|No
+
|Yes
+
|Yes
+
|No
+
|-
+
|In event/condition type
+
|Yes
+
|Yes
+
|Yes
+
|No
+
|-
+
|In parameters type
+
|Yes
+
|Yes
+
|Yes
+
|Yes
+
|}
+
 
+
The AppManager supports the validation of the JSON files against a JSON schema. Schemas exist in the plugins and may be used by the developers of the applications.
+
 
+
=== 4.2. Architecture ===
+
 
+
The AppManager is designed to be used as any sNa service provider. Thus it provides an Install and an Uninstall resources, enabling a client to install/uninstall an application. These resources are accessible using different bridges, such as any actuators.
+
 
+
The AppManager architecture is also designed to easily add new functions and to handle the lifecycle of applications in order to perform checks.
+
 
+
==== 4.2.1. Plugins ====
+
 
+
Plugins enable to add new function to the AppManager. New plugins require to implements the mandatory interfaces Java interface to be found in the OSGi registry and thus be used by the AppManager. The AppManager is currently supporting the following functions.
+
 
+
{|
+
!Plugin
+
!Functions supported
+
|-
+
|Basic Plugin
+
|various operators (e.g., equals, greater than, lesser than, different), addition, subtraction, division, multiplication, modulo, concatenation, substring, ACT and SET methods on resources
+
|-
+
|CEP Plugin
+
|after, before, coincides, average, average deviation, count, max, min, median, standard deviation, sum
+
|}
+
 
+
==== 4.2.2. Lifecycle ====
+
 
+
The AppManager provides a lifecycle to manage the applications. It enables to process various checks during different steps of the lifecycle of the application (e.g., ADL consistency, resources permissions). The first step is to install the application, i.e., send the ADL of the application. If there is a problem, the AppManager returns an error. Once the application is installed, it can be started and its state changes to “Resolving”. If there is a problem during this step, the application enters in the “Unresolved” state. Otherwise, the application is active until it is stopped or an exception occurs.
+
 
+
<img src="./images/appmanager/lifecycle.svg" height="300"/>
+
 
+
==== 4.2.3. Instances ====
+
 
+
The AppManager allows multiple instances of the same application to run in parallel. When an event occurs, the InstanceFactory of the application instantiates a new set of components and passes the event to the first component. The number of instances can be set in the application properties. If, there is more events than available instances, events are stored and processed when an instance ends.
+
 
+
=== 4.3. How to use ===
+
 
+
The AppManager is accessible as any resources in the sensiNact Gateway. Thus, it is accessible using the RESTful Northbound bridge. At start, the AppManager holds only the '''admin''' service. To install/uninstall an application, you have to perform an ACT on the '''INSTALL'''/'''UNINSTALL''' resources in the AdminService of the AppManager.
+
 
+
To send JSON files, it is recommanded to use the sensiNact Studio that will format the JSON ADL from the sNa language.
+
 
+
You can also uses a REST client (e.g., [https://github.com/wiztools/rest-client WizTools/REST client]) to send JSON files to the AppManager but you need to send a valid JSON file.
+
 
+
 
+
-----
+
 
+
<div id="using-studio">
+
 
+
 
+
 
+
</div>
+
== 5. Using the Studio ==
+
 
+
<div id="configure-studio">
+
 
+
 
+
 
+
</div>
+
=== 5.1. Configure the Studio ===
+
 
+
First of all, launch the Studio by clicking its icon or by using the following command line in a terminal:
+
 
+
<pre>sensinact-studio</pre>
+
Once the Studio is launched, you should obtain something like this:
+
 
+
<img src="./images/tutorial/start-0.png"/>
+
 
+
On the left, in the '''Device Navigator view''', click on ''Add Gateway''.
+
 
+
<img src="./images/tutorial/start-1.png"/>
+
 
+
In the new window, provide the name of your choice, the address of the gateway, the port of the gateway and then, click on ''OK''.
+
 
+
<img src="./images/tutorial/start-2.png"/>
+
 
+
Finally, select the gateway in the ''Device Navigator view'' and then click on ''Connect gateway'' to connect to the gateway.
+
 
+
<img src="./images/tutorial/start-3.png"/>
+
 
+
In the '''Device Navigator view''', the gateway should appear and list the available devices connected on the gateway.
+
 
+
<img src="./images/tutorial/start-4.png"/>
+
 
+
<div id="create-application">
+
 
+
 
+
 
+
</div>
+
=== 5.2. Create an application ===
+
 
+
Once the Studio has been configured, you can create an application. Click on the '''Project Explorer view''' on the left side of the Studio.
+
 
+
<img src="./images/tutorial/app-0.png"/>
+
 
+
Right click on the window and select the menu ''New -&gt; Project...''. Then create a new project: select ''General -&gt; Project''.
+
 
+
<img src="./images/tutorial/app-1.png"/>
+
 
+
Provide a name for the project (for example: iot_week_belgrad) and click ''finish''.
+
 
+
<img src="./images/tutorial/app-2.png"/>
+
 
+
In the newly created project, create a '''sNa file''': right click on the newly created project, then ''New -&gt; File'' and finally provide a name for your application (be careful to use an unique name for your application in order to avoid conflict with others applications from others participants). End the name of the file with the extension ''.sna''. Finally click on ''Finish''.
+
 
+
<img src="./images/tutorial/app-3.png"/>
+
 
+
You may have a popup window asking: &quot;Do you want to add the Xtext nature to the project ?&quot;. Answer ''Yes''.
+
 
+
The Studio should have opened a text view, with the name of your file, in the bottom of the main window. You can now write your application.
+
 
+
<img src="./images/tutorial/app-4.png"/>
+
 
+
To ease the development of an application, the Studio provides an auto-completion feature using the ''Ctrl + Space'' key combo.
+
 
+
Now, we will explain the structure of an application. A sensiNact application is based on the Event-Condition-Action axiom. First your define the resources you are going to use in your application. To do this, you use the ''resource'' keyword followed by a custom name for reusing your resource later in your application. Next, you associate your custom name with the URL of the real resource. For example, you can have something like that:
+
 
+
<pre>resource myCustomeName1=[nameOfTheGateway/device/service/resource1]
+
resource myCustomeName2=[nameOfTheGateway/device/service/resource2]</pre>
+
Next, you define on which '''event''' the application will be triggered. You use the ''on'' keyword followed by the resource the application will listen for events. You end your sentence by the ''subscribe()'' keyword. For example:
+
 
+
<pre>on myCustomResource1.subscribe()</pre>
+
Then, you define the '''condition''' that will enable to perform the actions. You use the ''if'' keyword followed by a condition and ended by the ''do'' keyword. For example:
+
 
+
<pre>if myCustomName1.get() == true do</pre>
+
You can also use the ''else if <condition> do'' or the ''else do'' keywords to create more complex applications.
+
 
+
And finally, you perform the '''action''' using the ''act()'' keyword. You can perform multiple actions in the same condition, simply separate them using a comma.
+
 
+
<pre>myCustomName2.act()</pre>
+
Each sNa application ends with the ''end if'' keyword. Save your work, your first application has been created.
+
 
+
At the end, your sNa application should look like the following example (running on a local gateway):
+
 
+
<pre>resource button=[localgateway/button/switch/state]  // The button sensor
+
resource ON=[localgateway/light/switch/turn_on]    // The ON actuator of the light
+
resource OFF=[localgateway/light/switch/turn_off]  // The OFF actuator of the light
+
 
+
on button.subscribe()                              // The button that will trigger the application
+
 
+
if button.get() == true do                          // The condition to satisfy to perform the action
+
    ON.act()                            // Turning on the light
+
else do
+
    OFF.act()                          // Turning off the light
+
end if</pre>
+
This example turns on a light when the button is pressed the first time (returning ''true'' value) and switch off the light when the button is pressed a second time (returning ''false'' value).
+
 
+
<img src="./images/tutorial/app-5.png"/>
+
 
+
<div id="deploy-application">
+
 
+
 
+
 
+
</div>
+
=== 5.3. Deploy and start an application ===
+
 
+
To deploy an application, you just have to be connected to the gateway (follow the '''Configure Studio''' section). In the '''Project Explorer view''', right click on the file you just created and fulfilled with your sNa application and select ''Deploy IoT application''.
+
 
+
<img src="./images/tutorial/deploy-0.png"/>
+
 
+
This will send your application into the gateway and install it. A window should pop, notifying you that the application has been successfully installed.
+
 
+
Returns to the '''Device Navigator view''' and roll out the ''AppManager'' device. Your application should be there. Roll out your application and double click the ''START'' button.
+
 
+
<img src="./images/tutorial/deploy-1.png"/>
+
 
+
Your application is now started, thus when the event is sent, the action is performed.
+
 
+
Enjoy :-)
+
 
+
 
+
-----
+
 
+
<div id="legal-information">
+
 
+
 
+
 
+
</div>
+
== 6. Legal information ==
+
 
+
//TODO
+

Latest revision as of 12:08, 4 March 2019


Please refer sensinact home page


Back to the top