
🔌 PicoServer.Nano (for .NET nanoFramework)
PicoServer.Nano (NuGet package: PicoServer.Nano) is a lightweight port of PicoServer to the .NET nanoFramework ecosystem. It is a zero-dependency "Web glue library" designed specifically for resource-constrained microcontrollers, with special adaptation and optimization for ESP32.
What is .NET nanoFramework?
A project under the Microsoft .NET Foundation that shrinks the full .NET runtime to a few hundred KB, enabling C# code to run on microcontrollers like ESP32 and STM32. You can develop projects in Visual Studio and deploy to boards with one click.
Difference from Official WebServer Library
PicoServer.Nano does not use reflection, has lower memory and CPU footprint, leaving limited resources for business logic.
Quick Start
1. Environment Setup
Install nanoFramework development environment:
- Install nanoFramework Visual Studio Extension
- Flash nanoFramework firmware to ESP32:
nanoff --target ESP32_S3_ALL --serialport COM5 --update --masserase2. Add NuGet Package
dotnet add package PicoServer.Nano3. Write Code
using PicoServer.Nano;
using System.Net;
var server = new WebAPIServer();
server.AddRoute("/hello", (req, res) => res.Write("Hello from MCU!"), "GET");
server.StartServer();
Console.WriteLine($"Server started: http://{server.GetIPAddress()}/");Compile and deploy, then visit http://<device-IP>/hello in browser to see the response.
Core Capabilities
| Feature | Supported |
|---|---|
| Route Mapping | ✅ Exact routing |
| Custom Middleware | ✅ |
| Token Authentication | ✅ |
| Static File Hosting | ✅ |
| SSE Long Connection | ✅ |
| File Upload/Download | ✅ |
Route Registration
server.AddRoute("/api/user", UserHandler, "GET");
private static void UserHandler(HttpListenerRequest req, HttpListenerResponse res)
{
string token = req.GetToken();
res.Write("{\"id\":1}");
}Middleware
server.AddMiddleware((req, res) =>
{
if (req.Headers["X-Key"] != "secret")
{
res.Write("Unauthorized", 401);
return false;
}
return true;
});Static File Hosting
Host an entire folder with one line:
server.AddStaticFiles("/web", "I:\\www", maxAge: 3600);Visit http://device-IP/web/index.html to see the webpage.
Response Extensions
| Method | Description |
|---|---|
res.Write(content, contentType) | Write response and close |
res.SendFile(filePath) | Send file (streaming) |
res.WriteChunk(content) | Chunked push (SSE/long connection) |
Request Extensions
| Method | Description |
|---|---|
req.GetToken() | Get Token from Authorization header |
req.ReadBodyAsString() | Read request body as string |
req.SaveFile(savePath) | Save uploaded file |
Consistent C# Development Experience
PicoServer on Windows/Linux/macOS:
server.AddRoute("/hello", async (req, res) => await res.WriteAsync("Hello"));PicoServer.Nano on ESP32/STM32:
server.AddRoute("/hello", (req, res) => res.Write("Hello"));Almost the same API, enabling consistent Web development experience across desktop, cloud, and embedded microcontrollers.
Notes
- Path Format: Use backslash
\in nanoFramework, e.g.,"I:\\www" - Static File Hosting: Files must be deployed to device (set build action to "Content"), middleware executes in order, recommended to add first
- Whitelist: Routes added to whitelist can skip authentication
- Long Connection: Must call
res.Close()afterWriteChunkpush completes
Resources
- NuGet:
PicoServer.Nanohttps://www.nuget.org/packages/PicoServer.Nano - Website: https://picoserver.cn
- nanoFramework Website: https://www.nanoframework.net
