Connect your service to an OCN Node
If you have followed the previous steps in this tutorial you should now have the following things ready for making your connection to the Open 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 (TOKEN_A in OCPI Terms)
Steps for making the connection to your OCN Node
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
1. Get the Public URL of your selected OCN Node
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 selected OCN Node by doing this:
ocn-registry get-node 0xEada1b2521115e07578DBD9595B52359E9900104
Where 0xEada1b2521115e07578DBD9595B52359E9900104
is the operator's keypair address.
The Public URL could look something like this: https://test-node.emobilify.com
Please visit the OCN Registry Repository on Bitbucket for further details about this step.
2. Get OCN Node versions and endpoints
We will first send a GET request to the OCN Node’s versions endpoint, using the TOKEN_A we received from the faucet. Note that curl requests can be imported into e.g. Postman or Insomnia if desired.
curl https://test-node.emobilify.com/ocpi/versions -H 'Authorization: Token {{TOKEN_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 https://test-node.emobilify.com/ocpi/2.2. Do the same for this endpoint:
curl https://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’s database. For now though, we just need one endpoint. Find the endpoint URL for the module identifier “credentials”. This will be the one we use to connect to the node:
3. Ensure OCN Node can access our versions and endpoints
During the credentials handshake, the OCN Node will attempt to request our own versions and endpoints, just as we did before in step 1. The OCN Node 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 another 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, Express and UUID):
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 PUBLIC_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 public IP we set.
4. Credentials handshake
Now we are ready to connect to the OCN Node. The credentials request is detailed below. Make sure to replace the variables TOKEN_A
, TOKEN_B
and PUBLIC_IP
, PARTY_ID
and COUNTRY_CODE
where described. 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
should point to your publicly accessible web service. Lastly, PARTY_ID
and COUNTRY_CODE
refer to the same OCPI credentials that you used when generating the registration token and entering details to the OCN Registry.
If all goes well, you should see a response with OCPI status code 1000 and the OCN Node’s 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 points and authorize RFID cards of any other OCPI party that is connected to the network.