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.
Step 1: Get Azure CredentialsThe 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.
If you don't have an Azure account, you can sign up for free here!
1. Log into the Azure portal.
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.
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"
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 secrets.py file.
5. Get Subscription ID property
Next type and run:
az account list
Again, copy and save the "id" property together with the credentials from the previous step. Label this property SUBSCRIPTION ID
. We'll use it later in the secrets.py file.
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
Comments