Code Usage

Viewing Data on the PyPortal

When the PyPortal starts up, it will first load the azure_splash.bmp image in the images folder on your CIRCUITPY drive. This is a "loading screen" while the code waits for the fonts and display objects load on the screen.

You should see the PyPortal display update to display the temperature value and moisture level.

The status indicator at the bottom of the PyPortal will display when it's sending data to Azure IoT Hub and also display when the data is sent. 

Monitoring Azure IoT Hub Events

While your PyPortal shows that its sending data to the IoT Hub, you'll need to check that the hub is receiving your PyPortal's messages.

From your Azure Portal, open a new console instance by clicking the >_ icon on the top menubar. 

After the console connects, enter the following command, replacing your-test-hub with the name of your IoT Hub resource

Download: file
az iot hub monitor-events --hub-name your-azure-hub

If you're sending data to the Azure Hub from your CircuitPython device, data will be displayed in the Azure Console as it comes in:

Download: file
[email protected]:~$ az iot hub monitor-events --hub-name azure-airlift-test-hub
Starting event monitor, use ctrl-c to stop...
{
    "event": {
        "origin": "PyPortal",
        "payload": 67
    }
}
{
    "event": {
        "origin": "PyPortal",
        "payload": 627
    }
}

Here, we can see that two new pieces of data (called events) were received by the hub. The origin is the device identifier's name and the payload is the data sent by the PyPortal.

If you have a large amount of IoT devices sending the same type of data (lots of PyPortal Planters!), you would be able to identify them by sorting by the origin.

Not sure if the hub is receiving the correct data? Add a print() statement to your CircuitPython code to print the data to the REPL. Then, cross-verify the value displayed in the REPL against the value received by the Azure IoT Hub. 

Going Further

Ready to go further with your CircuitPython-Powered Azure-connected IoT Device? The CircuitPython_AzureIoT module provides usage examples for advanced Azure IoT operations such as device management, device-to-cloud communication, device twin operations, and cloud-to-device communication.

Since you have your device's data on an Azure IoT resource - you may also be interested in bridging Azure IoT and the rest of Microsoft's Azure tools:

This guide was first published on May 24, 2019. It was last updated on May 24, 2019. This page (Code Usage) was last updated on Oct 17, 2019.