[di10] iot を実践する最新のプラクティス ~ azure iot hub 、sdk 、azure iot suite...

Post on 21-Jan-2018

1.508 Views

Category:

Technology

0 Downloads

Preview:

Click to see full reader

TRANSCRIPT

3

Connectivity Data AnalyticsThings Action

Internet of Things

機器ごと、業界ごと、シーンごと、やりたいことで、シナリオいろいろ

組込み機器、人⇔送受信⇔蓄積、表示、分析、活用PaaSをビルディングブロックで組み合わせ、構築する

Microsoft Azure

デバイス接続サービス

データ実時間分析サービス

ML

ダッシュボード

サービス連携

データ・サービスを第三者へ売る

PC・タブレット・スマホ

開発・運用コスト低スケール可能!!

ストレージ

その他のビッグデータ

エンタープライズサービス等外部サービス

メッセージング

管理

Microsoft Azure

メッセージング

管理

Predictive Maintainance

Connected FactoryRemote Monitoring

RemoteMonitoring

PredictiveMaintenance

ConnectedFactory

http://www.azureiotsuites.com

https://github.com/Azure/azure-iot-remote-monitoring

https://github.com/Azure/azure-iot-connected-factory

https://github.com/Azure/azure-iot-predictive-maintenancehttps://github.com/Azure/LearnAnalytics-PredictiveAnalyticsForIoT

IoT の障壁を取り除く これまでの限界を超える 実績のある技術を活用する

Microsoft Azure

AzureIoT Hub

FieldGateway

CloudProtocolGateway

デバイス

Microsoft Azure

AzureIoT Hub

FieldGateway

CloudProtocolGateway

メッセージング(双方向)ファイルアップロード

デバイス

プロパティ同期メソッドコール

デバイスレジストリ

メッセージング(受信)

メッセージング(送信)

Twin – プロパティ同期

クエリ

ジョブ

デバイス毎の秘密鍵デバイス毎の証明書

受信のルーティング

モニタリング

ファイルアップロード

https://microsoft.github.io/techcasestudies/iot/2017/03/03/seraku.html

http://azure.microsoft.com

http://github.com/Azure/azure-iot-sdks

SDKでの接続が確認済みの組込み機器カタログhttps://catalog.azureiotsuite.com/

Microsoft Azure

デバイス

Microsoft Azure

デバイス

接続

受信スレッド作成

メッセージ作成

メッセージ送信

切断

var client = DeviceClient.CreateFromConnectionString(“接続文字列",TransportType.Mqtt);

await client.OpenAsync();

ReceiveMessagesAsync(client);

var data = new{

MeasuredTime = DateTime.Now,Muscle = arduino.analogRead("A1")

};var json = JsonConvert.SerializeObject(data);var msg = new Message(Encoding.UTF8.GetBytes(json));

await client.SendEventAsync(msg);

await client.CloseAsync();

private async void ReceiveMessagesAsync(DeviceClient client){

while (true){

var message = await client.ReceiveAsync();var content = Encoding.UTF8.GetString(message.GetBytes());

・・・ 受信メッセージの処理

await client.CompleteAsync(message);}

}

https://github.com/Azure/azure-iot-sdk-c/blob/master/doc/ubuntu_apt-get_sample_setup.md

接続

受信スレッド作成

メッセージ作成

メッセージ送信

切断

#include "iothub_client.h“#include "iothub_message.h“#include "iothubtransportamqp.h“…IOTHUB_CLIENT_HANDLE iotHubClientHandle;iotHubClientHandle = IoTHubClient_CreateFromConnectionString(cs, AMQP_Protocol));

IoTHubClient_SetMessageCallback(iotHubClientHandle, ReceiveMessageCallback, NULL);

EVENT_INSTANCE* eventinstance = (EVENT_INSTANCE*)malloc(sizeof(EVENT_INSTANCE));unsigned char* msg = “{¥”MeasuredTime¥”:¥”…eventinstance->messageHandle = IoTHubMessage_CreateFromByteArray(msg, msgLen));

IoTHubClient_SendEventAsync(iotHubClientHandle,eventinstance->messageHandle,SendConfirmationCallback, eventinstance)

HostName=IoTHubName.azure-devices.net;DeviceId=myDeviceId;SharedAccessKey=myBase64EncodedAccessKey

http://catalog.azureiotsuite.com

https://www.unirobot.com/

Microsoft Azure

IoT Hub

Local Netwoark

登録済

http://github.com/Azure/azure-iot-edge

Microsoft Azure

IoT Hub

Message Bus

Module A Module B Module D Module E

メッセージバスに送信したメッセージは他のすべてのモジュールが受信

リンクの設定による送信元・先の限定

Module の役割は任意

JSONによる定義ファイル

静的、動的両方をサポート

Message Bus

LocalCommModule

ExtendedModule

IoT HubMapper

IoT HubClient

IoT SDK

リモートモニタリング・制御多数のIoTデバイスからの収集データをマージ先進AIの適用を可能にする、無限に近いコンピューティングリソースとストレージ

リアルタイム応答に必要なローレーテンシーでタイトなコントロールループプライバシーデータや知的財産の保護

MessageBus

Module

Embedded Georgehttp://github.com/ms-iotkithol-jp/AzureIoTGatewayExtention

ドローンワークス(株)http://github.com/drone-works/AzureIoTGatewaySDKExtention

Gateway Box

StreamAnalytics

PowerBIBlobStorage

すべてのイベントデータをアーカイブ保存

ダッシュボード表示

SQLDatabase

EventHubs

ソーラーパネル 制御機器

RC485 ソーラーパネル稼働状況

アラート情報

Armadillo

ModbusAzure IoT

Gateway SDK

KES Software

IoTHub

アラート情報をルーティング

SoftBank 3G/4GModule

WebJob/Functions SendGrid

担当者へメールを送信

Microsoft Azure

Edge

×金沢エンジニアリングシステムズ

プロジェクト全体統括LTE回線提供 Edgeソフトウェア開発

(Azure IoT Gateway SDKを活用)

Azure IoT Gateway SDKを活用しEdgeソフトウェア開発工期を圧縮

KESのEdge側開発ノウハウを活用し200種類のプロトコルへの対応を実現可能

Message Bus

LocalCommModule

ExtendedModule

IoT HubMapper

IoT HubClient

IoT SDK

Microsoft Azure

http://pcn.club/katsuyama/azure201703/

計画

プロビジョニング

構成監視

使用中止

計画:• 管理用メタデータ検討と定義プロビジョニング:• デバイスの登録と管理用メタデータ設定構成:• 正常性とセキュリティの維持• 一括構成変更、ファームウェア更新監視:• 継続的なモニタリングと異常時の通知使用中止:• 使用停止と資格情報の安全な破棄• デバイス交換中の、デバイス情報保持

49クラウドのバックエンドサービスDevice App

IoT Hub

C2D

D2C

Device Twin

Direct Methods

テレメタリー

クラウドからメッセージをデバイスに送る

Properties

経過も通知受信可能なデバイスのメソッドを起動

Propertiesクラウド側から指定可能な変数デバイス側由来の変数

クラウド側で付与可能なメタデータ

Methods

Read/Write Read

Read/WriteRead/Notification

プロパティ更新、メソッドコールはIoT Hubに履歴として保存される

Microsoft Azure

RegistryManager registryManager = RegistryManager.CreateFromConnectionString(“サービス接続文字列”);await registryManager.OpenAsync();

var newDevice = new Device(newDeviceId);newDevice = await registryManager.AddDeviceAsync(newDevice);

var twin = await registryManager.GetTwinAsync(newDevice.Id);

var props = new { dmConfig = new {TelemetryCycle = TelemetryCycle, Latitude = Latitude, …

} };Var json = JsonConvert.SerializeObject(props);

await registryManager.UpdateTwinAsync(newDevice.Id, json, twin.ETag);

接続

デバイス登録

Twin取得

DesiredProperties設定

HostName=IoTHubEndPoint; SharedAccessKeyName =roleName;SharedAccessKey=Base64EncodedAccessKey

var deviceClient = DeviceClient.CreateFromConnectionString(cs, TransportType.Mqtt);await deviceClient.SetDesiredPropertyUpdateCallback(DPUpdateCallback, this);

private Task DPUpdateCallback(TwinCollection desiredProperties, object userContext){

return Task.Run(() =>{

var json = desiredProperties.ToJson();…

});}

var registedDeviceTwin = await registryManager.GetTwinAsync(deviceId);var rp =

JsonConvert.DeserializeObject(registedDeviceTwin.Properties.Reported.ToJson();var rpJSON = (JObject)JsonConvert.DeserializeObject(rp);

var reportedProps = new Models.ReportedProperties() {BatteryLevel = ThingsCar.BatteryLevel,…, ThingsCar.Status };

var json = JsonConvert.SerializeObject(reportedProps);var patch =JsonConvert.DeserializeObject<TwinCollection>(json);await deviceClient.UpdateReportedPropertiesAsync(patch);

ServiceClient serviceClient =ServiceClient.CreateFromConnectionString(cs);var method = new CloudToDeviceMethod("reboot");var payload = “after 30 seconds…"method.SetPayloadJson(payload);var callResult = await serviceClient.InvokeDeviceMethodAsync(deviceId, method);

after 30 seconds…

var deviceClient = DeviceClient.CreateFromConnectionString(cs,TransportType.Mqtt);await deviceClient.SetMethodHandlerAsync("reboot", RebootMethod, this);

private Task<MethodResponse> RebootMethod(MethodRequest request, object context){

return Task.Run(() => {…return new MethodResponse(

Encoding.UTF8.GetBytes("{¥"Status¥":¥"Rebooting¥"}"),0);});

}

※Payloadは、request.DataAsJsonで取得

IoT Hub

Device Twin/Methods

Device

Device Twin/MethodsDevice Twin/Methods

Device Twin/MethodsDevice Twin/Methods

Device Twin/MethodsDevice Twin/Methods

Device Twin/MethodsDevice Twin/Methods

Device Twin/MethodsDevice Twin/Methods

Device Twin/MethodsDevice Twin/Methods

Device Twin/MethodsDevice Twin/Methods

Device Twin/Methods

Jobs

Schedule and Broadcast Device Twin Changes

Set Desired Properties, Tags, Call Methods

Queries – SQL like

Query Across Device Twin State

For Business Logic, Reporting and Compliance

JSONで結果取得

IoT Hub Device ManagementのJobコレクション

IoT Hub

デフォルトのメッセージングDevice

Device

Device

Device Twin

Properties

プロパティ、タグでフィルタリング

Tag.ServiceType = …

Desired.DeviceType = …

• タグ/プロパティで条件付け、後続の処理を分離

• 大規模 IoT への対応

Microsoft Azure

デバイス接続管理(ID、Device Key)

メッセージング(送受信、受信確認)

機器管理(Device Twin、Query、Job)

デバイス

IoTシナリオ用モジュール

IoT Edge Ext

計測データ、コマンド

HTTPS/AMQPS/MQTT

OS/Firmware

プロパティ、ジョブ

MqTT

“IoTシナリオアプリ”FA、医療、流通、リテール、社会インフラなど、それぞれの事業領域毎の専門アプリケーション

“IoT Edge Ext”特定の事業領域によらず、機器としての管理機能向けロジックアプリ実行状況確認、アプリやファームウェアのアップデートなど

DeviceTwin

メッセージング

Azure IoT Edge IoT Hub

Devic

es

Local Storage

Azure Machine Learning

(Container)

FunctionsRuntimeContainer

ManagementDeviceTwin

DeviceTwin

Azure Stream Analytics

(Container)

Azure Functions(Container)

Cognitive Services(Container)

Custom Code(Container)

Module Twin

Module Twin

Module Twin

Module Twin

Module Twin

Module TwinModule TwinModule TwinModule TwinModule Twin

https://microsoft.qualtrics.com/jfe/form/SV_0oknoIujzm1haOV

Microsoft Azure

セッションアンケートにご協力ください

専用アプリからご回答いただけます。

decode 2017

スケジュールビルダーで受講セッションを登録後、アンケート画面からご回答ください。

アンケートの回答時間はたったの 15 秒です!

Ask the Speaker のご案内本セッションの詳細は『Ask the Speaker Room』各コーナーカウンタにてご説明させていただきます。是非、お立ち寄りください。

© 2017 Microsoft Corporation. All rights reserved.

本情報の内容(添付文書、リンク先などを含む)は、作成日時点でのものであり、予告なく変更される場合があります。

top related