03 Deploy the CO2 monitor - gloveboxes/HealthySpacesAnomalyDetection GitHub Wiki

Clone the CO2 monitor healthy workspaces repo

The CO2 healthy spaces solution is part of the Azure Sphere Gallery. Clone the Azure Sphere Gallery repository to your computer.

From a command prompt, run the following command.

git clone --recurse-submodules https://github.com/gloveboxes/HealthySpacesAnomalyDetection.git

Open the lab project

  1. Start Visual Studio Code
  2. From the main menu, select File, then select Open Folder....
  3. Open the azure-sphere-gallery/CO2_MonitorHealthySpaces/src project folder.
  4. Select Select Folder or OK to open the project.

The CO2 monitor project structure

There're four files in the project you need to understand.

File Function
app_manifest.json Used for network configuration and security settings.
azsphere_board.txt Used to select your Azure Sphere developer board.
main.c The application code.
main.h The application declarations.

Take a moment to familiarize yourself with these files.

The image shows the CO2 project structure in Visual Studio Code


Select your Avnet starter board and CO2 sensor

The default board is the Avnet Starter Kit Rev 1, and the default sensor is the MikroE HVAC CO2 Click. If this is the board and sensor you're using, then skip to the next step.

If you have an Avnet Starter Kit Rev 2 board or the Seeed Studio CO2 sensor, then follow these instructions.

  1. Open the azsphere_board.txt file.
  2. Comment out the Avnet Rev 1 board with a #.
  3. Uncomment the Avnet Rev 2 board by removing the leading # character.
  4. Comment out the default CO2 sensor, and uncomment the Seeed Studio CO2 sensor.
  5. Save the changes.
  6. Press Ctrl+Shift+P to open the Visual Studio Code command palette.
  7. Type and select CMake: Delete Cache and Reconfigure.

Configure network and security settings

  1. Open the app_manifest.json file.

  2. Update the CmdArgs property with your IoT Central ID Scope.

  3. Get your Azure Sphere Tenant ID. From a command prompt, run the following command.

    azsphere tenant show-selected -o yaml

    The output of this command will be similar to the following. The id property value is your Azure Sphere Tenant ID.

    id: 9abc79eb-9999-43ce-9999-fa8888888894
    name: myAzureSphereTenant
    roles:
    - Administrator
  4. Update the DeviceAuthentication property with your Azure Sphere Tenant ID.

  5. Update the AllowedConnections property with the IoT Central Application endpoint URLs you copied to Notepad.

  6. Review your updated manifest_app.json file. It should be similar to the following.

    {
      "SchemaVersion": 1,
      "Name": "co2monitor",
      "ComponentId": "25025d2c-66da-4448-bae1-ac26fcdd3627",
      "EntryPoint": "/bin/app",
      "CmdArgs": [ "--ScopeID", "0ne0099999D" ],
      "Capabilities": {
        "SystemEventNotifications": true,
        "SoftwareUpdateDeferral": true,
        "Gpio": [ "$AZURE_CONNECTED_LED", "$BUTTON_B" ],
        "Pwm": [ "$PWM_CLICK_CONTROLLER", "$PWM_RGB_CONTROLLER" ],
        "I2cMaster": [ "$I2C_ISU2" ],
        "Adc": [ "$AVNET_MT3620_SK_ADC_CONTROLLER0" ],
        "AllowedConnections": [
            "global.azure-devices-provisioning.net",
            "iotc-9999bc-3305-99ba-885e-6573fc4cf701.azure-devices.net",
            "iotc-789999fa-8306-4994-b70a-399c46501044.azure-devices.net",
            "iotc-7a099966-a8c1-4f33-b803-bf29998713787.azure-devices.net",
            "iotc-97299997-05ab-4988-8142-e299995acdb7.azure-devices.net",
            "iotc-d099995-7fec-460c-b717-e99999bf4551.azure-devices.net",
            "iotc-789999dd-3bf5-49d7-9e12-f6999991df8c.azure-devices.net",
            "iotc-29999917-7344-49e4-9344-5e0cc9999d9b.azure-devices.net",
            "iotc-99999e59-df2a-41d8-bacd-ebb9999143ab.azure-devices.net",
            "iotc-c0a9999b-d256-4aaf-aa06-e90e999902b3.azure-devices.net",
            "iotc-f9199991-ceb1-4f38-9f1c-13199992570e.azure-devices.net"
        ],
        "DeviceAuthentication": "9abc79eb-9999-43ce-9999-fa8888888894"
      },
      "ApplicationType": "Default"
    }

Deploying the CO2 monitor to Azure Sphere

Start the app build deploy process.

  1. Press Ctrl+Shift+P to open the Visual Studio Code command palette.
  2. Type and select CMake: Select Variant, then select Debug.
  3. Press F5 to build, deploy, and attach the debugger to the CO2 monitor application now running the Azure Sphere device.

View debugger output

  1. Open the Visual Studio Code Output tab to view the output from the Log_Debug statements in the code.

    Pro Tip. You can open the output window by using the Visual Studio Code Ctrl+K Ctrl+H shortcut or selecting the Output tab.

  2. You will see the device negotiating security, and then it will start sending telemetry to Azure IoT Central.


Expected device behavior

The image shows a photo in the Azure Sphere with the CO2 sensor and the click buzzer

  1. The yellow App LED will blink rapidly when the application starts.
  2. The App LED will blink on and off while the device connects to IoT Central.
  3. When connected to IoT Central, the App LED will not blink.
  4. The User LED will likely blink blue every 8 seconds to indicate the recorded CO2 level is below the CO2 alert level.
  5. The User LED will blink red every 8 seconds if the recorded CO2 level is higher than the CO2 alert level.
  6. The BUZZ click will emit a high-pitched sound if the recorded CO2 level is greater than the CO2 alert level. You can press button B to mute the buzzer.
⚠️ **GitHub.com Fallback** ⚠️