SlideShare a Scribd company logo
Cross-Platform Azure IoT Device
With C# Source Code Generator and .NET 6.0
Alon Fliess
Chief Architect
alonf@codevalue.net
@alon_fliess
http://alonfliess.me
http://codevalue.net
Ingredients
 IoT Device (Raspberry Pi)
 .NET 6.0 + .NET IoT Libraries
 C# Source Code Generator
 Azure IoT Hub + Azure IoT Client SDK for C#
 VS Code
About Alon Fliess
3
 Chief Architect & Founder – CodeValue
 Microsoft Regional Director
 Microsoft Azure MVP
 alonf@codevalue.net
 @alon_fliess
 http://alonfliess.me
 http://codevalue.net
IoT 101
var sensorData = await _bmp180.GetSensorDataAsync(Bmp180.UltraHighResolution);
var messageString = JsonConvert.SerializeObject(sensorData);
var message = new
Microsoft.Azure.Devices.Client.Message(Encoding.ASCII.GetBytes(messageString));
await deviceClient.SendEventAsync(message);
.NET IoT Libraries
System.Device.Gpio
 Hardware + OS
 Raspberry Pi, BeagleBoard, HummingBoard, ODROID,
and other single-board-computers that are supported
by Linux and Windows 10 IoT Core OS
 Wraps hardware access libraries on both Windows
and Linux
 Provides API for:
 General-purpose I/O (GPIO)
 Inter-Integrated Circuit (I2C)
 Serial Peripheral Interface (SPI)
 Pulse Width Modulation (PWM)
 Serial port
Device Binding
 Built on top of System.Device.Gpio
 Cross-Platform hardware driver classes
 Sensors, Displays, HMI devices and anything else that
requires software to control
 Cross-targeting .NET Standard 2.0 and up
 Full Framework, 3.1, 5, 6, mono
5
The wonder of Azure IoT Hub
IoT Hub
Receive device-to-cloud messages
Send cloud-to-device messages
Receive delivery acks
Receive file notifications
Direct method invocation
Receive operations monitoring events
Module identity management
Module twin management
Job Management
Send device-to-cloud
messages
Receive cloud-to-device
messages
Initiates file
uploads
Retrieve and update
twin properties
Receive direct method
requests
Service
Per-Device
Configuration Management
Message Routing
Message Enrichment
Device identity management
Device twin management
IoT Edge Device IoT Edge Management
Device Twin
Tags
Properties
Desired
Reported
What is a source generator?
 It lets you generate source code
 What does “generate source” mean?
 Why isn’t he saying any of these bullet points?
 So “source” I guess means source code
 And “generate” means create
 Wait.. Are source generators going to take our jobs?!
Your .cs
files
The C# Compiler
Project.dll
Parse
Source
Generator
Compile Emit
CST
AST
CST
Compilation IL
Source
(string)
CST
Referencing and Defining a Source Generator
A Simplified Flow
 Initialize  Register for a syntax node notification
context.RegisterForSyntaxNotifications(() => new SyntaxReceiver());
 Syntax node notification  gather code generation information
public void OnVisitSyntaxNode(SyntaxNode syntaxNode)
{
//collect information
…
}
 Execute  Generate source files and add them to the compilation
10
Your Implementation
IoTHubClientGenerator
 Build an IoT Device client program in seconds
 Handle configuration in multiple ways
 Use IoT Device Connection String, or Device Provisioning Service
 Support most of Azure IoT Hub protocols and protocols’ security
 Support Device Twin, Sending Telemetry, Direct Method and Cloud to Device
messages
 Support device connection status changed notification
11
Demo
Show me an
example!
• Raspberry Pi
• .NET 6.0 + .NET IoT
Libraries
• C# Source Code
Generator
• Azure IoT Hub + Azure
IoT Client SDK for C#
• VS Code
Summary & Takeaways
 .NET IoT Libraries – cross platform IoT foundation
 Azure IoT Hub – cloud scale IoT Platform
 C# + Source generators (IoTHubClientGenerator) – The easiest way to
develop Azure connected IoT device
13
Q
A
14
Alon Fliess
Chief Architect & Founder
alonf@codevalue.net
@alon_fliess
http://alonfliess.me
http://codevalue.net
Appendix – Demo Code
1. using System;
2. using System.Device.I2c;
3. using System.Device.Gpio;
4. using System.Threading;
5. using Iot.Device.Tcs3472x;
6. using System.Threading.Tasks;
7. using IoTHubClientGeneratorSDK;
8. using Microsoft.Azure.Devices.Client;
9. using Microsoft.Azure.Devices.Client.Exceptions;
10. using Microsoft.Azure.Devices.Client.Transport.Mqtt;
11. using System.Text;
12.
Appendix – Demo Code
17
13. namespace DotnetConf
14. {
15. [IoTHub(GeneratedSendMethodName = "SendAsync")]
16. partial class DotNetDevice
17. {
18. [Reported("LastColorName")]
19. private string _lastColorName;
20.
[Desired]
21. private int ReportingIntervalInSeconds { get; set; } = 10;
22.
[Device(ConnectionString="[Configuration.IoTHubConnectionString]")]
23. DeviceClient MyClient {get;set;}
24.
Appendix – Demo Code
18
25. static async Task Main(string[] args)
26. {
27. var device = new DoteNetDevice();
28. await device.InitIoTHubClientAsync();
29.
30. I2cConnectionSettings i2cSettings = new(1, 0x29);
31. using I2cDevice i2cDevice =
32. I2cDevice.Create(i2cSettings);
33. using Tcs3472x tcs3472X = new(i2cDevice);
34. long i = 0;
35. device.InitGpioController();
36.
Appendix – Demo Code
19
37. while (!Console.KeyAvailable)
38. {
39. Console.WriteLine(
40. $"ID: {tcs3472X.ChipId} Gain: {tcs3472X.Gain} Time to wait: {tcs3472X.IsClearInterrupt}");
41. var col = tcs3472X.GetColor();
42. var color = $"{col.R},{col.G},{col.B}";
43. device.LastColorName = col.Name;
44.
Console.WriteLine($"Valid data: {tcs3472X.IsValidData} Clear Interrupt: {tcs3472X.IsClearInterrupt}");
45.
46. if (tcs3472X.IsValidData)
47. {
48. Console.WriteLine(
49. $"{device.ReportingIntervalInSeconds} seconds trigger, sending data, color: {color}");
50. await device.SendAsync($"{{"color":"{color}"}}", (++i).ToString(), new CancellationToken());
51. }
52. await Task.Delay(TimeSpan.FromSeconds(device.ReportingIntervalInSeconds));
53. }
54. }
Appendix – Demo Code
20
55. private GpioController _gpioController;
56.
57. private void InitGpioController()
58. {
59. _gpioController = new GpioController ();
60. // Sets the pin to output mode so we can switch something on
61. _gpioController.OpenPin(Configuration.GreenLedPin,
62. PinMode.Output);
63. }
64.
Appendix – Demo Code
21
65. [C2DMessage(AutoComplete = true)]
66. private void Cloud2DeviceMessage(Message receivedMessage)
67. {
68. string messageData = Encoding.ASCII.GetString(receivedMessage.GetBytes());
69. Console.WriteLine($"Received message: [{messageData}]");
70. try
71. {
72. var colors = messageData.Split(",");
73. var red = int.Parse(colors[0]);
74. var green = int.Parse(colors[1]);
75. var blue = int.Parse(colors[2]);
76.
77. Console.WriteLine($"Color: red:{red}, green:{green}, blue:{blue}");
78.
Appendix – Demo Code
22
79. if (green > red && green > blue)
80. {
81. _gpioController.Write(Configuration.GreenLedPin, PinValue.High);
82. }
83. else
84. {
85. _gpioController.Write(Configuration.GreenLedPin, PinValue.Low);
86. }
87. }
88. catch (System.Exception e)
89. {
90.
Console.WriteLine(e);
91. }
92. }
Appendix – Demo Code
23
93. [ConnectionStatus]
94. private (ConnectionStatus Status, ConnectionStatusChangeReason Reason) DeviceConnectionStatus { get; set; }
95.
96. [IoTHubErrorHandler]
97. void IoTHubErrorHandler(string errorMessage, Exception exception)
98. {
99. Console.WriteLine($"{errorMessage}, Exception: {exception.Message}");
100. }
101. }
102.}

More Related Content

PPTX
What's new in c# 10
PPTX
Tamir Dresher - Async Streams in C#
PDF
OSCON 2014 - API Ecosystem with Scala, Scalatra, and Swagger at Netflix
PDF
Arduino、Web 到 IoT
PDF
Build resource server & client for OCF Cloud (2018.8.30)
PDF
Service Oriented Web Development with OSGi - C Ziegeler
ODP
Networking and Data Access with Eqela
PPT
Java client socket-20070327
What's new in c# 10
Tamir Dresher - Async Streams in C#
OSCON 2014 - API Ecosystem with Scala, Scalatra, and Swagger at Netflix
Arduino、Web 到 IoT
Build resource server & client for OCF Cloud (2018.8.30)
Service Oriented Web Development with OSGi - C Ziegeler
Networking and Data Access with Eqela
Java client socket-20070327

What's hot (19)

PDF
Extending Retrofit for fun and profit
PPTX
Durable functions
PDF
Parse cloud code
PDF
maxbox starter72 multilanguage coding
PDF
SPIFFE Meetup Tokyo #2 - Attestation Internals in SPIRE - Shingo Omura
PPTX
HTTP Middlewares in PHP by Eugene Dounar
PPTX
2012: ql.io and Node.js
PPT
Network programming1
PDF
Hacking the Mesh: Extending Istio with WebAssembly Modules | DevNation Tech Talk
PPTX
[NDC 2019] Functions 2.0: Enterprise-Grade Serverless
PPT
Manage software dependencies with ioc and aop
PDF
Talk KVO with rac by Philippe Converset
PDF
I Can See Clearly Now - Observing & understanding your Spring applications at...
PDF
Tech Webinar: AUMENTARE LA SCALABILITÀ DELLE WEB APP CON SERVLET 3.1 ASYNC I/O
DOCX
Fidl analysis
PDF
Webエンジニアから見たiOS5
PPT
ITK Tutorial Presentation Slides-944
PDF
Retrofit
PDF
All you need to know about Callbacks, Promises, Generators
Extending Retrofit for fun and profit
Durable functions
Parse cloud code
maxbox starter72 multilanguage coding
SPIFFE Meetup Tokyo #2 - Attestation Internals in SPIRE - Shingo Omura
HTTP Middlewares in PHP by Eugene Dounar
2012: ql.io and Node.js
Network programming1
Hacking the Mesh: Extending Istio with WebAssembly Modules | DevNation Tech Talk
[NDC 2019] Functions 2.0: Enterprise-Grade Serverless
Manage software dependencies with ioc and aop
Talk KVO with rac by Philippe Converset
I Can See Clearly Now - Observing & understanding your Spring applications at...
Tech Webinar: AUMENTARE LA SCALABILITÀ DELLE WEB APP CON SERVLET 3.1 ASYNC I/O
Fidl analysis
Webエンジニアから見たiOS5
ITK Tutorial Presentation Slides-944
Retrofit
All you need to know about Callbacks, Promises, Generators
Ad

Similar to Generating cross platform .NET based azure IoTdevice (20)

PDF
Global Azure Bootcamp 2016 - Real-world Internet of Things Backend with Azure...
PPTX
DWX2018 IoT lecture
PPTX
Azure Internet of Things
PPTX
Azure IoT Hubs with Raspberry Pi and Node.js - DDD 14 Microsoft - Reading - 1...
PPTX
Architecting IoT solutions with Microsoft Azure
PPTX
IoT on Raspberry PI v1.2
PPTX
IoT on Raspberry Pi
PPTX
IoT on Azure
PPTX
Windows 10 IoT-Core to Azure IoT Suite
PPTX
IoT on azure
PPTX
Azure IoT hub
PDF
IoT Seminar (Oct. 2016) Juan Perez - Microsoft
PDF
Athens IoT meetup #7 - Create the Internet of your Things - Laurent Ellerbach...
PPTX
Azure IoT Hubs with Raspberry Pi and Node.js - Azure Bootcamp - 27-04-19
PPTX
Developers Safari into the Internet of Things (IoT) with Pi
PPTX
Raspberry pi and Azure
PPTX
IoTSummit - Introduction to IoT Hub
PDF
Can we build an Azure IoT controlled device in less than 40 minutes that cost...
PPTX
Aymeric Weinbach - IoT et Azure - Global Azure Bootcamp 2016 Paris
PPTX
[GAB2016] IoT and Azure - Aymeric Weinbach
Global Azure Bootcamp 2016 - Real-world Internet of Things Backend with Azure...
DWX2018 IoT lecture
Azure Internet of Things
Azure IoT Hubs with Raspberry Pi and Node.js - DDD 14 Microsoft - Reading - 1...
Architecting IoT solutions with Microsoft Azure
IoT on Raspberry PI v1.2
IoT on Raspberry Pi
IoT on Azure
Windows 10 IoT-Core to Azure IoT Suite
IoT on azure
Azure IoT hub
IoT Seminar (Oct. 2016) Juan Perez - Microsoft
Athens IoT meetup #7 - Create the Internet of your Things - Laurent Ellerbach...
Azure IoT Hubs with Raspberry Pi and Node.js - Azure Bootcamp - 27-04-19
Developers Safari into the Internet of Things (IoT) with Pi
Raspberry pi and Azure
IoTSummit - Introduction to IoT Hub
Can we build an Azure IoT controlled device in less than 40 minutes that cost...
Aymeric Weinbach - IoT et Azure - Global Azure Bootcamp 2016 Paris
[GAB2016] IoT and Azure - Aymeric Weinbach
Ad

More from Alon Fliess (8)

PPTX
Generative AI in CSharp with Semantic Kernel.pptx
PPTX
Zionet Overview
PPTX
Observability and more architecture next 2020
PPTX
C# Production Debugging Made Easy
PPTX
We Make Debugging Sucks Less
PPTX
Architecting io t solutions with microisoft azure ignite tour version
PPTX
To microservice or not to microservice - ignite version
PPTX
Net core microservice development made easy with azure dev spaces
Generative AI in CSharp with Semantic Kernel.pptx
Zionet Overview
Observability and more architecture next 2020
C# Production Debugging Made Easy
We Make Debugging Sucks Less
Architecting io t solutions with microisoft azure ignite tour version
To microservice or not to microservice - ignite version
Net core microservice development made easy with azure dev spaces

Recently uploaded (20)

PDF
Design an Analysis of Algorithms I-SECS-1021-03
PDF
Navsoft: AI-Powered Business Solutions & Custom Software Development
PDF
Raksha Bandhan Grocery Pricing Trends in India 2025.pdf
PDF
wealthsignaloriginal-com-DS-text-... (1).pdf
PPTX
Essential Infomation Tech presentation.pptx
PDF
System and Network Administraation Chapter 3
PDF
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
PDF
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
PPTX
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
PDF
How to Migrate SBCGlobal Email to Yahoo Easily
PDF
How to Choose the Right IT Partner for Your Business in Malaysia
PDF
top salesforce developer skills in 2025.pdf
PDF
Design an Analysis of Algorithms II-SECS-1021-03
PPTX
Transform Your Business with a Software ERP System
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 41
PPTX
L1 - Introduction to python Backend.pptx
PDF
AI in Product Development-omnex systems
PDF
Upgrade and Innovation Strategies for SAP ERP Customers
PPTX
ai tools demonstartion for schools and inter college
PDF
EN-Survey-Report-SAP-LeanIX-EA-Insights-2025.pdf
Design an Analysis of Algorithms I-SECS-1021-03
Navsoft: AI-Powered Business Solutions & Custom Software Development
Raksha Bandhan Grocery Pricing Trends in India 2025.pdf
wealthsignaloriginal-com-DS-text-... (1).pdf
Essential Infomation Tech presentation.pptx
System and Network Administraation Chapter 3
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
How to Migrate SBCGlobal Email to Yahoo Easily
How to Choose the Right IT Partner for Your Business in Malaysia
top salesforce developer skills in 2025.pdf
Design an Analysis of Algorithms II-SECS-1021-03
Transform Your Business with a Software ERP System
Internet Downloader Manager (IDM) Crack 6.42 Build 41
L1 - Introduction to python Backend.pptx
AI in Product Development-omnex systems
Upgrade and Innovation Strategies for SAP ERP Customers
ai tools demonstartion for schools and inter college
EN-Survey-Report-SAP-LeanIX-EA-Insights-2025.pdf

Generating cross platform .NET based azure IoTdevice

  • 1. Cross-Platform Azure IoT Device With C# Source Code Generator and .NET 6.0 Alon Fliess Chief Architect alonf@codevalue.net @alon_fliess http://alonfliess.me http://codevalue.net
  • 2. Ingredients  IoT Device (Raspberry Pi)  .NET 6.0 + .NET IoT Libraries  C# Source Code Generator  Azure IoT Hub + Azure IoT Client SDK for C#  VS Code
  • 3. About Alon Fliess 3  Chief Architect & Founder – CodeValue  Microsoft Regional Director  Microsoft Azure MVP  alonf@codevalue.net  @alon_fliess  http://alonfliess.me  http://codevalue.net
  • 4. IoT 101 var sensorData = await _bmp180.GetSensorDataAsync(Bmp180.UltraHighResolution); var messageString = JsonConvert.SerializeObject(sensorData); var message = new Microsoft.Azure.Devices.Client.Message(Encoding.ASCII.GetBytes(messageString)); await deviceClient.SendEventAsync(message);
  • 5. .NET IoT Libraries System.Device.Gpio  Hardware + OS  Raspberry Pi, BeagleBoard, HummingBoard, ODROID, and other single-board-computers that are supported by Linux and Windows 10 IoT Core OS  Wraps hardware access libraries on both Windows and Linux  Provides API for:  General-purpose I/O (GPIO)  Inter-Integrated Circuit (I2C)  Serial Peripheral Interface (SPI)  Pulse Width Modulation (PWM)  Serial port Device Binding  Built on top of System.Device.Gpio  Cross-Platform hardware driver classes  Sensors, Displays, HMI devices and anything else that requires software to control  Cross-targeting .NET Standard 2.0 and up  Full Framework, 3.1, 5, 6, mono 5
  • 6. The wonder of Azure IoT Hub IoT Hub Receive device-to-cloud messages Send cloud-to-device messages Receive delivery acks Receive file notifications Direct method invocation Receive operations monitoring events Module identity management Module twin management Job Management Send device-to-cloud messages Receive cloud-to-device messages Initiates file uploads Retrieve and update twin properties Receive direct method requests Service Per-Device Configuration Management Message Routing Message Enrichment Device identity management Device twin management IoT Edge Device IoT Edge Management Device Twin Tags Properties Desired Reported
  • 7. What is a source generator?  It lets you generate source code  What does “generate source” mean?  Why isn’t he saying any of these bullet points?  So “source” I guess means source code  And “generate” means create  Wait.. Are source generators going to take our jobs?!
  • 8. Your .cs files The C# Compiler Project.dll Parse Source Generator Compile Emit CST AST CST Compilation IL Source (string) CST
  • 9. Referencing and Defining a Source Generator
  • 10. A Simplified Flow  Initialize  Register for a syntax node notification context.RegisterForSyntaxNotifications(() => new SyntaxReceiver());  Syntax node notification  gather code generation information public void OnVisitSyntaxNode(SyntaxNode syntaxNode) { //collect information … }  Execute  Generate source files and add them to the compilation 10 Your Implementation
  • 11. IoTHubClientGenerator  Build an IoT Device client program in seconds  Handle configuration in multiple ways  Use IoT Device Connection String, or Device Provisioning Service  Support most of Azure IoT Hub protocols and protocols’ security  Support Device Twin, Sending Telemetry, Direct Method and Cloud to Device messages  Support device connection status changed notification 11
  • 12. Demo Show me an example! • Raspberry Pi • .NET 6.0 + .NET IoT Libraries • C# Source Code Generator • Azure IoT Hub + Azure IoT Client SDK for C# • VS Code
  • 13. Summary & Takeaways  .NET IoT Libraries – cross platform IoT foundation  Azure IoT Hub – cloud scale IoT Platform  C# + Source generators (IoTHubClientGenerator) – The easiest way to develop Azure connected IoT device 13
  • 15. Alon Fliess Chief Architect & Founder alonf@codevalue.net @alon_fliess http://alonfliess.me http://codevalue.net
  • 16. Appendix – Demo Code 1. using System; 2. using System.Device.I2c; 3. using System.Device.Gpio; 4. using System.Threading; 5. using Iot.Device.Tcs3472x; 6. using System.Threading.Tasks; 7. using IoTHubClientGeneratorSDK; 8. using Microsoft.Azure.Devices.Client; 9. using Microsoft.Azure.Devices.Client.Exceptions; 10. using Microsoft.Azure.Devices.Client.Transport.Mqtt; 11. using System.Text; 12.
  • 17. Appendix – Demo Code 17 13. namespace DotnetConf 14. { 15. [IoTHub(GeneratedSendMethodName = "SendAsync")] 16. partial class DotNetDevice 17. { 18. [Reported("LastColorName")] 19. private string _lastColorName; 20. [Desired] 21. private int ReportingIntervalInSeconds { get; set; } = 10; 22. [Device(ConnectionString="[Configuration.IoTHubConnectionString]")] 23. DeviceClient MyClient {get;set;} 24.
  • 18. Appendix – Demo Code 18 25. static async Task Main(string[] args) 26. { 27. var device = new DoteNetDevice(); 28. await device.InitIoTHubClientAsync(); 29. 30. I2cConnectionSettings i2cSettings = new(1, 0x29); 31. using I2cDevice i2cDevice = 32. I2cDevice.Create(i2cSettings); 33. using Tcs3472x tcs3472X = new(i2cDevice); 34. long i = 0; 35. device.InitGpioController(); 36.
  • 19. Appendix – Demo Code 19 37. while (!Console.KeyAvailable) 38. { 39. Console.WriteLine( 40. $"ID: {tcs3472X.ChipId} Gain: {tcs3472X.Gain} Time to wait: {tcs3472X.IsClearInterrupt}"); 41. var col = tcs3472X.GetColor(); 42. var color = $"{col.R},{col.G},{col.B}"; 43. device.LastColorName = col.Name; 44. Console.WriteLine($"Valid data: {tcs3472X.IsValidData} Clear Interrupt: {tcs3472X.IsClearInterrupt}"); 45. 46. if (tcs3472X.IsValidData) 47. { 48. Console.WriteLine( 49. $"{device.ReportingIntervalInSeconds} seconds trigger, sending data, color: {color}"); 50. await device.SendAsync($"{{"color":"{color}"}}", (++i).ToString(), new CancellationToken()); 51. } 52. await Task.Delay(TimeSpan.FromSeconds(device.ReportingIntervalInSeconds)); 53. } 54. }
  • 20. Appendix – Demo Code 20 55. private GpioController _gpioController; 56. 57. private void InitGpioController() 58. { 59. _gpioController = new GpioController (); 60. // Sets the pin to output mode so we can switch something on 61. _gpioController.OpenPin(Configuration.GreenLedPin, 62. PinMode.Output); 63. } 64.
  • 21. Appendix – Demo Code 21 65. [C2DMessage(AutoComplete = true)] 66. private void Cloud2DeviceMessage(Message receivedMessage) 67. { 68. string messageData = Encoding.ASCII.GetString(receivedMessage.GetBytes()); 69. Console.WriteLine($"Received message: [{messageData}]"); 70. try 71. { 72. var colors = messageData.Split(","); 73. var red = int.Parse(colors[0]); 74. var green = int.Parse(colors[1]); 75. var blue = int.Parse(colors[2]); 76. 77. Console.WriteLine($"Color: red:{red}, green:{green}, blue:{blue}"); 78.
  • 22. Appendix – Demo Code 22 79. if (green > red && green > blue) 80. { 81. _gpioController.Write(Configuration.GreenLedPin, PinValue.High); 82. } 83. else 84. { 85. _gpioController.Write(Configuration.GreenLedPin, PinValue.Low); 86. } 87. } 88. catch (System.Exception e) 89. { 90. Console.WriteLine(e); 91. } 92. }
  • 23. Appendix – Demo Code 23 93. [ConnectionStatus] 94. private (ConnectionStatus Status, ConnectionStatusChangeReason Reason) DeviceConnectionStatus { get; set; } 95. 96. [IoTHubErrorHandler] 97. void IoTHubErrorHandler(string errorMessage, Exception exception) 98. { 99. Console.WriteLine($"{errorMessage}, Exception: {exception.Message}"); 100. } 101. } 102.}

Editor's Notes

  • #6: The System.Device.Gpio package supports general-purpose I/O (GPIO) pins, PWM, I2C, SPI and related interfaces for interacting with low level hardware pins to control hardware sensors, displays and input devices on single-board-computers; Raspberry Pi, BeagleBoard, HummingBoard, ODROID, and other single-board-computers that are supported by Linux and Windows 10 IoT Core OS can be used with .NET Core and System.Device.Gpio.  On Windows 10 IoT Core OS, the library wraps the Windows.Devices.Gpio.dll assembly.  On Linux, the library supports three driver modes: libgpiod for fast full-featured GPIO access on all Linux distros since version 4.8 of the Linux kernel; slower and limited-functionality GPIO access via the deprecated Sysfs interface (/sys/class/gpio) when running on older Linux distro versions with a Linux kernel older than version 4.8; and lastly board-specific Linux drivers that access GPIO addresses in /dev/mem for fasted performance at the trade-off of being able to run on very specific versions of single-board-computers.  In the future, the board-specific Linux drivers may be removed in favor of only supporting libgpiod and sysfs Linux interfaces.  In addition to System.Device.Gpio, the optional IoT.Device.Bindings NuGet package contains device bindings for many sensors, displays, and input devices that can be used with System.Device.Gpio.
  • #7: Microsoft Azure IoT Hub provides capabilities for securely connecting, provisioning, updating and sending commands to devices. IoT Hub enables companies to control millions of IoT assets running on a broad set of operating systems and protocols to jumpstart their Internet of Things projects. IoT Hub enables companies to: Establish reliable bi-directional communication with IoT assets, even if they are intermittently connected, so companies can analyze incoming telemetry data and send commands and notifications as needed. Enhance security of IoT solutions by leveraging per-device authentication to communicate with devices with the appropriate credentials. Revoke access rights to specific devices, if needed, to maintain the integrity of the system.
  • #8: A Source Generator is a .NET Standard 2.0
  • #9: CST- Concrete Syntax Tree https://devblogs.microsoft.com/dotnet/introducing-c-source-generators/ A Source Generator is a new kind of component that C# developers can write that lets you do two major things: Retrieve a Compilation object that represents all user code that is being compiled. This object can be inspected and you can write code that works with the syntax and semantic models for the code being compiled, just like with analyzers today. Generate C# source files that can be added to a Compilation object during the course of compilation. In other words, you can provide additional source code as input to a compilation while the code is being compiled.
  • #13: Demonstrate using source code generator from NuGet