Twitter icon
Facebook icon
LinkedIn icon
Google icon
Reddit icon
StumbleUpon icon icon

Azure Cost Monitor

Added to IoTplaybook or last updated on: 06/02/2021
Azure Cost Monitor


When using Microsoft Azure services, it's helpful to know how much you're spending on a day-to-day basis. This Azure cost monitor uses the low-power, wireless Adafruit MagTag board to display a daily cost forecast for your Azure subscription.*

This project is intended to show you how to use the Azure cost management API. Take a look at this project and adapt it to fit your needs!

Please note that it's only possible to get a cost forecast -- actual costs are only available once you're billed.

Things used in this project

Hardware components

Adafruit MagTag Starter Kit
× 1


Adafruit USB Type A to Type C
× 1


Software apps and online services

VS Code
Microsoft VS Code

Visual Studio

Microsoft Azure
Microsoft Azure
  Microsoft Azure

Step 1: Get Azure Credentials

The way we'll get the cost forecast of your Azure subscription is by registering an application on Azure. This allows you to make REST API calls directly from the MagTag using secure credentials. To do this, you'll create a Service Principal using the Azure CloudShell.

1. Log into the Azure portal.

CloudShell Icon

CloudShell Icon

2. Click on the CloudShell icon as shown in the photo above.

If this is the first time you're using CloudShell you'll need to select a storage account to use it with.

Note: using a storage account for this project costs <$0.01 a day.

For more info on CloudShell visit this site.


Get your Azure credentials

Get your Azure credentials

3. Once the CLI loads type and run:

az ad sp create-for-rbac --name [APP_NAME]Replace "[APP_NAME]" with a name like "cost-monitor"

Grab and save your Azure credentials

Grab and save your Azure credentials

4. Save Credentials

Copy the APP ID, PASSWORD, and TENANT ID and save into a secure location. We'll need this later for the MagTag's file.

Step 2: Install CircuitPython and CircuitPython Libraries

CircuitPython is a derivative of MicroPython designed to simplify experimentation and education on low-cost microcontrollers. It makes it easier than ever to get prototyping by requiring no upfront desktop software downloads. Simply copy and edit files on the CIRCUITPY drive to iterate.

1. Get CircuitPythonfiles.

Download the latest CircuitPython release for your board here.

2. Follow thisinstallation guide on Adafruit Learn!

CircuitPython installation varies depending on which board you're using. Follow the Adafruit Guide for the MagTag to install CircuitPython.

3. Download CircuitPython libraries here.

Download the adafruit-circuitpython-bundle-version-mpy-*.zip bundle zip file, and unzip a folder of the same name. Inside you'll find a lib folder. The entire collection of libraries is too large to fit on the CIRCUITPY drive. Instead, add each library as you need it, this will reduce the space usage but you'll need to put in a little more effort.

You will need a few libraries for this project. Be sure that you have the following libraries in the CIRCUITPY/lib directory on your MagTag:

  • adafruit_bitmap_font
  • adafruit_bus_device
  • adafruit_display_text
  • adafruit_io
  • adafruit_magtag
  • adafruit_portalbase
  • adafruit_rsa
  • adafruit_binascii.mpy
  • adafruit_fakerequests.mpy
  • adafruit_logging.mpy
  • adafruit_miniqr.mpy
  • adafruit_pyportal.mpy
  • adafruit_requests.mpy
  • neopixel.mpy
  • simpleio.mpy


Azure Cost Monitor

Code for programming the Adafruit MagTag (or other ESP32S2 board) to monitor costs for your Azure subscription.

microsoft / azure-cost-monitor

Read More

Latest commit to the master branch on 2-3-2021

Download as zip


Jen Fox

Jen Fox

Dabbled in dark matter, settled into engineering w/ a blend of inventing and education! Sr.PM @ Microsoft Founder/CEO of FoxBot Industries.


Adi Azulay

Adi Azulay

Software Engineer at Microsoft, working in the Office of the CTO. Exploring what the future of maker technologies hold.


This content is provided by our content partner, an Avnet developer community for learning, programming, and building hardware. Visit them online for more great content like this.

This article was originally published at It was added to IoTplaybook or last modified on 06/02/2021.