電子發(fā)燒友App

硬聲App

0
  • 聊天消息
  • 系統(tǒng)消息
  • 評(píng)論與回復(fù)
登錄后你可以
  • 下載海量資料
  • 學(xué)習(xí)在線課程
  • 觀看技術(shù)視頻
  • 寫文章/發(fā)帖/加入社區(qū)
會(huì)員中心
創(chuàng)作中心

完善資料讓更多小伙伴認(rèn)識(shí)你,還能領(lǐng)取20積分哦,立即完善>

3天內(nèi)不再提示
創(chuàng)作
電子發(fā)燒友網(wǎng)>電子資料下載>電子資料>Azure支持的AI冷凍機(jī)監(jiān)視器

Azure支持的AI冷凍機(jī)監(jiān)視器

2022-11-22 | zip | 0.22 MB | 次下載 | 免費(fèi)

資料介紹

描述

Azure 支持的 AI Freezer Monitor 是基于制造商硬件IoT 監(jiān)視器,它使用機(jī)器學(xué)習(xí) (ML) 來提供潛在設(shè)備故障的早期警告。本指南涵蓋了構(gòu)建設(shè)備、收集訓(xùn)練數(shù)據(jù)、設(shè)置電子郵件警報(bào)、訓(xùn)練自定義自動(dòng)編碼器機(jī)器學(xué)習(xí)模型以及將模型部署到 ESP32 開發(fā)板。

該項(xiàng)目旨在為低溫科學(xué)冷凍機(jī)(-60 C)提供功能,目標(biāo)是減少災(zāi)難性故障和保持備用冷凍機(jī)全時(shí)運(yùn)行的需要。但是,請(qǐng)注意,該項(xiàng)目主要用于演示和教育目的,尚未經(jīng)過廣泛的測試。

這個(gè)項(xiàng)目大約需要一個(gè)小時(shí)才能完全完成。

Azure 設(shè)置

下面有關(guān)于此示例的成本和架構(gòu)的詳細(xì)信息,但如果您只想讓它立即運(yùn)行,這里是開始的步驟。

部署資源

1. 登錄您的 Azure 帳戶

2. 單擊上面的Deploy to Azure鏈接,為該項(xiàng)目預(yù)配所有資源

作為替代方案,您可以使用Azure 門戶中的部署自定義模板服務(wù)部署模板,并在編輯器中選擇構(gòu)建您自己的模板并從該存儲(chǔ)庫上傳azuredeploy.json文件。

3.為項(xiàng)目新建資源組

4.為您的資源選擇一個(gè)區(qū)域,選擇一個(gè)靠近您以獲得最佳性能的區(qū)域

注意:某些資源并非在所有地區(qū)都可用

5. 為所有資源提供唯一名稱

注意:某些資源需要全局唯一名稱

設(shè)置 Azure 函數(shù)

1. 部署完成后,使用左側(cè)導(dǎo)航打開新功能應(yīng)用程序

2.從左側(cè)導(dǎo)航中選擇功能

3.選擇左上角的添加

4. 在窗口中選擇以下選項(xiàng):

開發(fā)環(huán)境:在門戶中開發(fā)

模板:定時(shí)器觸發(fā)器

新功能:dataSaver

您可以保留任何其他設(shè)置
poYBAGN6f9aATjuVAADI5xpT5II461.png
?

5. 創(chuàng)建函數(shù)后,從左側(cè)導(dǎo)航中選擇Code + Test

poYBAGN6f9iACEpwAABkTg_X3HI619.png
?

6. 在run.csx中,將所有現(xiàn)有代碼替換為:

// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

#r "Newtonsoft.Json"

using System;
using Newtonsoft.Json;

public static void Run(string myIoTHubMessage, ICollector outputTable, ILogger log)
{
    log.LogInformation($"C# IoT Hub trigger function processed a message: {myIoTHubMessage}");
    dynamic input = JsonConvert.DeserializeObject(myIoTHubMessage);
    Guid guid = Guid.NewGuid();
    log.LogInformation($"Message guid: {guid}");
    outputTable.Add(
            new outTable() { 
                PartitionKey = "test", 
                RowKey = guid.ToString(), 
                deviceId = input.deviceId.ToString(),
                temperature = input.Temperature}
            );
}

public class outTable
{
    public string PartitionKey { get; set; }
    public string RowKey { get; set; }
    public string deviceId { get; set; }
    public float temperature {get; set;}

}

導(dǎo)航到function.json并將所有現(xiàn)有代碼替換為:

{
    "bindings": [
      {
        "type": "eventHubTrigger",
        "name": "myIoTHubMessage",
        "direction": "in",
        "eventHubName": "samples-workitems",
        "connection": "ai-freezer-hub_events_IOTHUB",
        "consumerGroup": "$Default"
      },
      {
        "name": "outputTable",
        "direction": "out",
        "type": "table",
        "tableName": "tempTable",
        "connection": "AzureWebJobsStorage"
      }
    ]
  }

8. 使用以下選項(xiàng)對(duì)異常檢測器功能重復(fù)這些步驟:

開發(fā)環(huán)境:在門戶中開發(fā)

模板:IoT 中心(事件中心)

新功能:異常檢測器

您可以保留任何其他設(shè)置

運(yùn)行.csx:

// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

#r "Microsoft.WindowsAzure.Storage"
#r "Newtonsoft.Json"
#r "System.Text.Json"

using Microsoft.Extensions.Logging;
using Microsoft.WindowsAzure.Storage.Table;
using System.Threading.Tasks;
using System;
using System.IO;
using System.Net;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Text;
using System.Text.Json;
using System.Text.Json.Serialization;

public static readonly string emailAlertUrl = Environment.GetEnvironmentVariable("EMAIL_ALERT_URL");
public static readonly HttpClient client1 = new HttpClient();

// Anomaly detection API secrets
public static readonly string subscriptionKey = Environment.GetEnvironmentVariable("ANOMALY_DETECTOR_KEY");
public static readonly string endpoint = Environment.GetEnvironmentVariable("ANOMALY_DETECTOR_ENDPOINT");

const string latestPointDetectionUrl = "/anomalydetector/v1.0/timeseries/last/detect";
public const string batchDetectionUrl = "/anomalydetector/v1.0/timeseries/entire/detect";

public static DateTimeOffset targetTime;

public static async Task Run(TimerInfo myTimer, CloudTable inputTable, ILogger log)
{
    log.LogInformation($"C# Timer trigger function executed at: {DateTime.Now}");
    
    // Get traget time from when to start reading the data
    targetTime = DateTime.UtcNow;
    targetTime = targetTime.AddHours(-6);
    log.LogInformation($"Target start time is: {targetTime}");

    TableQuery rangeQuery = new TableQuery().Where(
        TableQuery.GenerateFilterConditionForDate("Timestamp", QueryComparisons.GreaterThan, targetTime));

    // Execute the query and loop through the results
    List data = new List();
    foreach (DataPoint entity in 
    await inputTable.ExecuteQuerySegmentedAsync(rangeQuery, null))
    {
        data.Add(new DataPoint() {Timestamp = entity.Timestamp, temperature = entity.temperature});
    }

    // Sort data by Timestamp
    data.Sort((dp1, dp2) => DateTimeOffset.Compare(dp1.Timestamp, dp2.Timestamp));
    
    List formatedData = new List();
    data.ForEach( delegate(DataPoint point)
    {
        formatedData.Add(new FormatedData() { timestamp = point.Timestamp.ToString("yyyy-MM-ddTHH:mm:00Z"), value = point.temperature});
    });

    var options = new JsonSerializerOptions
    {
        IgnoreNullValues = true,
        // PropertyNamingPolicy = new LowerCaseNamingPolicy()
    };

    List jsonFormat = new List();
    jsonFormat.Add(new JsonFormat() {series = formatedData, granularity = "minutely", customInterval = 1, period = 90, sensitivity = 85});
    string dataToSend = JsonSerializer.Serialize(jsonFormat, options);

    // Call anomaly detection API
    var anomalies = detectAnomaliesBatch(dataToSend, log);

    if (anomalies != null){
        var json = JsonSerializer.Serialize(anomalies);
        var content = new StringContent(json, Encoding.UTF8, "application/json");
        var response = await client1.PostAsync(emailAlertUrl, content);
        log.LogInformation(response.ToString());
    }
}



static async Task Request(string apiAddress, string endpoint, string subscriptionKey, string requestData)
{
    using (HttpClient client = new HttpClient { BaseAddress = new Uri(apiAddress) })
    {
        System.Net.ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls;
        client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
        client.DefaultRequestHeaders.Add("Ocp-Apim-Subscription-Key", subscriptionKey);

        var content = new StringContent(requestData, Encoding.UTF8, "application/json");
        var res = await client.PostAsync(endpoint, content);
        return await res.Content.ReadAsStringAsync();
    }
}

static string detectAnomaliesBatch(string requestData, ILogger log)
{
    log.LogInformation("Detecting anomalies as a batch");
   
    requestData = requestData.TrimEnd(']').TrimStart('[');

    //construct the request
    var result = Request(
        endpoint,
        batchDetectionUrl,
        subscriptionKey,
        requestData).Result;

    //deserialize the JSON object, and display it
    dynamic jsonObj = Newtonsoft.Json.JsonConvert.DeserializeObject(result);
    System.Console.WriteLine(jsonObj);

    string foundAnomalies = "Anomalies detected in the following data positions: ";

    if (jsonObj["code"] != null)
    {
        System.Console.WriteLine($"Detection failed. ErrorCode:{jsonObj["code"]}, ErrorMessage:{jsonObj["message"]}");
        
        log.LogInformation($"Detection failed. ErrorCode:{jsonObj["code"]}, ErrorMessage:{jsonObj["message"]}");
    }
    else
    {
        // log.LogInformation(result);
        //Find and display the positions of anomalies in the data set
        bool[] anomalies = jsonObj["isAnomaly"].ToObject<bool[]>();
        System.Console.WriteLine("\nAnomalies detected in the following data positions:");
        log.LogInformation("\nAnomalies detected in the following data positions:");
        for (var i = 0; i < anomalies.Length; i++)
        {
            if (anomalies[i])
            {
                System.Console.Write(i + ", ");
                log.LogInformation(i + ", ");
                foundAnomalies += i;
                foundAnomalies += ", ";
            }
        }
        if (anomalies.Any(item => item == true))
        {
            return foundAnomalies;
        }
    }
    return null;
}

public class FormatedData
{
    public string timestamp { get; set; }
    public string value { get; set; }
}

public class DataPoint : TableEntity
{
    [JsonPropertyName("value")]
    public string temperature { get; set;}
    public string timestamp { get; set; }
    
}

public class JsonFormat
{
    public List series { get; set; }
    public string granularity { get; set; }
    public int customInterval { get; set; }
    public int period { get; set; }
    // public float maxAnomalyRatio { get; set; }
    public int sensitivity { get; set; }
}

public class LowerCaseNamingPolicy : JsonNamingPolicy
{
    public override string ConvertName(string name) =>
        name.ToLower();
}

函數(shù).json:

// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

#r "Microsoft.WindowsAzure.Storage"
#r "Newtonsoft.Json"
#r "System.Text.Json"

using Microsoft.Extensions.Logging;
using Microsoft.WindowsAzure.Storage.Table;
using System.Threading.Tasks;
using System;
using System.IO;
using System.Net;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Text;
using System.Text.Json;
using System.Text.Json.Serialization;

public static readonly string emailAlertUrl = Environment.GetEnvironmentVariable("EMAIL_ALERT_URL");
public static readonly HttpClient client1 = new HttpClient();

// Anomaly detection API secrets
public static readonly string subscriptionKey = Environment.GetEnvironmentVariable("ANOMALY_DETECTOR_KEY");
public static readonly string endpoint = Environment.GetEnvironmentVariable("ANOMALY_DETECTOR_ENDPOINT");

const string latestPointDetectionUrl = "/anomalydetector/v1.0/timeseries/last/detect";
public const string batchDetectionUrl = "/anomalydetector/v1.0/timeseries/entire/detect";

public static DateTimeOffset targetTime;

public static async Task Run(TimerInfo myTimer, CloudTable inputTable, ILogger log)
{
    log.LogInformation($"C# Timer trigger function executed at: {DateTime.Now}");
    
    // Get traget time from when to start reading the data
    targetTime = DateTime.UtcNow;
    targetTime = targetTime.AddHours(-6);
    log.LogInformation($"Target start time is: {targetTime}");

    TableQuery rangeQuery = new TableQuery().Where(
        TableQuery.GenerateFilterConditionForDate("Timestamp", QueryComparisons.GreaterThan, targetTime));

    // Execute the query and loop through the results
    List data = new List();
    foreach (DataPoint entity in 
    await inputTable.ExecuteQuerySegmentedAsync(rangeQuery, null))
    {
        data.Add(new DataPoint() {Timestamp = entity.Timestamp, temperature = entity.temperature});
    }

    // Sort data by Timestamp
    data.Sort((dp1, dp2) => DateTimeOffset.Compare(dp1.Timestamp, dp2.Timestamp));
    
    List formatedData = new List();
    data.ForEach( delegate(DataPoint point)
    {
        formatedData.Add(new FormatedData() { timestamp = point.Timestamp.ToString("yyyy-MM-ddTHH:mm:00Z"), value = point.temperature});
    });

    var options = new JsonSerializerOptions
    {
        IgnoreNullValues = true,
        // PropertyNamingPolicy = new LowerCaseNamingPolicy()
    };

    List jsonFormat = new List();
    jsonFormat.Add(new JsonFormat() {series = formatedData, granularity = "minutely", customInterval = 1, period = 90, sensitivity = 85});
    string dataToSend = JsonSerializer.Serialize(jsonFormat, options);

    // Call anomaly detection API
    var anomalies = detectAnomaliesBatch(dataToSend, log);

    if (anomalies != null){
        var json = JsonSerializer.Serialize(anomalies);
        var content = new StringContent(json, Encoding.UTF8, "application/json");
        var response = await client1.PostAsync(emailAlertUrl, content);
        log.LogInformation(response.ToString());
    }
}



static async Task Request(string apiAddress, string endpoint, string subscriptionKey, string requestData)
{
    using (HttpClient client = new HttpClient { BaseAddress = new Uri(apiAddress) })
    {
        System.Net.ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls;
        client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
        client.DefaultRequestHeaders.Add("Ocp-Apim-Subscription-Key", subscriptionKey);

        var content = new StringContent(requestData, Encoding.UTF8, "application/json");
        var res = await client.PostAsync(endpoint, content);
        return await res.Content.ReadAsStringAsync();
    }
}

static string detectAnomaliesBatch(string requestData, ILogger log)
{
    log.LogInformation("Detecting anomalies as a batch");
   
    requestData = requestData.TrimEnd(']').TrimStart('[');

    //construct the request
    var result = Request(
        endpoint,
        batchDetectionUrl,
        subscriptionKey,
        requestData).Result;

    //deserialize the JSON object, and display it
    dynamic jsonObj = Newtonsoft.Json.JsonConvert.DeserializeObject(result);
    System.Console.WriteLine(jsonObj);

    string foundAnomalies = "Anomalies detected in the following data positions: ";

    if (jsonObj["code"] != null)
    {
        System.Console.WriteLine($"Detection failed. ErrorCode:{jsonObj["code"]}, ErrorMessage:{jsonObj["message"]}");
        
        log.LogInformation($"Detection failed. ErrorCode:{jsonObj["code"]}, ErrorMessage:{jsonObj["message"]}");
    }
    else
    {
        // log.LogInformation(result);
        //Find and display the positions of anomalies in the data set
        bool[] anomalies = jsonObj["isAnomaly"].ToObject<bool[]>();
        System.Console.WriteLine("\nAnomalies detected in the following data positions:");
        log.LogInformation("\nAnomalies detected in the following data positions:");
        for (var i = 0; i < anomalies.Length; i++)
        {
            if (anomalies[i])
            {
                System.Console.Write(i + ", ");
                log.LogInformation(i + ", ");
                foundAnomalies += i;
                foundAnomalies += ", ";
            }
        }
        if (anomalies.Any(item => item == true))
        {
            return foundAnomalies;
        }
    }
    return null;
}

public class FormatedData
{
    public string timestamp { get; set; }
    public string value { get; set; }
}

public class DataPoint : TableEntity
{
    [JsonPropertyName("value")]
    public string temperature { get; set;}
    public string timestamp { get; set; }
    
}

public class JsonFormat
{
    public List series { get; set; }
    public string granularity { get; set; }
    public int customInterval { get; set; }
    public int period { get; set; }
    // public float maxAnomalyRatio { get; set; }
    public int sensitivity { get; set; }
}

public class LowerCaseNamingPolicy : JsonNamingPolicy
{
    public override string ConvertName(string name) =>
        name.ToLower();
}

配置邏輯應(yīng)用

1. 部署完成后,使用左側(cè)導(dǎo)航打開新創(chuàng)建的 Logic App

2.從左側(cè)導(dǎo)航中選擇邏輯應(yīng)用程序設(shè)計(jì)器

3.選擇+新步驟

4. 搜索您要使用的電子郵件客戶端(Office 365 Outlook、Gmail 和 Outlook.com)

poYBAGN6f9-AFqx7AAA-9pe8Y9k475.png
Azure 邏輯應(yīng)用設(shè)計(jì)器
?

5. 選擇發(fā)送電子郵件操作

注意:這將根據(jù)您使用的電子郵件客戶端而有所不同

6. 使用您的電子郵件帳戶登錄

7. 自定義您的消息,此電子郵件將在任何時(shí)候檢測到異常時(shí)發(fā)送。

設(shè)置物聯(lián)網(wǎng)設(shè)備

1. 接下來,您需要獲取設(shè)備的連接字符串,導(dǎo)航到您之前創(chuàng)建的 IoT 中心

2.在左側(cè)導(dǎo)航中選擇物聯(lián)網(wǎng)設(shè)備

3.在頁面左上角選擇+新建

4.給設(shè)備一個(gè)ID

pYYBAGN6f-qAbWCDAABjuP9k5kk826.png
物聯(lián)網(wǎng)設(shè)備配置
?

5. 按屏幕底部的保存

6.選擇您創(chuàng)建的設(shè)備

7. 復(fù)制您將在下一節(jié)中使用的主連接字符串

pYYBAGN6f-2AVrTKAAB7a9HJXb0269.png
IoT 設(shè)備的連接字符串
?

設(shè)備構(gòu)建

pYYBAGN6f--Af-MvAACU92IQLgI779.jpg
溫度監(jiān)視器的完整構(gòu)建
?

1. 將螺絲端子焊接到 MCP9600 的頂部。

poYBAGN6f_KAfuIDAACM8kZfLJc876.jpg
?

2. 將引腳焊接到 MCP9600 的底部。

提示:將引腳放在面包板上,以便在焊接時(shí)將它們固定到位。
poYBAGN6f_WANeCIAACz9xdzg7I342.jpg
?

3. 將 ESP32 和熱電偶放大器插入面包板。

4. 按照下面的接線圖,使用跳線將熱電偶放大器連接到 ESP32。

poYBAGN6f_eAZF56AAEbGfX1bgY829.png
?

5. 將熱電偶連接到 MCP9600 上的螺絲端子

下圖使用通用 ESP32 開發(fā)板,即將推出帶有 Adafruit Huzzah32 的新圖片!
pYYBAGN6f_qAa_mCAADAL9fVRks425.jpg
?

設(shè)備代碼

1. 如果您還沒有,請(qǐng)將此 repo 克隆到您的計(jì)算機(jī)

2.用VS Code打開AiFreezer文件夾

3.在這個(gè)文件夾中新建一個(gè)文件,命名為config.h

4. 將以下代碼粘貼到config.h

const char* ssid     = "";
const char* password = "";
static const char* connectionString = "";

5. 填寫您的網(wǎng)絡(luò)憑據(jù)

6. 從 IoT 中心粘貼連接字符串

7. 按照本 [指南] 的第一部分將 ESP32 擴(kuò)展添加到 Arduino IDE。

8. 使用 Arduino 的庫管理器安裝下面列出的庫。如果您在 [此處]之前使用過庫管理器,這是一個(gè)有用的指南。

9. Adafruit MCP9600

注意:如果系統(tǒng)提示您為這些庫安裝其他依賴項(xiàng),請(qǐng)選擇全部安裝

10. 在 VS Code 中打開 FreezerTempAlert.ino,打開命令面板(CTL+SHIFT+P)并輸入Arduino:Change Board Type然后搜索Adafruit ESP32 Feather

11.接下來選擇活動(dòng)串口,打開命令面板并輸入Arduino:選擇串口

12. 最后將您的代碼上傳到您的羽毛板,打開命令面板并輸入Arduino:


下載該資料的人也在下載 下載該資料的人還在閱讀
更多 >

評(píng)論

查看更多

下載排行

本周

  1. 1山景DSP芯片AP8248A2數(shù)據(jù)手冊(cè)
  2. 1.06 MB  |  532次下載  |  免費(fèi)
  3. 2RK3399完整板原理圖(支持平板,盒子VR)
  4. 3.28 MB  |  339次下載  |  免費(fèi)
  5. 3TC358743XBG評(píng)估板參考手冊(cè)
  6. 1.36 MB  |  330次下載  |  免費(fèi)
  7. 4DFM軟件使用教程
  8. 0.84 MB  |  295次下載  |  免費(fèi)
  9. 5元宇宙深度解析—未來的未來-風(fēng)口還是泡沫
  10. 6.40 MB  |  227次下載  |  免費(fèi)
  11. 6迪文DGUS開發(fā)指南
  12. 31.67 MB  |  194次下載  |  免費(fèi)
  13. 7元宇宙底層硬件系列報(bào)告
  14. 13.42 MB  |  182次下載  |  免費(fèi)
  15. 8FP5207XR-G1中文應(yīng)用手冊(cè)
  16. 1.09 MB  |  178次下載  |  免費(fèi)

本月

  1. 1OrCAD10.5下載OrCAD10.5中文版軟件
  2. 0.00 MB  |  234315次下載  |  免費(fèi)
  3. 2555集成電路應(yīng)用800例(新編版)
  4. 0.00 MB  |  33566次下載  |  免費(fèi)
  5. 3接口電路圖大全
  6. 未知  |  30323次下載  |  免費(fèi)
  7. 4開關(guān)電源設(shè)計(jì)實(shí)例指南
  8. 未知  |  21549次下載  |  免費(fèi)
  9. 5電氣工程師手冊(cè)免費(fèi)下載(新編第二版pdf電子書)
  10. 0.00 MB  |  15349次下載  |  免費(fèi)
  11. 6數(shù)字電路基礎(chǔ)pdf(下載)
  12. 未知  |  13750次下載  |  免費(fèi)
  13. 7電子制作實(shí)例集錦 下載
  14. 未知  |  8113次下載  |  免費(fèi)
  15. 8《LED驅(qū)動(dòng)電路設(shè)計(jì)》 溫德爾著
  16. 0.00 MB  |  6656次下載  |  免費(fèi)

總榜

  1. 1matlab軟件下載入口
  2. 未知  |  935054次下載  |  免費(fèi)
  3. 2protel99se軟件下載(可英文版轉(zhuǎn)中文版)
  4. 78.1 MB  |  537798次下載  |  免費(fèi)
  5. 3MATLAB 7.1 下載 (含軟件介紹)
  6. 未知  |  420027次下載  |  免費(fèi)
  7. 4OrCAD10.5下載OrCAD10.5中文版軟件
  8. 0.00 MB  |  234315次下載  |  免費(fèi)
  9. 5Altium DXP2002下載入口
  10. 未知  |  233046次下載  |  免費(fèi)
  11. 6電路仿真軟件multisim 10.0免費(fèi)下載
  12. 340992  |  191187次下載  |  免費(fèi)
  13. 7十天學(xué)會(huì)AVR單片機(jī)與C語言視頻教程 下載
  14. 158M  |  183279次下載  |  免費(fèi)
  15. 8proe5.0野火版下載(中文版免費(fèi)下載)
  16. 未知  |  138040次下載  |  免費(fèi)