An implementation of the Open Charge Point Protocol (OCPP
) in C#.
Currently supported versions:
- Ocpp 1.6
- Ocpp 2.0.1
- Newtonsoft.Json
- .NET 8
- C# classes for all messages of the OCPP-Protocol.
- Easy to set up server and event system for processing messages.
It's not a ready-to-go backend server. You still have to implement what happens once an OCPP-Message has been received and how respond accordingly.
- Automating certain ocpp-communication
- Emulating a charge point
- Implementation of a basic backend server for charge points
A minimalistic client and server example can be found under /ocpp-sharp.examples
Start the server:
cd ./ocpp-sharp.examples/server
dotnet run
And then a client:
cd ./ocpp-sharp.examples/client
dotnet run
The examples are preconfigured to connect to each other on localhost:8000
and exchange some example messages.
using OcppSharp.Server;
using OcppSharp.Protocol.Version16.RequestPayloads;
using OcppSharp.Protocol.Version16.ResponsePayloads;
using OcppSharp.Protocol;
namespace OcppApp;
public class Program
{
public static void Main(string[] args)
{
// Set up a server to listen on port 80
// Stations will be connecting to ws://<Hostname>/ocpp16/<Station ID>
OcppSharpServer server = new("/ocpp16", ProtocolVersion.OCPP16, 80);
server.RegisterHandler<BootNotificationRequest>((server, sender, request) =>
{
Console.WriteLine($"Received BootNotification! (Message ID = {request.FullRequest!.MessageId})");
Console.WriteLine($"Vendor: {request.ChargePointVendor}");
Console.WriteLine($"Serial Number: {request.ChargePointSerialNumber}");
// ...
// Always need to send a response
return new BootNotificationResponse()
{
CurrentTime = DateTime.Now,
Interval = 90 // Heartbeat Interval
};
});
server.Start();
Console.WriteLine("Server started!");
Console.ReadLine();
server.Stop();
}
}
This project was part of a private OCPP-Backend project. It was then split up into its own project here.