automated development for cross-platform internet of thingsraspberry pi board •insert the microsd...

20
Automated Development for Cross-Platform Internet of Things Develop a secure, certified hardware prototype in 15 minutes Clarke Stevens Shaw Communications [email protected]

Upload: others

Post on 02-Jun-2020

1 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Automated Development for Cross-Platform Internet of ThingsRaspberry Pi board •Insert the microSD card •Connect the network •Connect keyboard and monitor (or SSH) •Plug in

Automated Development for

Cross-Platform Internet of ThingsDevelop a secure, certified hardware prototype in 15 minutes

Clarke StevensShaw [email protected]

Page 2: Automated Development for Cross-Platform Internet of ThingsRaspberry Pi board •Insert the microSD card •Connect the network •Connect keyboard and monitor (or SSH) •Plug in

• Standards body for interoperable IoT

• Strong security built in from the start

• Works interoperably with existing ecosystems

• Three pillar alignment

• International specification

• Open source implementation

• Automated certification tool and international authorized test labs

• Flexible, RESTful, data-model-based architecture

What is the Open Connectivity Foundation?

July 11, 2018 2

Page 3: Automated Development for Cross-Platform Internet of ThingsRaspberry Pi board •Insert the microSD card •Connect the network •Connect keyboard and monitor (or SSH) •Plug in

• Online tool for crowd-sourcing data models and building ecosystem interoperability

• Data models drive everything

• Automated tool chain creates

• Server source code

• Introspection file

• Automated test case file

• Secure onboarding file

• Client tool user interface

• Several test and development tools

Complete suite of development tools

July 11, 2018 3

Page 4: Automated Development for Cross-Platform Internet of ThingsRaspberry Pi board •Insert the microSD card •Connect the network •Connect keyboard and monitor (or SSH) •Plug in

Set up the Hardware

July 11, 2018 4

• Install the EnviroPhat board on

the GPIO header on the

Raspberry Pi board

• Insert the microSD card

• Connect the network

• Connect keyboard and monitor

(or SSH)

• Plug in the power

Page 5: Automated Development for Cross-Platform Internet of ThingsRaspberry Pi board •Insert the microSD card •Connect the network •Connect keyboard and monitor (or SSH) •Plug in

• oneIoTa is an IDE and process management tool for the resource data models at the center of OCF.

• OCF atomic resource models are entered in the editor windows in oneIoTa

• More complex resources can be composed of atomic resources

• Completed resources are submitted to an approval process for OCF (or partner organizations

• Other organizations use the same approval process in oneIoTa

• Mappings between OCF and other ecosystems are also entered in oneIoTa

• Resource models are used to build specifications, devices, source code, GUIs, PICS files and bridges

oneIoTa (oneiota.org)

July 11, 2018 5

Page 6: Automated Development for Cross-Platform Internet of ThingsRaspberry Pi board •Insert the microSD card •Connect the network •Connect keyboard and monitor (or SSH) •Plug in

• Go to http://www.oneiota.org

• Search for any resources you will need

• Use these descriptions when defining your device description file

• All devices consist of a list of resources

• All tools will consider oneIoTa as the authoritative source of resources

oneIoTa is the source of all resources you will need

July 11, 2018 6

Page 7: Automated Development for Cross-Platform Internet of ThingsRaspberry Pi board •Insert the microSD card •Connect the network •Connect keyboard and monitor (or SSH) •Plug in

• In this demo, we will use C/C++ on Raspian on the Raspberry Pi

• Install the development environment

• IoTivity, DeviceBuilder and MRAA (to actually control the hardware)

• Check out the resources in oneIoTa to see what your device will need

• Create a JSON device definition

• Run gen.sh

• This creates the server source file, introspection file, PICS file and security file and puts them in the correct directories

• Run build.sh

• This runs scons to compile the code and put it in the executable directory

• Run edit_code.sh

• Edit the automatically generated source code to add your specific application code

• Run run.sh

• This runs the server code. Your device is built and working!

Let’s build a device

July 11, 2018 7

New device

New device

New device

Development cycle

Development cycle

Development cycle

Just once!

Page 8: Automated Development for Cross-Platform Internet of ThingsRaspberry Pi board •Insert the microSD card •Connect the network •Connect keyboard and monitor (or SSH) •Plug in

• Go through the NOOBS process to install the headless Raspian Stretch Lite located here: https://www.raspberrypi.org/downloads/raspbian/

• Enable ssh: copy an empty file called “ssh” (no extension) to the SD card root directory (https://github.com/openconnectivity/Sample-Raspberry-Pi-Code/blob/master/ssh)

• Optionally set up a Wi-Fi connection by copying wpa_supplicant.conf to the SD card root directory and edit for your Wi-Fi (https://github.com/openconnectivity/Sample-Raspberry-Pi-Code/blob/master/wpa_supplicant.conf)

• Boot the Raspbery Pi by inserting the SD card and powering the board on.

• Get a terminal view using a monitor and keyboard or ssh

• Set up everything for Raspberry Pi development:

• curl https://openconnectivity.github.io/IOTivity-setup/install.sh | bash

• Creates ~/iot directory where the development processes run

• Clones IoTivity

• Sets up the DeviceBuilder scripts

• Installs the MRAA libraries to interface with several popular hardware boards

Set up the operating system and OCF development

environment

July 11, 2018 8

Page 9: Automated Development for Cross-Platform Internet of ThingsRaspberry Pi board •Insert the microSD card •Connect the network •Connect keyboard and monitor (or SSH) •Plug in

• Run the gen.sh, build.sh and run.sh scripts as instructed to verify that you can build a working server.

• cd ~/iot

• Generate the source code and supporting files (./gen.sh, 20s)

• Generate the server.cpp IoTivity code (C/C++)

• Generate the introspection file for device information and user interface (JSON and CBOR)

• Generate the onboarding file to manage security (JSON and CBOR)

• Copy the files to correct directories

• Edit the source code and add your functionality (./edit_code.sh)

• Compile the code and copy to the correct directories (./build.sh,13:30-1st, 2:00-2nd, 35s)

• Builds the server executable using scons

• Run the server (./run.sh, 3s)

• Run the server code in the correct directory

Generate the server software and support files

July 11, 2018 9

Expected execution time on Raspberry Pi 3B in red

Page 10: Automated Development for Cross-Platform Internet of ThingsRaspberry Pi board •Insert the microSD card •Connect the network •Connect keyboard and monitor (or SSH) •Plug in

Simple device description file

July 11, 2018 10

[

{

"path" : "/binaryswitch",

"rt" : [ "oic.r.switch.binary" ],

"if" : ["oic.if.a", "oic.if.baseline" ],

"remove_properties" : [ "range", "step" , "id", "precision" ]

},

{

"path" : "/oic/p",

"rt" : [ "oic.wk.p" ],

"if" : ["oic.if.baseline", "oic.if.r" ],

"remove_properties" : [ "n", "range", "value", "step", "precision", "vid" ]

}

]

Page 11: Automated Development for Cross-Platform Internet of ThingsRaspberry Pi board •Insert the microSD card •Connect the network •Connect keyboard and monitor (or SSH) •Plug in

Build the prepared examples

11

• curl https://openconnectivity.github.io/Sample-Raspberry-Pi-Code/pi-boards/install.sh | bash

• This loads the sample code, overwrites scripts and modifies the environment variables to use and link Python with IoTivity

• Answer “y” to any questions you are asked to ensure that everything is installed

• sudo reboot

• This is necessary to make sure everything is set up correctly

• At this point, you will need to reconnect to the Raspberry Pi using ssh (just like you did at the beginning)

• Development cycle

• ./gen.sh <automation-phat>

• This loads the device description file for the specified example, generates the example code with empty code stubs, creates the introspection file and the PICS file

• Other examples are (automation-hat, enviro-phat, mraa-example, and example)

• Without the optional parameter, it just works like the old gen.sh to build whatever example was loaded last

• ./build.sh <automation-phat>

• This script loads the modified server code with the code stubs filled in with interfaces to the target hardware. It also loads interface code to the Python Pimoronilibraries, and modifies the SConscript file overwriteing the default code to support the particular example specified

• It then builds the specific example with all dependencies

• ./run.sh

• ./reset.sh

• This resets the security to “ready for onboarding transfer method” (RFOTM). You only need to do this if you want to go through onboarding again.

• ./edit_code.sh

• If you want to modify your code

July 11, 2018

Page 12: Automated Development for Cross-Platform Internet of ThingsRaspberry Pi board •Insert the microSD card •Connect the network •Connect keyboard and monitor (or SSH) •Plug in

Adding specific source code (mraa-example)

12

> //#ifdef MRAA

> #include "mraa.hpp"

> //#endif

> ----------------------------------

> mraa::Gpio *gpio;

> int ledPin = 7;

> ----------------------------------

> gpio = new mraa::Gpio(ledPin);

> if (!gpio)

> {

> std::cout << "Error instantiating gpio" << std::endl;

> }

> gpio->dir(mraa::DIR_OUT);

>

> gpio->write(1);

> sleep(1);

> gpio->write(0);

> ----------------------------------

> gpio->write(1);

Beginning of server.cpp

Definition of BinarySwitchResource structure

Constructor of BinarySwitchResource

Post method of BinarySwitchResource

July 11, 2018

Page 13: Automated Development for Cross-Platform Internet of ThingsRaspberry Pi board •Insert the microSD card •Connect the network •Connect keyboard and monitor (or SSH) •Plug in

• The OTGC is an open source tool that can onboard OCF devices and create a generic GUI for the device by reading the introspection file.

• Get the Android APK here: (available soon)

• Install the APK

• Run the OTGC

• Onboard the device

– The device will be discovered automaticall

– Click on the “+” to onboard the device

• Test the interface

– Click on the device to move to the GUI screen

• You can offboard the device if you want. This will free it up for onboarding elsewhere.

• Go back and do the development iteration as necessary

Test the code using Onboarding Tool and Generic Client

(OTGC)

July 11, 2018 13

Page 14: Automated Development for Cross-Platform Internet of ThingsRaspberry Pi board •Insert the microSD card •Connect the network •Connect keyboard and monitor (or SSH) •Plug in

• Onboard the discovered device to make it available for use and assign

ownership to the OTGC

• Click the button on the GUI to turn the light on and off on the Raspberry

Pi and Pimoroni Automation pHat board.

• IT WORKS!

What Should Happen

July 11, 2018 14

In about 15 minutes!

Page 15: Automated Development for Cross-Platform Internet of ThingsRaspberry Pi board •Insert the microSD card •Connect the network •Connect keyboard and monitor (or SSH) •Plug in

Testing with Device Spy

July 11, 2018 15

• Device Spy is a lower level client that allows you to construct the actual payloads that are sent

• Discover the device by clicking the [Discover] button

• Onboard the device by clicking SVRs, selecting an address and clicking the [Onboard] button

• Inspect the resource payload by setting the resource URI, selecting the GET method and clicking the [Send Secure] button

• Change the value of the resource (e.g. false to true) by selecting the POST message and clicking the [Send Secure] button

• The state of the light should change accordingly

Page 16: Automated Development for Cross-Platform Internet of ThingsRaspberry Pi board •Insert the microSD card •Connect the network •Connect keyboard and monitor (or SSH) •Plug in

Run the Certification Test Tool

16

• The Certification Test Tool is and automated test too that devices must pass to get OCF certification

• Run the CTT

• Select the PICS file generated by gen.sh

• Select the discovered device and the interface to use

• Click the play button to start the tests

• Go get coffee

• But don’t take too long because you will need to change the onboarding state to RFOTM a few times

• Pass the CTT and work with a certified lab to get official certification.

Available to OCF members

July 11, 2018

Page 17: Automated Development for Cross-Platform Internet of ThingsRaspberry Pi board •Insert the microSD card •Connect the network •Connect keyboard and monitor (or SSH) •Plug in

• Define your own input file

• Run the tooling!

• Build it… and see if it works

• For example: Check it against OTGC/DeviceSpy/CTT

• To get a feeling what is there..

• Change the code, to what you want it to do

What to do next

July 11, 2018 17

Page 18: Automated Development for Cross-Platform Internet of ThingsRaspberry Pi board •Insert the microSD card •Connect the network •Connect keyboard and monitor (or SSH) •Plug in

• The DeviceBuilder can be modified for any programming language

using templates

• The OTGC will be available on Android, iOS, Linux and Windows this fall

• The OTGC will be available as open source, so you can use a product

that is already OCF certified as the basis for your own client tool on

multiple operating systems

• There is a node.js version of IoTivity available

• There is a more compact version of IoTivity called IoTivity-lite.

DeviceBuilder will support IoTivity-lite as well.

• IoT boards from other companies will be supported with these tools

What else?

July 11, 2018 18

Page 19: Automated Development for Cross-Platform Internet of ThingsRaspberry Pi board •Insert the microSD card •Connect the network •Connect keyboard and monitor (or SSH) •Plug in

• All of this has been developed by the dedicated volunteers and

contractors of Open Connectivity Foundation

(http://openconnectivity.org)

• Wouter van der Beek of Cisco is the Chair of the OCF Technical Steering,

is responsible for key architectural design and personally developed the

DeviceBuilder and the key scripts in this presentation.

• Dekra created the OTGC tool under contract to OCF. The tool will be

available as open source on Android, iOS, Linux and Windows in the Fall.

• Comarch created the CTT and DeviceSpy under contract to OCF. These

tools are available to OCF members.

Acknowledgments and references

July 11, 2018 19

Page 20: Automated Development for Cross-Platform Internet of ThingsRaspberry Pi board •Insert the microSD card •Connect the network •Connect keyboard and monitor (or SSH) •Plug in