A discussion about what you can and can’t do with a Blazor app running on a Raspberry Pi wrt interacting with Sensors on the Pi whilst sending the data to an Azure IoT Hub. Includes some exploration of attempts to get around limitations.

Wishlist

Wouldn’t it be nice if you could run a Blazor WASM manifestation such that the Server runs on one device, acting as an Edge Gateway to IoT hub and the WASM client runs runs on multiple devices each with sensors…Nah!

About Blazor

Blazor is based upon ASP.NET Core which in turn is based upon .NET Core. It facilitates the develop of apps that are presented over the web and run in a device’s browser.

A Blazor app may just be a server side app with the client browser just rendering the content the server generates and sends to it. It runs in this mode as a traditional web server, except that it has full access to .NET Core APIs. This means it can us the dotnet/iot API to interact with hardware connected to the device on which it runs. So, or example, a temperature sensor connected to a a RPi running a Blazor server app can read the temperature and render this as content back to the client’s browser.

An alternative scenario is, Blazor Web Assembly (WASM). With this there is a still an (optional) Blazor server, but it can deliver a browser based app that can also exploit much of the .NET Core functionality. This client app can actually be installed on the client and run off line, if it has been set as a PWA app.

Introduction to ASP.NET Core Blazor on Microsoft Docs
Blazor University
.NET Core/ASP.NET Core Installations: Download .NET Core Landing Page
Awesome Blazor resource on GitHub

Blazor Project Types

With a Blazor Web Assembly scenario, the Server is an ASP.NET Core (.NET Core) project, the Client is a .NET Standard project as is the third Shared project.

About dotnet/iot

Previous blogs on this site have discussed the use of this library for accessing hardware on devices such as the RPi running Windows 10 IoT-Core or running Raspian. It targets .NET Core so possibly could be used with ASP.NET Core. There also a significant number of posts, including numerous samples, on this site with respect to communicating with an Azure IoT Hub from .NET Core.

This API, as available on GiTHub, support access to hardware on devices that are running Linux or Windows 10 IoT-Core, such as the Raspberry Pi. The primary support is via GPIO through the System.Device.GPIO Library that can be installed in projects via Nuget. The package is built from a .NetStandard project. The second Library, built on top of this, is the IoT.Device.Bindings API. This provides drivers for a vast range of device add-ons such as sensors and actuators. With each driver there is a .NET Core sample project to demonstrate its use. The project for this is a .NET Core project and therefore this API cannot be used with a .NET Standard project. It can though be used with .NET core and ASP.NET Core project. Again, it added through Nuget.

Ref: dotnet/iot on GitHub.
An app for specifically browsing the Device Sample app and for getting them without downloading the whole repository:
dotnet/iot Sample Apps A Blazor PWA App hosted on Azure.

Nuget Install to a Project:

nuget install System.Device.Gpio
nuget install Iot.Device.Bindings

What Can and Can’t be done with Blazor and IoT

  • The Blazor server (whether part of a WASM scenario or not) can interact with sensors and actuators connected to it.
  • The Blazor client cannot (directly) interact with hardware connected to it whether running aa a WASM app or just rendering server content.
    • The (directly) qualification is because you could run both the client and server on the one device.

Look Ahead at Apps in this Blog Sequence:

Next: A Blazor Simulated IoT Hub Device. (Coming)


 TopicSubtopic
<  Prev:   Blazor
   
 This Category Links 
Category:IoT Index:IoT
  Next: > Blazor-IoT
<  Prev:   az-iothub-ps