Date: Thu, 28 Mar 2024 11:23:07 +0000 (UTC) Message-ID: <2103209432.23.1711624987707@9521b5b37733> Subject: Exported From Confluence MIME-Version: 1.0 Content-Type: multipart/related; boundary="----=_Part_22_1084122875.1711624987706" ------=_Part_22_1084122875.1711624987706 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Content-Location: file:///C:/exported.html
If you have followed the previous steps in this tutorial you sho= uld now have the following things ready for making your connection to the O= pen Charging Network:
a backend service that has an OCN-ready API
an OCN Identity
the OCN Identity of your selected OCN Node and a registration token (TOK= EN_A in OCPI Terms)
Get the Public URL of your selected OCN Node
Get OCN Node versions and endpoints
Ensure OCN Node can access our versions and endpoints
Credentials handshake
If you are using the Command Line Interface provided in the OCN Registry= Repository on Bitbucket you can simply check the Public URL of your select= ed OCN Node by doing this:
ocn-reg= istry get-node 0xEada1b2521115e07578DBD9595B52359E9900104
Where 0xEada1b2521115e07578DBD9595B52359E9900104
=
is the operator's keypair address.
The Public URL could look something like this: https://test-node.e=
mobilify.com
Please visit the OCN Registry Repository on = Bitbucket for further details about this step.
We will first send a GET request to the OCN Node=E2=80=99s versions endp= oint, using the TOKEN_A we received from the faucet. Note that curl request= s can be imported into e.g. Postman or Insomnia if desired.
curl ht= tps://test-node.emobilify.com/ocpi/versions -H 'Authorization: Token {{TOKE= N_A}}'
You should see a JSON response with OCPI status code 1000. The response = data will tell you that version 2.2 can be found at http= s://test-node.emobilify.com/ocpi/2.2. Do the same for this endpoint:
curl ht= tps://test-node.emobilify.com/ocpi/2.2 -H 'Authorization: Token {{TOKEN_A}}= '
You should see a long list of OCPI version 2.2 endpoints implemented by = the OCN Node. You will want to save these endpoints for future reference in= your application=E2=80=99s database. For now though, we just need one endp= oint. Find the endpoint URL for the module identifier =E2=80=9Ccredentials= =E2=80=9D. This will be the one we use to connect to the node:
{ "identifier": "credentials", "role": "SENDER", "url": "https://test-node.emobilify.com/ocpi/2.2/credentials" }
During the credentials handshake, the OCN Node will attempt to request o= ur own versions and endpoints, just as we did before in step 1. The OCN Nod= e needs to know where to contact us in case there is a message from another= party that needs to be routed to us. It can also help to filter requests, = in the case that we have not implemented a specific OCPI module that anothe= r party is requesting from us.
If you have not already done so, we can spin up a quick server that will= display our versions and endpoints as follows (note: requires NodeJS, Expr= ess and UUID):
const e= xpress =3D require("express") const uuid =3D require("uuid") const app =3D express() const PUBLIC_URL =3D "https://service.msp.com" const TOKEN_B =3D uuid.v4() console.log("Auth TOKEN_B =3D " + TOKEN_B) const authorize =3D (req, res, next) =3D> { =09if (req.headers.authorization !=3D=3D `Token ${TOKEN_B}`) { =09=09return res.status(401).send({ =09=09=09status_code: 2001, =09=09=09status_message: "Unauthorized", =09=09=09timestamp: new Date() =09=09}) =09} =09next() }=20 app.get("/ocpi/versions", authorize, async (_, res) =3D> { =09res.send({ =09=09status_code: 1000, =09=09data: { =09=09=09versions: [{ =09=09=09=09version: "2.2", =09=09=09=09url: `${PUBLIC_URL}/ocpi/2.2` =09=09=09}] =09=09}, =09=09timestamp: new Date() =09}) }) app.get("/ocpi/2.2", authorize, async (_, res) =3D> { =09res.send({ =09=09status_code: 1000, =09=09data: { =09=09=09version: "2.2", =09=09=09endpoints: [ =09=09=09=09/* { =09=09=09=09=09identifier: "locations", =09=09=09=09=09role: "RECEIVER", =09=09=09=09=09url: `${PUBLIC_URL}/ocpi/2.2/receiver/locations` =09=09=09=09} */ =09=09=09] =09=09}, =09=09timestamp: new Date() =09}) }) app.listen(3000, () =3D> { console.log("Started on port 3000") })
This will create an authorization token that the OCN Node should use to =
access our own endpoints. It is logged on start. Be sure to make a note of =
the authorization token as we will need it later. Note also the PUBLI=
C_IP
. We want the OCN Node to be able to access these endpoints from=
the outside, so we should make sure that the server is reachable via the p=
ublic IP we set.
Now we are ready to connect to the OCN Node. The credentials request is =
detailed below. Make sure to replace the variables TOKEN_A
, PUBLIC_IP
, PARTY_ID
and TOKEN_A
should match =
the one generated for you by the faucet. TOKEN_B
should match =
the authorization token that you have created. Meanwhile, PUBLIC_IP=
code> should point to your publicly accessible web service. Lastly,
P=
ARTY_ID
and COUNTRY_CODE
refer to the same OCPI credent=
ials that you used when generating the registration token and entering deta=
ils to the OCN Registry.
curl ht= tps://test-node.emobilify.com/ocpi/2.2/credentials \ -H 'Authorization: Token {{TOKEN_A}}' \ -H 'Content-Type: application/json' \ -d '{ "token": "{{TOKEN_B}}", "url": "{{PUBLIC_IP}}/ocpi/versions", "roles": [{ "party_id": "{{PARTY_ID}", "country_code": "{{COUNTRY_CODE}}", "role": "EMSP", "business_details": { "name": "Tutorial MSP" } }] }'
If all goes well, you should see a response with OCPI status code 1000 a= nd the OCN Node=E2=80=99s credentials returned in the body.
Now that we have connected to the Open Charging Network we can make use = of OCPI to find point of interest data, issue remote commands at charge poi= nts and authorize RFID cards of any other OCPI party that is connected to t= he network.