Diapositiva 1

Download Report

Transcript Diapositiva 1

HOW TO INTERACT THROUGH
BETAAS APIS
Adaptation, Service and Extended Service Programming Interfaces
BETaaS APIs Webinar
1
WEBINARS AGENDA
Dec 2014
BETaaS: a horizontal platform for IoT
Jan 2015
How to interact through BETaaS API
Feb 2015
How to use local and remote cloud instances at BETaaS
Feb 2015
CoAP Adaptation Plugin
Feb 2015
Running apps BETaaS enabled proprietary devices
Feb 2015
How to setup security environment in BETaaS
BETaaS APIs Webinar
2
THE LAYERED ARCHITECTURE
GW
GW
GW
BETaaS APIs Webinar
3
EXTERNAL INTERACTIONS - ADAPTATION
Things
BETaaS APIs Webinar
4
EXTERNAL INTERACTIONS - SERVICE
Smartphones,
Laptops, etc.
Things
BETaaS APIs Webinar
5
INTERACTIONS - EXTENDED SERVICES
Smartphones,
Laptops, etc.
Custom
Business
Logic
Extended
Services
Things
BETaaS APIs Webinar
6
ADAPTATION INTERFACE (1/3)
To be implemented by every OSGi adaptor bundle
CoAP
Plug-in
ETSI
Plug-in
Thing Simulator
Adaptor Plug-in
…
Once installed, the bundle is automatically exploited by BETaaS
Sub-project: betaas-plugins\betaas-adaptation-plugin
Java Interfaces: IAdaptorPlugin
BETaaS APIs Webinar
7
ADAPTATION INTERFACE (2/3)
Adaptation bundles are used by BETaaS to:
DISCOVER new Things
+ Context
Information
GET
sensors measurements
and/or SUBSCRIBE
SET
actuators
BETaaS APIs Webinar
Plug-in
Bundle
8
ADAPTATION INTERFACE (3/3)
Interface IAdaptorPlugin (IMPLEMENTED)
public Vector<HashMap<String, String>> discover()
Key
Value
ID
0323Ar-BTU2-a
Key
Value
ID
MNOS-4520-21
public String getData(String sensorID);
type
Presence
public boolean register(String sensorID);
…
…
public boolean unregister(String sensorID);
type
Humidity
public String setData(String
sensorID,
String value);
latitude
43.192416
…
…
…
Interface IAdaptorListener (USED)
Key
Value
measurement
7.21
latitude
43.192418
…
…
public boolean notify(String type, String resourceID,
HashMap<String, String> value);
BETaaS APIs Webinar
9
SERVICE INTERFACE (1/2)
Used by external applications to:
> Request the resources allocation
> Get the list of allocated Thing Services
> Get and Set data using Thing Services
> Retrieve extended services data
> Request the execution of background tasks on Thing Services data
Available both through SOAP and REST
Sub-project: betaas-service\betaas-service-servicemanager
Java Interfaces: ServiceManagerExternalIF
Services description also available at http://<karaf host>:8181/cxf
BETaaS APIs Webinar
10
SERVICE INTERFACE (2/2)
public String
installApplication(String
public String
getApplicationServices(String
public boolean
public String
public boolean
manifestContent);
uninstallApplication(String
getThingServiceData(String
appID);
appID, String manifestContent);
appID, String serviceID, String token);
setThingServiceData(String
appID,
String serviceID, String data, String token);
public String getExtendedServiceData(String appID, String extServUniqueName, String additionalInfo);
public boolean
register(String
public boolean
unregister(String
public String
appID,
getTaskData(String
String serviceID,
String token);
appID, String serviceID, String token);
appID, String taskID);
BETaaS APIs Webinar
11
MANIFEST – AN EXAMPLE
<?xml version='1.0'?>
<manifest>
<Application>
<name>eu.betaas.test.testBETaaSREST</name>
<credentials>MIIGogIBAzCCBlwGCSqGSIb3DQEHAaCCBk[…]</credentials>
<notificationAddress>http://192.168.31.44:8080/TestBETaaSREST/</notificationAddress>
</Application>
<ServiceDescriptionTerm>
<ServiceDefinition>
<Feature>STREET LAMP</Feature>
<Areas>
<Environment>Public</Environment>
<Altitude>30</Altitude>
<Latitude>43.656998</Latitude>
<Longitude>10.437418</Longitude>
<Radius>1000.0</Radius>
</Areas>
<Delivery>betaas.delivery.SET</Delivery>
<Trust>3</Trust>
<QoS>
<MaxInterRequestTimeSec>5</MaxInterRequestTimeSec>
<MaxResponseTimeSec>15</MaxResponseTimeSec>
<MinAvailability>1</MinAvailability>
</QoS>
<credentials></credentials>
</ServiceDefinition>
</ServiceDescriptionTerm>
</manifest>
BETaaS APIs Webinar
12
SERVICE INTERFACE – AN EXAMPLE
BETaaS APIs Webinar
13
SERVICE INTERFACE – INTRUSION DETECTION
<Feature>presence</Feature>
<Areas>
<Environment>
Private
</Environment>
<LocationKeyword>
home
</LocationKeyword>
<Floor>1</Floor>
</Areas>
Uses SOAP service interfaces
Allocates one TS for PRESENCE anywhere in the HOME
GET TS data (combined value) and requests a simple data TASK
BETaaS APIs Webinar
14
EXTENDED SERVICE INTERFACE (1/2)
Extended service are OSGi bundles that use Service Layer APIs
(ServiceManagerInternalIF) to:
> Request the resources allocation
> Get and Set data using Thing Services
> Request the execution of background tasks on Thing Services data
Standard Java calls to APIs methods
Extended Services must implement an interface
Sub-project: betaas-service\betaas-service-servicemanager
Java Interface: IExtendedService
BETaaS APIs Webinar
15
EXTENDED SERVICE INTERFACE (2/2)
Methods to provide:
public String getUniqueID();
public void notifyInstallation(boolean success,
String msg,
String extServId,
ArrayList<String> servList,
ArrayList<String> tokenList);
public void notifySLAViolation(String serviceID);
public void notifyData(String serviceID, JsonObject data);
public String getResult(String additionalInfo);
BETaaS APIs Webinar
16
EXTENDED SERVICE – LEZ TRAFFIC MGMT
Traffic Intensity data
MUNICIPALITY
Compute
dynamic fees
Adaptation APIs
GW
Service
APIs
Extended Service APIs
Cars position
User App
BETaaS APIs Webinar
17
MOBILE APP INTERACTION
Difficulty to interact with SOAP interfaces in mobile development
> Complexity
> Lack of libraries
Difficulty to implement a “receptor” service (for PUSH mode)
> Use Google Cloud Messaging
> Proprietary system
> Not free
> Vendor lock-in
> Use open source queuing tools (RabbitMQ)
> RabbitMQ
> Battery consumption
> Implement your own server
> Not possible in some systems
> Good luck!
BETaaS APIs Webinar
18
MOBILE APP INTERACTION
Use of the REST interface in PULL mode:
Install App
App Id
loop
Get services IDs
Services IDs
loop
Get Data
Get Data
Data
Data
Set Data
Set Data
OK/KO
OK/KO
BETaaS APIs Webinar
19
MOBILE APP INTERACTION
<?xml version='1.0'?>
<manifest>
<Application>
<name>IntrusionDetection</name>
<credentials>MIIGogIBAzCCBlwGCSqGSIb3DQEHAaCCBk[…]</credentials>
<notificationAddress>http://localhost:8080/betaasapptester/</notificationAddress>
</Application>
<ServiceDescriptionTerm>
<ServiceDefinition>
<Feature>presence</Feature>
<Areas>
<Environment>Private</Environment>
<LocationKeyword>home</LocationKeyword>
<Floor>1</Floor>
</Areas>
<Delivery>betaas.delivery.RTPULL</Delivery>
<Trust>5</Trust>
<QoS>
<MaxInterRequestTimeSec>5</MaxInterRequestTimeSec>
<MaxResponseTimeSec>15</MaxResponseTimeSec>
<MinAvailability>2</MinAvailability>
</QoS>
<credentials></credentials>
</ServiceDefinition>
</ServiceDescriptionTerm>
</manifest>
BETaaS APIs Webinar
20
MOBILE APP INTERACTION – REST API 1/2
Install Application:
HTTP Method: POST
URL: http://<sm-IP>:8181/cfx/sm/application/
Headers: “Content-Type : application/xml”
Body: manifest string
Returns: <Gateway ID0>::<App Id>
Get Services IDs:
HTTP Method: GET
URL: http://<sm-IP>:8181/cfx/sm/application/<appID>
Returns: {
InstallationInfo: {
serviceList : [<service1>, <service2>...],
tokenList : [<token1>, <token2>...]
}
}
BETaaS APIs Webinar
21
MOBILE APP INTERACTION – REST API 2/2
Get data:
HTTP Method: GET
URL: http://<sm-IP>:8181/cfx/sm/data/<applicationID>/<serviceID>
Headers: “token : <token>”
Returns: true/false
Uninstall application:
HTTP Method: DELETE
URL: http://<sm-IP>:8181/cfx/sm/application/<applicationID>
Headers: “token : <token>”
Returns: 200 OK
Full specification: http://<sm-IP>:8181/cfx/sm?_wadl
BETaaS APIs Webinar
22
MOBILE APP INTERACTION - SAMPLE
Mobile App
BETaaS Gateway
AsyncTask (background thread)
UI Thread
GatewayFragment
GatewayManager
installApplication(gwId)
GWCommunicatorREST
installApplication(gwId)
REST client
postResource(appData)
POST …
200 OK - appId
[200 OK, appId]
getResource(app)
REST server
GET …
loop
200 OK – {InstallationInfo…}
[200 OK, {Installatio…}]
notifyApplicationInstalled(d)
{<appId>, [serv1, serv2], …
getPresence(servId)
getResource(servId)
getPresence(servId)
GET …
loop
[200 OK, 0/1]
notifyDataUpdate(res)
200 OK - 0/1
true/false
BETaaS APIs Webinar
23
NEXT WEBINAR
February 2015
HOW TO USE LOCAL AND REMOTE CLOUD INSTANCES
AT BETAAS
www.betaas.eu
BETaaS APIs Webinar