RaspberryPi 1.0.3

There is a newer prerelease version of this package available.
See the version list below for details.
dotnet add package RaspberryPi --version 1.0.3
                    
NuGet\Install-Package RaspberryPi -Version 1.0.3
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="RaspberryPi" Version="1.0.3" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="RaspberryPi" Version="1.0.3" />
                    
Directory.Packages.props
<PackageReference Include="RaspberryPi" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add RaspberryPi --version 1.0.3
                    
#r "nuget: RaspberryPi, 1.0.3"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package RaspberryPi@1.0.3
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=RaspberryPi&version=1.0.3
                    
Install as a Cake Addin
#tool nuget:?package=RaspberryPi&version=1.0.3
                    
Install as a Cake Tool

RaspberryPi

RaspberryPi is a .NET library that wraps a number of Raspberry Pi and Linux administration tasks behind a simple API. It is aimed at applications that need to inspect Raspberry Pi system state, manage Wi-Fi configuration, interact with systemctl, or install systemd services from managed code.

The library targets netstandard2.0 and netstandard2.1, so it can be used from many modern .NET applications.

Platform Support

When the library runs on a Raspberry Pi or another Linux system, AddRaspberryPi() registers the real implementations that call Linux tools such as systemctl, hostnamectl, vcgencmd, and Wi-Fi/network configuration commands. When the same code runs on a non-Linux system, the registration switches several services to null or no-op implementations so the application can still start, but Raspberry Pi specific operations are effectively unavailable.

Supported Raspberry Pi models:

Model Supported
Raspberry Pi 4
Raspberry Pi Zero
Raspberry Pi Zero W
Raspberry Pi Zero 2W
Raspberry Pi 400 ?
Raspberry Pi 5 ?

Support assumes the device is running Raspberry Pi OS or another Linux distribution with the required tools and services available. Features related to Wi-Fi, access point mode, and low-level device information can still vary depending on the wireless chipset, driver support, and system configuration.

What This Library Covers

This library currently provides APIs for:

  • Reading Raspberry Pi host and hardware information
  • Reading memory usage and CPU sensor status
  • Managing Wi-Fi station mode and access point configuration
  • Editing WPA and DHCP related configuration
  • Running Linux commands through an abstraction
  • Installing and managing systemd services
  • Working with systemctl

The repository also contains sample applications under Samples/ that demonstrate how the library can be wired into a console app.

Download and Install RaspberryPi

This project is designed as a reusable .NET library with package id RaspberryPi.

Use the NuGet Package Manager Console:

PM> Install-Package RaspberryPi

Or the .NET CLI:

dotnet add package RaspberryPi

Dependency Injection Integration

The easiest way to use the library is through Microsoft.Extensions.DependencyInjection. Call AddRaspberryPi() to register the main services:

using Microsoft.Extensions.DependencyInjection;

var services = new ServiceCollection();
services.AddRaspberryPi();

var serviceProvider = services.BuildServiceProvider();

On Linux, the real implementations are registered. On other platforms, several services fall back to no-op implementations so applications can still start without immediately failing.

If you want to skip the platform guard during testing or local development, use:

services.AddRaspberryPi();

API Usage

Read System Information

ISystemInfoService can be used to read Raspberry Pi specific system information such as host info, CPU sensor values, and memory usage.

using Microsoft.Extensions.DependencyInjection;
using RaspberryPi;
using UnitsNet.Units;

var services = new ServiceCollection();
services.AddRaspberryPi();

var serviceProvider = services.BuildServiceProvider();
var systemInfoService = serviceProvider.GetRequiredService<ISystemInfoService>();

var hostInfo = await systemInfoService.GetHostInfoAsync();
Console.WriteLine($"Hostname: {hostInfo?.Hostname}");
Console.WriteLine($"OS: {hostInfo?.OperatingSystem}");
Console.WriteLine($"Kernel: {hostInfo?.Kernel}");

var cpuSensors = systemInfoService.GetCpuSensorsStatus();
Console.WriteLine($"CPU temperature: {cpuSensors?.Temperature}");
Console.WriteLine($"Voltage: {cpuSensors?.Voltage}");
Console.WriteLine($"Currently throttled: {cpuSensors?.CurrentlyThrottled}");

var memoryInfo = systemInfoService.GetMemoryInfo();
Console.WriteLine(
    $"RAM used: {memoryInfo?.RandomAccessMemory?.Used.ToUnit(InformationUnit.Megabyte)} MB");

You can also update the device hostname:

systemInfoService.SetHostname("raspberrypi-kiosk");

Configure Wi-Fi Station Mode

INetworkManager can connect the Raspberry Pi to an existing Wi-Fi network by updating wpa_supplicant and related networking configuration.

using System.Net;
using Microsoft.Extensions.DependencyInjection;
using RaspberryPi;
using RaspberryPi.Network;

var services = new ServiceCollection();
services.AddRaspberryPi();

var serviceProvider = services.BuildServiceProvider();
var networkManager = serviceProvider.GetRequiredService<INetworkManager>();

await networkManager.SetupStationModeAsync(
    iface: new NetworkInterface("wlan0"),
    network: new WPASupplicantNetwork
    {
        SSID = "MyWifi",
        PSK = "SuperSecretPassword",
        ScanSSID = false
    },
    country: Countries.Switzerland);

Configure Access Point Mode

The same INetworkManager can also prepare an access point configuration.

using System.Net;
using Microsoft.Extensions.DependencyInjection;
using RaspberryPi;
using RaspberryPi.Network;

var services = new ServiceCollection();
services.AddRaspberryPi();

var serviceProvider = services.BuildServiceProvider();
var networkManager = serviceProvider.GetRequiredService<INetworkManager>();

await networkManager.SetupAccessPointAsync(
    iface: new NetworkInterface("wlan0"),
    ssid: "MyPiAccessPoint",
    psk: "ChangeMe123",
    ipAddress: IPAddress.Parse("192.168.4.1"),
    channel: 6,
    country: Countries.Switzerland);

The repository includes the sample project Samples/RaspiAP which demonstrates station mode, scanning, access point setup, and status commands.

Install a systemd Service

IServiceConfigurator and ServiceDefinition can be used to generate and install a unit file in /etc/systemd/system. These operations require elevated privileges and a Linux system with systemd.

using Microsoft.Extensions.DependencyInjection;
using RaspberryPi.Services;

var services = new ServiceCollection();
services.AddRaspberryPi();

var serviceProvider = services.BuildServiceProvider();
var serviceConfigurator = serviceProvider.GetRequiredService<IServiceConfigurator>();

serviceConfigurator.InstallService(new ServiceDefinition("my-worker")
{
    Description = "My background worker",
    WorkingDirectory = "/opt/my-worker",
    ExecStart = "/usr/bin/dotnet /opt/my-worker/MyWorker.dll",
    Restart = ServiceRestart.OnFailure,
    RestartSec = 10,
    WantedBy = new[] { "multi-user.target" }
});

Control Existing Services with systemctl

ISystemCtl is a lightweight wrapper around common systemctl operations.

using Microsoft.Extensions.DependencyInjection;
using RaspberryPi.Services;

var services = new ServiceCollection();
services.AddRaspberryPi();

var serviceProvider = services.BuildServiceProvider();
var systemCtl = serviceProvider.GetRequiredService<ISystemCtl>();

if (!systemCtl.IsActive("ssh"))
{
    systemCtl.StartService("ssh");
}

Notes

  • Most of the library is intended to run on Linux, especially on Raspberry Pi OS.
  • Some operations call tools such as vcgencmd, hostnamectl, systemctl, wpa_cli, and other Linux utilities.
  • Service installation and certain networking operations require sudo privileges.
  • For broader usage examples, see Samples/RaspberryPi.ConsoleApp and Samples/RaspiAP.

License

This project is Copyright © 2026 Thomas Galliker. Free for non-commercial use. For commercial use please contact the author.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 is compatible. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.4-pre 101 4/23/2026
1.0.3 131 4/2/2026
1.0.1-pre 112 3/31/2026
1.0.0-pre 88 3/31/2026

1.0
- Initial release.