https://social.samsunginter.net/web/statuses/101091908485239453# #Cdl2018 : #WebThing using #WebThingIotJs on #TizenRT on #ARTIK05x connected to @MozillaIot featuring @The_Jst #JerryScript + #IotJs , video to be published by @CapitoleDuLibre
webthing-iotjs-tizenrt-cdl2018-20181117rzr
1. 1
https://social.samsunginter.net/@rzrSamsung Open Source Group 2018
Webthings
Using IoT.js
for RT
on boards
#CDL2018, Capitole du libre
ENSEEIHT, Toulouse, France <2018-11-18>
Philippe Coval <p.coval@samsung.com>
Samsung Open Source Group / SRUK
2. https://social.samsunginter.net/@rzrSamsung Open Source Group 2018
2
Hello world, $who am I ?
●
Philippe Coval
– Belongs to Samsung Research UK
●
in OpenSource group
– French
●
from Toulouse then Rennes
●
Interests:
– Libre Soft/Hard/ware communities
– Embedded, IoT, Web, DIY…
Need help? Ping me online:
http://social.samsunginter.net/@rzr
3. 3
https://social.samsunginter.net/@rzrSamsung Open Source Group 2018
Agenda
●
Context:
– IoT status, Privacy matters !
– Motivations for Web of Thing
●
Mozilla Webthings framework
●
Connecting constrained IoT devices
– Easily with JavaScript!
4. 4
https://social.samsunginter.net/@rzrSamsung Open Source Group 2018
IoT status
●
The Internet of Things is a system of physical objects
– that can be discovered, monitored, controlled,
– or interacted with by electronic devices
– that communicate over various networking interfaces
●
and eventually can be connected to the wider Internet.
●
Addresses many domains:
– Health, Agriculture, Transport, Cities, Industry
●
Critical in many cases: Need to Secure & Privacy Proof
5. 5
https://social.samsunginter.net/@rzrSamsung Open Source Group 2018
Privacy is about Trust and Control
●
Ownership of personal data
– Shared, Transferred, Revoked, Logged, Retrieved and DELETED
●
depend on time and context
●
Services operators should comply regulations:
– EU: General Data Protection Regulation (GDPR 2018)
●
Threat to privacy in the IoT is HIGH!!!
●
“Privacy by design” opportunities
– Prevent data collection in first place→Keep data local if possible
●
Limit usage of cloud, apps or “captive models”
– New security challenges (Decentralize, reduce surface of attacks)
6. 6
https://social.samsunginter.net/@rzrSamsung Open Source Group 2018
Motivations for Open Web Of Things
●
Open web platform promises:
– Security (isolation in browser)
– Enhanced privacy (DNT)
●
Security is not same as Privacy !
●
Think decentralized !
– may be harder to secure
●
but more resilient
– Edge: Computation on nodes
●
Web of Things (WoT)
– An application layer for IoT
– with interoperability
– Specification work by
– And FLOSS implementations
●
Thing
●
Node-Wot
●
...
8. 8
https://social.samsunginter.net/@rzrSamsung Open Source Group 2018
Mozilla’s IoT Project Things Overview
●
Framework of software/services
– for connecting "things" to the web
●
Things Model: Semantic to describe things’ properties
●
WebThings: provide Http(s) REST API
●
Gateway to connect WebThings
– Rule engine and nice Web UI (PWA)
●
Cloud: Remote access facilities (opt.)
9. 9
https://social.samsunginter.net/@rzrSamsung Open Source Group 2018
W3C WebThing model & Thing Description
●
Models complies to W3C schemas served on HTTP
– using Javascript, C/C++, Rust, Python, uPython etc…
●
Actuator example: RGB Lamp (webthing-ardiuno/example)
curl http://esp8266.local
[{"name":"Dimmable Color Light", "type":"dimmableColorLight",
"href":"/things/dimmable-color-light",
"properties":{"on":{"type":"boolean", "href":
"/things/dimmable-color-light/properties/on"},
"level":{"type":"number", "href":
"/things/dimmable-color-light/properties/level"},
"color":{"type":"string", "href":
"/things/dimmable-color-light/properties/color"}}
}]
Names
= endpoints
10. 10
https://social.samsunginter.net/@rzrSamsung Open Source Group 2018
Mozilla IoT gateway
●
Connects all webthings locally:
– IP (WiFi, Eth), BT, Zigbee, Z-Wave...
●
Provides progressive web app:
– To monitor and control things
●
Users management:
– Access control using JsonWebToken
●
Optional remote control using proxy:
– LetsEncrypt certs + PageKite tunnel
●
Extensible using add-ons
– Adapters for other protocols/ecosystems
11. 11
https://social.samsunginter.net/@rzrSamsung Open Source Group 2018
Setup Mozilla IoT gateway
●
Reference image for RPi
– Dump Raspbian image to SD
●
Or rebuild on any GNU/Linux
– 0.6.x version uses Node-8 (LTS 2017)
– container (node/debian)
●
ARTIK710 dev board:
– WiFi, Eth, BT, Zigbee, Thread
– GPIO, ADC, UART, PWM...
– User Buttons and LED
●
710 (+530) can be also supported
– With Node-10 (LTS 2018)
– Using nvm or
https://github.com/rzr/webthing-iotjs/wiki/Gateway
12. 12
https://social.samsunginter.net/@rzrSamsung Open Source Group 2018
Sharing flow between owner and user
●
Owner setup gateway (connect lamp):
– create and allow user(s) to control thing
●
User login to GW using OAuth (JWT issued)
gateway="https://sosg.mozilla-iot.org" or "gateway.local"
thing="things/http---esp8266.local-things-dimmable-color-lamp"
property="properties/color"
curl "$gateway/$thing/$property"
-H "$auth"
-H 'Accept: application/json' {"color":"#ffff6f"}
← Or use alternative app: webthings-webapp:
Tizen or Android/SamsungInternet (PWA)
14. 14
https://social.samsunginter.net/@rzrSamsung Open Source Group 2018
IoT Problems and Solutions
●
Constrained IoT devices:
– Cloud connected
●
Privacy issues
– Easy to prototype: (Arduino...)
– Harder to deploy at scale
●
Limited on resources
●
Native development
– on many RTOS
●
Few experts developers
●
Technical strategies:
– Edge computing
●
Data stay on nodes or in LAN
– Abstraction with high level API
●
Port runtimes not apps code
– Portability and standards
●
Script languages for MCU
– JavaScript, Python, LUA…
●
Target existing developers base
15. 15
https://social.samsunginter.net/@rzrSamsung Open Source Group 2018
JavaScript: Language of the Web for IoT ?
●
JavaScript is everywhere!
●
Many web developers:
– So many application developers
●
Few embedded developers
– To focus more on runtime or app engines:
●
For high end & low end (MCU)
●
Standardized (ECMA)
●
Established communities:
–
"Any application
that can be written in JavaScript,
will eventually be written in JavaScript"
~Jeff Atwood
Over
837K
Modules!
(2019-11-15)
…
But
relative
quality !
16. 16
https://social.samsunginter.net/@rzrSamsung Open Source Group 2018
IoT.js runtime use JerryScript engine
●
Lightweight JavaScript engine
– Supports constrained devices
●
<64 KB RAM & <200 KB ROM
– On-device compilation, exec
●
Complies ECMAScript 5.1 std
●
FLOSS: Apache-2.0, (C) JSF
●
https://JerryScript.net
●
IoT.js is JavaScript framework
– for Internet of Things
●
Features: GPIO, I2C, app protocols...
– built on 'JerryScript'
– event driven using libtuv
●
non-blocking I/O model
●
Inspired by Node.js’s runtime
– Node is built on V8 interpreter
– IoT.js is smaller and faster for MCUs
Supporting: GNU/Linux, Tizen, TizenRT, NuttX and more…
(Prototype on desktop, deploy to contrained devices)
19. 19
https://social.samsunginter.net/@rzrSamsung Open Source Group 2018
Installing IoT.js runtime for webthings
●
Install from or GNU/Linux
– Rebuild from sources
●
https://github.com/Samsung/iotjs
– Or download snapshot .deb:
●
For for (RPi 0+) or
●
Write hello world & evaluate it:
Hello IoT.js
{
"env": { //...
"IOTJS_ENV": "",
"IOTJS_EXTRA_MODULE_PATH":""
},
"builtin_modules": { //...
"platform": "linux", (...) }
"iotjs": {
"board": ""
},
"argv": [
"iotjs",
"demo.js"
],
// (...)
}
● cat demo.js
console.log(“Hello IoT.js”)
console.log(process)
● iotjs demo.js
https://github.com/rzr/webthing-iotjs/wiki/IotJs
20. 20
https://social.samsunginter.net/@rzrSamsung Open Source Group 2018
WebThing-IoT.js to power WebThings on IoT.js
●
Fork of webthing-node
– for IoT.js runtime (On JerryScript)
– Transpilation from modern JS
●
to ES5.1 (using Babel.js)
– Some parts removed:
●
mDNS, Websockets
●
actions, events…
– Continuously rebasing
– Supports:
●
GNU/Linux, Tizen, TizenRT
●
Aligning IoT.js to :
– For API, IO drivers, NPM modules:
●
GPIO, ADC
– Compatible examples:
●
SingleBoard Computers’s IO (PHats)
●
Sensors (I2C) & Actuators
21. 21
https://social.samsunginter.net/@rzrSamsung Open Source Group 2018
Try Webthing-iotjs’s simplest sensor:
● var thing = new Thing('SensorExample',
['MultiLevelSensor']);
● this.level = new Value(0);
● thing.addProperty(
new Property(thing, 'level',
this.level,
{label:'Level', type:'number'}
);
● var server = new WebThingServer
(new SingleThing(thing));
● server.start();
● (...)
● this.level.notifyOfExternalUpdate(42);
●
Show thing’s description:
– properties listed as JSON (REST):
curl
-H 'Content-Type: application/json'
http://localhost:8888
{"name":"SensorExample",...
"properties":{"level":{"type":"number", ... }
●
Get Property on property’s endpoint:
curl
-H 'Content-Type: application/json'
http://localhost:8888/properties/level
{"level":42}
Name
(=
endpoint)
22. 22
https://social.samsunginter.net/@rzrSamsung Open Source Group 2018
Try Webthing-iotjs’s simplest actuator:
● var thing = new Thing
('ActuatorExample',['OnOffSwitch'];
● thing.addProperty(
new Property(thing, 'on',
new Value(true, function(data){
console.log(Boolean(data));
}),
{label:'On/Off', type:'boolean'}
);
● var server = new WebThingServer
(new SingleThing(thing));
● server.start();
●
Run application from sources:
iotjs example/simplest-thing.js [port]
●
Set Property value (using HTTP):
curl -X PUT
-H 'Content-Type: application/json'
--data '{"on":false}'
http://localhost:8888/properties/on
{"on":false}Callback
Capabilties
23. 23
https://social.samsunginter.net/@rzrSamsung Open Source Group 2018
Real world use cases and more...
●
GenericSensorsLite module to build webthings
– Based on specification (for browsers)
– Abstract I2C Drivers
●
using NPM community modules
– Cross engine compatible: IoT.js, Node.js (NPM)
– High level concepts: AmbientLight, Temperature…
– Also supported on gateway as addon adaper
– More: https://github.com/rzr/webthing-iotjs/wiki/Sensor
●
Link any physical or logical component:
– Actuator to be triggered on sensor data using mozilla rule engine
– Social Web Example: MastodonActuator https://github.com/rzr/webthing-iotjs/wiki/Social
24. 24
https://social.samsunginter.net/@rzrSamsung Open Source Group 2018
IoT.js modules
●
A repository for IoT.js packages (JS):
– git clone --recursive https://github.com/samsung/iotjs-modules iotjs_modules
– Or clone them individually using git submodules or scripts (GNUmake)
●
Add IoT.js support to existing Node.js packages
– Transpile to ES5.1 if using modern JS standards (use BabelJs.io)
– https://www.npmjs.com/search?q=keywords:iotjs-supported
●
Try to align IoT.js ↔Node.js APIs to ensure compatibility:
– Prototype on GNU/Linux and then deploy to MCU supporting IoT.js
26. 26
https://social.samsunginter.net/@rzrSamsung Open Source Group 2018
TizenRT extends Tizen ecosystem
●
Tizen
– Is based on Linux Kernel
– Shipped into
●
High end consumer electronics
– Mobile, TV, Wearables etc
– Open to developers
●
Native, C/C++ (EFL)
●
HTML5
●
DotNet
●
TizenRT
– Is based on NuttX Kernel
●
for constrained devices:
– Ie: Cortex M3 (RAM=30KB Flash=512KB)
– For low end IoT devices:
●
Open APIs (C, JavaScript)
●
Connectivity
●
Reliability
●
Security
– Support:
●
Qemu, ARTIK05x...
27. https://social.samsunginter.net/@rzrSamsung Open Source Group 2018
27
TizenRT supports 05X
●
System on module : 053, 053S (5V DC) or 055S (3.3V DC)
●
Dev kits: ARTIK 055S SoM on interposer board:
– 32-bit ARM® Cortex® R4 @ 320MHz
– R for Real Time and safety critical
– S for Secure: SE+TEE, Secure Sub System
●
Crypto (Certs, Key, ECDSA, RNG, PUF), Signed boot loader
– 1280KB RAM, 8MB Flash, WiFi
– IO: GPIO*29, ADC*4, PWM*5, UART*4 (2-pin), SPI*2, I2C*2, I2S
– RTC, JTAG (lock), Arduino header, Extra sensor boards
28. 28
https://social.samsunginter.net/@rzrSamsung Open Source Group 2018
Integrate WebThing-iotjs app to TizenRT
●
Use my helper scripts (GNU/Linux)
– make demo: build, deploy, monitor
●
Or manually:
– Setup TizenRT’s environment
– Upgrade IoT.js-2018 in TizenRT-2+
– Enable IoT.js launcher task
●
Using menuconfig (Kconfig)
●
Setup main script, PATH,
●
WiFi credentials
– Populate ROM fs with
●
Scripts, iotjs_modules
– Build and deploy static image
●
Connect board from gateway webapp:
https://github.com/rzr/webthing-iotjs/wiki/TizenRT
31. 31
https://social.samsunginter.net/@rzrSamsung Open Source Group 2018
Summary: Open Web matters for IoT !
●
Open Web of Things: to link WWW to physical world
●
Mozilla Things framework to connect devices in LAN
●
Privacy Is about user's data control of flows
●
Javascript aims to reduce integration complexity
●
Try webthing-iotjs on GNU/Linux or TizenRT !
●
Support & comply to W3C standards, contribute to FLOSS
32. 32
https://social.samsunginter.net/@rzrSamsung Open Source Group 2018
Resources
●
Entry point:
– https://github.com/rzr/webthing-iotjs/wiki
●
More:
– https://www.w3.org/WoT/
– https://iot.mozilla.org/
– https://2018.capitoledulibre.org/
●
Keep in touch online:
– https://social.samsunginter.net/@rzr
– https://wiki.tizen.org/User:Pcoval
Resources: flaticons CC