jsdc 2017 - 使用google cloud 從雲到端,動手刻個iot

28
使用Google Cloud 從雲到端,動手刻個IoT Simon Su @ GCPUG.TW https://goo.gl/QxoSB2

Upload: simon-su

Post on 22-Jan-2018

493 views

Category:

Technology


6 download

TRANSCRIPT

Page 1: JSDC 2017 - 使用google cloud 從雲到端,動手刻個IoT

使用Google Cloud從雲到端,動手刻個IoT

Simon Su @ GCPUG.TW

https://goo.gl/QxoSB2

Page 2: JSDC 2017 - 使用google cloud 從雲到端,動手刻個IoT

About me

var simon = {/** I am at GCPUG.TW **/};

simon.cloud_gde = true;

simon.blog = ‘http://peihsinsu.blogspot.com';

simon.slideshare = ‘http://slideshare.net/peihsinsu/';

simon.email = ‘[email protected]’;

simon.say(‘Give me IV100 Mewtow!!');

Page 3: JSDC 2017 - 使用google cloud 從雲到端,動手刻個IoT

From iThome: https://www.ithome.com.tw/news/111022

Page 4: JSDC 2017 - 使用google cloud 從雲到端,動手刻個IoT

What is IoT?

The Internet of things (IoT) is the network of physical

devices, vehicles, home appliances, and other items

embedded with electronics, software, sensors, actuators,

and network connectivity which enable these objects to

connect and exchange data.

From Wikipedia: https://en.wikipedia.org/wiki/Internet_of_things

Page 5: JSDC 2017 - 使用google cloud 從雲到端,動手刻個IoT

What is IoT…

Page 6: JSDC 2017 - 使用google cloud 從雲到端,動手刻個IoT

Device Cloud BigData, ML, AISensor, BLE, NBIoT

microprocessor mips / arm x86 / x64 / unix iaas / paas / saas

Page 7: JSDC 2017 - 使用google cloud 從雲到端,動手刻個IoT

Device Cloud

● Connectivity: Async, Sync

● Install & Upgrade: Container,

Package

● AI / ML

● Remote Control / Managment

● Data Cache: Queue

● Data Process: Batch, Streaming

● Data Store: Object Store, Data

Query

● BI: Report, Business Integration

● AI / ML

Page 8: JSDC 2017 - 使用google cloud 從雲到端,動手刻個IoT

從Google IoT架構看看Google Cloud Platform上的IoT Family

IoT低加

結合serverless

GCP上的BigData系列

當紅的Machine Learning

我才是主角

Page 9: JSDC 2017 - 使用google cloud 從雲到端,動手刻個IoT

Cloud PubSub

● Deliver event data wherever you need it

● Build multi-cloud and hybrid applications on open

architecture

● Scale responsively and automatically

● Bring reliability and security tools to real-time apps

Page 10: JSDC 2017 - 使用google cloud 從雲到端,動手刻個IoT

Cloud PubSub

Repo: https://github.com/gcpug-tw/pubsub-example.git

subscription.pull(options, function (err, messages) { if (err) return callback(err);

// Do something for each message messages.forEach(handleMessage); console.log('Pulled %d messages!', messages.length);

// Acknowledge messages

var subscription = pubsub.subscription(subscriptionName);

if(messages && messages.length > 0) subscription.ack(messages.map(function (message) { return message.ackId; }), function (err) { if (err) { return callback(err); }

console.log('Acked %d messages!', messages.length); return callback(null, messages); }); });

Page 11: JSDC 2017 - 使用google cloud 從雲到端,動手刻個IoT

● Microservices Over Monoliths

● Connect & Extend Cloud Services

● Serverless Economics

● Mobile Ready

● Just Add Code

● Open and Familiar

Cloud Function

Page 12: JSDC 2017 - 使用google cloud 從雲到端,動手刻個IoT

Cloud Function

Page 13: JSDC 2017 - 使用google cloud 從雲到端,動手刻個IoT

● Enterprise Cloud Data Warehouse

● Speed & Scale

● Incredible Pricing

● Security & Reliability

● Partnerships & Integrations

BigQuery

Page 14: JSDC 2017 - 使用google cloud 從雲到端,動手刻個IoT

var bigqueryClient = bigquery({

projectId: 'grape-spaceship-123',

keyFilename: '/path/to/keyfile.json'

});

// Access an existing dataset and table.

var schoolsDataset = bigqueryClient.dataset('schools');

var schoolsTable = schoolsDataset.table('schoolsData');

// Import data into a table.

schoolsTable.import('/local/file.json', function(err, job) {});

// Get results from a query job.

var job = bigqueryClient.job('job-id');

// Use a callback.

job.getQueryResults(function(err, rows) {});

// Or get the same results as a readable stream.

job.getQueryResults().on('data', function(row) {});

From: https://github.com/GoogleCloudPlatform/google-cloud-node#google-bigquery-beta

google-cloud-node for BigQuery

Page 15: JSDC 2017 - 使用google cloud 從雲到端,動手刻個IoT

ML APIs - Vision, Speech, Natural Language

Vision Natural Language Speech

Page 16: JSDC 2017 - 使用google cloud 從雲到端,動手刻個IoT

google-cloud-node for Vision

var visionClient = vision({ projectId: 'grape-spaceship-123', keyFilename: '/path/to/keyfile.json'});

var gcsImageUri = 'gs://gapic-toolkit/President_Barack_Obama.jpg';var source = { gcsImageUri : gcsImageUri};var image = { source : source};var type = vision.v1.types.Feature.Type.FACE_DETECTION;var featuresElement = { type : type};var features = [featuresElement];var requestsElement = { image : image, features : features};var requests = [requestsElement];visionClient.batchAnnotateImages({requests: requests}).then(function(responses) { var response = responses[0]; // doThingsWith(response)}).catch(function(err) { console.error(err);});

From: https://github.com/GoogleCloudPlatform/google-cloud-node#cloud-vision-beta

Page 17: JSDC 2017 - 使用google cloud 從雲到端,動手刻個IoT

Google Cloud - IoT Core

● Make informed decisions at Global Scale

● Securely connect your existing device network

● Establish two-way communication with your

devices

● Get straight to work

Page 18: JSDC 2017 - 使用google cloud 從雲到端,動手刻個IoT
Page 19: JSDC 2017 - 使用google cloud 從雲到端,動手刻個IoT
Page 20: JSDC 2017 - 使用google cloud 從雲到端,動手刻個IoT
Page 21: JSDC 2017 - 使用google cloud 從雲到端,動手刻個IoT
Page 22: JSDC 2017 - 使用google cloud 從雲到端,動手刻個IoT

const mqttClientId = `projects/${argv.project_id}/locations/${argv.cloud_region}/registries/${argv.registry_id}/devices/${argv.device_id}`;

const connectionArgs = { host: argv.mqtt_bridge_hostname, port: argv.mqtt_bridge_port, clientId: mqttClientId, username: 'unused', password: createJwt(argv.project_id, argv.private_key_file, argv.algorithm), protocol: 'mqtts'};

const client = mqtt.connect(connectionArgs);

const mqttTopic = `/devices/${argv.device_id}/${argv.message_type}`;

client.on('connect', () => { //TODO …}

IoT Core - MQTT example

Page 23: JSDC 2017 - 使用google cloud 從雲到端,動手刻個IoT

Google DataStudio

Page 24: JSDC 2017 - 使用google cloud 從雲到端,動手刻個IoT

● Build add-ons to extend Google Sheets,

Docs, Slides, and Forms

● A living, breathing platform (well,

metaphorically)

● Free

Apps Script

Page 25: JSDC 2017 - 使用google cloud 從雲到端,動手刻個IoT

App Script url monitor example

Page 26: JSDC 2017 - 使用google cloud 從雲到端,動手刻個IoT
Page 27: JSDC 2017 - 使用google cloud 從雲到端,動手刻個IoT

Reference

● Today’s Demo: https://github.com/peihsinsu/try-cloud-iot.git

● Cloud Function Examples:

https://github.com/GoogleCloudPlatform/nodejs-docs-samples/tree/master/functions

● Apps Script for BigQuery: https://developers.google.com/apps-script/advanced/bigquery

● Node.js BigQuery SDK:

https://googlecloudplatform.github.io/google-cloud-node/#/docs/bigquery/0.9.6/bigquery

● Cloud IoT MQTT bridge: https://cloud.google.com/iot/docs/how-tos/mqtt-bridge

Page 28: JSDC 2017 - 使用google cloud 從雲到端,動手刻個IoT