Home
%3CLINGO-SUB%20id%3D%22lingo-sub-892261%22%20slang%3D%22en-US%22%3EIoT%20Plug%20and%20Play%20-%20A%20deep%20dive%20using%20a%20Raspberry%20Pi%20and%20Sense%20HAT%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-892261%22%20slang%3D%22en-US%22%3E%3CP%3EWe%20recently%20%3CA%20href%3D%22https%3A%2F%2Fazure.microsoft.com%2Fen-ca%2Fblog%2Fiot-plug-and-play-is-now-available-in-preview%2F%22%20target%3D%22_self%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%3Eannounced%3C%2FA%3E%20IoT%20Plug%20and%20Play%20(in%20preview)%20as%20part%20of%20a%20broader%20effort%20to%20reduce%20the%20time%20needed%20to%20integrate%20IoT%20devices%20into%20IoT%20solutions%20and%20%3CA%20href%3D%22https%3A%2F%2Fazure.microsoft.com%2Fen-ca%2Fservices%2Fiot-central%2F%22%20target%3D%22_self%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%3EIoT%20Central%3C%2FA%3E.%20What%20Windows%20Plug%20and%20Play%20did%20for%20connecting%20hardware%20devices%20to%20Windows%2C%20IoT%20Plug%20and%20Play%20aims%20to%20do%20the%20same%20for%20IoT%20devices%20connecting%20to%20IoT%20solutions.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EThere%20is%20some%20excellent%20Plug%20and%20Play%20documentation%20available%20at%20%3CA%20href%3D%22https%3A%2F%2Faka.ms%2Fiotpnpdocs%2F%22%20target%3D%22_self%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Faka.ms%2Fiotpnpdocs%2F%3C%2FA%3E.%20Take%20some%20time%20to%20read%20through%20this%20documentation%20and%20familiarize%20yourself%20with%20Plug%20and%20Play%20concepts%2C%20including%20%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2FAzure%2FIoTPlugandPlay%2Ftree%2Fmaster%2FDTDL%22%20target%3D%22_self%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%3EDTDL%3C%2FA%3E%20concepts.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EWhat%20this%20blog%20post%20attempts%20to%20do%20is%20take%20the%20Plug%20and%20Play%20documentation%20a%20step%20further%20and%20apply%20it%20to%20a%20real%20world%20device.%20In%20this%20case%2C%20a%20%3CA%20href%3D%22https%3A%2F%2Fwww.raspberrypi.org%2Fproducts%2Fraspberry-pi-3-model-b-plus%2F%22%20target%3D%22_self%22%20rel%3D%22nofollow%20noopener%20noreferrer%20noopener%20noreferrer%22%3ERaspberry%20Pi%203%20Model%20B%2B%3C%2FA%3E%20with%20a%20%3CA%20href%3D%22https%3A%2F%2Fwww.raspberrypi.org%2Fproducts%2Fsense-hat%2F%22%20target%3D%22_self%22%20rel%3D%22nofollow%20noopener%20noreferrer%20noopener%20noreferrer%22%3ESense%20HAT%3C%2FA%3E%20installed.%20We%20will%20configure%20the%20Sense%20HAT%20LED%20and%20sensors%20for%20Plug%20and%20Play%20and%20develop%20the%20underlying%20code%20to%20read%20from%20these%20sensors%20and%20control%20the%20LED%20display.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EThis%20blog%20is%20targeted%20at%20device%20builders%20(interested%20in%20device%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fazure%2Fiot-pnp%2Ftutorial-certification-test%22%20target%3D%22_self%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%3Ecertification%3C%2FA%3E%20and%20getting%20their%20device%20listed%20on%20our%20%3CA%20href%3D%22https%3A%2F%2Fcatalog.azureiotsolutions.com%2Falldevices%3Ffilters%3D%7B%252220%2522%3A%5B%25221%2522%5D%7D%22%20target%3D%22_self%22%20rel%3D%22nofollow%20noopener%20noreferrer%20noopener%20noreferrer%22%3EDevice%20Catalog%3C%2FA%3E)%20and%20solution%20developers.%20This%20blog%20assumes%20you%20have%20a%20solid%20understanding%20of%20Raspberry%20Pi%20%2B%20Linux%2C%20Azure%20IoT%20services%20such%20as%20IoT%20Hub%20and%20the%20Azure%20IoT%20Device%20SDKs%2C%20as%20well%20as%20developing%20in%20Python%20and%20C.%20The%20steps%20in%20this%20blog%20are%20based%20on%20the%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fazure%2Fiot-pnp%2Ftutorial-pnp-visual-studio-code%22%20target%3D%22_self%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%3ETutorial%3A%20Create%20and%20test%20a%20device%20capability%20model%20using%20Visual%20Studio%20Code%3C%2FA%3E.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EReminder%2C%20Plug%20and%20Play%20is%20in%20Preview%20meaning%20no%20SLA%20and%20support%20is%20limited%20to%20certain%20regions%20(Central%20US%2C%20North%20Europe%2C%20or%20Japan%20East)%2C%20SDKs%20and%20for%20%3CU%3Edevices%3C%2FU%3E%20only%20(no%20IoT%20Edge%20support%20yet).%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH2%20id%3D%22toc-hId-1824765900%22%20id%3D%22toc-hId-1824877529%22%3EPrerequisites%3C%2FH2%3E%0A%3CUL%3E%0A%3CLI%3EInstall%20the%20software%20prerequisites%20on%20your%20PC%20that%20are%20listed%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fazure%2Fiot-pnp%2Ftutorial-pnp-visual-studio-code%23prerequisites%22%20target%3D%22_self%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%3Ehere%3C%2FA%3E%3C%2FLI%3E%0A%3CLI%3ECreate%20an%20IoT%20Hub%20in%20either%20%3CSTRONG%3ECentral%20US%2C%3C%2FSTRONG%3E%20%3CSTRONG%3ENorth%20Europe%3C%2FSTRONG%3E%2C%20or%20%3CSTRONG%3EJapan%20East%3C%2FSTRONG%3E.%3C%2FLI%3E%0A%3CLI%3EAdd%20an%20IoT%20Device%20to%20your%20IoT%20Hub.%3CSTRONG%3EMake%20a%20note%20of%20the%20connection%20string.%3C%2FSTRONG%3E%3C%2FLI%3E%0A%3CLI%3ESetup%20your%20Azure%20Cloud%20Shell%20as%20described%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fazure%2Fiot-pnp%2Ftutorial-pnp-visual-studio-code%23use-azure-cloud-shell%22%20target%3D%22_self%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%3Ehere%3C%2FA%3E%3C%2FLI%3E%0A%3CLI%3E%3CA%20href%3D%22https%3A%2F%2Fwww.raspberrypi.org%2Fproducts%2Fraspberry-pi-3-model-b-plus%2F%22%20target%3D%22_self%22%20rel%3D%22nofollow%20noopener%20noreferrer%20noopener%20noreferrer%22%3ERaspberry%20Pi%203%20Model%20B%2B%3C%2FA%3E%26nbsp%3Bwith%26nbsp%3BRaspbian%20GNU%2FLinux%209%20(stretch)%20installed%3C%2FLI%3E%0A%3CLI%3E%3CA%20href%3D%22https%3A%2F%2Fwww.raspberrypi.org%2Fproducts%2Fsense-hat%2F%22%20target%3D%22_self%22%20rel%3D%22nofollow%20noopener%20noreferrer%20noopener%20noreferrer%22%3ESense%20HAT%3C%2FA%3E%20installed%20on%20the%20Raspberry%20Pi%20device%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-center%22%20style%3D%22width%3A%20400px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F135376i9629DA8A0B41594D%2Fimage-size%2Fmedium%3Fv%3D1.0%26amp%3Bpx%3D400%22%20alt%3D%22a222a1d657906db95efbca8b8467037fa1a89def_sense-hat-1733x1080-1-1733x1080%22%20title%3D%22a222a1d657906db95efbca8b8467037fa1a89def_sense-hat-1733x1080-1-1733x1080%22%20%2F%3E%3CSPAN%20class%3D%22lia-inline-image-caption%22%20onclick%3D%22event.preventDefault()%3B%22%3ESense%20HAT%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EThe%20Sense%20HAT%20device%20has%20a%20LED%20display%20and%20number%20of%20sensors%20built%20into%20it%20including%3A%20temperature%2C%20humidity%20and%20pressure.%20It%20also%20has%20a%20well%20documented%20%3CA%20href%3D%22https%3A%2F%2Fpythonhosted.org%2Fsense-hat%2Fapi%2F%22%20target%3D%22_self%22%20rel%3D%22nofollow%20noopener%20noreferrer%20noopener%20noreferrer%22%3EPython%20API%3C%2FA%3E.%20But%20the%20biggest%20reason%20I%20like%20to%20use%20it%20is%20to%20avoid%20fiddling%20with%20breadboards%2C%20resistors%20and%20jumper%20cables%20%3CIMG%20class%3D%22lia-deferred-image%20lia-image-emoji%22%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Fhtml%2Fimages%2Femoticons%2Fsmile_40x40.gif%22%20alt%3D%22%3Asmile%3A%22%20title%3D%22%3Asmile%3A%22%20%2F%3E.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH2%20id%3D%22toc-hId--727391061%22%20id%3D%22toc-hId--727279432%22%3EGetting%20Started%3C%2FH2%3E%0A%3CP%3EOnce%20you%20have%20the%20Sense%20Hat%20installed%20on%20the%20Raspberry%20Pi%20along%20with%20Raspbian%209%20(stretch)%2C%20the%20next%20step%20is%20to%20install%20the%20Sense%20HAT%20Python%20API.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-markup%22%3E%3CCODE%3Esudo%20apt-get%20update%0Asudo%20apt-get%20install%20sense-hat%0Asudo%20reboot%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%20style%3D%22font-family%3A%20inherit%3B%22%3ENote%3A%20I%20haven't%20found%20a%20decently%20documented%20C-based%20API%20for%20the%20Sense%20HAT.%20If%20you%20know%20of%20one%2C%20please%20send%20me%20a%20link%20to%20it!%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ELet's%20also%20ensure%20we%20have%20Python%203%20installed.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-markup%22%3E%3CCODE%3Epi%40raspberrypi%3A%20python3%20--version%0APython%203.5.3%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ENow%20test%20that%20the%20Sense%20HAT%20is%20working%20with%20the%20following%20Python%20commands.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-markup%22%3E%3CCODE%3Epi%40raspberrypi%3A%2F%20%24%20python3%0APython%203.5.3%20(default%2C%20Sep%2027%202018%2C%2017%3A25%3A39)%0A%5BGCC%206.3.0%2020170516%5D%20on%20linux%0AType%20%22help%22%2C%20%22copyright%22%2C%20%22credits%22%20or%20%22license%22%20for%20more%20information.%0A%26gt%3B%26gt%3B%26gt%3B%20from%20sense_hat%20import%20SenseHat%0A%26gt%3B%26gt%3B%26gt%3B%20sense%20%3D%20SenseHat()%0A%26gt%3B%26gt%3B%26gt%3B%20sense.show_message(%22Hello%20world!%22)%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EIf%20all%20is%20successful%2C%20a%20%22Hello%20world!%22%20message%20should%20scroll%20across%20the%20LED%20display.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH2%20id%3D%22toc-hId-1015419274%22%20id%3D%22toc-hId-1015530903%22%3EModel%20your%20device%3C%2FH2%3E%0A%3CP%3EIf%20you%20are%20familiar%20with%20%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2FAzure%2FIoTPlugandPlay%2Ftree%2Fmaster%2FDTDL%22%20target%3D%22_self%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%3EDTDL%3C%2FA%3E%26nbsp%3B(which%20is%20based%20on%20JSON-LD)%20you'll%20know%20we%20need%20to%20first%20develop%20an%20%3CSTRONG%3EInterface%3C%2FSTRONG%3E%20for%20the%20Sense%20HAT%20and%20then%20create%20a%20%3CSTRONG%3EModel%3C%2FSTRONG%3E%20file.%20Together%20these%20form%20a%20%3CSTRONG%3EDevice%20Capability%20Model%3C%2FSTRONG%3E%20(DCM).%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH3%20id%3D%22toc-hId--1733251192%22%20id%3D%22toc-hId--1733139563%22%3ECreating%20an%20Interface%3C%2FH3%3E%0A%3CP%3EA%20%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2FAzure%2FIoTPlugandPlay%2Ftree%2Fmaster%2FDTDL%23interface%22%20target%3D%22_self%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%3EInterface%3C%2FA%3E%20describes%20the%20capabilities%20that%20are%20implemented%20by%20a%20device.%20Interfaces%20are%20reusable%20and%20can%20be%20used%20across%20different%20capability%20models.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EIn%20our%20case%2C%20the%20Interface%20we%20will%20develop%20will%20describe%20the%20Sense%20HAT's%3A%3C%2FP%3E%0A%3CUL%3E%0A%3CLI%3Etemperature%20sensor%3C%2FLI%3E%0A%3CLI%3Ehumidity%20sensor%3C%2FLI%3E%0A%3CLI%3Epressure%20sensor%3C%2FLI%3E%0A%3CLI%3ELED%20display%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CP%3EIn%20DTDL%2C%20the%20three%20(3)%20sensors%20are%20considered%20a%20%3CSTRONG%3ETelemetry%3C%2FSTRONG%3E%20data%20type%20since%20they%20emit%20data%20from%20the%20sensor.%20The%20LED%20display%20will%20be%20a%20%3CSTRONG%3ECommand%3C%2FSTRONG%3E%20data%20type%2C%20as%20our%20IoT%20solution%20will%20send%20a%20command%20to%20the%20Sense%20HAT%20to%20display%20a%20message%20on%20the%20LED.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EFollow%20the%20%22%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fazure%2Fiot-pnp%2Ftutorial-pnp-visual-studio-code%23create-the-interface-file%22%20target%3D%22_self%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%3ECreate%20the%20interface%20file%3C%2FA%3E%22%20instructions%2C%20substituting%20the%20following%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CUL%3E%0A%3CLI%3E%0A%3CP%3E%3CSTRONG%3ESenseHat%3C%2FSTRONG%3E%26nbsp%3Bas%20the%20name%20of%20the%20interface%20and%20press%20%3CSTRONG%3EEnter%3C%2FSTRONG%3E.%20VS%20Code%20creates%20a%20sample%20interface%20file%20called%20%3CSTRONG%3ESenseHat.interface.json%3C%2FSTRONG%3E.%3C%2FP%3E%0A%3C%2FLI%3E%0A%3CLI%3E%0A%3CP%3EReplace%20the%20contents%20of%20the%20sample%26nbsp%3B%3CSTRONG%3ESenseHat.interface.json%3C%2FSTRONG%3E%20file%20with%20the%20following%20JSON%3A%3C%2FP%3E%0A%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-markup%22%3E%3CCODE%3E%7B%0A%20%20%22%40id%22%3A%20%22urn%3Asense_hat%3ASenseHat%3A1%22%2C%0A%20%20%22%40type%22%3A%20%22Interface%22%2C%0A%20%20%22displayName%22%3A%20%22Sense%20Hat%20Interface%22%2C%0A%20%20%22contents%22%3A%20%5B%0A%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%22%40type%22%3A%20%22Telemetry%22%2C%0A%20%20%20%20%20%20%20%20%22comment%22%3A%20%22Sense%20Hat%20Temperature%22%2C%0A%20%20%20%20%20%20%20%20%22name%22%3A%20%22temperature%22%2C%0A%20%20%20%20%20%20%20%20%22schema%22%3A%20%22double%22%2C%0A%20%20%20%20%20%20%20%20%22unit%22%3A%20%22Units%2FTemperature%2Fcelsius%22%0A%20%20%20%20%7D%2C%0A%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%22%40type%22%3A%20%22Telemetry%22%2C%0A%20%20%20%20%20%20%20%20%22comment%22%3A%20%22Sense%20Hat%20Relative%20Humidity%22%2C%0A%20%20%20%20%20%20%20%20%22name%22%3A%20%22humidity%22%2C%0A%20%20%20%20%20%20%20%20%22schema%22%3A%20%22double%22%2C%0A%20%20%20%20%20%20%20%20%22unit%22%3A%20%22Units%2FHumidity%2Fpercent%22%0A%20%20%20%20%7D%2C%0A%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%22%40type%22%3A%20%22Telemetry%22%2C%0A%20%20%20%20%20%20%20%20%22comment%22%3A%20%22Sense%20Hat%20Pressure%22%2C%0A%20%20%20%20%20%20%20%20%22name%22%3A%20%22pressure%22%2C%0A%20%20%20%20%20%20%20%20%22schema%22%3A%20%22double%22%2C%0A%20%20%20%20%20%20%20%20%22unit%22%3A%20%22Units%2FPressure%2FkiloPascal%22%0A%20%20%20%20%7D%2C%0A%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%22%40type%22%3A%20%22Command%22%2C%0A%20%20%20%20%20%20%20%20%22description%22%3A%20%22This%20command%20will%20display%20a%20message%20on%20the%20Sense%20Hat%20LED%20display.%22%2C%0A%20%20%20%20%20%20%20%20%22name%22%3A%20%22show_message%22%2C%0A%20%20%20%20%20%20%20%20%22commandType%22%3A%20%22synchronous%22%2C%0A%20%20%20%20%20%20%20%20%22request%22%3A%20%7B%0A%20%20%20%20%20%20%20%20%20%20%22name%22%3A%20%22message%22%2C%0A%20%20%20%20%20%20%20%20%20%20%22schema%22%3A%20%22string%22%0A%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%7D%0A%20%20%5D%2C%0A%20%20%22%40context%22%3A%20%22%3CA%20href%3D%22http%3A%2F%2Fazureiot.com%2Fv1%2Fcontexts%2FIoTModel.json%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttp%3A%2F%2Fazureiot.com%2Fv1%2Fcontexts%2FIoTModel.json%3C%2FA%3E%22%0A%7D%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EAs%20you%20can%20see%20we've%20modeled%20the%203%20sensors%20and%20the%20LED%20display%20in%20the%20Interface%20using%20DTDL.%20For%20each%20data%20type%20there%20are%20a%20number%20of%20DTDL%20properties%20which%20can%20be%20set.%20In%20the%20above%20example%20I%20have%20configured%20a%20few%2C%20but%20there%20are%20more.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EIntelliSense%20is%20available%20when%20editing%20the%20DTDL%20using%20VS%20Code.%20Try%20changing%20any%20of%20the%20%22unit%22%20values%20and%20you'll%20see%20what%20I%20mean.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH3%20id%3D%22toc-hId-9559143%22%20id%3D%22toc-hId-9670772%22%3ECreating%20a%20Model%20file%3C%2FH3%3E%0A%3CP%3ENext%2C%20we%20will%20want%20to%20create%20a%20%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2FAzure%2FIoTPlugandPlay%2Ftree%2Fmaster%2FDTDL%23capabilitymodel%22%20target%3D%22_self%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%3EModel%3C%2FA%3E%20file.%20The%20model%20file%20specifies%20the%20interfaces%20that%20your%20device%20implements.%20There%20are%20typically%20at%20least%20two%20interfaces%20in%20a%20model%20-%20one%20or%20more%20that%20define%20the%20specific%20capabilities%20of%20your%20device%2C%20and%20a%20standard%20interface%20that%20all%20IoT%20Plug%20and%20Play%20devices%20must%20implement.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EFollow%20the%20%22%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fazure%2Fiot-pnp%2Ftutorial-pnp-visual-studio-code%23create-the-model-file%22%20target%3D%22_self%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%3ECreate%20the%20model%20file%3C%2FA%3E%22%20instructions%2C%20substituting%20the%20following%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CUL%3E%0A%3CLI%3EEnter%20%3CSTRONG%3ESenseHatModel%3C%2FSTRONG%3E%20as%20the%20name%20of%20the%20model.%20VS%20Code%20creates%20a%20sample%20interface%20file%20called%20%3CSTRONG%3ESenseHatModel.capabilitymodel.json%3C%2FSTRONG%3E.%3C%2FLI%3E%0A%3CLI%3EReplace%20the%20contents%20of%20the%20sample%20%3CSTRONG%3ESenseHatModel.capabilitymodel.json%3C%2FSTRONG%3E%20file%20(filename%20must%20end%20with%20.capabilitymodel.json)%20with%20the%20following%20JSON%3A%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-markup%22%3E%3CCODE%3E%7B%0A%20%20%22%40id%22%3A%20%22urn%3Asense_hat%3ASenseHatModel%3A1%22%2C%0A%20%20%22%40type%22%3A%20%22CapabilityModel%22%2C%0A%20%20%22displayName%22%3A%20%22Sense%20Hat%20Capability%20Model%22%2C%0A%20%20%22implements%22%3A%20%5B%0A%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%22schema%22%3A%20%22urn%3Asense_hat%3ASenseHat%3A1%22%2C%0A%20%20%20%20%20%20%20%20%22name%22%3A%20%22sensehat%22%0A%20%20%20%20%7D%2C%0A%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%22schema%22%3A%20%22urn%3Aazureiot%3ADeviceManagement%3ADeviceInformation%3A1%22%2C%0A%20%20%20%20%20%20%20%20%22name%22%3A%20%22deviceInfo%22%0A%20%20%20%20%7D%0A%20%20%5D%2C%0A%20%20%22%40context%22%3A%20%22%3CA%20href%3D%22http%3A%2F%2Fazureiot.com%2Fv1%2Fcontexts%2FIoTModel.json%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttp%3A%2F%2Fazureiot.com%2Fv1%2Fcontexts%2FIoTModel.json%3C%2FA%3E%22%0A%7D%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ENotice%20the%20%3CSTRONG%3EDeviceInformation%3C%2FSTRONG%3E%20interface%20(known%20as%20a%20standard%20interface)%20was%20automatically%20added%20and%20is%20required%20(e.g.%20for%20Device%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fazure%2Fiot-pnp%2Ftutorial-certification-test%22%20target%3D%22_self%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%3ECertification%3C%2FA%3E).%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ELastly%20download%20the%20%3CSTRONG%3EDeviceInformation%3C%2FSTRONG%3E%20interface%20from%20the%20public%20model%20repository%20using%20the%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fazure%2Fiot-pnp%2Ftutorial-pnp-visual-studio-code%23download-the-deviceinformation-interface%22%20target%3D%22_self%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%3Einstructions%3C%2FA%3E.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH2%20id%3D%22toc-hId-1948882983%22%20id%3D%22toc-hId-1948994612%22%3EPublish%20the%20model%3C%2FH2%3E%0A%3CP%3EAs%20part%20of%20the%20release%20of%20Plug%20and%20Play%2C%20Microsoft%20is%20hosting%20an%26nbsp%3B%3CSTRONG%3EAzure%20Certified%20for%20IoT%3C%2FSTRONG%3E%20%3CA%20href%3D%22https%3A%2F%2Faka.ms%2FACFI%22%20target%3D%22_self%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%3Erepository%3C%2FA%3E%20for%20you%20to%20host%20your%20model.%20Using%20the%20model%20repository%20is%20optional%3B%20you%20can%20store%20the%20model%20on%20the%20local%20device%20(not%20covered%20in%20this%20Blog%20post).%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EThere%20are%20two%20sides%20to%20the%20repository%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CUL%3E%0A%3CLI%3EPublic%20repository%20-%20where%20publicly%20published%20Models%20and%20Interfaces%20are%20stored.%3C%2FLI%3E%0A%3CLI%3ECompany%20repository%20-%20where%20private%20Models%20and%20Interfaces%20are%20stored%20(e.g.%20prior%20to%20publishing%20publicly%20or%20when%20you%20have%20feature%2Fdevice%20that%20is%20specific%20to%20your%20organization).%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CP%3EFollow%20the%20%22%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fazure%2Fiot-pnp%2Ftutorial-pnp-visual-studio-code%23publish-the-model%22%20target%3D%22_self%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%3EPublish%20your%20model%3C%2FA%3E%22%20instructions%20to%20publish%20the%20following%20two%20files%20to%20your%20%3CSTRONG%3ECompany%3C%2FSTRONG%3E%20%3CSTRONG%3Erepository%3C%2FSTRONG%3E%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CUL%3E%0A%3CLI%3E%3CSTRONG%3ESenseHat.interface.json%3C%2FSTRONG%3E%3C%2FLI%3E%0A%3CLI%3E%3CSTRONG%3ESenseHatModel.capabilitymodel.json%3C%2FSTRONG%3E%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CP%3EBy%20default%2C%20the%20model%20will%20be%20stored%20in%20the%26nbsp%3B%3CSTRONG%3ECompany%20repository%3C%2FSTRONG%3E.%20You%20can%20optionally%20publish%20it%20to%20the%20%3CSTRONG%3EPublic%20repository%3C%2FSTRONG%3E.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH2%20id%3D%22toc-hId--603273978%22%20id%3D%22toc-hId--603162349%22%3EGenerate%20stub%20code%3C%2FH2%3E%0A%3CP%3EUsing%20VS%20Code%20you%20can%20generate%20stub%20code%20for%20your%20IoT%20device.%20However%2C%20there%20are%20some%20limitations%20with%20this%20at%20the%20moment%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CUL%3E%0A%3CLI%3EYou%20will%20need%20to%20use%20Azure%20IoT%20Device%20SDKs%20that%20are%20Plug%20and%20Play-aware.%20Currently%2C%20only%20the%20C%20and%20Node%20Device%20SDKs%20are%20Plug%20and%20Play-aware.%20The%20other%20SDKs%20(e.g.%20Python)%20will%20be%20updated%20to%20be%20Plug%20and%20Play-aware%20in%20the%20future.%3C%2FLI%3E%0A%3CLI%3EVS%20Code%20only%20generates%20stub%20code%20in%20C%20(sorry%20Node%20%3CIMG%20class%3D%22lia-deferred-image%20lia-image-emoji%22%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Fhtml%2Fimages%2Femoticons%2Fcry_40x40.gif%22%20alt%3D%22%3Acry%3A%22%20title%3D%22%3Acry%3A%22%20%2F%3E).%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CP%3EThese%20limitations%20pose%20a%20problem%20for%20us%2C%20as%20you%20will%20see%20later%20(recall%2C%20the%20Sense%20HAT%20only%20ships%20with%20a%20Python%20API!).%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EFollow%20the%20%22%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fazure%2Fiot-pnp%2Ftutorial-pnp-visual-studio-code%23generate-code%22%20target%3D%22_self%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%3EGenerate%20code%3C%2FA%3E%22%20instructions%20to%20generate%20the%20stub%20C%20code%2C%20substituting%20the%20following%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CUL%3E%0A%3CLI%3E%3CSTRONG%3ESenseHatModel.capabilitymodel.json%3C%2FSTRONG%3E%20as%20the%20model%20file%3C%2FLI%3E%0A%3CLI%3E%3CSTRONG%3Esensehat_app%3C%2FSTRONG%3E%20as%20the%20app%20name%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CP%3E%3CFONT%20color%3D%22%23000000%22%3EOnce%20you%20have%20finished%20generating%20the%20stub%20code%20you%20will%20find%20the%20following%20files%20in%20a%20new%20%3CSTRONG%3Esensehat_app%3C%2FSTRONG%3E%20folder%3A%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-markup%22%3E%3CCODE%3ECMakeLists.txt%20%20%0Amain.c%20%20%0Apnp_device.c%20%20%0Apnp_device.h%20%20%0AReadme.md%20%20%0ASenseHatModel_impl.c%20%20%0ASenseHatModel_impl.h%20%20%0A%5Cutilities%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EThe%20primary%20file%20you%20need%20to%20concern%20yourself%20with%20is%20%3CSTRONG%3ESenseHatModel_impl.c%3C%2FSTRONG%3E.%20This%20is%20the%20file%20where%20we%20will%20add%20our%20implementation%20code.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH2%20id%3D%22toc-hId-1139536357%22%20id%3D%22toc-hId-1139647986%22%3EUpdate%20the%20stub%20code%3C%2FH2%3E%0A%3CP%3ENow%20let's%20add%20our%20implementation%20code%20to%20%3CSTRONG%3ESenseHatModel_impl.c%3C%2FSTRONG%3E.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3COL%3E%0A%3CLI%3EUsing%20VS%20Code%2C%20open%20the%20%3CSTRONG%3Esensehat_app%5CSenseHatModel_impl.c%3C%2FSTRONG%3E%20file.%3C%2FLI%3E%0A%3CLI%3EPaste%20in%20the%20implementation%20code%20from%20%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2Fkhilscher%2FSenseHATPnP%2Fblob%2Fmaster%2Fsensehat_app%2FSenseHatModel_impl.c%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fgithub.com%2Fkhilscher%2FSenseHATPnP%2Fblob%2Fmaster%2Fsensehat_app%2FSenseHatModel_impl.c%3C%2FA%3E%3C%2FLI%3E%0A%3C%2FOL%3E%0A%3CP%3ERecall%20that%20I%20mentioned%20earlier%20that%20the%20Sense%20HAT%20API%20is%20Python-based.%20To%20work%20around%20this%2C%20I%20am%20using%20%3CA%20href%3D%22https%3A%2F%2Fpubs.opengroup.org%2Fonlinepubs%2F009696799%2Ffunctions%2Fpopen.html%22%20target%3D%22_self%22%20rel%3D%22nofollow%20noopener%20noreferrer%20noopener%20noreferrer%22%3Epopen%3C%2FA%3E%20to%20run%20the%20Python%203%20process%20and%20pass%20in%20one%20of%20several%20Python%20scripts%20I%20developed%20for%20interacting%20with%20the%20Sense%20HAT%20hardware.%20Popen%20returns%20pointer%20to%20an%20open%20stream%2C%20which%20contains%20the%20return%20value%20from%20the%20Python%20script.%20I%20admit%20it's%20a%20bit%20of%20a%20hack%2C%20but%20it%20works.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH2%20id%3D%22toc-hId--1412620604%22%20id%3D%22toc-hId--1412508975%22%3EConfigure%20the%20Raspberry%20Pi%3C%2FH2%3E%0A%3CP%3ENow%20it's%20time%20to%20configure%20your%20Raspberry%20Pi.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3COL%3E%0A%3CLI%3E%3CSTRONG%3ESSH%3C%2FSTRONG%3E%20into%20your%20Raspberry%20Pi.%20Note%3A%20I%20am%20logged%20in%20as%20the%20user%20%22%3CSTRONG%3Epi%3C%2FSTRONG%3E%22%20and%20I%20will%20save%20everything%20to%20the%20pi%20user%20home%20directory.%3C%2FLI%3E%0A%3CLI%3ERun%20the%20following%20commands%3A%3C%2FLI%3E%0A%3C%2FOL%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-markup%22%3E%3CCODE%3Epi%40raspberrypi%3A%20cd%20%2Fhome%2Fpi%0Api%40raspberrypi%3A%20git%20clone%20%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2Fkhilscher%2FSenseHATPnP.git%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fgithub.com%2Fkhilscher%2FSenseHATPnP.git%3C%2FA%3E%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EThe%20last%20command%20will%20copy%20the%20Sense%20HAT%20Python%20scripts%20from%20GitHub%20to%20the%20%3CSTRONG%3E%2Fhome%2Fpi%2FSenseHatPnP%2Fpython_scripts%2F%3C%2FSTRONG%3E%20folder.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3ENote%3C%2FSTRONG%3E%3A%20The%20Python%20script%20paths%20are%20hard%20coded%20in%20the%20SenseHatModel_impl.c%20file.%20It%20expects%20them%20to%20be%20saved%20under%20%2Fhome%2Fpi%2FSenseHATPnP%2Fpython_scripts%2F.%20If%20you%20use%20another%20location%2C%20please%20update%20SenseHatModel_impl.c%20accordingly.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH2%20id%3D%22toc-hId-330189731%22%20id%3D%22toc-hId-330301360%22%3EBuild%20the%20code%3C%2FH2%3E%0A%3CP%3EThe%20final%20step%20is%20to%20build%20your%20code%20on%20the%20Raspberry%20Pi%20device.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EFollow%20the%26nbsp%3B%3CSTRONG%3EUbuntu%3C%2FSTRONG%3E%20instructions%20in%20the%20%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2Fkhilscher%2FSenseHATPnP%2Fblob%2Fmaster%2Fsensehat_app%2FReadme.md%22%20target%3D%22_self%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%3E%3CSTRONG%3EReadme.md%3C%2FSTRONG%3E%3C%2FA%3E%20file%20in%20the%20%3CSTRONG%3Esensehat_app%3C%2FSTRONG%3E%20folder%2C%20substituting%20the%20following%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3COL%3E%0A%3CLI%3EThe%20Readme.md%20references%20a%26nbsp%3B%3CSTRONG%3Eazure-iot-sdk-c-pnp%20%3C%2FSTRONG%3Efolder.%20This%20is%20incorrect.%20It%20is%20%3CSTRONG%3Eazure-iot-sdk-c%3C%2FSTRONG%3E.%3C%2FLI%3E%0A%3CLI%3EOpen%20a%20%3CSTRONG%3Ecmd%3C%2FSTRONG%3E%20prompt%20in%20your%20working%20folder%20on%20your%20PC.%3C%2FLI%3E%0A%3CLI%3EUse%20%3CSTRONG%3Escp%3C%2FSTRONG%3E%20to%20copy%20the%20%3CSTRONG%3Esensehat_app%3C%2FSTRONG%3E%20folder%20from%20your%20PC%20to%20the%20%3CSTRONG%3Eazure-iot-sdk-c%20%3C%2FSTRONG%3Efolder%20on%20you%20Pi%20device.%3C%2FLI%3E%0A%3C%2FOL%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-markup%22%3E%3CCODE%3Ec%3A%5Cmy_working_folder%26gt%3B%20scp%20-r%20sensehat_app%20pi%40%3CRPI%20ip%3D%22%22%20address%3D%22%22%3E%3A%2Fhome%2Fpi%2Fazure-iot-sdk-c%3C%2FRPI%3E%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ERun%20the%20remaining%20build%20steps%20contained%20in%20the%20Readme.md.%20Ignore%20warnings%20but%20fix%20any%20errors%20encountered%20during%20the%20build%20process.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH2%20id%3D%22toc-hId--1336690665%22%20id%3D%22toc-hId--1336579036%22%3ERunning%20the%20code%3C%2FH2%3E%0A%3CP%3ERunning%20your%20code%20involves%20executing%20the%20%3CSTRONG%3Esensehat_app%3C%2FSTRONG%3E.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-markup%22%3E%3CCODE%3Epi%40raspberrypi%3A%20cd%20%2Fhome%2Fpi%2Fazure-iot-sdk-c%2Fcmake%2Fsensehat_app%2F%0Api%40raspberrypi%3A%20.%2Fsensehat_app%20%22%5BIoTHub%20device%20connection%20string%5D%22%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EAfter%20executing%20the%20above%20commands%20the%20sensehat_app%20should%20be%20running%20and%20sending%20telemetry%20to%20Azure%20IoT%20Hub.%20During%20startup%2C%20watch%20how%20it%20logs%20the%20registration%20of%20its%20PnP%20interfaces%20with%20IoT%20Hub.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-markup%22%3E%3CCODE%3E...%0AInfo%3A%20DEVICEINFO_INTERFACE%3A%20Interface%20successfully%20registered.%0AInfo%3A%20Interface%20registration%20callback%20invoked%2C%20interfaces%20have%20been%20successfully%20registered%0AInfo%3A%20DigitalTwin%20interfaces%20successfully%20registered%0AInfo%3A%20DEVICEINFO_INTERFACE%3A%20Queued%20async%20report%20read%20only%20property%20for%20manufacturer%0AInfo%3A%20DEVICEINFO_INTERFACE%3A%20Queued%20async%20report%20read%20only%20property%20for%20model%0AInfo%3A%20DEVICEINFO_INTERFACE%3A%20Queued%20async%20report%20read%20only%20property%20for%20swVersion%0AInfo%3A%20DEVICEINFO_INTERFACE%3A%20Queued%20async%20report%20read%20only%20property%20for%20osName%0AInfo%3A%20DEVICEINFO_INTERFACE%3A%20Queued%20async%20report%20read%20only%20property%20for%20processorArchitecture%0AInfo%3A%20DEVICEINFO_INTERFACE%3A%20Queued%20async%20report%20read%20only%20property%20for%20processorManufacturer%0AInfo%3A%20DEVICEINFO_INTERFACE%3A%20Queued%20async%20report%20read%20only%20property%20for%20totalStorage%0AInfo%3A%20DEVICEINFO_INTERFACE%3A%20Queued%20async%20report%20read%20only%20property%20for%20totalMemory%0AInfo%3A%20DEVICE_INFO%3A%20Queuing%20of%20all%20properties%20to%20be%20reported%20has%20succeeded%0A%0A...%0A%0AInfo%3A%20Send%20telemetry%20data%20to%20IoT%20Hub%0A32.26278305053711%0AInfo%3A%20SENSEHAT_INTERFACE%3A%3A%20DigitalTwin_InterfaceClient_SendTelemetryAsync%20successfully%20sent%20temperature%0A32.638771057128906%0AInfo%3A%20SENSEHAT_INTERFACE%3A%3A%20DigitalTwin_InterfaceClient_SendTelemetryAsync%20successfully%20sent%20humidity%0AInfo%3A%20DigitalTwin%20Client%20Core%3A%20Processing%20telemetry%20callback.%20%20confirmationResult%3DIOTHUB_CLIENT_CONFIRMATION_OK%2C%20userContextCallback%3D0x66c418%0AInfo%3A%20DigitalTwin%20Interface%3A%20Invoking%20telemetry%20confirmation%20callback%20for%20interface%3Dsensehat%2C%20reportedStatus%3DDIGITALTWIN_CLIENT_RESULT_INVALID%2C%20userContextCallback%3D0xacb4c%0AInfo%3A%20DigitalTwin%20successfully%20delivered%20telemetry%20message%20for%20Sensehat%3A%3Atemperature%0AInfo%3A%20SENSEHAT_INTERFACE%3A%20DigitalTwin%20successfully%20delivered%20telemetry%20message%20for%20%3CTEMPERATURE%3E%0AInfo%3A%20DigitalTwin%20Interface%3A%20Invoking%20telemetry%20confirmation%20returned%0A880.73828125%0AInfo%3A%20SENSEHAT_INTERFACE%3A%3A%20DigitalTwin_InterfaceClient_SendTelemetryAsync%20successfully%20sent%20pressure%0AInfo%3A%20DigitalTwin%20Client%20Core%3A%20Processing%20telemetry%20callback.%20%20confirmationResult%3DIOTHUB_CLIENT_CONFIRMATION_OK%2C%20userContextCallback%3D0x6538e8%0AInfo%3A%20DigitalTwin%20Interface%3A%20Invoking%20telemetry%20confirmation%20callback%20for%20interface%3Dsensehat%2C%20reportedStatus%3DDIGITALTWIN_CLIENT_RESULT_INVALID%2C%20userContextCallback%3D0xacb58%0AInfo%3A%20DigitalTwin%20successfully%20delivered%20telemetry%20message%20for%20Sensehat%3A%3Ahumidity%0AInfo%3A%20SENSEHAT_INTERFACE%3A%20DigitalTwin%20successfully%20delivered%20telemetry%20message%20for%20%3CHUMIDITY%3E%0AInfo%3A%20DigitalTwin%20Interface%3A%20Invoking%20telemetry%20confirmation%20returned%0AInfo%3A%20SENSEHAT_INTERFACE%3A%20Queuing%20of%20all%20telemetries%20to%20be%20sent%20has%20succeeded%0AInfo%3A%20DigitalTwin%20Client%20Core%3A%20Processing%20telemetry%20callback.%20%20confirmationResult%3DIOTHUB_CLIENT_CONFIRMATION_OK%2C%20userContextCallback%3D0x66c418%0AInfo%3A%20DigitalTwin%20Interface%3A%20Invoking%20telemetry%20confirmation%20callback%20for%20interface%3Dsensehat%2C%20reportedStatus%3DDIGITALTWIN_CLIENT_RESULT_INVALID%2C%20userContextCallback%3D0xacb64%0AInfo%3A%20DigitalTwin%20successfully%20delivered%20telemetry%20message%20for%20Sensehat%3A%3Apressure%0AInfo%3A%20SENSEHAT_INTERFACE%3A%20DigitalTwin%20successfully%20delivered%20telemetry%20message%20for%20%3CPRESSURE%3E%0A...%3C%2FPRESSURE%3E%3C%2FHUMIDITY%3E%3C%2FTEMPERATURE%3E%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EUsing%20Device%20Explorer%2C%20you%20will%20see%20messages%20arriving%20at%20your%20IoT%20Hub%20that%20resemble%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-markup%22%3E%3CCODE%3EReceiving%20events...%0A10%2F3%2F2019%2010%3A11%3A34%20AM%26gt%3B%20Device%3A%20%5BSenseHat%5D%2C%20Data%3A%5B%7B%22modelInformation%22%3A%7B%22capabilityModelId%22%3A%22urn%3Asense_hat%3ASenseHatModel%3A1%22%2C%22interfaces%22%3A%7B%22urn_azureiot_ModelDiscovery_ModelInformation%22%3A%22urn%3Aazureiot%3AModelDiscovery%3AModelInformation%3A1%22%2C%22urn_azureiot_Client_SDKInformation%22%3A%22urn%3Aazureiot%3AClient%3ASDKInformation%3A1%22%2C%22sensehat%22%3A%22urn%3Asense_hat%3ASenseHat%3A1%22%2C%22deviceInfo%22%3A%22urn%3Aazureiot%3ADeviceManagement%3ADeviceInformation%3A1%22%7D%7D%7D%5DProperties%3A%0A'iothub-message-schema'%3A%20'modelInformation'%0ASYSTEM%26gt%3Biothub-interface-id%3Durn%3Aazureiot%3AModelDiscovery%3AModelInformation%3A1%0ASYSTEM%26gt%3Biothub-interface-name%3Durn_azureiot_ModelDiscovery_ModelInformation%0ASYSTEM%26gt%3Biothub-connection-device-id%3DSenseHat%0ASYSTEM%26gt%3Biothub-connection-auth-method%3D%7B%22scope%22%3A%22device%22%2C%22type%22%3A%22sas%22%2C%22issuer%22%3A%22iothub%22%2C%22acceptingIpFilterRule%22%3Anull%7D%0ASYSTEM%26gt%3Biothub-connection-auth-generation-id%3D637055717398532553%0ASYSTEM%26gt%3Biothub-enqueuedtime%3D10%2F3%2F2019%204%3A11%3A34%20PM%0ASYSTEM%26gt%3Biothub-message-source%3DTelemetry%0ASYSTEM%26gt%3Bx-opt-sequence-number%3D467%0ASYSTEM%26gt%3Bx-opt-offset%3D222592%0ASYSTEM%26gt%3Bx-opt-enqueued-time%3D10%2F3%2F2019%204%3A11%3A34%20PM%0ASYSTEM%26gt%3BEnqueuedTimeUtc%3D10%2F3%2F2019%204%3A11%3A34%20PM%0ASYSTEM%26gt%3BSequenceNumber%3D467%0ASYSTEM%26gt%3BOffset%3D222592%0ASYSTEM%26gt%3Bcontent-type%3Dapplication%2Fjson%0A%0A10%2F3%2F2019%2010%3A11%3A46%20AM%26gt%3B%20Device%3A%20%5BSenseHat%5D%2C%20Data%3A%5B%7B%20%22temperature%22%3A%2032.170456%20%7D%5DProperties%3A%0A'iothub-message-schema'%3A%20'temperature'%0ASYSTEM%26gt%3Biothub-interface-name%3Dsensehat%0ASYSTEM%26gt%3Biothub-connection-device-id%3DSenseHat%0ASYSTEM%26gt%3Biothub-connection-auth-method%3D%7B%22scope%22%3A%22device%22%2C%22type%22%3A%22sas%22%2C%22issuer%22%3A%22iothub%22%2C%22acceptingIpFilterRule%22%3Anull%7D%0ASYSTEM%26gt%3Biothub-connection-auth-generation-id%3D637055717398532553%0ASYSTEM%26gt%3Biothub-enqueuedtime%3D10%2F3%2F2019%204%3A11%3A46%20PM%0ASYSTEM%26gt%3Biothub-message-source%3DTelemetry%0ASYSTEM%26gt%3Bx-opt-sequence-number%3D468%0ASYSTEM%26gt%3Bx-opt-offset%3D223520%0ASYSTEM%26gt%3Bx-opt-enqueued-time%3D10%2F3%2F2019%204%3A11%3A46%20PM%0ASYSTEM%26gt%3BEnqueuedTimeUtc%3D10%2F3%2F2019%204%3A11%3A46%20PM%0ASYSTEM%26gt%3BSequenceNumber%3D468%0ASYSTEM%26gt%3BOffset%3D223520%0ASYSTEM%26gt%3Bcontent-type%3Dapplication%2Fjson%0A%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EThe%20above%20shows%20that%20Plug%20and%20Play%20information%20is%20passed%20between%20the%20device%20and%20IoT%20Hub%20using%20message%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fazure%2Fiot-hub%2Fiot-hub-devguide-messages-construct%22%20target%3D%22_self%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%3Eproperties%3C%2FA%3E.%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH2%20id%3D%22toc-hId-406119670%22%20id%3D%22toc-hId-406231299%22%3EPlug%20and%20Play%20testing%20with%20IoT%20explorer%3C%2FH2%3E%0A%3CP%3E%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fazure%2Fiot-pnp%2Fhowto-install-iot-explorer%22%20target%3D%22_self%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%3EIoT%20explorer%3C%2FA%3E%20is%20a%20new%20tool%20that%20allows%20you%20to%20test%20Plug%20and%20Play%20interfaces%20as%20well%20as%20view%20the%20telemetry%20being%20received%20by%20IoT%20Hub%20from%20the%20device.%20Think%20of%20it%20as%20Device%20Explorer%20with%20Plug%20and%20Play%20support.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3COL%3E%0A%3CLI%3EDownload%20and%20install%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fazure%2Fiot-pnp%2Fhowto-install-iot-explorer%22%20target%3D%22_self%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%3EIoT%20explorer%3C%2FA%3E%26nbsp%3Bon%20you%20PC.%3C%2FLI%3E%0A%3CLI%3ELaunch%20IoT%20explorer%20and%20connect%20to%20your%20IoT%20Hub%20using%20the%20connection%20string.%3C%2FLI%3E%0A%3CLI%3ESelect%20%3CSTRONG%3ESettings%3C%2FSTRONG%3E%20in%20the%20top%20right%20corner.%3C%2FLI%3E%0A%3CLI%3EUnder%20%22%3CSTRONG%3EWe'll%20look%20for%20your%20model%20definition%20in%20the%20following%20locations%20(in%20order)%3C%2FSTRONG%3E%22%20click%20%3CSTRONG%3ENew%3C%2FSTRONG%3E%20and%20add%20the%20connection%20string%20to%20your%20%3CSTRONG%3ECompany%20model%20repository%20%3C%2FSTRONG%3Efrom%20the%20%3CSTRONG%3EAzure%20Certified%20for%20IoT%20%3CA%20href%3D%22https%3A%2F%2Faka.ms%2FACFI%22%20target%3D%22_self%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%3Erepository%3C%2FA%3E%3C%2FSTRONG%3E%20If%20you've%20published%20your%20device%20model%20to%20the%20%3CSTRONG%3EPublic%20repository%3C%2FSTRONG%3E%2C%20you%20can%20skip%20this%20step.%3C%2FLI%3E%0A%3CLI%3ESelect%20%3CSTRONG%3ESave%20%3C%2FSTRONG%3Eand%26nbsp%3Bclose%20Settings.%3C%2FLI%3E%0A%3CLI%3ESelect%20your%20Plug%20and%20Play%20device%20and%20select%20%3CSTRONG%3EDevice%20Twin.%3C%2FSTRONG%3E%3C%2FLI%3E%0A%3C%2FOL%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-center%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F135476iB51F4FC01E9FB46E%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20alt%3D%22IoTExplorer1.jpg%22%20title%3D%22IoTExplorer1.jpg%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3ENotice%20how%20the%20device%20information%20is%20now%20available%20from%20the%20IoT%20Hub%20device%20twin!%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EUnder%20%3CSTRONG%3EDigital%20Twin%3C%2FSTRONG%3E%2C%20expand%20%3CSTRONG%3Eurn%3Asense_hat%3ASenseHat%3A1%3C%2FSTRONG%3E%20and%20select%20%3CSTRONG%3ECommands%3C%2FSTRONG%3E.%20Send%20a%20message%20to%20the%20LED%20on%20the%20Sense%20HAT.%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-center%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F135477i8704278762460647%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20alt%3D%22IoTExplorer2.jpg%22%20title%3D%22IoTExplorer2.jpg%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ETo%20view%20the%20telemetry%20from%20the%20Sense%20HAT%2C%20select%20%3CSTRONG%3ETelemetry%3C%2FSTRONG%3E%20and%20click%20%3CSTRONG%3EStart%3C%2FSTRONG%3E.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-center%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F135478iEA24F49C1A699C71%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20alt%3D%22IoTExplorer3.jpg%22%20title%3D%22IoTExplorer3.jpg%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ECongratulations!%20You%20have%20successfully%20Plug%20and%20Play-enabled%20your%20Sense%20HAT%20device.%20But%20wait%2C%20that's%20not%20all!%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH2%20id%3D%22toc-hId--2146037291%22%20id%3D%22toc-hId--2145925662%22%3EIoT%20Central%3C%2FH2%3E%0A%3CP%3EIoT%20Central%20has%20preview%20support%20for%20Plug%20and%20Play%20as%20well!%20In%20my%20next%20blog%20post%20I%20will%20show%20you%20how%20to%20connect%20the%20Sense%20HAT%20to%20IoT%20Central%20using%20Plug%20and%20Play.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH2%20id%3D%22toc-hId--403226956%22%20id%3D%22toc-hId--403115327%22%3EConclusion%3C%2FH2%3E%0A%3CP%3EHopefully%20this%20blog%20post%20has%20provided%20you%20the%20details%20needed%20to%20get%20your%20device%20working%20with%20Plug%20and%20Play%20and%20helps%20you%20avoid%20some%20of%20the%20pitfalls%20I%20ran%20into.%20I%20would%20also%20love%20to%20hear%20your%20feedback%20on%20what%20you%20like%20(and%20don't%20like)%20about%20Plug%20and%20Play.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ECheers%2C%3C%2FP%3E%0A%3CP%3EKevin%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ETwitter%3A%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Ftwitter.com%2Fkhilscher%22%20target%3D%22_self%22%20rel%3D%22nofollow%20noopener%20noreferrer%20noopener%20noreferrer%22%3E%40khilscher%3C%2FA%3E%3C%2FP%3E%0A%3CP%3ELinkedIn%3A%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Fwww.linkedin.com%2Fin%2Fkevinhilscher%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fwww.linkedin.com%2Fin%2Fkevinhilscher%3C%2FA%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH2%20id%3D%22toc-hId-1339583379%22%20id%3D%22toc-hId-1339695008%22%3EReferences%3C%2FH2%3E%0A%3CUL%3E%0A%3CLI%3ECode%20samples%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2Fkhilscher%2FSenseHATPnP%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fgithub.com%2Fkhilscher%2FSenseHATPnP%3C%2FA%3E%3C%2FLI%3E%0A%3CLI%3EDeep%20Dive%3A%20Build%20Solutions%20and%20Certify%20Devices%20with%20IoT%20Plug%20and%20Play%20%3CA%20href%3D%22https%3A%2F%2Fchannel9.msdn.com%2FShows%2FInternet-of-Things-Show%2FDeep-Dive-IoT-Plug-and-Play%22%20target%3D%22_self%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fchannel9.msdn.com%2FShows%2FInternet-of-Things-Show%2FDeep-Dive-IoT-Plug-and-Play%3C%2FA%3E%3C%2FLI%3E%0A%3CLI%3ESense%20Hat%20Overview%20%3CA%20href%3D%22https%3A%2F%2Fwww.raspberrypi.org%2Fproducts%2Fsense-hat%2F%22%20target%3D%22_self%22%20rel%3D%22nofollow%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fwww.raspberrypi.org%2Fproducts%2Fsense-hat%2F%3C%2FA%3E%3C%2FLI%3E%0A%3CLI%3ESense%20Hat%20Python%20Examples%20%3CA%20href%3D%22https%3A%2F%2Fprojects.raspberrypi.org%2Fen%2Fprojects%2Fgetting-started-with-the-sense-hat%22%20target%3D%22_self%22%20rel%3D%22nofollow%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fprojects.raspberrypi.org%2Fen%2Fprojects%2Fgetting-started-with-the-sense-hat%3C%2FA%3E%3C%2FLI%3E%0A%3CLI%3ESense%20Hat%20API%20%3CA%20href%3D%22https%3A%2F%2Fpythonhosted.org%2Fsense-hat%2Fapi%2F%22%20target%3D%22_self%22%20rel%3D%22nofollow%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fpythonhosted.org%2Fsense-hat%2Fapi%2F%3C%2FA%3E%3C%2FLI%3E%0A%3CLI%3EDTDL%20%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2FAzure%2FIoTPlugandPlay%2Ftree%2Fmaster%2FDTDL%22%20target%3D%22_self%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fgithub.com%2FAzure%2FIoTPlugandPlay%2Ftree%2Fmaster%2FDTDL%3C%2FA%3E%3C%2FLI%3E%0A%3CLI%3EPlug%20and%20Play%20Announcement%20%3CA%20href%3D%22https%3A%2F%2Fazure.microsoft.com%2Fen-ca%2Fblog%2Fiot-plug-and-play-is-now-available-in-preview%2F%22%20target%3D%22_self%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fazure.microsoft.com%2Fen-ca%2Fblog%2Fiot-plug-and-play-is-now-available-in-preview%2F%3C%2FA%3E%3C%2FLI%3E%0A%3CLI%3EMXChip%20Plug%20and%20Play%20Code%20Sample%20%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2FMXCHIP%2FIoTDevKit%2Ftree%2Fmaster%2Fpnp%22%20target%3D%22_self%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fgithub.com%2FMXCHIP%2FIoTDevKit%2Ftree%2Fmaster%2Fpnp%3C%2FA%3E%3C%2FLI%3E%0A%3C%2FUL%3E%3C%2FLINGO-BODY%3E%3CLINGO-TEASER%20id%3D%22lingo-teaser-892261%22%20slang%3D%22en-US%22%3E%3CP%3ELearn%20how%20to%20configure%20the%20Sense%20HAT%20LED%20and%20sensors%20on%20a%20Raspberry%20Pi%20for%20Plug%20and%20Play%20and%20develop%20the%20underlying%20code%20to%20read%20from%20these%20sensors%20and%20control%20the%20LED%20display.%3C%2FP%3E%3C%2FLINGO-TEASER%3E%3CLINGO-LABS%20id%3D%22lingo-labs-892261%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EIoT%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EPlug%20and%20Play%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3Eraspberry%20pi%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3ESense%20HAT%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E
Microsoft

We recently announced IoT Plug and Play (in preview) as part of a broader effort to reduce the time needed to integrate IoT devices into IoT solutions and IoT Central. What Windows Plug and Play did for connecting hardware devices to Windows, IoT Plug and Play aims to do the same for IoT devices connecting to IoT solutions.

 

There is some excellent Plug and Play documentation available at https://aka.ms/iotpnpdocs/. Take some time to read through this documentation and familiarize yourself with Plug and Play concepts, including DTDL concepts.

 

What this blog post attempts to do is take the Plug and Play documentation a step further and apply it to a real world device. In this case, a Raspberry Pi 3 Model B+ with a Sense HAT installed. We will configure the Sense HAT LED and sensors for Plug and Play and develop the underlying code to read from these sensors and control the LED display.

 

This blog is targeted at device builders (interested in device certification and getting their device listed on our Device Catalog) and solution developers. This blog assumes you have a solid understanding of Raspberry Pi + Linux, Azure IoT services such as IoT Hub and the Azure IoT Device SDKs, as well as developing in Python and C. The steps in this blog are based on the Tutorial: Create and test a device capability model using Visual Studio Code.

 

Reminder, Plug and Play is in Preview meaning no SLA and support is limited to certain regions (Central US, North Europe, or Japan East), SDKs and for devices only (no IoT Edge support yet).

 

Prerequisites

  • Install the software prerequisites on your PC that are listed here
  • Create an IoT Hub in either Central US, North Europe, or Japan East.
  • Add an IoT Device to your IoT Hub.Make a note of the connection string.
  • Setup your Azure Cloud Shell as described here
  • Raspberry Pi 3 Model B+ with Raspbian GNU/Linux 9 (stretch) installed
  • Sense HAT installed on the Raspberry Pi device

a222a1d657906db95efbca8b8467037fa1a89def_sense-hat-1733x1080-1-1733x1080Sense HAT

 

The Sense HAT device has a LED display and number of sensors built into it including: temperature, humidity and pressure. It also has a well documented Python API. But the biggest reason I like to use it is to avoid fiddling with breadboards, resistors and jumper cables :smile:.

 

Getting Started

Once you have the Sense Hat installed on the Raspberry Pi along with Raspbian 9 (stretch), the next step is to install the Sense HAT Python API.

 

sudo apt-get update
sudo apt-get install sense-hat
sudo reboot

 

 

Note: I haven't found a decently documented C-based API for the Sense HAT. If you know of one, please send me a link to it!

 

Let's also ensure we have Python 3 installed.

 

pi@raspberrypi: python3 --version
Python 3.5.3

 

 

Now test that the Sense HAT is working with the following Python commands.

 

pi@raspberrypi:/ $ python3
Python 3.5.3 (default, Sep 27 2018, 17:25:39)
[GCC 6.3.0 20170516] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from sense_hat import SenseHat
>>> sense = SenseHat()
>>> sense.show_message("Hello world!")

 

If all is successful, a "Hello world!" message should scroll across the LED display.

 

Model your device

If you are familiar with DTDL (which is based on JSON-LD) you'll know we need to first develop an Interface for the Sense HAT and then create a Model file. Together these form a Device Capability Model (DCM).

 

Creating an Interface

A Interface describes the capabilities that are implemented by a device. Interfaces are reusable and can be used across different capability models.

 

In our case, the Interface we will develop will describe the Sense HAT's:

  • temperature sensor
  • humidity sensor
  • pressure sensor
  • LED display

In DTDL, the three (3) sensors are considered a Telemetry data type since they emit data from the sensor. The LED display will be a Command data type, as our IoT solution will send a command to the Sense HAT to display a message on the LED.

 

Follow the "Create the interface file" instructions, substituting the following:

 

  • SenseHat as the name of the interface and press Enter. VS Code creates a sample interface file called SenseHat.interface.json.

  • Replace the contents of the sample SenseHat.interface.json file with the following JSON:

 

{
  "@id": "urn:sense_hat:SenseHat:1",
  "@type": "Interface",
  "displayName": "Sense Hat Interface",
  "contents": [
    {
        "@type": "Telemetry",
        "comment": "Sense Hat Temperature",
        "name": "temperature",
        "schema": "double",
        "unit": "Units/Temperature/celsius"
    },
    {
        "@type": "Telemetry",
        "comment": "Sense Hat Relative Humidity",
        "name": "humidity",
        "schema": "double",
        "unit": "Units/Humidity/percent"
    },
    {
        "@type": "Telemetry",
        "comment": "Sense Hat Pressure",
        "name": "pressure",
        "schema": "double",
        "unit": "Units/Pressure/kiloPascal"
    },
    {
        "@type": "Command",
        "description": "This command will display a message on the Sense Hat LED display.",
        "name": "show_message",
        "commandType": "synchronous",
        "request": {
          "name": "message",
          "schema": "string"
        }
      }
  ],
  "@context": "http://azureiot.com/v1/contexts/IoTModel.json"
}

 

As you can see we've modeled the 3 sensors and the LED display in the Interface using DTDL. For each data type there are a number of DTDL properties which can be set. In the above example I have configured a few, but there are more.

 

IntelliSense is available when editing the DTDL using VS Code. Try changing any of the "unit" values and you'll see what I mean.

 

Creating a Model file

Next, we will want to create a Model file. The model file specifies the interfaces that your device implements. There are typically at least two interfaces in a model - one or more that define the specific capabilities of your device, and a standard interface that all IoT Plug and Play devices must implement.

 

Follow the "Create the model file" instructions, substituting the following:

 

  • Enter SenseHatModel as the name of the model. VS Code creates a sample interface file called SenseHatModel.capabilitymodel.json.
  • Replace the contents of the sample SenseHatModel.capabilitymodel.json file (filename must end with .capabilitymodel.json) with the following JSON:

 

{
  "@id": "urn:sense_hat:SenseHatModel:1",
  "@type": "CapabilityModel",
  "displayName": "Sense Hat Capability Model",
  "implements": [
    {
        "schema": "urn:sense_hat:SenseHat:1",
        "name": "sensehat"
    },
    {
        "schema": "urn:azureiot:DeviceManagement:DeviceInformation:1",
        "name": "deviceInfo"
    }
  ],
  "@context": "http://azureiot.com/v1/contexts/IoTModel.json"
}

 

 

Notice the DeviceInformation interface (known as a standard interface) was automatically added and is required (e.g. for Device Certification).

 

Lastly download the DeviceInformation interface from the public model repository using the instructions.

 

Publish the model

As part of the release of Plug and Play, Microsoft is hosting an Azure Certified for IoT repository for you to host your model. Using the model repository is optional; you can store the model on the local device (not covered in this Blog post).

 

There are two sides to the repository:

 

  • Public repository - where publicly published Models and Interfaces are stored.
  • Company repository - where private Models and Interfaces are stored (e.g. prior to publishing publicly or when you have feature/device that is specific to your organization).

Follow the "Publish your model" instructions to publish the following two files to your Company repository:

 

  • SenseHat.interface.json
  • SenseHatModel.capabilitymodel.json

By default, the model will be stored in the Company repository. You can optionally publish it to the Public repository.

 

Generate stub code

Using VS Code you can generate stub code for your IoT device. However, there are some limitations with this at the moment:

 

  • You will need to use Azure IoT Device SDKs that are Plug and Play-aware. Currently, only the C and Node Device SDKs are Plug and Play-aware. The other SDKs (e.g. Python) will be updated to be Plug and Play-aware in the future.
  • VS Code only generates stub code in C (sorry Node :cry:).

These limitations pose a problem for us, as you will see later (recall, the Sense HAT only ships with a Python API!).

 

Follow the "Generate code" instructions to generate the stub C code, substituting the following:

 

  • SenseHatModel.capabilitymodel.json as the model file
  • sensehat_app as the app name

Once you have finished generating the stub code you will find the following files in a new sensehat_app folder:

 

CMakeLists.txt  
main.c  
pnp_device.c  
pnp_device.h  
Readme.md  
SenseHatModel_impl.c  
SenseHatModel_impl.h  
\utilities

 

 

The primary file you need to concern yourself with is SenseHatModel_impl.c. This is the file where we will add our implementation code.

 

Update the stub code

Now let's add our implementation code to SenseHatModel_impl.c.

 

  1. Using VS Code, open the sensehat_app\SenseHatModel_impl.c file.
  2. Paste in the implementation code from https://github.com/khilscher/SenseHATPnP/blob/master/sensehat_app/SenseHatModel_impl.c

Recall that I mentioned earlier that the Sense HAT API is Python-based. To work around this, I am using popen to run the Python 3 process and pass in one of several Python scripts I developed for interacting with the Sense HAT hardware. Popen returns pointer to an open stream, which contains the return value from the Python script. I admit it's a bit of a hack, but it works.

 

Configure the Raspberry Pi

Now it's time to configure your Raspberry Pi.

 

  1. SSH into your Raspberry Pi. Note: I am logged in as the user "pi" and I will save everything to the pi user home directory.
  2. Run the following commands:

 

pi@raspberrypi: cd /home/pi
pi@raspberrypi: git clone https://github.com/khilscher/SenseHATPnP.git

 

 

The last command will copy the Sense HAT Python scripts from GitHub to the /home/pi/SenseHatPnP/python_scripts/ folder.

 

Note: The Python script paths are hard coded in the SenseHatModel_impl.c file. It expects them to be saved under /home/pi/SenseHATPnP/python_scripts/. If you use another location, please update SenseHatModel_impl.c accordingly.

 

Build the code

The final step is to build your code on the Raspberry Pi device.

 

Follow the Ubuntu instructions in the Readme.md file in the sensehat_app folder, substituting the following:

 

  1. The Readme.md references a azure-iot-sdk-c-pnp folder. This is incorrect. It is azure-iot-sdk-c.
  2. Open a cmd prompt in your working folder on your PC.
  3. Use scp to copy the sensehat_app folder from your PC to the azure-iot-sdk-c folder on you Pi device.

 

c:\my_working_folder> scp -r sensehat_app pi@<RPi IP address>:/home/pi/azure-iot-sdk-c

 

 

Run the remaining build steps contained in the Readme.md. Ignore warnings but fix any errors encountered during the build process.

 

Running the code

Running your code involves executing the sensehat_app.

 

pi@raspberrypi: cd /home/pi/azure-iot-sdk-c/cmake/sensehat_app/
pi@raspberrypi: ./sensehat_app "[IoTHub device connection string]"

 

 

After executing the above commands the sensehat_app should be running and sending telemetry to Azure IoT Hub. During startup, watch how it logs the registration of its PnP interfaces with IoT Hub.

 

...
Info: DEVICEINFO_INTERFACE: Interface successfully registered.
Info: Interface registration callback invoked, interfaces have been successfully registered
Info: DigitalTwin interfaces successfully registered
Info: DEVICEINFO_INTERFACE: Queued async report read only property for manufacturer
Info: DEVICEINFO_INTERFACE: Queued async report read only property for model
Info: DEVICEINFO_INTERFACE: Queued async report read only property for swVersion
Info: DEVICEINFO_INTERFACE: Queued async report read only property for osName
Info: DEVICEINFO_INTERFACE: Queued async report read only property for processorArchitecture
Info: DEVICEINFO_INTERFACE: Queued async report read only property for processorManufacturer
Info: DEVICEINFO_INTERFACE: Queued async report read only property for totalStorage
Info: DEVICEINFO_INTERFACE: Queued async report read only property for totalMemory
Info: DEVICE_INFO: Queuing of all properties to be reported has succeeded

...

Info: Send telemetry data to IoT Hub
32.26278305053711
Info: SENSEHAT_INTERFACE:: DigitalTwin_InterfaceClient_SendTelemetryAsync successfully sent temperature
32.638771057128906
Info: SENSEHAT_INTERFACE:: DigitalTwin_InterfaceClient_SendTelemetryAsync successfully sent humidity
Info: DigitalTwin Client Core: Processing telemetry callback.  confirmationResult=IOTHUB_CLIENT_CONFIRMATION_OK, userContextCallback=0x66c418
Info: DigitalTwin Interface: Invoking telemetry confirmation callback for interface=sensehat, reportedStatus=DIGITALTWIN_CLIENT_RESULT_INVALID, userContextCallback=0xacb4c
Info: DigitalTwin successfully delivered telemetry message for Sensehat::temperature
Info: SENSEHAT_INTERFACE: DigitalTwin successfully delivered telemetry message for <temperature>
Info: DigitalTwin Interface: Invoking telemetry confirmation returned
880.73828125
Info: SENSEHAT_INTERFACE:: DigitalTwin_InterfaceClient_SendTelemetryAsync successfully sent pressure
Info: DigitalTwin Client Core: Processing telemetry callback.  confirmationResult=IOTHUB_CLIENT_CONFIRMATION_OK, userContextCallback=0x6538e8
Info: DigitalTwin Interface: Invoking telemetry confirmation callback for interface=sensehat, reportedStatus=DIGITALTWIN_CLIENT_RESULT_INVALID, userContextCallback=0xacb58
Info: DigitalTwin successfully delivered telemetry message for Sensehat::humidity
Info: SENSEHAT_INTERFACE: DigitalTwin successfully delivered telemetry message for <humidity>
Info: DigitalTwin Interface: Invoking telemetry confirmation returned
Info: SENSEHAT_INTERFACE: Queuing of all telemetries to be sent has succeeded
Info: DigitalTwin Client Core: Processing telemetry callback.  confirmationResult=IOTHUB_CLIENT_CONFIRMATION_OK, userContextCallback=0x66c418
Info: DigitalTwin Interface: Invoking telemetry confirmation callback for interface=sensehat, reportedStatus=DIGITALTWIN_CLIENT_RESULT_INVALID, userContextCallback=0xacb64
Info: DigitalTwin successfully delivered telemetry message for Sensehat::pressure
Info: SENSEHAT_INTERFACE: DigitalTwin successfully delivered telemetry message for <pressure>
...

 

 

Using Device Explorer, you will see messages arriving at your IoT Hub that resemble:

 

Receiving events...
10/3/2019 10:11:34 AM> Device: [SenseHat], Data:[{"modelInformation":{"capabilityModelId":"urn:sense_hat:SenseHatModel:1","interfaces":{"urn_azureiot_ModelDiscovery_ModelInformation":"urn:azureiot:ModelDiscovery:ModelInformation:1","urn_azureiot_Client_SDKInformation":"urn:azureiot:Client:SDKInformation:1","sensehat":"urn:sense_hat:SenseHat:1","deviceInfo":"urn:azureiot:DeviceManagement:DeviceInformation:1"}}}]Properties:
'iothub-message-schema': 'modelInformation'
SYSTEM>iothub-interface-id=urn:azureiot:ModelDiscovery:ModelInformation:1
SYSTEM>iothub-interface-name=urn_azureiot_ModelDiscovery_ModelInformation
SYSTEM>iothub-connection-device-id=SenseHat
SYSTEM>iothub-connection-auth-method={"scope":"device","type":"sas","issuer":"iothub","acceptingIpFilterRule":null}
SYSTEM>iothub-connection-auth-generation-id=637055717398532553
SYSTEM>iothub-enqueuedtime=10/3/2019 4:11:34 PM
SYSTEM>iothub-message-source=Telemetry
SYSTEM>x-opt-sequence-number=467
SYSTEM>x-opt-offset=222592
SYSTEM>x-opt-enqueued-time=10/3/2019 4:11:34 PM
SYSTEM>EnqueuedTimeUtc=10/3/2019 4:11:34 PM
SYSTEM>SequenceNumber=467
SYSTEM>Offset=222592
SYSTEM>content-type=application/json

10/3/2019 10:11:46 AM> Device: [SenseHat], Data:[{ "temperature": 32.170456 }]Properties:
'iothub-message-schema': 'temperature'
SYSTEM>iothub-interface-name=sensehat
SYSTEM>iothub-connection-device-id=SenseHat
SYSTEM>iothub-connection-auth-method={"scope":"device","type":"sas","issuer":"iothub","acceptingIpFilterRule":null}
SYSTEM>iothub-connection-auth-generation-id=637055717398532553
SYSTEM>iothub-enqueuedtime=10/3/2019 4:11:46 PM
SYSTEM>iothub-message-source=Telemetry
SYSTEM>x-opt-sequence-number=468
SYSTEM>x-opt-offset=223520
SYSTEM>x-opt-enqueued-time=10/3/2019 4:11:46 PM
SYSTEM>EnqueuedTimeUtc=10/3/2019 4:11:46 PM
SYSTEM>SequenceNumber=468
SYSTEM>Offset=223520
SYSTEM>content-type=application/json

 

 

The above shows that Plug and Play information is passed between the device and IoT Hub using message properties

 

Plug and Play testing with IoT explorer

IoT explorer is a new tool that allows you to test Plug and Play interfaces as well as view the telemetry being received by IoT Hub from the device. Think of it as Device Explorer with Plug and Play support.

 

  1. Download and install IoT explorer on you PC.
  2. Launch IoT explorer and connect to your IoT Hub using the connection string.
  3. Select Settings in the top right corner.
  4. Under "We'll look for your model definition in the following locations (in order)" click New and add the connection string to your Company model repository from the Azure Certified for IoT repository If you've published your device model to the Public repository, you can skip this step.
  5. Select Save and close Settings.
  6. Select your Plug and Play device and select Device Twin.

IoTExplorer1.jpg

Notice how the device information is now available from the IoT Hub device twin!

 

Under Digital Twin, expand urn:sense_hat:SenseHat:1 and select Commands. Send a message to the LED on the Sense HAT.

IoTExplorer2.jpg

 

To view the telemetry from the Sense HAT, select Telemetry and click Start.

 

IoTExplorer3.jpg

 

Congratulations! You have successfully Plug and Play-enabled your Sense HAT device. But wait, that's not all!

 

IoT Central

IoT Central has preview support for Plug and Play as well! In my next blog post I will show you how to connect the Sense HAT to IoT Central using Plug and Play.

 

Conclusion

Hopefully this blog post has provided you the details needed to get your device working with Plug and Play and helps you avoid some of the pitfalls I ran into. I would also love to hear your feedback on what you like (and don't like) about Plug and Play.

 

Cheers,

Kevin

 

Twitter: @khilscher

LinkedIn: https://www.linkedin.com/in/kevinhilscher

 

References