Simple C# code to collect data readings from Raspberry Pi SenseHat temperature & humidity sensors and send to Azure IoT Hub.
Two repos were helpful when I put this together:
- Azure IoT Samples CSharp Iot Hub Quickstart: https://github.com/Azure-Samples/azure-iot-samples-csharp/tree/main/iot-hub/Quickstarts/SimulatedDevice
- SenseHatNet: https://github.com/johannesegger/SenseHatNet
This could be expanded to include other sensors on the SenseHat device, I'm only using temperature and humidity.
Instructions to get this working:
- Install dotnet SDK
- Download the repo or copy the code in the Program.cs and SenseDotnetIoT.csproj files.
- Navidate into the directory where Program.cs and SenseDotnetIoT.csproj files are stored on the device.
- Modify the connection string near the top of Program.cs to be the connection string to your Azure IoT device (create one if needed).
- Save the Program.cs file with the updated connection string.
- Run
dotnet build
- Run
dotnet run
- Monitor sensor data flowing into Azure IoT Hub.
I'm happy to take suggestions or improvements to this code. Thank you!