Giter Club home page Giter Club logo

ai-freezer-azure's Introduction

Azure Powered AI Freezer Monitor

The Azure Powered AI Freezer Monitor is a maker hardware based IoT monitor that uses machine learning, or ML, to provide early warnings of potential equipment failure. This guide covers building the device, collecting training data, setting up email alerts, training a custom auto encoder machine learning model, and deploying the model to an ESP32 development board.

The project is designed to be functional for low temperature scientific freezers (-60 C), with the goal of reducing catastrophic failure and the need to keep backup freezers running full-time. However, please note that this project is primarily for demonstrative and educational purposes and has not gone through extensive testing.

This project takes about one hour to fully complete.

Prerequisites

  1. An active Azure account. If you don't have one, you can sign up for a free account.
  2. VS Code with the Arduino extension installed
  3. Hardware specified below (if you'd like to use a different device refer to the message specifications)

Materials and Tools

Materials Description Vendor
Adafruit Feather Huzzah32 (a) WiFi enabled ESP32 based prototyping board Adafruit
Adafruit MCP9600 (b) I2C Thermocouple amplifier Adafruit
Adafruit Type K Thermocouple (c) 2 wire thermocouple effective temperature ranger -200c to 800c +/-2c Adafruit
Jumper Wires (d) Adafruit
Breadboard (e) Adafruit
Micro USB cable Used to power the ESP32 board Adafruit
USB Power Supply Adafruit
Tools
00 Philips Head Screw Driver
Soldering Iron

Picture of all the materials used in the project

Project Setup

There are details below about the cost and architecture of this sample, but if you just want to get it running right away here are the steps to get started.

Azure Setup

Deploy to Azure

Deploy Resources

  1. Log in to your Azure account
  2. Click the Deploy to Azure button above to provision all the resources for this project

    As an alternative you can deploy the template by using the Deploy Custom Template service in the Azure portal, and selecting Build your own template in the editor and uploading the azuredeploy.json file from this repo.

  3. Create a new resource group for the project
  4. Select a region for the your resources, choose one that near you for the best performance

    Note: Some resources aren't available in all regions.

  5. Provide names for all the resources

Setup Azure Functions

  1. Once your deployment is complete use the left navigation to open you new functions app

  2. Select Functions from the left navigation

  3. Select Add in the top left

  4. Select the following options in the window:

    Development environment: Develop in portal

    Template: Timer trigger

    New Function: dataSaver

    you can leave any other settings as they are

    Add new function setup menu

  5. Once the function is created select Code + Test from the left navigation.

  6. In run.csx, replace all the existing code with the code from here

  7. Navigate to function.json and replace all the existing code there with the code form here

    Changing files in portal editor

  8. Repeat these steps for the anomaly detector function using the options below:

    Development environment: Develop in portal

    Template: IoT Hub (Event Hub)

    New Function: anomalyDetector

    you can leave any other settings as they are

    run.csx code

    function.json code

Configure Logic App

  1. Once the deployment is complete use the left navigation to open the newly created Logic App
  2. Select Logic app designer from the left navigation
  3. Select + New step
  4. Search for the email client you'd like to use (Office 365 Outlook, Gmail, and Outlook.com) Image of Azure Logic Apps
  5. Select the Send an email action

    Note: This will be a little different depending on which email client you use

  6. Log in with your email account
  7. Customize your message, this email will be sent any time an anomaly is detected.

Set up IoT Device

  1. Next you'll need to get the connection string for you device, navigate to the IoT Hub you created earlier
  2. In the left navigation select IoT devices
  3. At the top left of the page select + New
  4. Give the device an ID IoT hub device creation
  5. Press Save at the bottom of the screen
  6. Select the device you created
  7. Copy the Primary Connection String you'll use this string in the next section IoT hub device keys and strings

Device Build

Build

  1. Solder the screw terminal to the top side of your MCP9600.

  2. Solder the pins to the bottom side of the MCP9600.

    Tip: Put the pins in the breadboard to hold them in place when soldering.

  3. Insert the ESP32 and thermocouple amplifier into the breadboard.

  4. Follow the wiring diagram below to connect the thermocouple amplifier to the ESP32 using your jumper wires.

  5. Connect the Thermocouple to the screw terminals on the MCP9600

    The picture below use a generic ESP32 Dev board, new picture with the Adafruit Huzzah32 coming soon!

Code

  1. If you haven't already, clone this repo to your computer

  2. Open the AiFreezer folder with VS Code

  3. Create a new file in this folder and name it config.h

  4. Paste the code below in config.h

    const char* ssid     = "<YOUR-NETWORK-NAME>";
    const char* password = "<YOUR-WIFI-PASSWORD>";
    
    static const char* connectionString = "<YOUR-CONNECTION-STRING>";
  5. Fill in your network credentials

  6. Paste the connection string from IoT Hub

  7. Follow the first section of this guide to add the ESP32 extension to the Arduino IDE.

  8. Install the library listed below using Arduino's Library manager. If you have used the library manager before here is a helpful guide.

    1. Adafruit MCP9600

    Note: If you're prompted to install other dependencies for these libraries, select Install All

  9. With FreezerTempAlert.ino open in the VS Code open the command palette (CTL+SHIFT+P) and type in Arduino: Change Board Type then search Adafruit ESP32 Feather

  10. Next select the the active serial port, open the command palette and type in Arduino: Select Serial Port

  11. Finally upload your code to your Feather board, open the command palette and type in Arduino: Upload

Cost

While an Azure account is free, using resources will incur a cost. Some of the resources offer a free version, we've compiled an estimate costs to run this project per month. If your account is new you should receive a $200 credit which should cover about five and a half years of these services.

Resource Free Tier Cost
IoT Hub Yes $0
Azure Functions Yes $0
Azure Table Storage No $1
Anomaly detection cognitive service Yes $0
Logic Apps No $1
Total ~$2

Azure Budgets

It's a good idea to also set up a budget for resource group (don't worry if you don't know what all these terms mean yet, we'll explain everything as we go). An Azure budget will send you email warning you that you've reached the amount specified. It won't turn off your services, so you will still have to log in and turn off any service you no longer want to be charged for. We've included a budget set at $5/mo as part of the Azure template, but if you want to learn more about costs on Azure, here is a good starting place.

Azure Resources

Resources are what tools and services on Azure are called. You'll use a variety of resources for this project. Some of them for compute, some for storage, others are hubs that act as connectors. Below is a list of the resources used in this project and links to where you can learn more about them.

Resource Description
IoT Hub Managed service for bidirectional communication between IoT devices and Azure
Azure Functions Event-driven serverless compute platform
Azure Table Storage NoSQL key-value store
Anomaly detection cognitive service An AI service that helps you foresee problems before they occur
Logic Apps No code platform for integration solutions

Message Specification

The message sent from your device should be a JSON formatted string and needs to include a device id as a string and the temperature reading as a float. You should send exactly 1 data point per minute.

{"deviceId":"ESP32_device", "temperature": 25.235}

The anomaly detection service expected message to be evenly timed. Using a delay or an internal counter on the device is not sufficient, we recommend using an NTP server to synchronize the time the messages are sent.

Contributing

This project welcomes contributions and suggestions. Most contributions require you to agree to a Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us the rights to use your contribution. For details, visit https://cla.opensource.microsoft.com.

When you submit a pull request, a CLA bot will automatically determine whether you need to provide a CLA and decorate the PR appropriately (e.g., status check, comment). Simply follow the instructions provided by the bot. You will only need to do this once across all repos using our CLA.

This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact [email protected] with any additional questions or comments.

ai-freezer-azure's People

Contributors

adiazulay avatar microsoftopensource avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.