iot community workshop for renesas iot sandbox 2017-01-20

43
Learn IoT Meetup and Workshop January 23, 2017

Upload: craig-oda

Post on 13-Apr-2017

442 views

Category:

Technology


3 download

TRANSCRIPT

Page 1: IoT Community Workshop for Renesas IoT Sandbox 2017-01-20

LearnIoT

MeetupandWorkshopJanuary23,2017

Page 2: IoT Community Workshop for Renesas IoT Sandbox 2017-01-20

This workshop will enable you to rapidly prototype an IoT application using best-in-class technologies

We will … Present IoT cloud concepts including security, analytics, and real-time applications

You will … Get hands on experience building a simple IoT application with the Renesas IoT Fast Prototyping Kit and Medium One’s platform

Welcome!

Page 3: IoT Community Workshop for Renesas IoT Sandbox 2017-01-20

GETTING STARTED WITH THE KIT

Page 4: IoT Community Workshop for Renesas IoT Sandbox 2017-01-20

•  User account created based on email (if one does not exist)•  Smart Chef workflows are automatically created•  Welcome email with credentials are sent•  Web Login email credentials (if this is a new account)

•  Note: Do not create a “blank” account – the kit won’t work•  Each kit has a unique activation page configured to work with the

specific board and sensors

What Happens During Smart Chef Activation?

Page 5: IoT Community Workshop for Renesas IoT Sandbox 2017-01-20

How Renesas IoT Sandbox Works

Collec:onsofdataviaAPITimeSeriesData

(fromdevices)

Triggerandexecute

Workflows

GeneratedJSON(feedback)Servicescalledby

Workflows

hSp://renesas-docs.mediumone.com/?workflowstudio

Page 6: IoT Community Workshop for Renesas IoT Sandbox 2017-01-20

•  Drag and Drop pre-built modules•  Embed custom python for flexibility•  Power functions via simple commands

Powerful Python-based Workflows

Classification, Recommendation and Prediction

MACHINE LEARNING

Formatting outputsREPORTS

3rd party integrations

CONNECTORS

Trends and StatsLocal and GlobalANALYTICS

Multi ProtocolCOMMUNICATION

Built In Services

Page 7: IoT Community Workshop for Renesas IoT Sandbox 2017-01-20

•  Basic data flow between S3A7 and Renesas IoT Sandbox

Smart Chef Data Flow

S3A7

Transmitvibra:onatsetfrequency

Setvibra:ontransmitfrequency

RequestAMSsensorvalue

Printtodisplaybyrow

SendAMSsensorvalue

Page 8: IoT Community Workshop for Renesas IoT Sandbox 2017-01-20

API

Events, Tags, Streams & API Endpoints

Stream‘profile’

Stream‘sensor’

{“name”:“John”,“zip”:95054}

{“temperature”:57.6,“sensor_id”:“SN-123”}

i.e.api-renesas-na-sandbox.mediumone.com/v2/events/profile/

i.e.api-renesas-na-sandbox.mediumone.com/v2/events/sensor/

event Secureendpoint streamtag

Event•  JSONdic:onarywithobservedat:mestampTag•  KeyfromJSON•  UsedbyMediumOneWorkflows&Dashboards

Stream•  Adatacollec:onorgroupingofevents•  Logicalorganiza:onEndpoint•  URLtoaspecificStream

hSp://renesas-docs.mediumone.com/?streamstagsdatatypes

Page 9: IoT Community Workshop for Renesas IoT Sandbox 2017-01-20

Smart Chef: Data Streams

Raweventdatadirectfromboard

RecipesforSmartChef

UserSekngs(email,sms,etc)

DecodeddatafromAMSsensor

Savedno:fica:onsevents

Savedlookedupgeo-loca:ondata

Savedhistoricweatherdata

Signaltosamplesensordataduringrecipe

Page 10: IoT Community Workshop for Renesas IoT Sandbox 2017-01-20

User Roles and Identity Management

hSp://renesas-docs.mediumone.com/?permissions

Page 11: IoT Community Workshop for Renesas IoT Sandbox 2017-01-20

REST requires the following components: <Cookie> <Command> <Endpoint + Param> <JSON Payload>

Cookie: Session token retrieved at login

Command: GET, POST, PATCH, DELETE

Endpoint + Param–  API URL (https://api-renesas-na-sandbox.mediumone.com/v2/events/raw)–  Param: data range, limits, etc

HTTP header options:–  Content-Encoding: gzip* Non cookie (token) option available, see documentation

REST API Basics

hSp://renesas-docs.mediumone.com/?api#restapi

SupportsSSLSecure

Connec:onsonly

Page 12: IoT Community Workshop for Renesas IoT Sandbox 2017-01-20

REST Endpoints

hSp://renesas-docs.mediumone.com/?api#restapi

FuncCon API DescripCon

Login hSps://api-renesas-na-sandbox.mediumone.com/v2/login

SubmitAPIUsercreden:als,returnsessioncookie.Cookiesexpireamer1day

Users hSps://api-renesas-na-sandbox.mediumone.com/v2/users

APIBasicUsermanagement(create/retrieve/update/delete/list)

Events hSps://api-renesas-na-sandbox.mediumone.com/v2/events/<stream_name>/<login_id>

Read/Writeeventdata

Page 13: IoT Community Workshop for Renesas IoT Sandbox 2017-01-20

MQTT is a Publish-Subscribe messaging protocol–  Device listen on a socket (low power)–  No Cookies to Tokens–  Configurable keep-alive ping frequency sockets–  Access control via username and password

Pub/Sub on Topics–  Path with hierarchical format–  Eg: “0/Ldfgf0g/PakS4c/device_id_123/”–  Topics are derived based on Medium One project settings

MQTT Basics

hSp://renesas-docs.mediumone.com/?api#mqS

SupportsTLSsecureconnec:ons

Nonsecureconnec:onavailablefordevicesthat

donotsupportTLS

Page 14: IoT Community Workshop for Renesas IoT Sandbox 2017-01-20

MQTT Authentication

Notes:•  SupportTLS1.xsecurity•  OnlyAPIBasicUserscanpublish/subscribe•  MQTTusernameandpassworddifferentfromRESTbecauseofcharactersetrestric:ons

Proportnumber Sandboxportnumber

EncryptedMQTT 61617 61619UnencryptedMQTT 61618 61620

URL:mqS.mediumone.comUsername:"<project_mqS_id>/<user_hash>”Password:"<api_key>/<user_password>”project_mqS_id:webportal=>setup=>MQTTuser_mqS_id:webportal=>setup=>ManageUser

hSp://renesas-docs.mediumone.com/?api#mqS

Page 15: IoT Community Workshop for Renesas IoT Sandbox 2017-01-20

Device to Cloud–  Topic: 0/<project_mqtt_id>/<user_mqtt_id>/<device_id>/–  device_id – Optional field for use as unique or device group identifier–  Single JSON event in body creates new event in raw stream

Cloud to Device•  Topic: 1/<project_mqtt_id>/<user_mqtt_id>/<device_id>/event

–  JSON body structure contains the event–  A device without an active connection will not receive events–  Published by Workflows (more on this in next module)

* More information on docs page

MQTT: Bi-Directional Events

hSp://renesas-docs.mediumone.com/?api#mqS

Page 16: IoT Community Workshop for Renesas IoT Sandbox 2017-01-20

•  Handled by Medium One VSA•  Sends “connect” message with meta data

from FMI and NetX

•  Transmits JSON event once during initial connection

•  Will transmit again if MQTT connection is re-established (recover from wifi connection)

Board Connection

{":mestamp":"2016-10-13T00:14:13.943Z","user":"device","raw":{"quality_code":0,"kit_version":"0.0.1","lan_address":"192.168.43.53","ssp_version_code":16843008,"connected":true,"m1_version":"0.0.1","ip_address":"172.56.39.176","product_name":"R7FS3A77C3A01CFB","unique_id":"\u000e%\u00078608653�ᅢ��\u001fWK","device_id":"s3a7"}}

TIP:hSps://mediumone.com/renesas/vsadocumenta:on

TAG

Page 17: IoT Community Workshop for Renesas IoT Sandbox 2017-01-20

•  Connecting: –  WIFI -> Mqtt ->”Connect” event is sent

•  Bosch accelerometer: send 1 event every 10 min by default

•  AMS sensors: cloud request sample reading. Frequency defined by workflow.

•  Screen: touch immediately sends screen coordinates to cloud

•  GPS module is optional

Device to Cloud: Data flow

Page 18: IoT Community Workshop for Renesas IoT Sandbox 2017-01-20

•  Aggregate data over window set by workflow (default 1 per 10 mins)

•  Units: G force

•  x|y|z_min|avg|max: during window•  x|y|z_zero_cross: number cycles during window•  Sample_cnt: number of samples during

window•  No decoding required (driver on board)

•  Transmits JSON event once per aggregation window

Bosch Vibration Sensor Data

{":mestamp":"2016-11-02T07:14:55.991Z","user":"device","raw":{"y_avg":0.009451,"z_avg":0.90952,"y_min":-0.03528,"sample_cnt":1001,"z_max":1.15836,"z_zero_cross":204,"y_max":0.05586,"x_avg":-0.415729,"x_zero_cross":187,"z_min":-0.00098,"x_max":-0.00098,"y_zero_cross":200,"x_min":-0.4655,"device_id":"s3a7"}}

Page 19: IoT Community Workshop for Renesas IoT Sandbox 2017-01-20

AMS Sensor Data (Proximity)

{":mestamp":"2016-10-13T00:18:21.277Z","user":"device","raw":{"proximity":[152,0],"device_id":"s3a7"}}

{":mestamp":"2016-10-13T00:18:21.277Z","user":"device","processed":{"proximity":152}}

RawDataSamplefromDevice(encoded) ProcessedDatabyWorkflow(amerCloudDriver)

workflow

Proximity:highernumbermeansclosertheobject

Page 20: IoT Community Workshop for Renesas IoT Sandbox 2017-01-20

AMS Sensor Data (Color)

{":mestamp":"2016-10-27T08:56:28.089Z","user":"device","raw":{"color":[236,0,62,0,90,0,74,0],"device_id":"s3a7"}}

{":mestamp":"2016-10-13T00:18:21.249Z","user":"device","processed":{"blue":388,"alpha":1583,"green":571,"red":623}}

RawDataSamplefromDevice(encoded) ProcessedDatabyWorkflow(amerCloudDriver)

workflow

Page 21: IoT Community Workshop for Renesas IoT Sandbox 2017-01-20

AMS Sensor Data (Air Quality)

{":mestamp":"2016-11-02T06:34:28.016Z","user":"device","raw":{"air_quality":[7,82,0,0,2,25,98],"device_id":"s3a7"}}

{":mestamp":"2016-10-13T00:17:40.212Z","user":"device","processed":{"status":"OK","air_quality":450,"resistance":340223}}

Status:•  OK=opera:onal•  RUNNING=calibra:ngmode

RawDataSamplefromDevice(encoded) ProcessedDatabyWorkflow(amerCloudDriver)

workflow

Page 22: IoT Community Workshop for Renesas IoT Sandbox 2017-01-20

AMS Sensor Data (Temperature & Humidity)

{":mestamp":"2016-11-02T06:34:28.016Z","user":"device","raw":{"air_quality":[7,82,0,0,2,25,98],"device_id":"s3a7"}}

{":mestamp":"2016-10-13T00:18:21.567Z","user":"device","processed":{"temperature":25.71,"humidity":40.29}}

RawDataSamplefromDevice(encoded) ProcessedDatabyWorkflow(amerCloudDriver)

workflow

Page 23: IoT Community Workshop for Renesas IoT Sandbox 2017-01-20

GPS PMOD

{":mestamp":"2016-10-13T00:18:00.684Z","user":"device","raw":{"gps-module":",0.00,060180,,,N*4A\r\n$GPVTG,0.00,T,,M,0.00,N,0.00,K,N*32\r\n$GPGGA,000258.800,,,,,0,0,,,M,,M,,*4F\r\n$GPGSA,A,1,,,,,,,,,,,,,,,*1E$GPGGA,000255.800,,,,,0,0,,,M,,M,,*42\r\n$GPGSA,A,1,,,,,,,,,,,,,,,*1E\r\n$GPRMC,000255.800,V,,,,,0.00,0.00,060180,,,N*48\r\n$GPVTG,0.00,T,,M,0.00,N,0.00,K,N*32\r\n$GPGGA,000256.800,,,,,0,0,,,M,,M,,*41\r\n$GPGSA,A,1,,,,,,,,,,,,,,,*1E\r\n$GPRMC,000256.800,V,,,,,0.00,0.00,060180,,,N*4B\r\n$GPVTG,0.00,T,,M,0.00,N,0.00,K,N*32\r\n$GPGGA,000257.800,,,,,0,0,,,M,,M,,*40\r\n$GPGSA,A,1,,,,,,,,,,,,,,,*1E\r\n$GPGSV,1,1,00*79\r\n$GPRMC,000257.800,V,,,,,0.00","device_id":"s3a7"}}

{":mestamp":"2016-10-12T22:53:00.000Z","user":"device","processed":{"geopoint":"+37.38728-122.06044"}}

RawDataSamplefromDevice(encoded) ProcessedDatabyWorkflow(amerCloudDriver)

hSp://store.digilen:nc.com/pmod-gps-gps-receiver/

workflow

Page 24: IoT Community Workshop for Renesas IoT Sandbox 2017-01-20

•  Transmits x,y coordinates when screen is touched immediately

Touched Screen

{":mestamp":"2016-10-13T00:12:56.292Z","user":"device","raw":{"y":187,"x":177,"touched":true,"device_id":"s3a7"}}

Page 25: IoT Community Workshop for Renesas IoT Sandbox 2017-01-20

•  Smart Chef workflows create notification messages to notification stream

•  Separate “Send Notification” workflow will process and transmit•  Options: for push, sms, email or screen/line

Notification Messages

{":mestamp":"2016-11-02T14:25:48.321Z","user":"device","no:fica:ons":{"screen":true,"line":5,"message":"CurrentWeather:14.33C38%Humidityfewclouds"}}

{":mestamp":"2016-11-02T14:25:48.321Z","user":"device","no:fica:ons":{"push":true,"message":"It'sagreatdayforabarbecue!","sms":true,"email":true}}

Page 26: IoT Community Workshop for Renesas IoT Sandbox 2017-01-20

Build Dashboard Views

TypesofWidgets:•  ViewdataforspecificAPIUser•  ViewdataacrossgroupsofAPIUser•  Senddataperusertotriggerworkflows

*Remembertosave.Viewsaresavedperwebuser.

hSp://renesas-docs.mediumone.com/?widgets

Easilyaddwidgets

Page 27: IoT Community Workshop for Renesas IoT Sandbox 2017-01-20

Mobile App •  ConnecttoRESTAPIviausercreden:als.•  1APIcreditperread(refreshonceper5seconds)orwrite

hSp://renesas-blog.mediumone.com/renesas-iot-sandbox-mobile-app-quick-start-guide/

AddProfile(connecttomul:ple

projects)AddWidget EachWidgetmapsto

stream/tag

Remembertoselect“Renesas”

Rememberto“save”foriOSversion

SpecifyAPIcreden:alsforuser(fromwebportalorac:va:onemail)

Page 28: IoT Community Workshop for Renesas IoT Sandbox 2017-01-20

Toolbars

WorkflowStudio

Workflow Studio Components

TimerTrigger

InputEvent

Triggers&Inputs

Pre-builtPythonSnippets

OutputEvents

Debugger

VersionControl

UsageAnaly:cs

ProcessEvent

OutputEvent

hSp://renesas-docs.mediumone.com/?workflowstudio

Workflowscanbeac:vatedinstantlytogolive

SEELIVEDEMO

Page 29: IoT Community Workshop for Renesas IoT Sandbox 2017-01-20

Programmatic Python Module

Comments

ImportWorkflowlibraries

Calllibraryfunc:ons

CheckSyntax

hSp://renesas-docs.mediumone.com/?workflowstudio

SEELIVEDEMO

Page 30: IoT Community Workshop for Renesas IoT Sandbox 2017-01-20

Smart Chef Workflows

26pre-createdWorkflowstopowerSmartChefFeatures:-  SampleAMSsensor-  Setvibra:onwindow-  Monitoronline/offline-  MonitorGPS-  Getweather-  Sendno:fica:ons-  Processrecipe-  AMSclouddriver-  PrinttoScreen

PrintscreenfromSmartChefworkflows

Page 31: IoT Community Workshop for Renesas IoT Sandbox 2017-01-20

Smart Chef Workflows

connect

device_id

Setaggrega:onwindowviaMQTT

ip_address

connect

GetcurrentweatherbasedonIPaddressNo:fica:on:Email/pushgree:ngNo:fica:on:Printweatheronscreen

Getcurrentloca:onbasedonIPaddressNo:fica:on:Printloca:ononscreen

Ifboardwentfrom“offline”to“online”No:fica:on::Email/push“BoardOnline”

Tag

WhenboardConnectstoMQTT

Heartbeatforboard.Tagispartofeveryeventfromboard

Page 32: IoT Community Workshop for Renesas IoT Sandbox 2017-01-20

Smart Chef Workflows

Timer(10min) WriteandreadRegistertogetTemp/Humiditysensorreading(AMS)

Ifboardwentfrom“online”to“offline”No:fica:on:Email/push“BoardOffline”

Timer(10min)

Timer(10min)

Timer(10min)

Timer(10min)

write_register(0x21,0x03)MQTT.publish_event_to_client('s3a7',mqS_buffer,'la:n1')mqS_buffer=u''write_register(0x22,0x03)MQTT.publish_event_to_client('s3a7',mqS_buffer,'la:n1')mqS_buffer=u''read_register(0x30,6,'temp_and_humidity')MQTT.publish_event_to_client('s3a7',mqS_buffer,'la:n1')

WriteandreadRegistertogetGPSreading(op:onalGPSPMOD)

WriteandreadRegistertogetAirQualitysensorreading(AMS)

WriteandreadRegistertogetColorandProximitysensorreading(AMS)

Page 33: IoT Community Workshop for Renesas IoT Sandbox 2017-01-20

Smart Chef Workflows

air_quality

color

Decoderegistervalues

proximity

gps-module

temp_and_humidity

processed/air_quality

Stream/tag

Decoderegistervalues processed/geopoint

Decoderegistervalues processed/proximity

Decoderegistervalues processed/temperatureprocessed/humidity

Decoderegistervaluesprocessed/alphaprocessed/redprocessed/greenprocessed/blue

CloudDriver

AMS/G

PSRegisters

Page 34: IoT Community Workshop for Renesas IoT Sandbox 2017-01-20

Smart Chef Workflows

No:fica:on:push/email“ImpactAlert”

BBQmoved>100meters?No:fica:on:push/email“BBQmoved”

MobileGPSvsBoardGPS>50meters?No:fica:on:push/email“In/outofrange”

No:fica:on:push/email“Screentouched”

Sendno:fica:ontoscreen,email,smsorpush

(MobileGPS)

(BoardGPS)

vibra:on

processed/geopoint

myGPS.device_loca:on

touched

No:fica:ons/message

Page 35: IoT Community Workshop for Renesas IoT Sandbox 2017-01-20

•  Print string/text based on rows•  40 characters per row•  20 rows of text•  Row 0 is reserved

•  Smart Chef notifications start at row 9

Printing to Screen

ExampleCommand:MQTT.publish_event_to_client('s3a7',’D9;hello’,'la:n1')Prints“hello”torow9

Page 36: IoT Community Workshop for Renesas IoT Sandbox 2017-01-20

•  Uses Google’s Firebase Cloud Messaging (FCM)•  Mobile app sends FCM_token to raw stream if

push notification is enabled. Will send when profile is open.

•  Note: Smart Chef workflow only sends push to most recent FCM token. It’s possible to support multi but not implemented on this workflow.

Push Notification {":mestamp":"2016-10-24T16:19:13.487Z","user":"device","raw":{"FCM_token":

"csw50JiLPwI:APA91bFEIOwlTCTR3eU179MgNsrSmPJOIosUBCmIfzNuuQ784b5dFl51udzV33cjsKCr9ohOTTyL2ywtk841YNriExQ0nzc_NvZMEFmUofaCChcoNWsU"

}

ExampleCommandtoSendNo:fica:on:

importFCM

FCM.send_fcm_no:fica:on_to_m1_applica:on([FCM_token],”hello”,sound="chime”)

FCMToken

Page 37: IoT Community Workshop for Renesas IoT Sandbox 2017-01-20

•  Tips:–  Test workflows with manual trigger to avoid lots of errors–  Turn off debugger to save credits when workflow is complete–  Workflows will time out after 30 sec and de-activated after 20

consecutive timeouts–  Avoid unbound (very large) queries, generate derived data if

possible

Workflow Tips

Page 38: IoT Community Workshop for Renesas IoT Sandbox 2017-01-20

•  Quick!–  Write simple apps very fast

•  Easy to read and maintain

–  Write complex apps too•  Leverage vast open source code•  Advanced techniques (eg OOP)

•  Use for practically any application–  Web apps, automation, even data science

•  Interpreted scripting language–  Platform independent–  No compilation

Introduction to Python

Page 39: IoT Community Workshop for Renesas IoT Sandbox 2017-01-20

•  Load external modules•  Flexible dictionaries

–  Key / value pairs–  Translate easily to JSON–  Use instead of structs

•  Prescribed indentation

•  Good Python Reference (5-10 min)•  https://www.tutorialspoint.com/python/python_quick_guide.htm

•  Sample output

Introduction to Python Con’t

Page 40: IoT Community Workshop for Renesas IoT Sandbox 2017-01-20

•  Creating workflows is easy!

How To Create A Workflow

Clickcreate

Settriggerandconnecttopythonbox

Writeyourpython

ac:vate

Page 41: IoT Community Workshop for Renesas IoT Sandbox 2017-01-20

Workflow Libraries

hSp://renesas-docs.mediumone.com/?libraries/introduc:on

•  Simple programmatic interfaces to powerful functions and services

•  Organized into Python modules •  Library calls cost Workflow Credits

•  Most library calls cost 1 credit •  Free accounts have limited Daily quota •  Balance on Project Info web portal page

•  Permissions required for some libraries

Page 42: IoT Community Workshop for Renesas IoT Sandbox 2017-01-20

•  What you learned?–  How the Smart Chef demo works–  How Renesas IoT Sandbox works–  Introduction to workflows, python, the cloud environment

•  Up Next:–  Prototype a Smart Garage Monitoring and build workflows

yourself

Summary

Page 43: IoT Community Workshop for Renesas IoT Sandbox 2017-01-20

Lab: Make Your Garage Smarter with Renesas IoT Sandbox and S3A7 Fast Prototyping Kit

•  Prototype Smart Garage monitoring system in under 90 minutes. Ready to use at home.

•  http://renesas-blog.mediumone.com for Online Tutorial

Dooropenvsclosewithproximity

Dooropeningwithvibra:onsensor

Carexhaustrunningwithair

quality

no:fica:ons

Interac:vetouchscreen