In the previous post, an app to read environment values using the BME280 was presented using an Azure Sphere with the device connected by a Grove Shield. With this, the device isn’t directly connected to the Az Sphere’s I2C but connects via an I2C bus master on the shield which communicates with the Az Sphere via a UART. This article discusses the use of an existing GitHub project that supports direct connection of the BME280 to the Azure Sphere via I2C. This project also sends the data to an Azure IoT Hub as telemetry using Device Provisioning Service (DPS).

Bosch provides a direct connect I2C library for the BME280. The full general C code for the device is listed here at Bosch.

Luckily there is an existing sample project that wrappers this library around I2C for the Azure Sphere. It also provides telemetry data for an IoT Hub via Azure IoT Central . The sample project Connecting an I2C sensor (Bosch BME280) and send telemetry to Azure IoT Central is part of the GitHub Hub repository JuergenSchwertl/AzureSphereSamples from Juergen Schwertl .. Thx 😄.

BME280App Azure Sphere Log:

[I2C read ] reg 0xf7 : 47 75 80 7c 65 40 6b 4a
[BME280] Temperature: 19.72 °C, Pressure: 100534.83 Pa, Humidity: 47.29 %
[Send] {"temperature":19.72,"pressure":1005.35,"humidity":47.29}

[Azure IoT] INFO: IoTHubClient accepted the message for delivery
[Azure IoT Hub client] INFO: AzureIoT_DoPeriodicTasks calls in progress...
[Azure IoT] INFO: Message received by IoT Hub. Result is: 0

The corresponding data as displayed in Azure IoT Explorer

11:03:19 PM, April 19, 2020:
{
  "body": {
    "temperature": 19.72,
    "pressure": 1005.35,
    "humidity": 47.29
  },
  "enqueuedTime": "2020-04-19T13:03:19.371Z",
  "properties": {}
}

Nb: » Azure IoT Explorer is now the recommended alternative to Device Explorer.

Azure IoT Hub SDK Quickstart Service app

As extensively discussed in other posts on this site, there exists a .Net Core C# app that can also monitor and display the telemetry to an IoT Hub. This is the read-d2c-message app under the Telemetry scenario. The az-iothub-ps PowerShell script can now set you up to directly run that along with the required hub connectivity metadata as a json file. The following is the same telemetry as above when read by this app.

Listening for messages on: 3
Message received on partition 3:
  {"temperature":19.72,"pressure":1005.35,"humidity":47.29}:
Application properties (set by device):
System properties (set by IoT Hub):
  iothub-connection-device-id: a11a0868bf545048ba18c591b726c121d05a72f8847cf269ccb4817050e9b0f73c11e5da2e1167320eb18ead4ff047c35c7c4c583d01acca770191c6bd6084c2
  iothub-connection-auth-method: {"scope":"device","type":"x509Certificate","issuer":"external","acceptingIpFilterRule":null}
  iothub-connection-auth-generation-id: 637228952629780805
  iothub-enqueuedtime: 19/04/2020 1:03:19 PM
  iothub-message-source: Telemetry
  x-opt-sequence-number: 2216
  x-opt-offset: 4295053960
  x-opt-enqueued-time: 19/04/2020 1:03:19 PM
Listening for messages on: 3

The DPS in this case was configured to connect directly to the IoT Hub, not via IoT Central. Note that when displayed in az-iothub-ps the iothub-connection-device-id is displayed for the Az Sphere, even though it wasn’t connected there:

  A Z U R E  I o T  H U B     S E T U P   using PowerShell AND Azure CLI

   Subscription :"Visual Studio Ultimate with MSDN"
          Group :"IoTEdgeResources"
            Hub :"TheHub3142"
         Device :"a11a0868bf545048ba18c591b726c121d05a72f8847cf269ccb4817050e9b0f73c11e5da2e1167320eb18ead4ff047c35c7c4c583d01acca770191c6bd6084c2"
            DPS :"DPStreamMe

 TopicSubtopic
<  Prev:    
   
 This Category Links 
Category:Azure Sphere Index:Azure Sphere
  Next: > Azure Sphere Projects
<  Prev:   Azure Sphere Projects