Introduction and Use Case:

This project is intended to demonstrate a real-world use-case for leveraging the Azure cost management API with an ESP32/wireless enabled EInk IoT display device

In this post, we will create and/or leverage the following:

πŸ‘‰1. Azure Requirements:

  • An Azure Web App & Assign an RBAC Role
  • AppID
  • Password
  • TenantID
  • SubscriptionID
  • Assign Cost Management Reader Privileges to Subscription

πŸ‘‰2. Software Requirements:

  • Generate a secrets.py file
  • Deploy Circuit Python locally & Connect to Azure cost management API

πŸ‘‰3. Hardware Requirements:

  • Connect a battery and magnets so it can run on any magnetic surface (whiteboard, fridge, etc.) completely wirelessly

Create Azure Web App & Assign RBAC Role

  • Login to the Azure Portal

  • Select the CloudShell button illustrated below:

  • Run this command in the Azure Command Line Interface (CLI):
    az ad sp create-for-rbac --name azure-cost-monitor
    


  • Note the following from the output:
    AppID
    Password
    TenantID
    


  • Navigate to β€œSubscriptions” in the top search bar, illustrated below:

  • Select your Subscription and navigate to the Overview Blade

  • Grab your SubscriptionID

Build your secrets.py File

  • Take the information you just gathered and enter it into the secrets.py file like this:
secrets = {
  "ssid" : "Your-WiFi-SSID",
  "password" : "Your-WiFi-PSK",
  "appId": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
  "clientSecret": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
  "tenant": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
  "subscription": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
}


Assign Cost Management Reader Role

Next we have to give our web app permissions to read the cost management information:

  • Navigate to your Subscription and select the Identity & Access Management (IAM) Blade:



  • Click on + Add then Add Role Assignment:



  • Search for, and select Cost Management Reader:


  • Search for, and select the Azure-Cost-Monitor entity we created earlier, then click Next/Save:


Program the MagTag

  1. Plug your MagTag into your computer using a USB-C cable capable of transmitting data and not just charging!
  2. Launch UF2 boot loader by double-clicking the Reset button (the one next to the USB C port). You may have to try a few times to get the timing right.
  3. You will see a new disk drive appear called MAGTAGBOOT or CIRCUITPY (depending on your hardware model).
  4. Copy these files to your device:
  5. It should look something like this:


πŸ’‘ Pro-Tip: you can also program this hardware using the Web Serial ESPTool and even connect via COM port with PuTTY (on Windows, check DevMgmt.msc for COM devices and note the COM port). The REPL Tool is pretty handy for troubleshooting on the fly too.

Assembly

  • Connect the LiPo battery and screw in the magnetic feet:




In this post, we accomplished the following:

  • βœ“ Built an Azure Web App & Assigned an RBAC Role
  • βœ“ Built a secrets.py file from retrieved AppID, Password, TenantID, and SubscriptionID data
  • βœ“ Assigned Cost Management Reader Privileges to Subscription
  • βœ“ Deployed Circuit Python locally
  • βœ“ Connected a battery and magnets so it can run on any magnetic surface (whiteboard, fridge, etc.) completely wirelessly
  • βœ“ Connected to Azure cost management API
  • βœ“ Attained a state of awesome

Hardware

Resources