欧美一级特黄大片做受成人-亚洲成人一区二区电影-激情熟女一区二区三区-日韩专区欧美专区国产专区

如何使用DPS通過對稱密鑰進行設(shè)備組注冊?-創(chuàng)新互聯(lián)

圖文講解:

1. 在DPS添加組注冊:

如何使用DPS通過對稱密鑰進行設(shè)備組注冊?

為潛山等地區(qū)用戶提供了全套網(wǎng)頁設(shè)計制作服務,及潛山網(wǎng)站建設(shè)行業(yè)解決方案。主營業(yè)務為做網(wǎng)站、成都網(wǎng)站設(shè)計、潛山網(wǎng)站設(shè)計,以傳統(tǒng)方式定制建設(shè)網(wǎng)站,并提供域名空間備案等一條龍服務,秉承以專業(yè)、用心的態(tài)度為用戶提供真誠的服務。我們深信只要達到每一位用戶的要求,就會得到認可,從而選擇與我們長期合作。這樣,我們也可以走得更遠!

注意:組注冊中,沒有注冊ID的概念,也沒有Device ID的概念。

機制

有三種:x509證書,對稱密鑰

在本例中,我們使用對稱密鑰方式以便我們快速理解和驗證組注冊的業(yè)務邏輯;

密鑰我們采用自動生成,當然也可以手動輸入符合要求的自定義密鑰;

注意:本文中使用對稱密鑰方式做演示,后續(xù)章節(jié)介紹X509證書的方式,證書也是推薦的海量設(shè)備方案中應用的方案。

如何分配設(shè)備到中心

  1. 最低延遲:將設(shè)備預配到具有最低延遲的 IoT 中心,注意最低延遲不是指地理位置,例如中國北部的設(shè)備根據(jù)網(wǎng)絡情況可能出現(xiàn)分配到中國東部IoT Hub的情況。

  2. 均勻加權(quán)分發(fā)(默認):鏈接的 IoT 中心等可能地獲得預配到它們的設(shè)備。 此設(shè)置為默認設(shè)置。 如果只將設(shè)備預配到一個 IoT 中心,則可以保留此設(shè)置。

  3. 通過注冊列表進行靜態(tài)配置:注冊列表中所需 IoT 中心的規(guī)范優(yōu)先于設(shè)備預配服務級別的分配策略。

  4. 使用Azure Function(自定義):該方案可以使用自定義邏輯判斷分發(fā)到哪個IoT Hub。

在本例中,我們只配置了一個IoT Hub,因此采用默認的均勻加權(quán)即可。

初始設(shè)備孿生狀態(tài)

例如可以設(shè)置版本號為 1.11,會按照device twin的邏輯進行版本升級;

添加之后的狀態(tài)為:

如何使用DPS通過對稱密鑰進行設(shè)備組注冊?

注冊記錄為空:

如何使用DPS通過對稱密鑰進行設(shè)備組注冊?

2.準備示例代碼

項目中使用的示例代碼,https://codeload.github.com/Azure-Samples/azure-iot-samples-csharp/zip/master

關(guān)鍵處請參加如下代碼中的中文注釋:

// Copyright (c) Microsoft. All rights reserved.// Licensed under the MIT license. See LICENSE file in the project root for full license information.using Microsoft.Azure.Devices.Provisioning.Client;using Microsoft.Azure.Devices.Provisioning.Client.Samples;using Microsoft.Azure.Devices.Provisioning.Client.Transport;using Microsoft.Azure.Devices.Shared;using System;using System.Security.Cryptography;using System.Text;namespace SymmetricKeySample{    class Program     {        // The Provisioning Hub IDScope.         // For this sample either:         // - pass this value as a command-prompt argument         // - set the DPS_IDSCOPE environment variable          // - create a launchSettings.json (see launchSettings.json.template) containing the variable         //private static string s_idScope = Environment.GetEnvironmentVariable("DPS_IDSCOPE");         private static string s_idScope = "此處需要修改成dps的ID";        // In your Device Provisioning Service please go to "Manage enrollments" and select "Individual Enrollments".         // Select "Add individual enrollment" then fill in the following:         // Mechanism: Symmetric Key         // Auto-generate keys should be checked         // DeviceID: iothubSymmetricKeydevice1         // Symmetric Keys may also be used for enrollment groups.         // In your Device Provisioning Service please go to "Manage enrollments" and select "Enrollment Groups".         // Select "Add enrollment group" then fill in the following:         // Group name: <your  group name>         // Attestation Type: Symmetric Key         // Auto-generate keys should be checked         // You may also change other enrollment group parameters according to your needs                 //private const string GlobalDeviceEndpoint = "global.azure-devices-provisioning.net";         //此處應該改成中國的終結(jié)點.CN結(jié)尾         private const string GlobalDeviceEndpoint = "global.azure-devices-provisioning.cn";        //These are the two keys that belong to your enrollment group.          // Leave them blank if you want to try this sample for an individual enrollment instead         private const string enrollmentGroupPrimaryKey = "僅當使用組注冊時,必須填寫此值";        private const string enrollmentGroupSecondaryKey = "僅當使用組注冊時,必須填寫此值";        //registration id for enrollment groups can be chosen arbitrarily and do not require any portal setup.          //The chosen value will become the provisioned device's device id.         //         //registration id for individual enrollments must be retrieved from the portal and will be unrelated to the provioned         //device's device id         //         //This field is mandatory to provide for this sample         private static string registrationId = "對于組注冊,此處為待注冊的設(shè)備DeviceID,通常填寫諸如MAC地址等唯一值";        //These are the two keys that belong to your individual enrollment.          // Leave them blank if you want to try this sample for an individual enrollment instead         private const string individualEnrollmentPrimaryKey = "";        private const string individualEnrollmentSecondaryKey = "";        public static int Main(string[] args)         {            if (string.IsNullOrWhiteSpace(s_idScope) && (args.Length > 0))             {                 s_idScope = args[0];             }            if (string.IsNullOrWhiteSpace(s_idScope))             {                 Console.WriteLine("ProvisioningDeviceClientSymmetricKey <IDScope>");                return 1;             }            string primaryKey = "";            string secondaryKey = "";            if (!String.IsNullOrEmpty(registrationId) && !String.IsNullOrEmpty(enrollmentGroupPrimaryKey) && !String.IsNullOrEmpty(enrollmentGroupSecondaryKey))             {                //Group enrollment flow, the primary and secondary keys are derived from the enrollment group keys and from the desired registration id                 //注意,此處的primaryKey和secondryKey即IoT Hub中新增Device 的primaryKey和secondryKey                 primaryKey = ComputeDerivedSymmetricKey(Convert.FromBase64String(enrollmentGroupPrimaryKey), registrationId);                 secondaryKey = ComputeDerivedSymmetricKey(Convert.FromBase64String(enrollmentGroupSecondaryKey), registrationId);             }            else if (!String.IsNullOrEmpty(registrationId) && !String.IsNullOrEmpty(individualEnrollmentPrimaryKey) && !String.IsNullOrEmpty(individualEnrollmentSecondaryKey))             {                //Individual enrollment flow, the primary and secondary keys are the same as the individual enrollment keys                 primaryKey = individualEnrollmentPrimaryKey;                 secondaryKey = individualEnrollmentSecondaryKey;             }            else             {                 Console.WriteLine("Invalid configuration provided, must provide group enrollment keys or individual enrollment keys");                return -1;             }            using (var security = new SecurityProviderSymmetricKey(registrationId, primaryKey, secondaryKey))            // Select one of the available transports:             // To optimize for size, reference only the protocols used by your application.             using (var transport = new ProvisioningTransportHandlerAmqp(TransportFallbackType.TcpOnly))            // using (var transport = new ProvisioningTransportHandlerHttp())             // using (var transport = new ProvisioningTransportHandlerMqtt(TransportFallbackType.TcpOnly))             // using (var transport = new ProvisioningTransportHandlerMqtt(TransportFallbackType.WebSocketOnly))             {                 ProvisioningDeviceClient provClient =                     ProvisioningDeviceClient.Create(GlobalDeviceEndpoint, s_idScope, security, transport);                var sample = new ProvisioningDeviceClientSample(provClient, security);                 sample.RunSampleAsync().GetAwaiter().GetResult();             }             Console.WriteLine("Enter any key to exit");             Console.ReadLine();            return 0;         }        /// <summary>         /// Generate the derived symmetric key for the provisioned device from the enrollment group symmetric key used in attestation         /// </summary>         /// <param name="masterKey">Symmetric key enrollment group primary/secondary key value</param>         /// <param name="registrationId">the registration id to create</param>         /// <returns>the primary/secondary key for the member of the enrollment group</returns>         public static string ComputeDerivedSymmetricKey(byte[] masterKey, string registrationId)         {            using (var hmac = new HMACSHA256(masterKey))             {                return Convert.ToBase64String(hmac.ComputeHash(Encoding.UTF8.GetBytes(registrationId)));             }         }     } }

3.運行程序,得到分配的IoT Hub名稱以及DeviceID

設(shè)備側(cè)程序可以得到IoT Hub的名稱,設(shè)備的ID,加上代碼里的key,則具備了連接IoT Hub的所有參數(shù),此時可以直接連接到IoT Hub。

如何使用DPS通過對稱密鑰進行設(shè)備組注冊?

此時,可以在組注冊中的注冊列表中看到對應的注冊記錄:

如何使用DPS通過對稱密鑰進行設(shè)備組注冊?

此時,在IoT Hub中能夠看到由DPS注冊過來的Device:

如何使用DPS通過對稱密鑰進行設(shè)備組注冊?

將代碼中的  private static string registrationId = "對于組注冊,此處為待注冊的設(shè)備DeviceID,通常填寫諸如MAC地址等唯一值"; 替換,可以通過DPS的這個組注冊添加多臺設(shè)備到IoT Hub中:

如何使用DPS通過對稱密鑰進行設(shè)備組注冊?

另外有需要云服務器可以了解下創(chuàng)新互聯(lián)cdcxhl.cn,海內(nèi)外云服務器15元起步,三天無理由+7*72小時售后在線,公司持有idc許可證,提供“云服務器、裸金屬服務器、高防服務器、香港服務器、美國服務器、虛擬主機、免備案服務器”等云主機租用服務以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡單易用、服務可用性高、性價比高”等特點與優(yōu)勢,專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應用場景需求。

網(wǎng)頁名稱:如何使用DPS通過對稱密鑰進行設(shè)備組注冊?-創(chuàng)新互聯(lián)
本文路徑:http://aaarwkj.com/article46/pjdeg.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站制作、網(wǎng)站策劃、品牌網(wǎng)站設(shè)計、定制網(wǎng)站、建站公司、動態(tài)網(wǎng)站

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

成都定制網(wǎng)站網(wǎng)頁設(shè)計
精品毛片av一区二区三区| 色婷婷综合激情一区二区| 亚洲成人av网址大全| 欧美口爆吞精在线播放| 欧美亚洲国产精品久久久| 亚洲七七久久精品中文国产| 日本一级黄色影视大全| 18禁的视频在线观看| 国产美女冒白浆视频免费| 日本成熟妇高潮视频在线观看不卡| 不卡的av中文字幕在线播放| 男人天堂插插综合搜索| 国产三级成人在线视频| 国产精品一级性生活片| 国产91人妻精品一区二区三区| 日本午夜一区二区在线观看| 国产产品在线免费看91| 精品欧美高清免费视频| 欧美日韩一区精品视频| 麻豆视频传媒入口在线播放| 欧美人妻精品一区二区| 人妻少妇久久中文字幕久久| 国产精品自产在线观看一| 91免费视频精品麻豆| 亚洲国产精品二区三区| 精品人妻一区二区三区乱码| 国产自拍免费在线观看视频| av一区二区三区三| 中文字幕一区二区中文字幕| 日韩视频在线不卡观看| 白白色最新福利视频二| 日本在线一区二区不卡视频 | 日本黄色中文字幕网站| 久久精品色妇熟妇丰满人妻| 亚洲精品国产av成人| 黄色成人av免费看| 91熟女成人精品一区二区| 精品国产一区二区三级四区| 91久久国产香蕉熟女| 亚洲综合色一区二区三区小说| 老熟妇仑乱换频一区二区|