fiware developers week_fiware iot: beginner's tutorial_conference

32
FIWARE IoT:Beginner’s Tutorial Carlos Ralli Ucendo, @carlosralli . Telefonica I+D IoT Chapter Architect, FIWARE

Upload: fiware

Post on 16-Jul-2015

759 views

Category:

Internet


2 download

TRANSCRIPT

Page 1: FIWARE Developers Week_FIWARE IoT: Beginner's tutorial_conference

FIWARE IoT:Beginner’s Tutorial

Carlos Ralli Ucendo, @carlosralli . Telefonica I+DIoT Chapter Architect, FIWARE

Page 2: FIWARE Developers Week_FIWARE IoT: Beginner's tutorial_conference

FIWARE (IoT) Target: Developers

ContextBroker

App Logic @FIWARE-Cloud

Desktop/Mobile/TabletUser Interface

Web 3D GE / Advanced UIWirecloud GE / Dashboards

OAuth2.0

SANTANDER

SMARTSPACES

SEVILLA 2) IoT Providers. Pretty Heterogeneous solutions/skills.• An incremental approach. Public/Private instances.• KISS philosophy for most (web)developers.• Advanced IoT architecture, e.g. for IoT Advanced

Devel.

1) IoT Consumers. Normally not just IoT.• A single point, API & Protocol for IoT, OpenData, etc.• Context: Data Entities + Data Entities events.• A Public & Secured Ecosystem at FIWARE Lab

MultiMediaEvents

ComplexEvent Processing

IoT-Agents (IDAS 3.0)

SmartcitiesOpenData

BigDataAnalytics

Page 3: FIWARE Developers Week_FIWARE IoT: Beginner's tutorial_conference

FIWARE Lab: OpenData/IoT Resources Ecosystem

3

SANTANDER

SEVILLA

MALAGA

TRENTO

Page 4: FIWARE Developers Week_FIWARE IoT: Beginner's tutorial_conference

Consuming IoT Data: ContextBroker

4

Developers need to know/discover the Ecosystem conventions. Examples:

Developers may:•Query an Entity (whole set or specific attributes) or Subscribe to changes of attributes of Entities.•Discover all Entities (entity_IDs) or all Entities with a specific “type”.•Discover all Entity types.

Full List of FIWARE Lab (Global Context Broker) conventions (section 3.5):https://forge.fi-ware.org/plugins/mediawiki/wiki/fiware/index.php/Publish/Subscribe_Broker_-_Orion_Context_Broker_-_User_and_Programmers_Guide

My FIWARE-App

ContextBroker

OAuth2.0

OMA NGSI10 - QueryContext

OMA NGSI10 - SubscribeContext

(type, entity_ID, attributes)

Entities

Page 5: FIWARE Developers Week_FIWARE IoT: Beginner's tutorial_conference

IoT Providers: Connect any “Thing”/System to FIWARE Lab

5

ContextBroker

OAuth2.0

Your IoT IoT

Backend

Gateway GEs Backend GEs

NGSI9/10

A) NGSI A

gent

B) IoT BE ( IoT-Agents)

C) Advanced Scenarios

UL2.0/HTTP, UL2.0/MQTT, LWM2M/CoAP

NGSI

PropietaryZigbeeZwave

CoAP/MTRunnerETSIM2M

CoAP/LWM2M

NGSI

NGSI

Page 6: FIWARE Developers Week_FIWARE IoT: Beginner's tutorial_conference

IDAS 3.0 Gei within FIWARE Catalogue

6

http://wiki.fi-ware.org/Internet_of_Things_(IoT)_Services_Enablement_Architecture

IoT-Agents (IDAS)

Page 7: FIWARE Developers Week_FIWARE IoT: Beginner's tutorial_conference

IDAS3.0 - Modular architecture: IoT-Agents

•Monolithic vs Modular -> Easier Installation, Cloud Blueprints•Coded in C++ vs Coded in any language -> Higher flexibility •Extensibility via C++ plugins vs a new IoT Agent -> Easier to get contribs/extensions•Scalability by design

FIWARE Context Broker

IoT Agent-UL2.0

IoT Agent-TT

IoT Agent-lwm2m

IoT Agent Manager

create/monitor

FIWARE IoT Backend Device Management

OMA NGSI API (Developers’ Interface)

(southbound interfaces)Thinking Things

Ultralight2.0 OMA LWM2M/IETF

CoAP

OMA NGSI APIBE DeviceManagement(IDAS)

Page 8: FIWARE Developers Week_FIWARE IoT: Beginner's tutorial_conference

IoT-Agent-UltraLight2.0 (IDAS) – FIGWAY Python2.7 Tools

Testing /Hackathons

https://github.com/telefonicaid/fiware-figway/

•Coded in Python. Tested with RaspberryPI, MACOS & Linux.•Tools for (virtual) Sensors via IDAS IoT-Agent (Ultralight2.0)•Tools to access a ContextBroker.

Page 9: FIWARE Developers Week_FIWARE IoT: Beginner's tutorial_conference

Annex I: FIGWAY - Configuration

figway/python/config.ini

 [user]# Please, configure here your username at FIWARE Cloud and a valid Oauth2.0 TOKEN for your user (you can use get_token.py to obtain a valid TOKEN). username=token=

 [local]#Choose here your System type. Examples: RaspberryPI, MACOSX, Linux, ...host_type=RaspberryPI# Here please add a unique identifier for you. Suggestion: the 3 lower hexa bytes of your Ethernet MAC. E.g. 79:ed:af# Also you may use your e-mail address.host_id=3F:2A:1A

Page 10: FIWARE Developers Week_FIWARE IoT: Beginner's tutorial_conference

Annex I: FIGWAY – Registering a (UL2.0) Sensor

SensorsUL20/> python RegisterDevice.py [DEV_MODEL] [DEV NAME] [ASSET]

> python RegisterDevice.py SENSOR_TEMP Sensor1 Temperature-Madrid28001

* YOUR DEVICE details:*** DEVICE ID = 3F:2A:1A:Sensor1*** ASSET ID = 3F:2A:1A:Temperature-Madrid28001

* This device will be sent to the ContextBroker with the following configuration*** Entity ID = SENSOR_TEMP.3F:2A:1A:Temperature-Madrid28001*** Entity Type = Device*** FIWARE_SERVICE = OpenIoT…* Status Code: 201* Response:

Page 11: FIWARE Developers Week_FIWARE IoT: Beginner's tutorial_conference

Annex I: FIGWAY - Sending Sensor Observations/Measurements

ContextBroker/> python SendObservation.py [DEV_ID] ‘[alias1|value1]’

> python SendObservation.py 3F:2A:1A:Sensor1 't|26'

* Asking to http://130.206.80.47:8002/d?k=4jggokgpepnvsb2uv4s40d59ov&i=3F:2A:1A:Sensor1* Headers: {'content-type': 'application/text', 'X-Auth-Token’: 'Zvcg**********************************************************************qvD6g'}* Sending PAYLOAD: t|26...* Status Code: 200* Response:

Page 12: FIWARE Developers Week_FIWARE IoT: Beginner's tutorial_conference

Annex I: FIGWAY – Check observation was correctly sent

SensorsUL20/> python ReadObservation.py [DEV_ID]

> Python ReadDeviceStatus.py 3F:2A:1A:Temperature-Madrid28001

{    "data": {        "status": "Active",         "isConcentrator": false,         "name": "3F:2A:1A:Sensor1",         "registrationTime": "2014-11-28T12:59:53Z", "creationTime": "2014-11-28T12:59:53Z",         "commands": [],         "sensorData": [            {                "ms": {                    "p": "Temperature",                     "u": "celsius",                     "v": 26.0                }, 

Page 13: FIWARE Developers Week_FIWARE IoT: Beginner's tutorial_conference

Annex I: FIGWAY – Read your Sensor data at the ContextBroker

ContextBroker/> python GetEntity.py [ENTITY_ID]

> python GetEntity.py SENSOR_TEMP.3F:2A:1A:Temperature-Madrid28001

*Asking to http://130.206.80.47:1026/ngsi10/queryContext* Headers: {'Fiware-Service': 'OpenIoT', 'content-type': 'application/json', 'accept': 'application/json', 'X-Auth-Token': 'xn6V**********************************************************************kDwxw'}

* Response: …  "contextElement" : {        "type" : "device",        "isPattern" : "false",        "id" : "SENSOR_TEMP.3F:2A:1A:Temperature-Madrid28001",        "attributes" : […            "name" : "Temperature",            "type" : "Quantity",            "value" : ”26",            "metadatas" : [

Page 14: FIWARE Developers Week_FIWARE IoT: Beginner's tutorial_conference

Annex I: FIGWAY – What if I want to create other kind of sensors?

SensorsUL20/> python DiscoverModels.py

> Python DiscoverModels.py 

* Asking to http://130.206.80.47:5371/m2m/v2/services/OpenIoT/models* Headers: {'content-type': 'application/json', 'X-Auth-Token': 'Zvcg**********************************************************************qvD6g'}…* Status Code: 200* Total Number of Models: 8

* Full List of Models:SENSOR_HUMSENSOR_LUMSENSOR_MOVSENSOR_TEMPSENSOR_TEMP_test2SENSOR_ZWAVE_4IN1

Page 15: FIWARE Developers Week_FIWARE IoT: Beginner's tutorial_conference

Annex I: FIGWAY – What if I want to create other kind of sensors? (II)

SensorsUL20/> python GetModel.py [MODEL_TYPE]

> python GetModel.py SENSOR_TEMP 

** Asking to http://130.206.80.47:5371/m2m/v2/services/OpenIoT/models/SENSOR_TEMP* Headers: {'content-type': 'application/json', 'X-Auth-Token': 'Zvcg**********************************************************************qvD6g'}…* Status Code: 200{"capabilities": [            {                "format": {                    "alias": "t",                     "type": "Quantity",                     "name": "Temperature",                     "uom": "celsius",                     "phenomenon": "urn:x-ogc:def:phenomenon:IDAS:1.0:temperature"                }, 

Page 16: FIWARE Developers Week_FIWARE IoT: Beginner's tutorial_conference

Annex I: FIGWAY – What if I want to create other kind of sensors? (III)

SensorsUL20/> python CreateModel.py [MODEL_FILE]

> python CreateModel.py SENSOR_TEMP_2 

** Asking to http://130.206.80.47:5371/m2m/v2/services/OpenIoT/models/SENSOR_TEMP_2* Headers: {'content-type': 'application/json', 'X-Auth-Token': 'Zvcg**********************************************************************qvD6g'}…* Status Code: 201

Page 17: FIWARE Developers Week_FIWARE IoT: Beginner's tutorial_conference

Annex I: FIGWAY – What if I want to connect Actuators?

SensorsUL20/> python CreateModel.py SWITCH

{ "name": "SWITCH", "commands" : [ { "name" : "RawCommand",

"parameters" : [{ "name" : "Command", "type" : "Text", "phenomenon" : "urn:x-ogc:def:phenomenon:IDAS:1.0:unknown" }] } ], "capabilities": [ …"protocol": "ul-2_0" }

Page 18: FIWARE Developers Week_FIWARE IoT: Beginner's tutorial_conference

Annex I: FIGWAY – What if I want to connect Actuators? (II)

SensorsUL20/> python RegisterDevice.py SWITCH lamp3 lamp3-Madrid

* YOUR DEVICE details:*** DEVICE ID = 3F:2A:1A:lamp3*** ASSET ID = 3F:2A:1A:lamp3-Madrid

* This device will be sent to the ContextBroker with the following configuration*** Entity ID = SWITCH.3F:2A:1A:lamp3-Madrid*** Entity Type = Device*** FIWARE_SERVICE = OpenIoT

* Status Code: 201

Page 19: FIWARE Developers Week_FIWARE IoT: Beginner's tutorial_conference

Annex I: FIGWAY – What if I want to connect Actuators? (III)

python SendCommand.py [ASSET_ID] RawCommand Command ‘[COMMAND]‘

> python SendCommand.py 3F:2A:1A:lamp3-Madrid RawCommand Command 'Set 95-10-23'

* Asking to http://130.206.80.47:5371/m2m/v2/services/OpenIoT/assets/3F:2A:1A:lamp3-Madrid/command* Headers: {'content-type': 'application/json', 'X-Auth-Token': 'xn6V**********************************************************************kDwxw'}* Sending PAYLOAD: {"name": "RawCommand", "params": [ { "name":"Command", "value": "Set 95-10-23" } ] }

...

* Status Code: 200* Response: {"commandResultML":"<commandResultML>Pending<\/commandResultML>"}

Page 20: FIWARE Developers Week_FIWARE IoT: Beginner's tutorial_conference

Annex I: FIGWAY – What if I want to connect Actuators (IV)

python GetPoolingCommands.py [DEV_ID]

> python GetPoolingCommands.py 3F:2A:1A:lamp3

* Asking to http://130.206.80.47:8002/d?k=4jggokgpepnvsb2uv4s40d59ov&i=3F:2A:1A:lamp3* Headers: {'content-type': 'application/text', 'X-Auth-Token': 'xn6V**********************************************************************kDwxw'}* Sending PAYLOAD: ...* Status Code: 200* Response: 3F:2A:1A:lamp3@RawCommand|Command=Set 95-10-23

Page 21: FIWARE Developers Week_FIWARE IoT: Beginner's tutorial_conference

Annex I: FIGWAY – What if I want to connect Actuators (V)

Python DebugCommand.py [ASSET_ID]

> python DebugCommand.py 3F:2A:1A:lamp3-Madrid

* Asking to http://130.206.80.47:5371/m2m/v2/services/OpenIoT/assets/3F:2A:1A:lamp3-Madrid/command* Headers: {'content-type': 'application/json', 'X-Auth-Token': 'xn6V**********************************************************************kDwxw'}* Sending PAYLOAD:

...

* Status Code: 200* Response: {"count":1,"data":[{"command_id":"3F:2A:1A:lamp3@RawCommand","timestamp":"2014-12-02T15:21:08.313135+01:00","status":"DELIVERED"}]}

Page 22: FIWARE Developers Week_FIWARE IoT: Beginner's tutorial_conference

Connect your IoT: IoT-Agent-UltraLight2.0 (IDAS)

For testing use:- Service: OpenIoT

Step 1 – Create ModelStep 2 – Create Asset (device)Step 3 – Send MeasurementsStep 4 – Send Commands

IDAS/SBC Testing details: •IPv4: 130.206.80.47 •IPv6: 2001:720:1514:80::47•Devices API (UL2.0). Port: 8002 (IPv4)•ADMIN API. Port: 5371 (IPv4/IPv6)•Testing Service: OpenIoT•APIKEY: 4jggokgpepnvsb2uv4s40d59ov•Service URL: <IDAS_HOST>/m2m/v2/services/OpenIoT

Page 23: FIWARE Developers Week_FIWARE IoT: Beginner's tutorial_conference

IoT-Agent-UltraLight2.0 (IDAS)

Step 1 – Create Model(REST ADMIN API)

Payload JSON Format: - Check IDAS documents(At FIWARE Catalogue)- TOKEN = FIWARE Oauth Token.- Measurements have an “alias”. E.g: Temperature=t

“Open IoT” example Models:•SENSOR_TEMP•SENSOR_HUM•SENSOR_LUM•SENSOR_MOV•SENSOR_ZWAVE_4IN1

HTTP POST: http://130.206.80.47:5371/m2m/v2/services/OpenIoT/models/Headers: {'content-type': 'application/json’; 'X-Auth-Token' : [TOKEN]}Payload:{ "name": "SENSOR_TEMP", "capabilities" : [ { "name" : "Temperature", "property" : "temperature", "format" : { "name" : "Temperature", "alias" : "t" , "phenomenon": "urn:x-ogc:def:phenomenon:IDAS:1.0:temperature", "type" : "Quantity", "uom": "celsius” } } ], "protocol": "ul-2_0” }

Page 24: FIWARE Developers Week_FIWARE IoT: Beginner's tutorial_conference

IoT-Agent-UltraLight2.0 (IDAS)

Step 2 – Create AssetASSET = LOGICAL DEVICE(REST ADMIN API)

Payload JSON Format: - Check IDAS documentsAt FIWARE Catalogue.- TOKEN = FIWARE Oauth Token.- Must reuse an existing Model.- DEV_ID = 1st “name” - ASSET_ID = 2nd (asset) “name”

HTTP POST: http://130.206.80.47:5371/m2m/v2/services/OpenIoT/assets/ Headers: {'content-type': 'application/json’; 'X-Auth-Token' : [TOKEN]}Payload:{ "name": ”gateway02:Arduino01-Temp-Garden", "model": "SENSOR_TEMP", "asset": { "name": ”TEMP-Garden-Madrid28027", "description": "asset model protocol” } }

IDASIDASDevice ID

ASSET ID

Devices API

ADMIN API

Page 25: FIWARE Developers Week_FIWARE IoT: Beginner's tutorial_conference

IoT-Agent-UltraLight2.0 (IDAS)

Step 3 – Send Measurements(UL2.0 DEVICE API)

Payload JSON Format: - TOKEN = FIWARE Oauth Token.- DEV_ID = Asset name (Step 2).

* Read Last Measurements:HTTP GET:/m2m/v2/services/OpenIoT/assets/[ASSET_ID]

HTTP POST: http://130.206.80.47:8002/d?k=[APIKEY]&i=[DEV_ID]http://130.206.80.47:8002/d?k=4jggokgpepnvsb2uv4s40d59ov&i=GW02:Arduino01-Temp-Garden

Headers: {'content-type': 'application/text’; 'X-Auth-Token' : [TOKEN]}Payload: ‘ t|25‘

- Sending multiple measurements with one request:

http://130.206.80.47:8002/d?k=4jggokgpepnvsb2uv4s40d59ov&i=RPI:79:ed:af:4IN1-Room

Headers: {'content-type': 'application/text’; 'X-Auth-Token' : [TOKEN]}Payload: ‘t|23#h|80#l|95#m|Quiet‘

Page 26: FIWARE Developers Week_FIWARE IoT: Beginner's tutorial_conference

IoT-Agent-UltraLight2.0 (IDAS)

Step 4 – Sending Commands to Devices

IDASIDAS

Page 27: FIWARE Developers Week_FIWARE IoT: Beginner's tutorial_conference

IoT-Agent-UltraLight2.0 (IDAS)

Step 4.2 - Send Commands via IDAS REST ADMIN API

Step 4.1a (PUSH)– Define Command & Register Commands URL

HTTP POST: http://130.206.80.47:5371/m2m/v2/services/[SERVICE]/assets/[ASSET_ID]/command

Headers: {'content-type': 'application/json’; 'X-Auth-Token' : [TOKEN]}Payload:{"name": ” [COMMAND]", "params": [ { "name":” [PARAMETER]", "value": ” [VALUE]" } ] }

HTTP PUT: http://130.206.80.47:5371/m2m/v2/services/[SERVICE]/assets/[ASSET_ID] Headers: {'content-type': 'application/json’; 'X-Auth-Token' : [TOKEN]}Payload:{ "commands" : [ { "name" : "RawCommand”, "parameters" : [{ "name" : "Command", "type" : "Text", "phenomenon" : "urn:x-ogc:def:phenomenon:IDAS:1.0:unknown" }]}],}

Page 28: FIWARE Developers Week_FIWARE IoT: Beginner's tutorial_conference

IoT-Agent-UltraLight2.0 (IDAS)

Step 4.2 - Send Commands via IDAS REST ADMIN API

Step 4.1b (POOLING) - Define Command & Get Commands from Device

HTTP GET: http://130.206.80.47:8002/d?k=[APIKEY]&i=[DEV_ID]

Headers: {'content-type': 'application/text’; 'X-Auth-Token' : [TOKEN]}

HTTP POST: http://130.206.80.47:5371/m2m/v2/services/[SERVICE]/assets/[ASSET_ID]/command

Headers: {'content-type': 'application/json’; 'X-Auth-Token' : [TOKEN]}Payload:{"name": ” [COMMAND]", "params": [ { "name":” [PARAMETER]", "value": ” [VALUE]" } ] }

HTTP PUT: http://130.206.80.47:5371/m2m/v2/services/[SERVICE]/assets/[ASSET_ID] Headers: {'content-type': 'application/json’; 'X-Auth-Token' : [TOKEN]}Payload:{ "commands" : [ { "name" : ” [COMMAND]”, "parameters" : [{ "name" : ” [PARAMETER]", "type" : "Text", "phenomenon" : "urn:x-ogc:def:phenomenon:IDAS:1.0:unknown" }]}],}

Page 29: FIWARE Developers Week_FIWARE IoT: Beginner's tutorial_conference

FIWARE Community: Kick off @ CPE’13

29

1st Prize………….SmartAdsComplete context-sensitive Ads solution developed in just 4 days & nights.

Neelie Kroes FIWARE Lab LaunchHackathon + Challenges Announcements

Massive, > 6K developersMainly young entrepreneurs

TalentDay&Night

Involving developers, debugging, improving training sessions

Page 30: FIWARE Developers Week_FIWARE IoT: Beginner's tutorial_conference

FIWARE Community: Smartcities IoT Data & SMEs involvement

30

Smartcity resources exploitation, involve local market & public policies makers

1st Prize………….MagicBox…………………………………………….….…..…TVs displaying Smartcities & Smartspaces.2nd Prize………….FI-BOT……………………………………………………..….…Robotics exploiting opendata & sensors.3rd Prize.…………OpenAlerts……..…..............................................Interfaces for citizens (mobile If-Then App). 4th Prize………….Traffic Heatmap…..............................................Traffic routing based on city real-time Info.

Winning Teams

33 succeeded building a product-like working App (of 77 registered developers)

Several participants own a Start-up & keep on using FIWARE

Page 31: FIWARE Developers Week_FIWARE IoT: Beginner's tutorial_conference

FIWARE Community: Emerging IoT Trends fast adoption

31

iBeacons in FI-WARE by Context Team.

•3rd prize within SmartBusiness FIWARE challenge.(Jan 2014 @ CPBR7 Sao Paulo)

Page 32: FIWARE Developers Week_FIWARE IoT: Beginner's tutorial_conference

Thanks!Thanks!