JavaScript for OCF Applications - Open Connectivity … · Express, mraa, MQTT and CoAP modules ...
Transcript of JavaScript for OCF Applications - Open Connectivity … · Express, mraa, MQTT and CoAP modules ...
Vision
3
GW
Smart Devices
REST
REST
CoAP, MQTT, 6LowPAN, BLE
JavaScriptEngine(s)
Web Server API Server
Resource Networking
Storage
Cloud
JavaScript for Everything
Application developer can use only web technologies to create end-to-end solutions.
Not the only option but focus of this talk.
Web App
Node.JS• JavaScript runtime for headless devices• V8 engine from Google• Chakra engine from Microsoft• Event loop (libuv)• Node package manager (NPM)• Node packages (www.npmjs.org)• Open source since 2008• Node Foundation (2015)
5
Why Node.JS for IoT• Young, with heritage• Experienced pool of developers• Thoroughly asynchronous, scales well• Wide adaptation, lots of packages including IoT specific• Perfect for REST APIs and extendable via modules (inc. native libs)• Tooling for REST API modeling languages (swagger, RAML, etc)• Full stack applications - JavaScript for both front and back end
6
Node.JS for IoT
7
Swagger or RAML can be used to define and document
the REST APIs
OS + Middleware + libs
Node.JS
Web App
Headless IoT Gateway reference architecture
REST APIs to services(HTTP + json/xml)
Cloud Services
Node.JS App for the business
logic.
Node.JS runtimeV8, event loop, OS integration
JS API for the Web Apps
npmjs.org modules (200K)
orproprietary
Cloud and device apps use services via REST
APIs
Node Modules
Node.JS APIModule API
APIJS
C/C++
The APISame OCF JavaScript API for everything
• Great API makes a difference• Iterative design process• Real usage• Web IDL specifications• Examples• The same OCF JS API
• Node.JS• Cordova and Crosswalk• Tizen• Soletta
8
OCF JS APIHighlights
9
Promise findResources();
Events:resourcefound
Promise<resource> register(data);
Events:retrieverequestupdaterequestobserverequest
Client Server
Promise retrieve();Promise update(data);Promise observe();
Events:update
Resource
OCF and IoTivity
• Specifications• Data models• Certification• Marketing• uPnP
• Open Source implementation• Apache 2.0• QA• API bindings
10
No JavaScript
• iotivity-node brings JavaScript API to IoTivity• Based on Node.JS and IoTivity• OCF JS API• Open source• Travis, sample code, demos• IoTivity 1.0.1• Used in IoTivity WSI, REST API Server, Smart Home demo
11
Iotivity-node• IoTivity CSDK features except security• Native NPM module• Works with Node.JS 0.10, 0.12, 4.x, 5.x• Linux, Ostro, OS X support• npm install iotivity-node
• Moving repository to iotivity.org !• Apache 2.0
12
Node.JS
iotivity-node
IoTivity
OS + Middleware + libs
Web App
OCF JS API
C API
APIJS
C/C++
Remote Access with REST APIs
16
Cloud
API SERVER
RESTOCF HTTP(S) and JSON
OCF Deviceson
Local Network
APIJS
C/C++
HTTP to CoAP
17
Resource/a/light
HTTP GET /oic/resRequest: DISCOVER
Response: URI, Type, ID HTTP 200 OK
HTTP GET /a/lightRequest: RETRIEVE (/a/light)
Response: DATAHTTP 200 OK
HTTP PUT /a/lightRequest UPDATE (/a/light)
Response: OKHTTP 200 OK
Discovery
Read
Update
API Server(REST) Cloud/MobileCoAP HTTP
REST API Server• OCF REST API compliant• All JavaScript• Node.js, Express, and
iotivity-node• Open source• Apache 2.0• Features
• DISCOVERY• RETRIEVE and UPDATE• OBSERVE
18
Node.JS
iotivity-node
IoTivity
OS + Middleware + libs
Express Web Server (npm)
JS API
C API
APIJS
C/C++
REST API Server
OCF REST API
Other npm modules
JavaScript on OstroDevelop with JavaScript
• Node.JS 4.2 and NPM• IoTivity• iotivity-node• OCF API• Express, mraa, MQTT and CoAP modules• Rest API Server
• with systemd socket activation and firewall rules• Soletta JS bindings
19
JavaScript on SolettaDevelop with JavaScript
• Soletta JS bindings are under development• APIs
• OCF JS API• HW IO (GPIO, I2C, UART, SPI, PWM)• Software Update• Platform
20
JavaScript on ZephyrDevelop with JavaScript
• Scale JS development down to MCU• Micro JavaScript runtime • JerryScript, Duktape, libtuv, IoT.JS and friends• JavaScript APIs
• Node.JS subset• OCF JS API• BLE, NFC, GPIO, I2C, UART, PWM
21
Cordova OCF Plugin
22
Cordova
OCF Plugin
IoTivity
Android
Web App
JS API
Java API
APIJS
C/C++
• HTML, CSS and JS Apps on Android• Crosswalk or WebView• OCF JS API• Open Source *• Available in Cordova registry *• npm i cordova-android-crosswalk
• npm i cordova-ocf-plugin
Java
* Available soon
Cordova OCF Sample App• Only HTML, CSS and JavaScript• Uses OCF Cordova Plugin• Android• Discover Resources• Read / Update Resources• Open Source *
23 * Available soon
Smart Home Demo• Iotivity-node, REST APIs• Cloud Integration• All Application code in
JavaScript• End-to-End OCF• Visit Intel Booth to see
24
References• https://gerrit.iotivity.org/gerrit/p/iotivity-node.git• https://github.com/solettaproject/soletta/blob/master/doc/js-spec/oic.md• https://github.com/01org/iot-rest-api-server• https://ostroproject.org/• https://www.zephyrproject.org/• https://github.com/01org/cordova-plugin-ocf
29