Energy Web Documentation
  • Energy Web Ecosystem
  • Launchpad by Energy Web
  • EWC Validator Documentation
  • Community Ressources
  • Legacy documentation
  • Welcome to Energy Web
  • Glossary
  • Solutions 2023
    • ↔️Data Exchange
      • Data Exchange Overview
      • Data Exchange Architecture
      • Use Cases and Refrence Implementations
        • Digital Spine for Electricity Markets
          • Digital Spine Integration Client Deployment Guide - from Azure marketplace
        • E-Mobility Management
    • 🔌Open Charging Network
      • Create and Manage an OCN Identity
      • Connect an OCPI/OCN Party to a Node
        • 1. Make your backend service OCN-ready
        • 2. Select an OCN Node and register in OCN Registry
        • 3. Manage your Whitelist and Blacklist
        • 4. Connect your service to an OCN Node
      • Run an OCN Node
      • Use the OCN Service Interface
        • Offer an OCN Service
        • Sign up for an OCN Service
      • Develop on the Test Network
      • Develop on the Production Network
      • Open Source Development
        • Maturity Model, Feature Roadmap and Releases
        • Developer Community Calls
      • E-Mobility Dashboard v0.1
  • EW-DOS Technology Components 2023
    • EW-DOS Overview
    • Worker Nodes
      • Worker Node Process Diagrams
      • Worker Node Architecture
      • Worker Node Guides
        • Deploy Worker Nodes
        • Customize Worker Logic
    • Identity and Access Management (IAM)
      • IAM Guides
        • Implement an SSI Hub instance
        • Verifiable Credential API
        • Sign-In with Ethereum
        • Using Switchboard
          • Switchboard Transaction Cost Estimates
      • IAM Patterns
        • Assets as Ownable Smart Contracts
        • Credential Lifecycle
        • Credential Metadata
        • SSI Credential Governance using ENS Domains
      • IAM Libraries
      • SSI Hub
      • Switchboard Application
    • Decentralized Data Hub (DDHub)
      • DDHub Message Broker
      • DDHub Client Gateway
      • DDHub Patterns
        • Channels and Topics
      • DDHub Guides
    • Green Proofs Contracts
    • Energy Web X
    • The Energy Web Chain
      • EWC Overview
      • System Architecture
        • Proof-of-Authority Consensus Mechanism
        • System Contracts
          • Name Registry
          • Holding Contract
          • Block Reward Contract
          • Validator-Set Contracts
        • Validator Node Architecture
      • Energy Web Block Explorer
      • Validator Node Installation Specifications
        • Volta Test Network: Validator Node Installation
      • Energy Web Chain Governance
      • EWC Guides and Tutorials
        • Getting started with Energy Web Chain
        • Developing on the Volta Test Network and Main Network (Energy Web Chain)
        • Run a Local RPC Node
          • Run RPC Node using Nethermind client
        • Deploy a Smart Contract on Volta with Remix
        • Interacting with Smart Contracts in EW-DOS
        • Set up MetaMask to interact with Energy Web Chain
        • Using the Ethereum Name Service
        • Using Oracles
      • Energy Web Token (EWT)
  • 🧠Foundational Concepts
    • Open-Source Software
    • Scaling Access to Grid Flexibility
    • Facilitating Clean Energy Purchases
    • Ethereum
      • Transactions and Transaction Costs
    • Self-Sovereign-Identity
      • Self-Sovereign Use Case Interaction
    • Cryptocurrency Wallets
      • Software cryptocurrency wallets
        • Metamask
        • Mycrypto wallet
      • Hardware cryptocurrency wallets
      • Hierarchical Deterministic (HD) Wallets
Powered by GitBook
On this page
  • 1. Get the Public URL of your selected OCN node from the OCN Registry
  • Using the CLI
  • Using the Typescript Library
  • Using the Java Library
  • 2. Get OCN Node versions and endpoints
  • 3. Ensure OCN Node can access our versions and endpoints
  • 4. Credentials handshake
Export as PDF
  1. Solutions 2023
  2. Open Charging Network
  3. Connect an OCPI/OCN Party to a Node

4. Connect your service to an OCN Node

Previous3. Manage your Whitelist and BlacklistNextRun an OCN Node

Last updated 2 years ago

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:

  • (TOKEN_A in OCPI Terms)

Follow the steps listed below to connect to your OCN Node

Access the full OCN technical documentation .

1. Get the Public URL of your selected OCN node from the OCN Registry

There are three methods of interacting with the OCN Registry:

Using the CLI

ocn-registry get-node 0xEada1b2521115e07578DBD9595B52359E9900104

Where 0xEada1b2521115e07578DBD9595B52359E9900104 is the operator's public address.

Using the Typescript Library

The Public URL could look something like this: https://test-node.emobilify.com

Once connected to the registry, you can use the getNode method to return the operator's public URL:

     /**
     * Get a registry node listing for a given operator.
     * @param operator Ethereum address of the operator.
     * @returns the domain name/url if listing exists.
     */
    public async getNode(operator: string): Promise<string | undefined> {
        this.verifyAddress(operator)
        const node = await this.registry.getNode(operator)
        return node || undefined
    }

Using the Java Library

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}}'

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:

{
  "identifier": "credentials",
  "role": "SENDER",
  "url": "https://test-node.emobilify.com/ocpi/2.2/credentials"
}

3. Ensure OCN Node can access our versions and endpoints

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.

const express = require("express")
const uuid = require("uuid")

const app = express()

const PUBLIC_URL = "https://service.msp.com"
const TOKEN_B = uuid.v4()
console.log("Auth TOKEN_B = " + TOKEN_B)


const authorize = (req, res, next) => {
	if (req.headers.authorization !== `Token ${TOKEN_B}`) {
		return res.status(401).send({
			status_code: 2001,
			status_message: "Unauthorized",
			timestamp: new Date()
		})
	}
	next()
} 


app.get("/ocpi/versions", authorize, async (_, res) => {
	res.send({
		status_code: 1000,
		data: {
			versions: [{
				version: "2.2",
				url: `${PUBLIC_URL}/ocpi/2.2`
			}]
		},
		timestamp: new Date()
	})
})


app.get("/ocpi/2.2", authorize, async (_, res) => {
	res.send({
		status_code: 1000,
		data: {
			version: "2.2",
			endpoints: [
				/* {
					identifier: "locations",
					role: "RECEIVER",
					url: `${PUBLIC_URL}/ocpi/2.2/receiver/locations`
				} */
			]
		},
		timestamp: new Date()
	})
})


app.listen(3000, () => { 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 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

  • PUBLIC_IP should point to your publicly accessible web service

curl https://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 the request is successful, 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.

If you are using the on GitHub, you can check the Public URL of your selected OCN Node by doing this:

You can find documentation on how to install and use the library .

Please visit the for further details about this step.

Use the documentation provided to connect to the OCN Registry using the Java library.

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 .

During the credentials handshake, the OCN Node will attempt to request our own versions and endpoints, just as we did before in

If you have not already done so, we can spin up a quick server and execite a node script that will display our versions and endpoints as follows (note: requires , and ):

PARTY_ID and COUNTRY_CODE refer to the same OCPI credentials that you used

🔌
Command Line Interface provided in the OCN Registry Repository
here
OCN Registry Repository
source
here
https://test-node.emobilify.com/ocpi/2.2
NodeJS
Express
UUID
when generating the registration token and entering details to the OCN Registry
A backend service that has an OCN-ready API and Signing service
An OCN Identity
The OCN Identity of your selected OCN Node, and a registration token
here
CLI
Typescript Library
Java Library
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
Step 2.