Home
%3CLINGO-SUB%20id%3D%22lingo-sub-776767%22%20slang%3D%22en-US%22%3EBuild%20Azure%20IoT%20Apps%20with%20.NET%20Core%20IoT%20targeting%20Raspberry%20Pi%20Linux%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-776767%22%20slang%3D%22en-US%22%3E%3CP%3ELearn%20how%20to%20Build%2C%20Deploy%20and%20Debug%20Azure%20IoT%20Apps%20with%20.NET%20Core%20IoT%20for%20Raspberry%20Pi%20and%20Visual%20Studio%20Code.%3C%2FP%3E%0A%3CP%3E%3CIMG%20src%3D%22https%3A%2F%2Fraw.githubusercontent.com%2Fgloveboxes%2FdotNET-Core-IoT-Raspberry-Pi-Linux.-How-to-Build-Deploy-and-Debug%2Fmaster%2Fdocs%2Fbanner.png%22%20border%3D%220%22%20alt%3D%22.net%20core%20loves%20single%20board%20computers%22%20%2F%3E%3C%2FP%3E%0A%3CH1%20id%3D%22net-core-iot-raspberry-pi-linux-and-azure-iot-hub-learn-how-to-build-deploy-and-debug%22%20id%3D%22toc-hId-1990890752%22%20id%3D%22toc-hId-1990890752%22%3E%26nbsp%3B%3C%2FH1%3E%0A%3CH2%20id%3D%22toc-hId--757779714%22%20id%3D%22toc-hId--757779714%22%3EFollow%20me%20(%40dglover)%20on%20%3CA%20href%3D%22https%3A%2F%2Ftwitter.com%2Fdglover%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noopener%20noreferrer%20noopener%20noreferrer%22%3ETwitter%3C%2FA%3E.%3C%2FH2%3E%0A%3CH2%20id%3D%22toc-hId-985030621%22%20id%3D%22toc-hId-985030621%22%3E%26nbsp%3B%3C%2FH2%3E%0A%3CH2%20id%3D%22source-code%22%20id%3D%22toc-hId--1567126340%22%20id%3D%22toc-hId--1567126340%22%3ESource%20Code%3C%2FH2%3E%0A%3CP%3EThe%20source%20and%20the%20samples%20for%20this%20walk-through%20can%20be%20found%20%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2Fgloveboxes%2FdotNET-Core-IoT-Raspberry-Pi-Linux.-How-to-Build-Deploy-and-Debug%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehere%3C%2FA%3E.%3C%2FP%3E%0A%3CH2%20id%3D%22toc-hId-175683995%22%20id%3D%22toc-hId-175683995%22%3E%26nbsp%3B%3C%2FH2%3E%0A%3CH2%20id%3D%22introduction%22%20id%3D%22toc-hId-1918494330%22%20id%3D%22toc-hId-1918494330%22%3EIntroduction%3C%2FH2%3E%0A%3CP%3EThe%20.NET%20Core%20IoT%20Library%20connects%20your%20applications%20to%20hardware.%20In%20this%20walk-through%20you%20will%20learn%20how%20to%3A%3C%2FP%3E%0A%3COL%3E%0A%3CLI%3EDevelop%20a%20C%23%20.NET%20Core%20IoT%20application%20from%20a%20Linux%2C%20macOS%20or%20Windows%2010%20desktop%2C%3C%2FLI%3E%0A%3CLI%3EDeploy%20the%20app%20to%20a%20Raspberry%20Pi%20running%20Linux%20(or%20another%20Linux%20board%20such%20as%20the%20BeagleBone%20Black)%2C%3C%2FLI%3E%0A%3CLI%3EDebug%20and%20step%20through%20your%20code%2C%3C%2FLI%3E%0A%3CLI%3EStream%20telemetry%20to%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fazure%2Fiot-hub%2Fabout-iot-hub%3FWT.mc_id%3Dtech-communities-blog-dglover%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%22%3EAzure%20IoT%20Hub%3C%2FA%3E%2C%3C%2FLI%3E%0A%3CLI%3EAnd%20if%20you%20are%20a%20glutton%20for%20punishment%20then%20check%20out%20the%20%5BF%23%20.Net%20Core%20IoT%5D%20in%20the%20%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2Fgloveboxes%2FdotNET-Core-IoT-Raspberry-Pi-Linux.-How-to-Build-Deploy-and-Debug%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%22%3Esamples%3C%2FA%3Efolder.%3C%2FLI%3E%0A%3C%2FOL%3E%0A%3CH2%20id%3D%22why-net-core%22%20id%3D%22toc-hId--633662631%22%20id%3D%22toc-hId--633662631%22%3EWhy%20.NET%20Core%3C%2FH2%3E%0A%3CP%3EIt%20used%20by%20millions%20of%20developers%2C%20it%20is%20mature%2C%20fast%2C%20supports%20multiple%20programming%20languages%20(C%23%2C%20F%23%2C%20and%20VB.NET)%2C%20runs%20on%20multiple%20platforms%20(Linux%2C%20macOS%2C%20and%20Windows)%2C%20and%20is%20supported%20across%20multiple%20processor%20architectures.%20It%20is%20used%20to%20build%20device%2C%20cloud%2C%20and%20IoT%20applications.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-au%2Fdotnet%2Fcore%3FWT.mc_id%3Dtech-communities-blog-dglover%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%22%3E.NET%20Core%3C%2FA%3Eis%20an%20%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2Fdotnet%2Fcoreclr%2Fblob%2Fmaster%2FLICENSE.TXT%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%22%3Eopen-source%3C%2FA%3E%2C%20general-purpose%20development%20platform%20maintained%20by%20Microsoft%20and%20the%20.NET%20community%20on%20%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2Fdotnet%2Fcore%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%22%3EGitHub%3C%2FA%3E.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH2%20id%3D%22the-net-core-iot-libraries-open-source-project%22%20id%3D%22toc-hId-1109147704%22%20id%3D%22toc-hId-1109147704%22%3EThe%20.NET%20Core%20IoT%20Libraries%20Open%20Source%20Project%3C%2FH2%3E%0A%3CP%3EThe%20Microsoft%20.NET%20Core%20team%20along%20with%20the%20developer%20community%20are%20building%20support%20for%20%3CA%20href%3D%22https%3A%2F%2Fen.wikipedia.org%2Fwiki%2FInternet_of_things%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noopener%20noreferrer%20noopener%20noreferrer%22%3EIoT%3C%2FA%3Escenarios.%20The%20%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2Fdotnet%2Fiot%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%22%3E.NET%20Core%20IoT%20Library%3C%2FA%3Eis%20supported%20on%20Linux%2C%20and%20Windows%20IoT%20Core%2C%20across%20ARM%20and%20Intel%20processor%20architectures.%20See%20the%20%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2Fdotnet%2Fiot%2Fblob%2Fmaster%2FDocumentation%2Froadmap.md%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%22%3E.NET%20Core%20IoT%20Library%20Roadmap%3C%2FA%3Efor%20more%20information.%3C%2FP%3E%0A%3CH3%20id%3D%22toc-hId--1639522762%22%20id%3D%22toc-hId--1639522762%22%3E%26nbsp%3B%3C%2FH3%3E%0A%3CH3%20id%3D%22systemdevicegpio%22%20id%3D%22toc-hId-103287573%22%20id%3D%22toc-hId-103287573%22%3ESystem.Device.Gpio%3C%2FH3%3E%0A%3CP%3EThe%20%3CA%20href%3D%22https%3A%2F%2Fwww.nuget.org%2Fpackages%2FSystem.Device.Gpio%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noopener%20noreferrer%20noopener%20noreferrer%22%3ESystem.Device.Gpio%3C%2FA%3Epackage%20supports%20general-purpose%20I%2FO%20(%3CA%20href%3D%22https%3A%2F%2Fen.wikipedia.org%2Fwiki%2FGeneral-purpose_input%2Foutput%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noopener%20noreferrer%20noopener%20noreferrer%22%3EGPIO%3C%2FA%3E)%20pins%2C%20PWM%2C%20I2C%2C%20SPI%20and%20related%20interfaces%20for%20interacting%20with%20low-level%20hardware%20pins%20to%20control%20hardware%20sensors%2C%20displays%20and%20input%20devices%20on%20single-board-computers%3B%20%3CA%20href%3D%22https%3A%2F%2Fwww.raspberrypi.org%2F%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noopener%20noreferrer%20noopener%20noreferrer%22%3ERaspberry%20Pi%3C%2FA%3E%2C%20%3CA%20href%3D%22https%3A%2F%2Fbeagleboard.org%2F%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noopener%20noreferrer%20noopener%20noreferrer%22%3EBeagleBoard%3C%2FA%3E%2C%20%3CA%20href%3D%22https%3A%2F%2Fwww.solid-run.com%2Fnxp-family%2Fhummingboard%2F%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noopener%20noreferrer%20noopener%20noreferrer%22%3EHummingBoard%3C%2FA%3E%2C%20%3CA%20href%3D%22https%3A%2F%2Fwww.hardkernel.com%2F%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noopener%20noreferrer%20noopener%20noreferrer%22%3EODROID%3C%2FA%3E%2C%20and%20other%20single-board-computers%20that%20are%20supported%20by%20Linux%20and%20Windows%2010%20IoT%20Core.%3C%2FP%3E%0A%3CH3%20id%3D%22toc-hId-1130936619%22%20id%3D%22toc-hId-1130936619%22%3E%26nbsp%3B%3C%2FH3%3E%0A%3CH3%20id%3D%22iotdevicebindings%22%20id%3D%22toc-hId--1421220342%22%20id%3D%22toc-hId--1421220342%22%3EIot.Device.Bindings%3C%2FH3%3E%0A%3CP%3EThe%20%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2Fdotnet%2Fiot%2Ftree%2Fmaster%2Fsrc%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%22%3E.NET%20Core%20IoT%20Repository%3C%2FA%3Econtains%20%3CA%20href%3D%22https%3A%2F%2Fwww.nuget.org%2Fpackages%2FIot.Device.Bindings%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noopener%20noreferrer%20noopener%20noreferrer%22%3EIoT.Device.Bindings%3C%2FA%3E%2C%20a%20growing%20set%20of%20community-maintained%20device%20bindings%20for%20IoT%20components%20that%20you%20can%20use%20with%20your%20.NET%20Core%20applications.%20If%20you%20can't%20find%20what%20you%20need%20then%20porting%20your%20own%20C%2FC%2B%2B%20driver%20libraries%20to%20.NET%20Core%20and%20C%23%20is%20pretty%20straight%20forward%20too.%26nbsp%3BThe%20drivers%20in%20the%20repository%20include%20sample%20code%20along%20with%20wiring%20diagrams.%20For%20example%20the%20%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2Fdotnet%2Fiot%2Ftree%2Fmaster%2Fsrc%2Fdevices%2FBmxx80%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%22%3EBMx280%20-%20Digital%20Pressure%20Sensors%20BMP280%2FBME280%3C%2FA%3E.%3C%2FP%3E%0A%3CP%3E%3CIMG%20src%3D%22https%3A%2F%2Fraw.githubusercontent.com%2Fgloveboxes%2FdotNET-Core-IoT-Raspberry-Pi-Linux.-How-to-Build-Deploy-and-Debug%2Fmasterdocs%2Frpi-bmp280_i2c.png%22%20border%3D%220%22%20alt%3D%22%22%20%2F%3E%3C%2FP%3E%0A%3CH2%20id%3D%22toc-hId-2118541352%22%20id%3D%22toc-hId-2118541352%22%3E%26nbsp%3B%3C%2FH2%3E%0A%3CH2%20id%3D%22software-set-up-for-linux-macos-and-windows-10-desktops%22%20id%3D%22toc-hId--433615609%22%20id%3D%22toc-hId--433615609%22%3ESoftware%20Set%20Up%20for%20Linux%2C%20macOS%2C%20and%20Windows%2010%20Desktops%3C%2FH2%3E%0A%3CP%3EYou%20can%20create%20.NET%20Core%20IoT%20projects%20on%20Linux%2C%20macOS%20and%20Windows%20desktops.%20You%20need%20to%20install%20the%20following%20software.%3C%2FP%3E%0A%3COL%3E%0A%3CLI%3E%3CA%20href%3D%22https%3A%2F%2Fdotnet.microsoft.com%2Fdownload%3FWT.mc_id%3Dtech-communities-blog-dglover%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%22%3E.NET%20Core%3C%2FA%3E%3C%2FLI%3E%0A%3CLI%3E%3CA%20href%3D%22https%3A%2F%2Fcode.visualstudio.com%3FWT.mc_id%3Dtech-communities-blog-dglover%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%22%3EVisual%20Studio%20Code%3C%2FA%3E%3C%2FLI%3E%0A%3C%2FOL%3E%0A%3CH3%20id%3D%22toc-hId--487756633%22%20id%3D%22toc-hId--487756633%22%3E%26nbsp%3B%3C%2FH3%3E%0A%3CH3%20id%3D%22additional-windows-10-software-requirements%22%20id%3D%22toc-hId-1255053702%22%20id%3D%22toc-hId-1255053702%22%3EAdditional%20Windows%2010%20Software%20Requirements%3C%2FH3%3E%0A%3COL%3E%0A%3CLI%3E%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fwindows%2Fwsl%2Finstall-win10%3FWT.mc_id%3Dtech-communities-blog-dglover%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%22%3EWindows%20Subsystem%20for%20Linux%20(WSL)%3C%2FA%3E.%20I%20suggest%20you%20install%20the%20Ubuntu%2018.04%20distribution.%3C%2FLI%3E%0A%3CLI%3E%3CA%20href%3D%22https%3A%2F%2Fwww.putty.org%2F%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noopener%20noreferrer%20noopener%20noreferrer%22%3EPuTTY%20SSH%20and%20telnet%20client%3C%2FA%3E%3C%2FLI%3E%0A%3CLI%3EThe%20%3CA%20href%3D%22https%3A%2F%2Fmarketplace.visualstudio.com%2Fitemdetails%3FitemName%3Dlfurzewaddock.vscode-wsl-workspacefolder%26amp%3BWT.mc_id%3Dtech-communities-blog-dglover%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%22%3EWSL%20workspaceFolder%3C%2FA%3EVisual%20Studio%20Extension%3C%2FLI%3E%0A%3C%2FOL%3E%0A%3CH2%20id%3D%22toc-hId-499848100%22%20id%3D%22toc-hId-499848100%22%3E%26nbsp%3B%3C%2FH2%3E%0A%3CH2%20id%3D%22setting-up-your-raspberry-pi%22%20id%3D%22toc-hId--2052308861%22%20id%3D%22toc-hId--2052308861%22%3ESetting%20up%20your%20Raspberry%20Pi%3C%2FH2%3E%0A%3CP%3E.Net%20Core%20requires%20an%20AMR32v7%20processor%20and%20above%2C%20so%20anything%20Raspberry%20Pi%202%20or%20better%20and%20you%20are%20good%20to%20go.%20Note%2C%20Raspberry%20Pi%20Zero%20is%20an%20ARM32v6%20processor%2C%20and%20not%20supported.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EIf%20you've%20not%20set%20up%20a%20Raspberry%20Pi%20before%20then%20this%20is%20a%20great%20guide.%20%22%3CA%20href%3D%22https%3A%2F%2Fdesertbot.io%2Fblog%2Fheadless-raspberry-pi-3-bplus-ssh-wifi-setup%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noopener%20noreferrer%20noopener%20noreferrer%22%3EHEADLESS%20RASPBERRY%20PI%203%20B%2B%20SSH%20WIFI%20SETUP%20(MAC%20%2B%20WINDOWS)%3C%2FA%3E%22.%20The%20Instructions%20outlined%20for%20macOS%20will%20work%20on%20Linux.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3EThis%20walk-through%20assumes%20the%20default%20Raspberry%20Pi%20network%20name%2C%20'raspberrypi.local'%2C%20and%20the%20default%20password%2C%20'raspberry'.%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CIMG%20src%3D%22https%3A%2F%2Fraw.githubusercontent.com%2Fgloveboxes%2FdotNET-Core-IoT-Raspberry-Pi-Linux.-How-to-Build-Deploy-and-Debug%2Fmasterdocs%2Fraspberrypi-3a-plus.jpg%22%20border%3D%220%22%20alt%3D%22%22%20%2F%3E%3C%2FP%3E%0A%3CH2%20id%3D%22configure-connection-to-your-raspberry-pi%22%20id%3D%22toc-hId--309498526%22%20id%3D%22toc-hId--309498526%22%3EConfigure%20Connection%20to%20your%20Raspberry%20Pi%3C%2FH2%3E%0A%3CP%3EThe%20following%20creates%20a%20new%20SSH%20key%2C%20copies%20the%20public%20key%20to%20the%20Raspberry%20Pi%2C%20and%20then%20installs%20the%20Visual%20Studio%20Debugger%20on%20the%20Raspberry%20Pi.%20Take%20the%20default%20options.%3C%2FP%3E%0A%3CH3%20id%3D%22toc-hId--363639550%22%20id%3D%22toc-hId--363639550%22%3E%26nbsp%3B%3C%2FH3%3E%0A%3CH3%20id%3D%22from-linux-and-macos%22%20id%3D%22toc-hId--676517844%22%20id%3D%22toc-hId--676517844%22%3EFrom%20Linux%20and%20macOS%3C%2FH3%3E%0A%3CP%3EOpen%20a%20new%20Terminal%2C%20and%20copy%20and%20paste%20the%20following%20command.%3C%2FP%3E%0A%3CPRE%3E%3CCODE%3Essh-keygen%20-t%20rsa%20%26amp%3B%26amp%3B%20ssh-copy-id%20pi%40raspberrypi.local%20%26amp%3B%26amp%3B%20%5C%0Assh%20pi%40raspberry.local%20%22curl%20-sSL%20https%3A%2F%2Faka.ms%2Fgetvsdbgsh%20%7C%20bash%20%2Fdev%2Fstdin%20-r%20linux-arm%20-v%20latest%20-l%20~%2Fvsdbg%22%0A%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CH3%20id%3D%22toc-hId-1066292491%22%20id%3D%22toc-hId-1066292491%22%3E%26nbsp%3B%3C%2FH3%3E%0A%3CH3%20id%3D%22from-windows-10%22%20id%3D%22toc-hId--1485864470%22%20id%3D%22toc-hId--1485864470%22%3EFrom%20Windows%2010%3C%2FH3%3E%0A%3CP%3EPress%20the%20Windows%20Key%20%3CIMG%20src%3D%22https%3A%2F%2Fraw.githubusercontent.com%2Fgloveboxes%2FdotNET-Core-IoT-Raspberry-Pi-Linux.-How-to-Build-Deploy-and-Debug%2Fmaster%2Fdocs%2Fwindows-key-small.png%22%20border%3D%220%22%20alt%3D%22windows%20key%22%20%2F%3E%2C%20type%20'cmd'%2C%20then%20press%20the%20Enter%20key%20to%20open%20the%20Windows%20command%20prompt.%20Then%20copy%20and%20paste%20the%20following%20commands.%3C%2FP%3E%0A%3CPRE%3E%3CCODE%3Eping%20raspberrypi.local%0A%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3EReplace%20xxx.xxx.xxx.xxx%20with%20the%20IP%20Address%20of%20the%20Raspberry%20Pi%20and%20then%20copy%20and%20paste%20the%20following%20command%20into%20the%20Windows%20Command%20prompt.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%3E%3CCODE%3Ebash%20-c%20%22ssh-keygen%20-t%20rsa%20%26amp%3B%26amp%3B%20ssh-copy-id%20pi%40xxx.xxx.xxx.xxx%22%20%26amp%3B%26amp%3B%20%5E%0Aplink%20-ssh%20-pw%20raspberry%20pi%40raspberrypi.local%20%22curl%20-sSL%20https%3A%2F%2Faka.ms%2Fgetvsdbgsh%20%7C%20bash%20%2Fdev%2Fstdin%20-r%20linux-arm%20-v%20latest%20-l%20~%2Fvsdbg%22%0A%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CH2%20id%3D%22creating-your-first-net-core-iot-project%22%20id%3D%22toc-hId-2053897224%22%20id%3D%22toc-hId-2053897224%22%3ECreating%20your%20first%20.NET%20Core%20IoT%20project%3C%2FH2%3E%0A%3CP%3EOpen%20a%20command%20prompt%20or%20terminal%20window%2C%20and%20paste%20in%20the%20following%20command(s).%20It%20will%20create%20the%20project%20directory%2C%20create%20the%20.NET%20Core%20Console%20app%2C%20add%20the%20Iot.Device.Bindings%20package%2C%20and%20then%20launch%20Visual%20Studio%20Code.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%3E%3CCODE%3Emkdir%20dotnet.core.iot.csharp%20%26amp%3B%26amp%3B%20cd%20dotnet.core.iot.csharp%0A%0Adotnet%20new%20console%20--langVersion%3Dlatest%20%26amp%3B%26amp%3B%20dotnet%20add%20package%20Iot.Device.Bindings%20--version%200.1.0-prerelease*%0A%0Acode%20.%0A%3C%2FCODE%3E%3C%2FPRE%3E%0A%3COL%3E%0A%3CLI%3EAdd%20the%20Visual%20Studio%20Code%20Build%20and%20Debug%20assets%3C%2FLI%3E%0A%3C%2FOL%3E%0A%3CP%3E%3CIMG%20src%3D%22https%3A%2F%2Fraw.githubusercontent.com%2Fgloveboxes%2FdotNET-Core-IoT-Raspberry-Pi-Linux.-How-to-Build-Deploy-and-Debug%2Fmasterdocs%2Fcreate-new-project.png%22%20border%3D%220%22%20alt%3D%22%22%20%2F%3E%3C%2FP%3E%0A%3COL%3E%0A%3CLI%3EReplace%20the%20code%20in%20program.cs%20file%20with%20the%20following%20code.%20This%20code%20will%20read%20the%20Raspberry%20Pi%20CPU%20Temperature%20and%20display%20it%20in%20the%20system%20console%20window.%3C%2FLI%3E%0A%3C%2FOL%3E%0A%3CPRE%3E%3CCODE%3Eusing%20System%3B%0Ausing%20Iot.Device.CpuTemperature%3B%0Ausing%20System.Threading%3B%0A%0Anamespace%20dotnet.core.iot%0A%7B%0A%20%20%20%20class%20Program%0A%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20static%20CpuTemperature%20temperature%20%3D%20new%20CpuTemperature()%3B%0A%20%20%20%20%20%20%20%20static%20void%20Main(string%5B%5D%20args)%0A%20%20%20%20%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20while%20(true)%0A%20%20%20%20%20%20%20%20%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20if%20(temperature.IsAvailable)%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20Console.WriteLine(%24%22The%20CPU%20temperature%20is%20%7Btemperature.Temperature.Celsius%7D%22)%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20Thread.Sleep(2000)%3B%20%2F%2F%20sleep%20for%202000%20milliseconds%2C%202%20seconds%0A%20%20%20%20%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%7D%0A%7D%0A%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3EYour%20Visual%20Studio%20Code%20%3CSTRONG%3Eprogram.cs%3C%2FSTRONG%3Efile%20should%20look%20like%20the%20following%20screenshot.%3C%2FP%3E%0A%3CP%3E%3CIMG%20src%3D%22https%3A%2F%2Fraw.githubusercontent.com%2Fgloveboxes%2FdotNET-Core-IoT-Raspberry-Pi-Linux.-How-to-Build-Deploy-and-Debug%2Fmaster%2Fdocs%2Fcpu-temperature-program.png%22%20border%3D%220%22%20alt%3D%22sample%20program%22%20%2F%3E%3C%2FP%3E%0A%3CH2%20id%3D%22toc-hId--498259737%22%20id%3D%22toc-hId--498259737%22%3E%26nbsp%3B%3C%2FH2%3E%0A%3CH2%20id%3D%22deploying-the-project-to-your-raspberry-pi%22%20id%3D%22toc-hId-1244550598%22%20id%3D%22toc-hId-1244550598%22%3EDeploying%20the%20project%20to%20your%20Raspberry%20Pi%3C%2FH2%3E%0A%3CP%3ETo%20deploy%20a%20project%20to%20your%20Raspberry%20Pi%20you%20need%20to%20configure%20Visual%20Studio%20Code%20to%20compile%20for%20%3CSTRONG%3Elinux-arm%3C%2FSTRONG%3E%2C%20how%20to%20copy%20the%20compiled%20code%20to%20the%20Raspberry%20Pi%2C%20and%20finally%20how%20to%20attach%20the%20debugger.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EFor%20this%20walk-through%2C%20we%20are%20going%20to%20use%20%3CA%20href%3D%22https%3A%2F%2Fen.wikipedia.org%2Fwiki%2FRsync%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ersync%3C%2FA%3Eto%20copy%20program%20files%20to%20the%20Raspberry%20Pi.%20Rsync%20is%20a%20very%20efficient%20file%20transfer%20protocol%2C%20comes%20standard%20with%20Linux%2C%20macOS%2C%20and%20Windows%20with%20the%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fwindows%2Fwsl%2Finstall-win10%3FWT.mc_id%3Dtech-communities-blog-dglover%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%22%3EWindows%20Subsystem%20for%20Linux%20(WSL)%3C%2FA%3Einstalled.%3C%2FP%3E%0A%3CH2%20id%3D%22toc-hId--1307606363%22%20id%3D%22toc-hId--1307606363%22%3E%26nbsp%3B%3C%2FH2%3E%0A%3CH2%20id%3D%22updating-the-visual-studio-code-build-files%22%20id%3D%22toc-hId-435203972%22%20id%3D%22toc-hId-435203972%22%3EUpdating%20the%20Visual%20Studio%20Code%20Build%20Files%3C%2FH2%3E%0A%3CP%3EWe%20need%20to%20update%20the%20%3CA%20href%3D%22https%3A%2F%2Fcode.visualstudio.com%2Fdocs%2Feditor%2Fdebugging%3FWT.mc_id%3Dtech-communities-blog-dglover%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%22%3Elaunch.json%3C%2FA%3Eand%20%3CA%20href%3D%22https%3A%2F%2Fcode.visualstudio.com%2Fdocs%2Feditor%2Fdebugging%3FWT.mc_id%3Dtech-communities-blog-dglover%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%22%3Etasks.json%3C%2FA%3Efiles%20with%20the%20following%20code.%3C%2FP%3E%0A%3CP%3E%3CIMG%20src%3D%22https%3A%2F%2Fraw.githubusercontent.com%2Fgloveboxes%2FdotNET-Core-IoT-Raspberry-Pi-Linux.-How-to-Build-Deploy-and-Debug%2Fmasterdocs%2Fbuild-configuration.png%22%20border%3D%220%22%20alt%3D%22%22%20%2F%3E%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3EThis%20walk-through%20assumes%20the%20default%20Raspberry%20Pi%20network%20name%2C%20'raspberrypi.local'%2C%20and%20the%20default%20password%2C%20'raspberry'.%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CH3%20id%3D%22toc-hId-381062948%22%20id%3D%22toc-hId-381062948%22%3E%26nbsp%3B%3C%2FH3%3E%0A%3CH3%20id%3D%22launchjson%22%20id%3D%22toc-hId-2123873283%22%20id%3D%22toc-hId-2123873283%22%3Elaunch.json%3C%2FH3%3E%0A%3CP%3EThe%20launch.json%20file%20calls%20a%20%3CSTRONG%3Epublish%3C%2FSTRONG%3Eprelaunch%20task%20which%20builds%20and%20copies%20the%20program%20to%20the%20Raspberry%20Pi%2C%20it%20then%20starts%20the%20program%20on%20the%20Raspberry%20Pi%20and%20attaches%20the%20debugger.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%3E%3CCODE%3E%7B%0A%20%20%20%20%22version%22%3A%20%220.2.0%22%2C%0A%20%20%20%20%22configurations%22%3A%20%5B%0A%20%20%20%20%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%22name%22%3A%20%22Raspberry%20Pi%20Publish%2C%20Launch%2C%20and%20Attach%20Debugger%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%22type%22%3A%20%22coreclr%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%22request%22%3A%20%22launch%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%22preLaunchTask%22%3A%20%22RaspberryPublish%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%22program%22%3A%20%22~%2F%24%7BworkspaceFolderBasename%7D%2F%24%7BworkspaceFolderBasename%7D%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%22cwd%22%3A%20%22~%2F%24%7BworkspaceFolderBasename%7D%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%22stopAtEntry%22%3A%20false%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%22console%22%3A%20%22internalConsole%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%22args%22%3A%20%5B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22https%3A%2F%2Fyour-dmx-function.azurewebsites.net%2Fapi%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%5D%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%22pipeTransport%22%3A%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22pipeCwd%22%3A%20%22%24%7BworkspaceRoot%7D%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22pipeProgram%22%3A%20%22%2Fusr%2Fbin%2Fssh%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22pipeArgs%22%3A%20%5B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22pi%40raspberrypi.local%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%5D%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22debuggerPath%22%3A%20%22~%2Fvsdbg%2Fvsdbg%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%7D%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%22windows%22%3A%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22pipeTransport%22%3A%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22pipeCwd%22%3A%20%22%24%7BworkspaceRoot%7D%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22pipeProgram%22%3A%20%22plink%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22pipeArgs%22%3A%20%5B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22-ssh%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22-pw%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22raspberry%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22pi%40raspberrypi.local%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%5D%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22debuggerPath%22%3A%20%22~%2Fvsdbg%2Fvsdbg%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%5D%0A%7D%0A%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CH3%20id%3D%22toc-hId-1810994989%22%20id%3D%22toc-hId-1810994989%22%3E%26nbsp%3B%3C%2FH3%3E%0A%3CH3%20id%3D%22tasksjson%22%20id%3D%22toc-hId--741161972%22%20id%3D%22toc-hId--741161972%22%3Etasks.json%3C%2FH3%3E%0A%3CP%3EThe%20tasks.json%20file%20defines%20how%20to%20compile%20the%20project%20for%20linux-arm%20and%20how%20to%20copy%20the%20program%20to%20the%20Raspberry%20Pi%20with%20rsync.%20On%20%3CSTRONG%3EWindows%3C%2FSTRONG%3E%2C%20you%20must%20explicitly%20specify%20the%20%3CSTRONG%3EIP%20Address%3C%2FSTRONG%3Eof%20the%20Raspberry%20Pi%20as%20rsync%20is%20called%20via%20Bash%20and%20the%20Windows%20Subsystem%20for%20Linux%20does%20not%20resolve%20.local%20DNS%20names.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%3E%3CCODE%3E%7B%0A%20%20%20%20%22version%22%3A%20%222.0.0%22%2C%0A%20%20%20%20%22tasks%22%3A%20%5B%0A%20%20%20%20%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%22label%22%3A%20%22RaspberryPublish%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%22command%22%3A%20%22sh%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%22type%22%3A%20%22shell%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%22problemMatcher%22%3A%20%22%24msCompile%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%22args%22%3A%20%5B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22-c%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22%5C%22dotnet%20publish%20-r%20linux-arm%20-o%20bin%2Flinux-arm%2Fpublish%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22%24%7BworkspaceFolder%7D%2F%24%7BworkspaceFolderBasename%7D.csproj%5C%22%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22%3B%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22sh%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22-c%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22%5C%22rsync%20-rvuz%20%24%7BworkspaceFolder%7D%2Fbin%2Flinux-arm%2Fpublish%2F%20pi%40raspberrypi.local%3A~%2F%24%7BworkspaceFolderBasename%7D%5C%22%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%5D%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%22windows%22%3A%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22command%22%3A%20%22cmd%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22args%22%3A%20%5B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22%2Fc%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22%5C%22dotnet%20publish%20-r%20linux-arm%20-o%20bin%5C%5Clinux-arm%5C%5Cpublish%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22%24%7BworkspaceFolder%7D%5C%5C%24%7BworkspaceFolderBasename%7D.csproj%5C%22%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22%26amp%3B%26amp%3B%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22bash%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22-c%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22%5C%22rsync%20-rvuz%20%24(wslpath%20'%24%7BworkspaceFolder%7D')%2Fbin%2Flinux-arm%2Fpublish%2F%20pi%40raspberrypi.local%3A~%2F%24%7BworkspaceFolderBasename%7D%5C%22%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%5D%0A%20%20%20%20%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%5D%0A%7D%0A%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CH2%20id%3D%22toc-hId--1496367574%22%20id%3D%22toc-hId--1496367574%22%3E%26nbsp%3B%3C%2FH2%3E%0A%3CH2%20id%3D%22build-deploy-and-debug-your-net-core-iot-app%22%20id%3D%22toc-hId-246442761%22%20id%3D%22toc-hId-246442761%22%3EBuild%2C%20Deploy%20and%20Debug%20your%20.NET%20Core%20IoT%20App%3C%2FH2%3E%0A%3CP%3EReview%20this%20%3CA%20href%3D%22https%3A%2F%2Fcode.visualstudio.com%2Fdocs%2Feditor%2Fdebugging%3FWT.mc_id%3Dtech-communities-blog-dglover%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%22%3EVisual%20Studio%20Debugger%20Guide%3C%2FA%3Eif%20you've%20not%20used%20the%20debugger%20before.%3C%2FP%3E%0A%3CP%3ESet%20a%20breakpoint%20in%20your%20code%2C%20for%20example%20at%20the%2015%2C%20and%20from%20Visual%20Studio%20Code%20click%20the%20Debug%20icon%20on%20the%20Activity%20bar%2C%20ensure%20%22%3CSTRONG%3EPublish%2C%20Launch%20and%20Attach%20Debugger%3C%2FSTRONG%3E%22%20is%20selected%20in%20the%20dropdown%2C%20and%20click%20the%20green%20run%20icon.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EYour%20code%20will%20build%2C%20it%20will%20be%20copied%20to%20your%20Raspberry%20Pi%20and%20the%20debugger%20will%20be%20attached%20and%20you%20can%20now%20start%20stepping%20through%20your%20code.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CIMG%20src%3D%22https%3A%2F%2Fraw.githubusercontent.com%2Fgloveboxes%2FdotNET-Core-IoT-Raspberry-Pi-Linux.-How-to-Build-Deploy-and-Debug%2Fmaster%2Fdocs%2Fbuild-deploy-debug.png%22%20border%3D%220%22%20alt%3D%22Publish%2C%20Launch%20and%20Attach%20Debugger%22%20%2F%3E%3C%2FP%3E%0A%3CH2%20id%3D%22toc-hId-1989253096%22%20id%3D%22toc-hId-1989253096%22%3E%26nbsp%3B%3C%2FH2%3E%0A%3CH2%20id%3D%22connect-your-raspberry-pi-to-azure-iot-hub%22%20id%3D%22toc-hId--562903865%22%20id%3D%22toc-hId--562903865%22%3EConnect%20your%20Raspberry%20Pi%20to%20Azure%20IoT%20Hub%3C%2FH2%3E%0A%3COL%3E%0A%3CLI%3E%0A%3CP%3EFollow%20the%20%22%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fazure%2Fiot-hub%2Fquickstart-send-telemetry-dotnet%3FWT.mc_id%3Dtech-communities-blog-dglover%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%22%3ECreate%20an%20Azure%20IoT%20Hub%20(Free)%3C%2FA%3E%22%20tutorial%20until%20the%20%22Send%20simulated%20telemetry%22%20section.%20You%20will%20need%20to%20the%20connection%20string%20of%20the%20device%20you%20created.%3C%2FP%3E%0A%3C%2FLI%3E%0A%3CLI%3E%0A%3CP%3EAdd%20the%20Package%20references%20for%20Azure%20IoT%20Hub%20and%20JSON.NET.%20This%20can%20either%20be%20done%20by%20executing%20the%20'dotnet%20add%20package'%20command%2C%20or%20by%20updating%20the%20references%20directly%20in%20the%20.csproj%20file.%3C%2FP%3E%0A%3C%2FLI%3E%0A%3C%2FOL%3E%0A%3CP%3EOpen%20the%20dotnet.core.iot.csharp.csproj%20file%20and%20update%20the%20section%20as%20follows.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%3E%3CCODE%3E%3CITEMGROUP%3E%0A%20%20%20%20%3CPACKAGEREFERENCE%20include%3D%22Iot.Device.Bindings%22%20version%3D%220.1.0-prerelease*%22%3E%3C%2FPACKAGEREFERENCE%3E%0A%20%20%20%20%3CPACKAGEREFERENCE%20include%3D%22Microsoft.Azure.Devices.Client%22%20version%3D%221.*%22%3E%3C%2FPACKAGEREFERENCE%3E%0A%20%20%20%20%3CPACKAGEREFERENCE%20include%3D%22Newtonsoft.Json%22%20version%3D%2212.0.1%22%3E%3C%2FPACKAGEREFERENCE%3E%20%20%0A%3C%2FITEMGROUP%3E%0A%3C%2FCODE%3E%3C%2FPRE%3E%0A%3COL%3E%0A%3CLI%3EReplace%20the%20code%20in%20program.cs%20file%20with%20the%20following%20code%20and%20add%20your%20device%20connection%20string.%3C%2FLI%3E%0A%3C%2FOL%3E%0A%3CP%3EThis%20code%20will%20read%20the%20Raspberry%20Pi%20CPU%20Temperature%2C%20display%20it%2C%20then%20send%20the%20telemetry%20to%20Azure%20IoT%20Hub.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%3E%3CCODE%3Eusing%20System%3B%0Ausing%20Iot.Device.CpuTemperature%3B%0Ausing%20Newtonsoft.Json%3B%0Ausing%20Microsoft.Azure.Devices.Client%3B%0Ausing%20System.Text%3B%0Ausing%20System.Threading%3B%0Ausing%20System.Threading.Tasks%3B%0A%0Anamespace%20dotnet.core.iot%0A%7B%0A%20%20%20%20class%20Program%0A%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20const%20string%20DeviceConnectionString%20%3D%20%22%3CYOUR%20azure%3D%22%22%20iot%3D%22%22%20hub%3D%22%22%20connection%3D%22%22%20string%3D%22%22%3E%22%3B%0A%0A%20%20%20%20%20%20%20%20%2F%2F%20Replace%20with%20the%20device%20id%20you%20used%20when%20you%20created%20the%20device%20in%20Azure%20IoT%20Hub%0A%20%20%20%20%20%20%20%20const%20string%20DeviceId%20%3D%20%22%3CYOUR%20device%3D%22%22%20id%3D%22%22%3E%22%3B%0A%20%20%20%20%20%20%20%20static%20DeviceClient%20_deviceClient%20%3D%20DeviceClient.CreateFromConnectionString(DeviceConnectionString%2C%20TransportType.Mqtt)%3B%0A%20%20%20%20%20%20%20%20static%20CpuTemperature%20_temperature%20%3D%20new%20CpuTemperature()%3B%0A%20%20%20%20%20%20%20%20static%20int%20_msgId%20%3D%200%3B%0A%20%20%20%20%20%20%20%20const%20double%20TemperatureThreshold%20%3D%2042.0%3B%0A%0A%20%20%20%20%20%20%20%20static%20async%20Task%20Main(string%5B%5D%20args)%0A%20%20%20%20%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20while%20(true)%0A%20%20%20%20%20%20%20%20%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20if%20(_temperature.IsAvailable)%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20Console.WriteLine(%24%22The%20CPU%20temperature%20is%20%7BMath.Round(_temperature.Temperature.Celsius%2C%202)%7D%22)%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20await%20SendMsgIotHub(_temperature.Temperature.Celsius)%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20Thread.Sleep(2000)%3B%20%2F%2F%20sleep%20for%202000%20milliseconds%0A%20%20%20%20%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20%7D%0A%0A%20%20%20%20%20%20%20%20private%20static%20async%20Task%20SendMsgIotHub(double%20temperature)%0A%20%20%20%20%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20var%20telemetry%20%3D%20new%20Telemetry()%20%7B%20Temperature%20%3D%20Math.Round(temperature%2C%202)%2C%20MessageId%20%3D%20_msgId%2B%2B%20%7D%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20string%20json%20%3D%20JsonConvert.SerializeObject(telemetry)%3B%0A%0A%20%20%20%20%20%20%20%20%20%20%20%20Console.WriteLine(%24%22Sending%20%7Bjson%7D%22)%3B%0A%0A%20%20%20%20%20%20%20%20%20%20%20%20Message%20eventMessage%20%3D%20new%20Message(Encoding.UTF8.GetBytes(json))%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20eventMessage.Properties.Add(%22temperatureAlert%22%2C%20(temperature%20%26gt%3B%20TemperatureThreshold)%20%3F%20%22true%22%20%3A%20%22false%22)%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20await%20_deviceClient.SendEventAsync(eventMessage).ConfigureAwait(false)%3B%0A%20%20%20%20%20%20%20%20%7D%0A%0A%20%20%20%20%20%20%20%20class%20Telemetry%0A%20%20%20%20%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%5BJsonPropertyAttribute%20(PropertyName%3D%22temperature%22)%5D%20%0A%20%20%20%20%20%20%20%20%20%20%20%20public%20double%20Temperature%20%7B%20get%3B%20set%3B%20%7D%20%3D%200%3B%0A%0A%20%20%20%20%20%20%20%20%20%20%20%20%5BJsonPropertyAttribute%20(PropertyName%3D%22messageId%22)%5D%20%0A%20%20%20%20%20%20%20%20%20%20%20%20public%20int%20MessageId%20%7B%20get%3B%20set%3B%20%7D%20%3D%200%3B%0A%0A%20%20%20%20%20%20%20%20%20%20%20%20%5BJsonPropertyAttribute%20(PropertyName%3D%22deviceId%22)%5D%20%0A%20%20%20%20%20%20%20%20%20%20%20%20public%20string%20DeviceId%20%7Bget%3B%20set%3B%7D%20%3D%20Program.DeviceId%3B%0A%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%7D%0A%7D%0A%3C%2FYOUR%3E%3C%2FYOUR%3E%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CH2%20id%3D%22toc-hId-1179906470%22%20id%3D%22toc-hId-1179906470%22%3E%26nbsp%3B%3C%2FH2%3E%0A%3CH2%20id%3D%22redeploy-the-app-to-the-raspberry-pi%22%20id%3D%22toc-hId--1372250491%22%20id%3D%22toc-hId--1372250491%22%3ERedeploy%20the%20App%20to%20the%20Raspberry%20Pi%3C%2FH2%3E%0A%3CP%3EPress%20F5%20to%20run%20the%20current%20'Publish%2C%20Launch%2C%20and%20Attach%20Debugger'%20build%20task.%3C%2FP%3E%0A%3CH2%20id%3D%22toc-hId-370559844%22%20id%3D%22toc-hId-370559844%22%3E%26nbsp%3B%3C%2FH2%3E%0A%3CH2%20id%3D%22monitor-the-azure-iot-hub-telemetry%22%20id%3D%22toc-hId-2113370179%22%20id%3D%22toc-hId-2113370179%22%3EMonitor%20the%20Azure%20IoT%20Hub%20Telemetry%3C%2FH2%3E%0A%3COL%3E%0A%3CLI%3E%0A%3CP%3EInstall%20the%20%3CA%20href%3D%22https%3A%2F%2Fmarketplace.visualstudio.com%2Fitemdetails%3FitemName%3Dvsciot-vscode.azure-iot-toolkit%26amp%3BWT.mc_id%3Dtech-communities-blog-dglover%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%22%3EVisual%20Studio%20IoT%20Hub%20Toolkit%3C%2FA%3E.%3C%2FP%3E%0A%3C%2FLI%3E%0A%3CLI%3E%0A%3CP%3EReview%20the%20%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2FMicrosoft%2Fvscode-azure-iot-toolkit%2Fwiki%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%22%3EVisual%20Studio%20IoT%20Hub%20Toolkit%3C%2FA%3E%5D%20Wiki%20for%20information%20on%20using%20the%20IoT%20Hub%20Toolkit%20Visual%20Studio%20Extension.%3C%2FP%3E%0A%3C%2FLI%3E%0A%3C%2FOL%3E%0A%3CH2%20id%3D%22toc-hId-1800491885%22%20id%3D%22toc-hId-1800491885%22%3E%26nbsp%3B%3C%2FH2%3E%0A%3CH2%20id%3D%22references%22%20id%3D%22toc-hId--751665076%22%20id%3D%22toc-hId--751665076%22%3EReferences%3C%2FH2%3E%0A%3CP%3E%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2FOmniSharp%2Fomnisharp-vscode%2Fwiki%2FRemote-Debugging-On-Linux-Arm%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%22%3ERemote%20Debugging%20On%20Linux%20Arm%3C%2FA%3E%3C%2FP%3E%0A%3CP%3E%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-au%2Fdotnet%2Fapi%2Foverview%2Fazure%2Fiot%3Fview%3Dazure-dotnet%26amp%3BWT.mc_id%3Dtech-communities-blog-dglover%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%22%3EAzure%20IoT%20libraries%20for%20.NET%3C%2FA%3E%3C%2FP%3E%0A%3CH2%20id%3D%22toc-hId-991145259%22%20id%3D%22toc-hId-991145259%22%3E%26nbsp%3B%3C%2FH2%3E%0A%3CH2%20id%3D%22quick-notes%22%20id%3D%22toc-hId--1561011702%22%20id%3D%22toc-hId--1561011702%22%3EQuick%20Notes%3C%2FH2%3E%0A%3CP%3EUsing%20the%20new%20built%20in%20Windows%20OpenSSH%20client.%20Windows%2010%201809%2B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EInstall%20OpenSSH%20Client%20on%20Windows%20(one%20time%20only%20operation).%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EFrom%20PowerShell%20as%20Administrator%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%3E%3CCODE%3EAdd-WindowsCapability%20-Online%20-Name%20OpenSSH.Client%0A%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EClose%20PowerShell%20and%20reopen%20as%20%3CSTRONG%3Enon%20administrator%3C%2FSTRONG%3Euser.%3C%2FP%3E%0A%3CPRE%3E%3CCODE%3Essh-keygen%20-t%20rsa%20%3B%20%60%0Acat%20~%2F.ssh%2Fid_rsa.pub%20%7C%20ssh%20user%40123.45.56.78%20%22mkdir%20~%2F.ssh%3B%20cat%20%26gt%3B%26gt%3B%20~%2F.ssh%2Fauthorized_keys%22%0A%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EReferences%3C%2FP%3E%0A%3CUL%3E%0A%3CLI%3E%3CA%20href%3D%22https%3A%2F%2Fserverfault.com%2Fquestions%2F224810%2Fis-there-an-equivalent-to-ssh-copy-id-for-windows%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noopener%20noreferrer%20noopener%20noreferrer%22%3EIs%20there%20an%20equivalent%20to%20ssh-copy-id%20for%20Windows%3F%3C%2FA%3E%3C%2FLI%3E%0A%3CLI%3E%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fwindows-server%2Fadministration%2Fopenssh%2Fopenssh_install_firstuse%3FWT.mc_id%3Dtech-communities-blog-dglover%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%22%3EInstallation%20of%20OpenSSH%20For%20Windows%20Server%202019%20and%20Windows%2010%3C%2FA%3E%3C%2FLI%3E%0A%3C%2FUL%3E%3C%2FLINGO-BODY%3E%3CLINGO-TEASER%20id%3D%22lingo-teaser-776767%22%20slang%3D%22en-US%22%3E%3CP%3ELearn%20how%20to%20Build%2C%20Deploy%20and%20Debug%20Azure%20IoT%20Apps%20with%20.NET%20Core%20IoT%20for%20Raspberry%20Pi%20and%20Visual%20Studio%20Code.%3C%2FP%3E%0A%3CP%3E%3CIMG%20src%3D%22https%3A%2F%2Fraw.githubusercontent.com%2Fgloveboxes%2FdotNET-Core-IoT-Raspberry-Pi-Linux.-How-to-Build-Deploy-and-Debug%2Fmaster%2Fdocs%2Fbanner.png%22%20border%3D%220%22%20alt%3D%22.net%20core%20loves%20single%20board%20computers%22%20%2F%3E%3C%2FP%3E%0A%3CH2%20id%3D%22why-net-core%22%20id%3D%22toc-hId-181798633%22%3EWhy%20.NET%20Core%3C%2FH2%3E%0A%3CP%3EIt%20used%20by%20millions%20of%20developers%2C%20it%20is%20mature%2C%20fast%2C%20supports%20multiple%20programming%20languages%20(C%23%2C%20F%23%2C%20and%20VB.NET)%2C%20runs%20on%20multiple%20platforms%20(Linux%2C%20macOS%2C%20and%20Windows)%2C%20and%20is%20supported%20across%20multiple%20processor%20architectures.%20It%20is%20used%20to%20build%20device%2C%20cloud%2C%20and%20IoT%20applications.%3C%2FP%3E%3C%2FLINGO-TEASER%3E
Microsoft

Learn how to Build, Deploy and Debug Azure IoT Apps with .NET Core IoT for Raspberry Pi and Visual Studio Code.

.net core loves single board computers

 

Follow me (@dglover) on Twitter.

 

Source Code

The source and the samples for this walk-through can be found here.

 

Introduction

The .NET Core IoT Library connects your applications to hardware. In this walk-through you will learn how to:

  1. Develop a C# .NET Core IoT application from a Linux, macOS or Windows 10 desktop,
  2. Deploy the app to a Raspberry Pi running Linux (or another Linux board such as the BeagleBone Black),
  3. Debug and step through your code,
  4. Stream telemetry to Azure IoT Hub,
  5. And if you are a glutton for punishment then check out the [F# .Net Core IoT] in the samples folder.

Why .NET Core

It used by millions of developers, it is mature, fast, supports multiple programming languages (C#, F#, and VB.NET), runs on multiple platforms (Linux, macOS, and Windows), and is supported across multiple processor architectures. It is used to build device, cloud, and IoT applications.

 

.NET Core is an open-source, general-purpose development platform maintained by Microsoft and the .NET community on GitHub.

 

The .NET Core IoT Libraries Open Source Project

The Microsoft .NET Core team along with the developer community are building support for IoT scenarios. The .NET Core IoT Library is supported on Linux, and Windows IoT Core, across ARM and Intel processor architectures. See the .NET Core IoT Library Roadmap for more information.

 

System.Device.Gpio

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.

 

Iot.Device.Bindings

The .NET Core IoT Repository contains IoT.Device.Bindings, a growing set of community-maintained device bindings for IoT components that you can use with your .NET Core applications. If you can't find what you need then porting your own C/C++ driver libraries to .NET Core and C# is pretty straight forward too. The drivers in the repository include sample code along with wiring diagrams. For example the BMx280 - Digital Pressure Sensors BMP280/BME280.

 

Software Set Up for Linux, macOS, and Windows 10 Desktops

You can create .NET Core IoT projects on Linux, macOS and Windows desktops. You need to install the following software.

  1. .NET Core
  2. Visual Studio Code

 

Additional Windows 10 Software Requirements

  1. Windows Subsystem for Linux (WSL). I suggest you install the Ubuntu 18.04 distribution.
  2. PuTTY SSH and telnet client
  3. The WSL workspaceFolder Visual Studio Extension

 

Setting up your Raspberry Pi

.Net Core requires an AMR32v7 processor and above, so anything Raspberry Pi 2 or better and you are good to go. Note, Raspberry Pi Zero is an ARM32v6 processor, and not supported.

 

If you've not set up a Raspberry Pi before then this is a great guide. "HEADLESS RASPBERRY PI 3 B+ SSH WIFI SETUP (MAC + WINDOWS)". The Instructions outlined for macOS will work on Linux.

 

This walk-through assumes the default Raspberry Pi network name, 'raspberrypi.local', and the default password, 'raspberry'.

 

Configure Connection to your Raspberry Pi

The following creates a new SSH key, copies the public key to the Raspberry Pi, and then installs the Visual Studio Debugger on the Raspberry Pi. Take the default options.

 

From Linux and macOS

Open a new Terminal, and copy and paste the following command.

ssh-keygen -t rsa && ssh-copy-id pi@raspberrypi.local && \
ssh pi@raspberry.local "curl -sSL https://aka.ms/getvsdbgsh | bash /dev/stdin -r linux-arm -v latest -l ~/vsdbg"

 

From Windows 10

Press the Windows Key windows key, type 'cmd', then press the Enter key to open the Windows command prompt. Then copy and paste the following commands.

ping raspberrypi.local

Replace xxx.xxx.xxx.xxx with the IP Address of the Raspberry Pi and then copy and paste the following command into the Windows Command prompt.

 

bash -c "ssh-keygen -t rsa && ssh-copy-id pi@xxx.xxx.xxx.xxx" && ^
plink -ssh -pw raspberry pi@raspberrypi.local "curl -sSL https://aka.ms/getvsdbgsh | bash /dev/stdin -r linux-arm -v latest -l ~/vsdbg"

Creating your first .NET Core IoT project

Open a command prompt or terminal window, and paste in the following command(s). It will create the project directory, create the .NET Core Console app, add the Iot.Device.Bindings package, and then launch Visual Studio Code.

 

mkdir dotnet.core.iot.csharp && cd dotnet.core.iot.csharp

dotnet new console --langVersion=latest && dotnet add package Iot.Device.Bindings --version 0.1.0-prerelease*

code .
  1. Add the Visual Studio Code Build and Debug assets

  1. Replace the code in program.cs file with the following code. This code will read the Raspberry Pi CPU Temperature and display it in the system console window.
using System;
using Iot.Device.CpuTemperature;
using System.Threading;

namespace dotnet.core.iot
{
    class Program
    {
        static CpuTemperature temperature = new CpuTemperature();
        static void Main(string[] args)
        {
            while (true)
            {
                if (temperature.IsAvailable)
                {
                    Console.WriteLine($"The CPU temperature is {temperature.Temperature.Celsius}");
                }
                Thread.Sleep(2000); // sleep for 2000 milliseconds, 2 seconds
            }
        }
    }
}

Your Visual Studio Code program.cs file should look like the following screenshot.

sample program

 

Deploying the project to your Raspberry Pi

To deploy a project to your Raspberry Pi you need to configure Visual Studio Code to compile for linux-arm, how to copy the compiled code to the Raspberry Pi, and finally how to attach the debugger.

 

For this walk-through, we are going to use rsync to copy program files to the Raspberry Pi. Rsync is a very efficient file transfer protocol, comes standard with Linux, macOS, and Windows with the Windows Subsystem for Linux (WSL) installed.

 

Updating the Visual Studio Code Build Files

We need to update the launch.json and tasks.json files with the following code.

This walk-through assumes the default Raspberry Pi network name, 'raspberrypi.local', and the default password, 'raspberry'.

 

launch.json

The launch.json file calls a publish prelaunch task which builds and copies the program to the Raspberry Pi, it then starts the program on the Raspberry Pi and attaches the debugger.

 

 

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Raspberry Pi Publish, Launch, and Attach Debugger",
            "type": "coreclr",
            "request": "launch",
            "preLaunchTask": "RaspberryPublish",
            "program": "~/${workspaceFolderBasename}/${workspaceFolderBasename}",
            "cwd": "~/${workspaceFolderBasename}",
            "stopAtEntry": false,
            "console": "internalConsole",
            "args": [
                "https://your-dmx-function.azurewebsites.net/api"
            ],
            "pipeTransport": {
                "pipeCwd": "${workspaceRoot}",
                "pipeProgram": "/usr/bin/ssh",
                "pipeArgs": [
                    "pi@raspberrypi.local"
                ],
                "debuggerPath": "~/vsdbg/vsdbg"
            },
            "windows": {
                "pipeTransport": {
                    "pipeCwd": "${workspaceRoot}",
                    "pipeProgram": "plink",
                    "pipeArgs": [
                        "-ssh",
                        "-pw",
                        "raspberry",
                        "pi@raspberrypi.local"
                    ],
                    "debuggerPath": "~/vsdbg/vsdbg"
                }
            }
        }
    ]
}

 

tasks.json

The tasks.json file defines how to compile the project for linux-arm and how to copy the program to the Raspberry Pi with rsync. On Windows, you must explicitly specify the IP Address of the Raspberry Pi as rsync is called via Bash and the Windows Subsystem for Linux does not resolve .local DNS names.

 

 

{
    "version": "2.0.0",
    "tasks": [
        {
            "label": "RaspberryPublish",
            "command": "sh",
            "type": "shell",
            "problemMatcher": "$msCompile",
            "args": [
                "-c",
                "\"dotnet publish -r linux-arm -o bin/linux-arm/publish",
                "${workspaceFolder}/${workspaceFolderBasename}.csproj\"",
                ";",
                "sh",
                "-c",
                "\"rsync -rvuz ${workspaceFolder}/bin/linux-arm/publish/ pi@raspberrypi.local:~/${workspaceFolderBasename}\""
            ],
            "windows": {
                "command": "cmd",
                "args": [
                    "/c",
                    "\"dotnet publish -r linux-arm -o bin\\linux-arm\\publish",
                    "${workspaceFolder}\\${workspaceFolderBasename}.csproj\"",
                    "&&",
                    "bash",
                    "-c",
                    "\"rsync -rvuz $(wslpath '${workspaceFolder}')/bin/linux-arm/publish/ pi@raspberrypi.local:~/${workspaceFolderBasename}\""
                ]
            }
        }
    ]
}

 

Build, Deploy and Debug your .NET Core IoT App

Review this Visual Studio Debugger Guide if you've not used the debugger before.

Set a breakpoint in your code, for example at the 15, and from Visual Studio Code click the Debug icon on the Activity bar, ensure "Publish, Launch and Attach Debugger" is selected in the dropdown, and click the green run icon.

 

Your code will build, it will be copied to your Raspberry Pi and the debugger will be attached and you can now start stepping through your code.

 

Publish, Launch and Attach Debugger

 

Connect your Raspberry Pi to Azure IoT Hub

  1. Follow the "Create an Azure IoT Hub (Free)" tutorial until the "Send simulated telemetry" section. You will need to the connection string of the device you created.

  2. Add the Package references for Azure IoT Hub and JSON.NET. This can either be done by executing the 'dotnet add package' command, or by updating the references directly in the .csproj file.

Open the dotnet.core.iot.csharp.csproj file and update the section as follows.

 

<ItemGroup>
    <PackageReference Include="Iot.Device.Bindings" Version="0.1.0-prerelease*" />
    <PackageReference Include="Microsoft.Azure.Devices.Client" Version="1.*" />
    <PackageReference Include="Newtonsoft.Json" Version="12.0.1" />  
</ItemGroup>
  1. Replace the code in program.cs file with the following code and add your device connection string.

This code will read the Raspberry Pi CPU Temperature, display it, then send the telemetry to Azure IoT Hub.

 

 

using System;
using Iot.Device.CpuTemperature;
using Newtonsoft.Json;
using Microsoft.Azure.Devices.Client;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace dotnet.core.iot
{
    class Program
    {
        const string DeviceConnectionString = "<Your Azure IoT Hub Connection String>";

        // Replace with the device id you used when you created the device in Azure IoT Hub
        const string DeviceId = "<Your Device Id>";
        static DeviceClient _deviceClient = DeviceClient.CreateFromConnectionString(DeviceConnectionString, TransportType.Mqtt);
        static CpuTemperature _temperature = new CpuTemperature();
        static int _msgId = 0;
        const double TemperatureThreshold = 42.0;

        static async Task Main(string[] args)
        {
            while (true)
            {
                if (_temperature.IsAvailable)
                {
                    Console.WriteLine($"The CPU temperature is {Math.Round(_temperature.Temperature.Celsius, 2)}");
                    await SendMsgIotHub(_temperature.Temperature.Celsius);
                }
                Thread.Sleep(2000); // sleep for 2000 milliseconds
            }
        }

        private static async Task SendMsgIotHub(double temperature)
        {
            var telemetry = new Telemetry() { Temperature = Math.Round(temperature, 2), MessageId = _msgId++ };
            string json = JsonConvert.SerializeObject(telemetry);

            Console.WriteLine($"Sending {json}");

            Message eventMessage = new Message(Encoding.UTF8.GetBytes(json));
            eventMessage.Properties.Add("temperatureAlert", (temperature > TemperatureThreshold) ? "true" : "false");
            await _deviceClient.SendEventAsync(eventMessage).ConfigureAwait(false);
        }

        class Telemetry
        {
            [JsonPropertyAttribute (PropertyName="temperature")] 
            public double Temperature { get; set; } = 0;

            [JsonPropertyAttribute (PropertyName="messageId")] 
            public int MessageId { get; set; } = 0;

            [JsonPropertyAttribute (PropertyName="deviceId")] 
            public string DeviceId {get; set;} = Program.DeviceId;
        }
    }
}

 

Redeploy the App to the Raspberry Pi

Press F5 to run the current 'Publish, Launch, and Attach Debugger' build task.

 

Monitor the Azure IoT Hub Telemetry

  1. Install the Visual Studio IoT Hub Toolkit.

  2. Review the Visual Studio IoT Hub Toolkit] Wiki for information on using the IoT Hub Toolkit Visual Studio Extension.

 

References

Remote Debugging On Linux Arm

Azure IoT libraries for .NET

 

Quick Notes

Using the new built in Windows OpenSSH client. Windows 10 1809+

 

Install OpenSSH Client on Windows (one time only operation).

 

From PowerShell as Administrator

 

Add-WindowsCapability -Online -Name OpenSSH.Client

 

Close PowerShell and reopen as non administrator user.

ssh-keygen -t rsa ; `
cat ~/.ssh/id_rsa.pub | ssh user@123.45.56.78 "mkdir ~/.ssh; cat >> ~/.ssh/authorized_keys"

 

References