jsdc 2017 - 使用google cloud 從雲到端,動手刻個iot
TRANSCRIPT
使用Google Cloud從雲到端,動手刻個IoT
Simon Su @ GCPUG.TW
https://goo.gl/QxoSB2
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!!');
From iThome: https://www.ithome.com.tw/news/111022
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
What is IoT…
Device Cloud BigData, ML, AISensor, BLE, NBIoT
microprocessor mips / arm x86 / x64 / unix iaas / paas / saas
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
從Google IoT架構看看Google Cloud Platform上的IoT Family
IoT低加
結合serverless
GCP上的BigData系列
當紅的Machine Learning
我才是主角
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
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); }); });
● Microservices Over Monoliths
● Connect & Extend Cloud Services
● Serverless Economics
● Mobile Ready
● Just Add Code
● Open and Familiar
Cloud Function
Cloud Function
● Enterprise Cloud Data Warehouse
● Speed & Scale
● Incredible Pricing
● Security & Reliability
● Partnerships & Integrations
BigQuery
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
ML APIs - Vision, Speech, Natural Language
Vision Natural Language Speech
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
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
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
Google DataStudio
● Build add-ons to extend Google Sheets,
Docs, Slides, and Forms
● A living, breathing platform (well,
metaphorically)
● Free
Apps Script
App Script url monitor example
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