Upgrade to Pro — share decks privately, control downloads, hide ads and more …

iotivity-example-20170511rzr.pdf

 iotivity-example-20170511rzr.pdf

Phil "RzR" Coval

May 11, 2017
Tweet

More Decks by Phil "RzR" Coval

Other Decks in Programming

Transcript

  1. Samsung Open Source Group 1
    Samsung Open Source Group #OSIS2017
    Framework for IoT interoperability
    Philippe Coval
    Samsung Open Source Group / SRUK
    [email protected]
    From sensors to Tizen devices and beyond ?
    Open Source Innovation Spring
    #OSIS2017, CNRS Paris, France <2017-07-11>

    View Slide

  2. Samsung Open Source Group 2
    Samsung Open Source Group #OSIS2017
    /whois Philippe Coval

    Software engineer for Samsung Research
    – Belongs to Open Source Group (S-OSG) EU/UK team

    I am based in Rennes, France
    – Commits into IoTivity, Tizen, Yocto, Automotive OS (GENIVI, AGL)...
    – Ask me about FLOSS, OSHW, DIY, Communities

    Find me online
    – https://wiki.tizen.org/wiki/User:Pcoval

    View Slide

  3. Samsung Open Source Group 3
    Samsung Open Source Group #OSIS2017
    Agenda

    What is Open Connectivity's IoTivity ?

    Demo and examples
    ?

    View Slide

  4. Samsung Open Source Group 4
    Samsung Open Source Group #OSIS2017
    Internet of Things is: A complex equation

    Where all parameters are correlated :
    – Connectivity: not only Internet, probably IP, but not only

    Personal (<1m), Local (<10m - 10km), Metropolitan (<10km), Wide Area
    (<1000Km)
    – Security matters ! (during all expected life span)

    Several surfaces of attacks: service, monitoring, upgrade
    – Cost of materials and cost of usage:

    Computing capability (CPU or MCU?), consumption, if 24x7

    Development, maintenance: FLOSS or Closed source ?

    View Slide

  5. Samsung Open Source Group 5
    Samsung Open Source Group #OSIS2017

    Many Silos / Many implementations :
    – One app per device (better than many remote controls)
    – Dependence on centralized models (hub/cloud)

    Many concerns or issues:
    – Security/Privacy concerns?
    – Long term support and maintenance?
    – Do we want critical devices exposed to the Internet ?

    Few Interoperability/Interconnection of today's things.
    IoT: Internet of Today or Internet of Troubles ?

    View Slide

  6. Samsung Open Source Group 6
    “Without trust there's no cooperation.
    And without cooperation there's no progress.
    History stops.”
    ~ Rick Yancey, The Last Star

    View Slide

  7. Samsung Open Source Group 7
    Samsung Open Source Group #OSIS2017
    Open connectivity foundation's mission

    Provide software linking the Internet Of Things
    – Focus on interoperability and seamless connectivity between devices

    Write specification, Establish a protocol,
    – Rely on existing standards (CoAP, TLS), or OSS libs

    Sponsor Reference implementation:
    – OpenSource (Apache 2.0 license)

    Hosted by Linux Foundation (like kernel, Tizen etc)
    – Rule: No unimplemented features in specification

    Certify conformance to standard of products

    Above 300 members already joined, did you?

    View Slide

  8. Samsung Open Source Group 8
    Samsung Open Source Group #OSIS2017
    Common technology for multiple profiles
    Architecture
    RESTful
    CRUD-N
    Communication
    CoAP, CBor
    +Security
    DTLS
    Semantics
    RAML
    Smart
    Home:
    Zigbee
    Blue
    Tooth
    Personal
    Devices
    Wearables:
    BLE
    Cloud: HTTP/ TCP
    Mobilty
    Automotive
    LTE*
    V2X*
    ...

    View Slide

  9. Samsung Open Source Group 9
    Samsung Open Source Group #OSIS2017
    IoTivity Framework for connecting devices

    Core cross platform libraries
    – C API: resource layer + connectivity abstraction (IP, BT, BLE...)

    Link to libcoap, tinycbor (code footprint ~128KiB-)
    – C++ API: C++11 bindings to build extra services

    + High level services (Mostly C++)
    – Data/Device Management: Container, Hosting, Encapsulation, Scene
    – Simulator (Eclipse based), http proxy

    + Plugins: Transport, Cloud Interface, Bridging

    Related projects
    – IoTivity-Node: Javascript bindings
    – IoTivity-contrainted: For thin devices (micro-controllers)

    View Slide

  10. Samsung Open Source Group 10
    Samsung Open Source Group #OSIS2017
    Flow: Create, Read, Update, Delete, Notify
    IoTivity Server IoTivity Client(s)
    Local IP Network
    Registration of resource
    Handling new requests Set/Get/ing properties values
    Initialization as server Initialization as client
    Handling new clients Discovery of resource
    POST/ GET
    UDP Multicast
    + CoAP
    Notify updated resource Observe resource change
    & Handling properties
    OBSERVE

    View Slide

  11. 11
    Samsung Open Source Group #OSIS2017
    CES2017 Smart Home+Automotive
    https://youtu.be/3d0uZE6lHo#smarthome-ces2017
    Automotive: SmartHome interaction and more
    – https://wiki.iotivity.org/automotive

    View Slide

  12. Samsung Open Source Group 12
    Samsung Open Source Group #OSIS2017
    Resource Model
    /example/BinarySwitchResURI
    {
    “p” : Discoverable & Observable & Secured,
    “if” : ["oic.if.a","oic.if.baseline"],
    “rt” : [“oic.r.switch.binary”],
    “value” : true
    ...
    }
    URI:
    + common
    properties:
    Policy:
    & Interface:
    Resource Type:
    + attribute(s)

    Well knows resources URI (/oic/*):
    – “res” discovery, “p” for platform , “d”: device (role: C/S), “sec/*” : security

    View Slide

  13. Samsung Open Source Group 13
    Samsung Open Source Group #OSIS2017
    Data models can be:

    Described
    – For RESTful operations (CRUD)
    – RAML+JSON Schemas

    Reviewed and validated
    – OCF check consistency

    Shared
    – OneIotA.org tool & repository

    Note:
    – IoTivity works with private models too

    oic.r.switch.binary.json
    – http://www.oneiota.org/revisions/1580

    /* … */ "definitions": {
    "oic.r.switch.binary": {
    "properties": {
    "value": {
    "type": "boolean",
    "description":
    "Status of the switch"
    } } } /* … */

    View Slide

  14. Samsung Open Source Group 14
    Samsung Open Source Group #OSIS2017
    Hardware Support

    Desktop, Mobile...

    Single Board Computers: RaspberryPI, ARTIK modules...
    – Full stack (CSDK, C++, C++ Services)
    – IoTivity-node (Javascript bindings)
    – OS: Tizen, Yocto, and most GNU/Linux distros

    Microcontollers:
    – IoTivity-constrained: implementation of OCF protocol
    – OS: Baremetal, Linux, Zephyr, TizenRT, RIOT (WIP)
    – Note CSDK (1.2.1-) supported ATmega2560

    View Slide

  15. Samsung Open Source Group 15
    Samsung Open Source Group #OSIS2017
    Security matters

    Connectivity Abstraction layer establishes secure channel using DTLS

    Devices need to be provisioned (using onboarding tool):
    – Establish ownership in user's network

    Secure Resource Manager (SRM)
    – Secure Virtual resources

    Device provisioning, Credentials, Access control list, persistence
    – Policy engine: Request filtering: Grant, deny resource requests

    Per policy, requester ID, ACL, device status...
    – Is an OIC resource (“/oic/sec/cred”)

    Hardware hardening: use encryption and secure contexts, RNG, IO etc

    View Slide

  16. Samsung Open Source Group 16
    “Talk is cheap.
    Show me the code.”
    ~ Linus Torvalds

    View Slide

  17. 17
    Samsung Open Source Group #OSIS2017
    Getting started with IoTivity

    IoTivity 1.2.1 is latest release
    – Uses Scons build system with many options: Transport, Security, Log...
    – Note: Upstream just enabled security on 1.3-rel

    Prefer to use or rebuild packages to local build/install
    – Use standard path (/usr/include …)

    Major Operating system are supported
    – Tizen provides RPM/spec for Tizen:3 profiles, with security enabled
    – Yocto's meta-oic ships it with security disabled like upstream
    – Debian, Ubuntu, deb packages are possible too

    Details: https://wiki.iotivity.org/os , https://wiki.iotivity.org/build
    Samsung Open Source Group

    View Slide

  18. 18
    Samsung Open Source Group #OSIS2017
    IoTivity-example tutorial

    OCF application developers might not develop in upstream source tree
    – SCons build system is complex (even for sample apps)

    A standalone project is better to get inspiration from or derivate (SDK?)
    – Tend to be minimalist, can be used as base (fork it at will)

    Download a collection of standalone subprojects:
    – git clone http://git.s-osg.org/iotivity-example/ ; make

    Each ”feature” subproject is a git module (pulling a branch based on other)
    – Nice history to understand each steps
    – For many OSes or build system (Currently, GNUmake, Linux, Tizen, More welcome)
    Samsung Open Source Group

    View Slide

  19. 19
    Samsung Open Source Group #OSIS2017
    Base example: Resource discovery

    branch=example/master (src/example/master/README.md)
    – Server register a “dummy” resource identified as “/ExampleResURI”
    – Client discover and list all resources' endpoints served in local network
    – GNUmake is used to build it
    – Systemd service provided to start it once installed

    branch=example/packaging is based on previous one
    – Yocto Bitbake recipe
    – Tizen RPM spec file
    – Debian/Ubuntu packaging files too (more welcome)
    Samsung Open Source Group

    View Slide

  20. 20
    Samsung Open Source Group #OSIS2017
    IoTivity
    Server
    IoTivity
    Client(s)
    IP Network
    Resource discovery example flow
    class IoTServer {
    int main() { init(); … }
    OC::PlatformConfig mPlatformConfig;
    void init() {
    mPlatformConfig = OC::PlatformConfig
    (OC::ServiceType::InProc,
    OC::ModeType::Server, // different that C
    "0.0.0.0", 0, // default for all subnets / ifaces
    OC::QualityOfService::LowQos //or HighQos
    );
    OCPlatform::Configure(mPlatformConfig);
    }
    };
    class IoTClient {
    int main() { init(); … }
    OC::PlatformConfig mPlatformConfig;
    void init() {
    mPlatformConfig = OC::PlatformConfig
    (OC::ServiceType::InProc,
    OC::ModeType::Client, // different than S
    "0.0.0.0", 0, // on any random port available
    OC::QualityOfService::LowQos // or HighQos
    );
    OCPlatform::Configure(mPlatformConfig);
    }
    };

    View Slide

  21. 21
    Samsung Open Source Group #OSIS2017
    main {
    IoTServer::init() { ModeType::Server }
    IoTServer::createResource()
    { OCPlatform::registerResource(... uri …) }
    // loop on OCProcess() is called internally
    }
    main {
    IoTClient::init() { ModeType::Client }
    IoTClient::start()
    { OCPlatform::findResource(onFindCallback) }
    IoTClient::onFind(resource)
    { print(resource->uri) }
    IoTivity
    Server
    IoTivity
    Client(s)
    IP Network
    Resource discovery example flow
    $ ./bin/server -v
    (...)
    log: { IoTServer::createResource(...)
    log: Successfully created\
    org.example.r.example resource
    log: } OCStackResult
    (...)
    $ ./bin/client -v
    (...)
    log: { void IoTClient::onFind(...)
    log: Resource: uri: /oic/d
    (...)
    log: Resource: uri: /ExampleResURI
    coap://[fe80::baca:3aff:fe9b:b934%25eth0]:47508

    View Slide

  22. Samsung Open Source Group 22
    Samsung Open Source Group #OSIS2017
    Binary switch example

    Actuator, client change value (on/off) of server's resource

    IoTivity-example's branch=switch/master
    – Is based on “example/packaging” and adapted

    Usage:
    ./bin/client
    menu:
    0) Set value off
    1) Set value on
    (...)
    1
    ./bin/server -v
    log: { OCEntityHandlerResult
    IoTServer::handleEntity(...)
    log: { OCStackResult IoTServer::handlePost(...)
    log: { void Platform::setValue(bool)
    1
    log: } void Platform::setValue(bool)
    log: { void
    IoTServer::postResourceRepresentation()

    View Slide

  23. Samsung Open Source Group 23
    Samsung Open Source Group #OSIS2017
    OCResource::post(rep, callback);
    onPost(...)
    Switch Example: Resource update
    OCPlatform::Configure(...);
    OCPlatform::registerResource( …);
    handleEntity(OCResourceRequest) {
    switch entityHandlerRequest->method {
    case 'POST:
    // update actuator resource (physically)
    ...
    OCPlatform::sendResponse(response);
    }}
    OCPlatform::Configure(...);
    OCPlatform::findResource(...);
    onFind(... resource ...)
    IoTivity Server IoTivity Client(s)
    IP Network
    IP Network

    Client controls actuator:
    – Set resource's value

    Server is handling request
    – and responding

    View Slide

  24. Samsung Open Source Group 24
    Samsung Open Source Group #OSIS2017
    Interaction with products

    Tizen is an Operating System based on FLOSS

    Shipped into consumer electronics products

    Tizen IoTivity
    – Tizen:3 contains as platform package (.rpm)
    – Tizen:2 can ship shared lib into native app (.tpk)

    For Samsung Z{1,2,3} (Tizen:2.4:Mobile)

    Samsung GearS{2,3} (Tizen:2.3.x:Wearable)

    View Slide

  25. 25
    Samsung Open Source Group #OSIS2017
    Derivate to Tizen native app

    iotivity-example branches for Tizen devices:
    – Mobile (Z1) : switch/tizen/2.4/mobile/master
    – Wearables (GearS2) : sandbox/pcoval/tizen/wearable/2.3.2/master

    Need to rebuild IoTivity’s shared lib (to be bundled in tpk):
    – Use helper script build rpm and unpack lib
    – ./tizen.mk ; ls lib/*.so
    – ./tizen.mk run # deploy on root device (ie TM1)

    More details or ask for help:
    – https://wiki.iotivity.org/tizen
    Samsung Open Source Group

    View Slide

  26. Samsung Open Source Group 26
    Samsung Open Source Group #OSIS2017
    Want more ?

    View Slide

  27. 27
    Samsung Open Source Group #OSIS2017
    Smart City’s Street lights use case

    Various examples combined in demo using nodejs
    – Branch “sandbox/pcoval/on/master/demo”

    Defective Street lights notification service
    – Sensor to read luminance
    – Switch front light on if too dark
    – Send message to ARTIK cloud
    – Using geolocation client/server
    Samsung Open Source Group
    1
    1
    2
    3
    5
    6
    4
    7

    View Slide

  28. Samsung Open Source Group 28
    Samsung Open Source Group #OSIS2017
    From devices to cloud AutoLinux demo
    https://vimeo.com/202478132#iotivity-artik-20170204rzr
    1
    2
    1

    View Slide

  29. Samsung Open Source Group 29
    Samsung Open Source Group #OSIS2017
    /GeoLocationResURI
    {
    latitude: 52.165,
    longitude: -2.21,
    }
    A Vehicle to Infrastructure notification service
    function handle(illuminance) {
    if (gThreshold > illuminance) {
    var data= { illuminance: illuminance,
    latitude: gGeo.latitude, longitude: gGeo.longitude };
    sender.send(data); // { ARTIK's client.post(url...); }
    } }
    client.on("resourcefound", function(resource) {
    if ("/IlluminanceResURI" === resource.resourcePath) {
    resource.on("update", handle);
    } else if ("/GeolocationResURI" === resource.resourcePath) {
    resource.on("update",
    function(resource) { gGeo = resource.properties; });
    } };
    1
    2
    /IlluminanceResURI
    {
    illuminance: 42
    }
    https://api.artik.cloud/
    {
    illuminance: 42,
    latitude: 52.165,
    longitude: -2.21
    }
    3
    1

    View Slide

  30. Samsung Open Source Group 30
    Samsung Open Source Group #OSIS2017
    Forward data to a cloud backend

    Login your artik.io dashboard
    – Select or (re)define “OCF” data models

    https://developer.artik.cloud/dashboard/devicetypes
    – Declare devices: (Copy IDs)

    https://my.artik.cloud/devices
    – Monitor:

    https://my.artik.cloud/data

    Send data on resource “update” event
    – Using http REST (or CoAP, WebSocket...)
    require("node-rest-client").Client;
    client.post(url, message, callback);
    https://api.artik.cloud/v1.1/messages
    message = {
    headers: {
    'Content­Type': 'application/json',
    Authorization: 'bearer
    BADC0DE(...)DEADBEEF42'
    }, data: {
    sdid:'deadbeef(...)badc0de13',
    ts: 1485178599672,
    type: 'message',
    data: { illuminance: 42 }
    } }

    View Slide

  31. Samsung Open Source Group 31
    Samsung Open Source Group #OSIS2017
    Summary

    OCF establishes a standard for interconnecting things
    – Resource model
    – RESTful architecture
    – Definitions must be shared to ensure interoperability

    Open Source project IoTivity
    – implements it in C, C++, Java and Javascript
    – Shipped into Tizen:3+ and available for many OS.
    – Provide core and hi level services for management, security, cloud

    View Slide

  32. Samsung Open Source Group 32
    Samsung Open Source Group #OSIS2017
    References

    Entry points:
    – https://wiki.iotivity.org/examples : git clone iotivity-example
    – https://wiki.iotivity.org/docker : cloud images from Ondrej Tomcik
    – http://wiki.iotivity.org/automotive

    Going further:
    – https://openconnectivity.org/resources/iotivity
    – https://openconnectivity.org/resources/oneiota-data-model-tool
    – https://news.samsung.com/global/samsung-contributes-to-open-iot-showcase-at-ces-2017

    Keep in touch online:
    – https://www.meetup.com/OCF-France/
    – https://wiki.iotivity.org/community
    – https://wiki.tizen.org/wiki/Meeting
    – https://blogs.s-osg.org/author/pcoval/

    View Slide

  33. Samsung Open Source Group 33
    Samsung Open Source Group #OSIS2017
    Thank you,
    Merci, Trugarez,
    맙습니다 , 谢谢
    Gracias, Danke Schoen!
    Resources: flaticons CC
    Contact:
    https://wiki.tizen.org/wiki/User:Pcoval

    View Slide