Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extensions/plugins #82

Open
andreasringdal opened this issue Oct 30, 2024 · 5 comments
Open

Extensions/plugins #82

andreasringdal opened this issue Oct 30, 2024 · 5 comments

Comments

@andreasringdal
Copy link
Contributor

@dallmann-consulting  Issue added to discuss commit 61511ff and further development of extensions/plugins

Extension framework is a great way of customizing OCPP.Core.

There is one more hook that we will need to add for our use. Authorize based on tagId and chargerId

Current the method will be something in the line of

/// <summary>
/// Authorize OCPP request in external system
/// </summary>
/// <param name="tagID">Charging token tagId</param>
/// <param name="chargerId">Identifier of charger</param>
/// <param name="tagID">Transaction ID. Used to check if tagId has access to stop the current transaction</param>
bool Authorize(string tagId, string chargerId, int? transactionId = null)

Background

On  the system we are forwarding OCPP messages to we have assigned charging token to users and chargers to rooms/areas in the system. 

We authorize users based on their current access to the room.

My current hack in Ocpp.server is to call a stored procedure with a custom connection string.

Planned Autorize  Extension takes tagId  + chargepointid as input and checks if the combination is allowed to use this charger at the current time.

The same procedure is run at starttransaction and stoptransaction.

We will develop our authorize extension custom for our system, but the hooks will be general for reuse.

We have current transaction data stored in our system and does not require information regarding transactionid and startTag but this information might be of use for Authorize adons for others

@dallmann-consulting
Copy link
Owner

Hi Andreas,

the current "raw" hook was only the first step. As you suggested an authentication hook and also a status hook (free/connected and current meter values) will be usefull.

With your suggested method signature:
The transaction id is not possible I think (at least with OCPP 1.6). At first the charger sends the Authorize request - kind of a pre charging request. If that is successfull the charger sends the StartTransaction request with the same token. The server needs to authorize this again. Afterwards the transaction data is written to the database and the id gets created. And the final step is to send the "OK" together with the id to the charger. So the transaction id only gets created after all authorizations.
With OCPP 2.x the transaction id becomes a uid which is created and send by the charger. OCPP.Core.Server stores this in the transaction (db) but uses internally the database id for reference.
With OCPP1.6 the backend (OCPP.Core.Server) could create a uid and pass that in the authorization hook and store it in the database. This way you have a reference of the transaction.

@andreasringdal
Copy link
Contributor Author

andreasringdal commented Nov 29, 2024

@dallmann-consulting 

Have you started looking into how to call extension methods from within ControllerOCPP*.cs

Moving _rawMessageSings along with a new _authorizeSinks into  a common extensionMethods object that is supplied to ControllerOCPPXX constructor is one option

I added initial work on this to this commit andreasringdal@19b32bd

andreasringdal added a commit to andreasringdal/OCPP.Core that referenced this issue Nov 29, 2024
andreasringdal added a commit to andreasringdal/OCPP.Core that referenced this issue Dec 4, 2024
Extensions for SQL authorize and Transaction handling.
Bugfix: Nullcheck on Charging tag to avoid exceptions when tag is not found
@andreasringdal
Copy link
Contributor Author

Ended up moving extension handling into separate class

@dallmann-consulting
Copy link
Owner

Sorry for the late response. I'm pretty busy at the moment.

I am on the same path. The integration for external authentications is more complex than forwarding messages. I will move it into a seperate class.

@andreasringdal
Copy link
Contributor Author

I have implemented a "SQLAuthentication" extension that calls a stored procedure for authenticating.
Checks if the chargeTag has access to a specific charger. Currently running in our test environment

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants