Start Charging
Learn how to initiate a charging session on a connected chargestation
Prerequisites
- Have an API key and verified it is working for you. See API Key
- Created and connected your chargestation to eDRV. See Connect a Chargestation
- Get Connector and User Id. All charging sessions on eDRV run on a connector on behalf of a user. You will need these two in order to start charging session.
- Connector Id: You can get this by calling the
GET /chargestations
endpoint.- You can also view and copy the connector Id by hovering your mouse over the connector in the admin dashboard
- User Id: You can get this by calling the
GET /users
endpoint.- You can also view and copy the User Id by hovering your mouse over the user in the admin dashboard
- Connector Id: You can get this by calling the
Step 1: Start a Session
Start a new charging session by sending a POST /sessions
request
Creating a new session is equivalent to a Charging Start attempt
eDRV attempts a remote start on the specified connector on each new
POST /sessions
request.
The session is one of your core data assets. It contains all the instantaneous details about the charging status, calculated costs, energy metrics etc. You will be using sessions extensively, learn more about Sessions.
const request = require('request');
const options = {
method: 'POST',
url: 'https://api.edrv.io/v1.1/sessions',
headers: {
Accept: 'application/json',
'Content-Type': 'application/json',
Authorization: 'Bearer <API_KEY>'
},
body: {connector: '5fca57b3fbfcc320b3b03f23',
user: '5fca57b3fbfcc320b3b03f24'
},
json: true
};
request(options, function (error, response, body) {
if (error) throw new Error(error);
console.log(body);
/*Save session Id within your appication*/
const session_id = body.result._id;
});
A successful response from the API will create a new session with the status field as created
Under the hood
Successfully creating a new session kicks off a chain of events on eDRV:
- eDRV sends a RemoteStartTransaction OCPP request for the specified user and connector
- The chargestation will wait for the driver to plug in their cable at which time charging can start.
- If the driver has plugged in their connector, the chargestation will start a charging transaction.
- If the driver does not plug in their cable within
300 seconds
the session is timed out.
Step 1.1: Start a Session with Target
You can pre-configure a session for a specific cost, time, and/or energy target by including a target
in the POST /sessions
request. This will automatically stop the session when it crosses the defined target in terms of cost, time, and/or energy. See Charging with Session Targets for further details.
const request = require('request');
const options = {
method: 'POST',
url: 'https://api.edrv.io/v1.1/sessions',
headers: {
Accept: 'application/json',
'Content-Type': 'application/json',
Authorization: 'Bearer <API_KEY>'
},
body: {connector: '5fca57b3fbfcc320b3b03f23',
user: '5fca57b3fbfcc320b3b03f24',
"target": {
"cost": 12,
"time": 60
}
},
json: true
};
request(options, function (error, response, body) {
if (error) throw new Error(error);
console.log(body);
/*Save session Id within your appication*/
const session_id = body.result._id;
});
For the above session target, the system will stop the session when the time goes beyond 60 minutes or the cost goes beyond 12 in the specified currency.
Session Targets Accuracy
Please note that the chargestation will send the energy reports every 30 seconds to 1 minute. Because of that, the session may not stop at the exact target values but when it exceeds the target limit. Therefore, consider adding some padding to the values when setting targets for a session.
Step 2: Save the Session Id
You will need the session Id to:
- Stop a charging session in progress
- Track the status of the charging session
- Report instantaneous charging cost and energy metrics to the driver via your applications
- Send end of session alerts, receipts and invoices
Step 3: Confirm Charging has started via Webhooks
Energy flow in a session can take some to to start. E.g. because a driver needs to insert the charging cable and then charging can start.
Please monitor your application Webhook for the following event that confirms a charging session has stopped:
Webhook Event session.created
A confirmation from eDRV that this session was created and is awaiting a charging start event from the chargestation.
Webhook Event session.cancelled
Chargestation did not confirm the start of a charging session within the allotted time window of 300s.
Webhook Event session.started
A confirmation directly from the chargestation that this session has successfully started.
Please see List Of Webhook Events for a full list of session webhooks.
Please do not poll the sessions endpoint for a change of status
This is an inefficient use of server resources on both sides. Please use Webhooks instead.
Updated 8 months ago
Time to learn how to stop this session and report instantaneous metrics to your drivers