JavaScript for OCF Applications Sakari Poussa, Intel @spoussa
1 Agenda
2 Vision
JavaScript for Everything
Cloud REST Web App
REST Web Server API Server
Application developer JavaScript GW can use only web Engine(s) technologies to create CoAP, MQTT, end-to-end solutions. 6LowPAN, BLE Resource Networking
Not the only option but focus of this talk. Smart Devices Storage
3 JavaScript…
4 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 Swagger or RAML can be used to define and document the REST APIs
Cloud REST APIs to services Services Node.JS App for the business (HTTP + json/xml) logic.
Web App Cloud and npmjs.org modules device apps use (200K) services via REST or Module API Node.JS API APIs proprietary Node Node.JS Modules Node.JS runtime API OS + Middleware + libs V8, event loop, OS integration JS API for the Web Apps JS Headless IoT Gateway reference architecture C/C++
7 The API Same 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 API Highlights
Client Server
Promise findResources(); Promise
Events: Events: resourcefound retrieverequest updaterequest observerequest Resource
Promise retrieve(); Promise update(data); Promise observe();
Events: update
9 OCF and IoTivity
• Specifications • Open Source implementation • Data models • Apache 2.0 • Certification • QA • Marketing • API bindings • uPnP No JavaScript
10 • 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 Web App • Native NPM module
OCF JS API • Works with Node.JS 0.10, 0.12, 4.x, 5.x iotivity-node • Linux, Ostro, OS X support • npm install iotivity-node C API • Moving repository to iotivity.org ! IoTivity Node.JS • Apache 2.0
OS + Middleware + libs API JS C/C++
12 OCF Discovery
Client Server
Request: DISCOVER
Response: URI, Type, ID
13 OCF Retrieve, Update
Client Server Request: RETRIEVE
Response: DATA
Request: UPDATE
Response: OK
14 Cloud
OCF and Cloud
REST API
CoAP over TCP
XMPP
15 Remote Access with REST APIs
Cloud OCF Devices on API RES Local Network OCF SERVER T HTTP(S) and JSON
API JS C/C++
16 HTTP to CoAP
Resource API Server Cloud/Mobile /a/light CoAP (REST) HTTP
Request: DISCOVER HTTP GET /oic/res Discovery Response: URI, Type, ID HTTP 200 OK
HTTP GET /a/light Request: RETRIEVE (/a/light) HTTP 200 OK Read Response: DATA
Request UPDATE (/a/light) HTTP PUT /a/light
HTTP 200 OK Update Response: OK
17 REST API Server
OCF REST API • OCF REST API compliant
REST API Server • All JavaScript
Express Web Server (npm) • Node.js, Express, and iotivity-node
JS API Other npm • Open source iotivity-node modules • Apache 2.0 • Features C API • DISCOVERY IoTivity Node.JS API • RETRIEVE and UPDATE JS OS + Middleware + libs • OBSERVE C/C++
18 JavaScript on Ostro Develop 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 Soletta Develop 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 Zephyr Develop 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
• HTML, CSS and JS Apps on Android Web App • Crosswalk or WebView
JS API • OCF JS API OCF Plugin • Open Source * • Available in Cordova registry * Java API • npm i cordova-android-crosswalk IoTivity Cordova API • npm i cordova-ocf-plugin JS Android C/C++ Java
22 * 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 Next • Node-Red • Zephyr • Soletta • Security
25 Summary JavaScript for Everything
OCF JS API
26 Questions?
27 28 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