A simple Blazor WASM apps that demonstrates what works and doesn’t work with dotnet/iot GPIO and Bindings.

Recap fom previous post. 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!

The Blazor WebAssembly App

The app on GitHUb: djaus2/BlazGPIO
Nb: The App is a PWA app which means it can be installed.
Demonstrates that a Blazor WASM Client can’t call hardware directly.
Can call it via the service though.
Focus is upon GPIO functionality and Bindings Devices functionality.
The tests do not require any connections on the RPi.

The Pages

All calls fail gracefully if hardware not available.

  • Get CPU Core Temperature
    • Gets the CPU Core temperature of a RPi when running Debian/Linux
    • Nb: Does not work with Windows 10 IoT-Core
    • Uses the CpuTemperature Device form IoT.Devices.Bindings
    • Call to Device is from .ASP.NET Core (.Net Core functionality)
  • Get Set GPIO Pins
    • Sets or clears a RPi pin
    • Does/should work with Windows 10 IoT-Core as well
    • Uses System.Device.GPIO directly
    • System.Device.GPIO is a .NET Standard library
    • Call is from the Shared Library (Which is also .NET Standard)
    • Nb: Call can only be via service. Call direct from WASM Client always fails.

So when the app runs on a desktop it reports that the hardware isn’t available.

BlazGPIOCPU
Getting the CPU Core Temperature on a RPi using a IoT.Device.Bindings Device Driver

BlazGPIOPins
Manipulating Pins on a RPi using System.Devices.GPIO

Conclusion

The dotnet/iot GPIO and Bindings interactions cannot occur directly from the Client, but can from the Service.

Further

With the app, the GPIO class to access the RPi pins resides in the Solution’s Shared project. That way the Client and Service can access the same code. The outcomes are the same if the class is added to the Client or to the Service. You can’t access the GPIO from the Client. Also as noted in the previous post, the Bindings library is .NET Core and so you can’t use it to access the Client’s CPU Core Temperature because the Client is a .NET Standard app.

Footnote: Set up for RPi app Development

  • Raspbian Version 10 installed on the RPi
  • I have installed .. on the RPi
  • I connect to the RPi via Remote Desktop Connection (that uses …)
  • I have a Share on the RPi
  • I develop the app in Visual Studio 2019 on desktop and get it running there.
    • Hence the fail gracefully with no detectable hardware.
  • I publish the app, Folder mode, to the Share.
    • Framework Dependant
    • Linux ARM
  • I have .NET Core 3.1 SDK Linux ARM in a folder on the RPi
    • I run a script to enable it
  • In the publish folder in a Terminal on the RPi run:
    • ./BlazorGPIO.Server

    Next: Some “hacks” trying to get around this limitation.


 TopicSubtopic
  Next: > Blazor-IoT
<  Prev:   Blazor-IoT
This Category:Blazor
  Next: > Blazor-IoT Azure IoT Hub Interaction using Blazor on a RPi - Some Hacks ... and a Solution. 
<  Prev:   Blazor-IoT