Skip to content

LarsWesselius/OCPPSharp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

OCPPSharp

Super simple OCPP 2.0(.1) server for use in a web app.

Source is not super nice, complete or anything of the sort, just needed to get something working and thought I'd share it on here.

using OCPPSharp;
using OCPPSharp.Broker;
using OCPPSharp.Messages;

var builder = WebApplication.CreateBuilder(args);

builder.Services.AddOCPPServer(x => x
    .WithPath("ocpp")
    .DetectMessageHandlersInAssembly(typeof(Program).Assembly));
var app = builder.Build();

app.UseWebSockets();
app.UseOCPPServer();
app.Run();

public class BootNotificationMessageHandler : MessageHandler<BootNotificationRequest>
{
    private readonly ILogger<BootNotificationMessageHandler> _logger;

    public BootNotificationMessageHandler(ILogger<BootNotificationMessageHandler> logger)
    {
        _logger = logger;
    }

    public override async Task<object?> HandleMessageAsync(BootNotificationRequest message, CancellationToken cancellationToken)
    {
        _logger.LogInformation($"Boot notification received! {message.ChargingStation.VendorName} {message.ChargingStation.Model} came knocking!");
        return new BootNotificationResponse()
        {
            Status = RegistrationStatusEnumType.Accepted,
            Interval = 60 * 1000
        };
    }
}

About

Simple OCPP 2.0.1 server

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages