Monday, October 16, 2023
HomeIoTConstructing an OCPP-compliant electrical car cost level operator resolution utilizing AWS IoT...

Constructing an OCPP-compliant electrical car cost level operator resolution utilizing AWS IoT Core


The shift from fossil fuels to electrical powered autos is a key part of presidency and industrial commitments to realize net-zero emissions by 2050. It’s projected that the USA alone would require a nationwide community of a minimum of 500,000 electrical car (EV) chargers by 2030 to help the projected variety of EVs on the street [1][2]. Globally, governments and industries are partnering to construct thousands and thousands of public charging and personal fleet charging networks [3].

Putting in and powering the bodily charging infrastructure is simply step one — chargers (Cost Factors or “CP”) have to be constantly monitored and managed by their operators (Cost Level Operators or “CPO”). CPOs are answerable for common distant and on-site upkeep, accumulating well being metrics, and managing operational configurations. CPOs are additionally answerable for guaranteeing that the CPs are appropriate with the most recent business requirements and protocols, like Open Cost Level Protocol (OCPP) and ISO 15118. And all this should be applied with safety measures that may help CPs at scale.

This submit demonstrates how AWS providers like AWS IoT Core, Amazon Elastic Container Service (Amazon ECS), and AWS Lambda can be utilized to construct a highly-scalable, low-latency electrical car cost level operator system primarily based on the EV business normal, OCPP.

About AWS IoT Core

AWS IoT Core allows you to join billions of gadgets and route trillions of messages to and from AWS providers with out managing infrastructure. AWS IoT Core handles the heavy-lifting of scaling and message routing—making it simpler for patrons needing to help giant fleets of distant gadgets, like CPs, speaking via publish-and-subscribe patterns. AWS IoT Core natively implements MQTT, HTTPS, and MQTT over WebSockets, and will be tailored to help different protocols, like OCPP.

Overview

Most commercially accessible CPs implement OCPP as a method of bi-directional publish-and-subscribe communication with a CPO. Working a CPO on AWS requires the introduction of an OCPP WebSocket endpoint, with which CPs talk. That endpoint, described right here because the OCPP Gateway, acts as a proxy between OCPP and MQTT, enabling integration with AWS IoT Core and downstream CPO providers constructed on AWS.

The next structure diagram illustrates the high-level end-to-end resolution you’ll construct on this weblog submit.

Figure 1: Charge Point OCPP message proxied to CPO Service via one-to-one relationship between WebSocket connection and MQTT topic
Determine 1: Cost Level OCPP message proxied to CPO Service through one-to-one relationship between WebSocket connection and MQTT subject

Structure

The structure diagram beneath depicts the assets that this resolution will deploy into your account.

Figure 2: OCPP Gateway solution stack architecture
Determine 2: OCPP Gateway resolution stack structure

The OCPP Gateway is deployed as an Amazon ECS software which might run on both AWS Fargate or Amazon Elastic Compute Cloud (EC2). AWS Fargate eliminates the necessity for infrastructure administration and is the popular choice for this resolution. Containerized purposes will be scaled horizontally, permitting the OCPP Gateway to routinely scale up or down because the variety of related CPs adjustments. The lengthy operating nature of ECS duties permits for WebSockets connections to be maintained for prolonged intervals, lowering community site visitors and connection overheads.

A Community Load Balancer (NLB) fronts a number of OCPP Gateway containers. The NLB offers a single, absolutely certified area identify (FQDN) that serves because the OCPP endpoint to which CPs provoke connection. Upon connection initiation, the NLB will route the cost level connection to one of many OCPP Gateway cases, which can set up the WebSocket connection between itself and the CP.

When a CP establishes a socket reference to an occasion of the OCPP Gateway, that Handler units up an MQTT connection to AWS IoT Core utilizing the CP’s distinctive identifier because the Factor ID. That shopper subscribes to MQTT message matters related to that CP.

The MQTT shopper applied by the OCPP Gateway is socket conscious, thereby offering a one-to-one affiliation between the MQTT subscription and the CP. Any messages initiated by the CPO will likely be delivered to the MQTT shopper related to the vacation spot CP and forwarded over the socket to that CP. AWS IoT Core is very elastic and can readily scale as extra CPs are on-boarded.

Answer walk-through

This resolution demonstrates how you should utilize AWS to construct a scalable CPO by deploying the OCPP Gateway to combine with AWS IoT Core. The steps beneath will stroll you thru the deployment of an OCPP Gateway into your AWS account, will reveal how one can simulate CP message, and can present examples of you ways can act on these message utilizing AWS assets.

Stipulations

Confirm that your surroundings satisfies the next conditions:

You’ve gotten:

  1. An AWS account
  2. AdministratorAccess coverage granted to your AWS account (for manufacturing, we suggest limiting entry as wanted)
  3. Each console and programmatic entry
  4. AWS CLI put in and configured to make use of along with your AWS account
  5. NodeJS 12+ put in
  6. Typescript 3.8+ put in
  7. AWS CDK CLI put in
  8. Docker put in
  9. Python 3+ put in

Put together the CDK

The answer will likely be deployed into your AWS account utilizing infrastructure-as-code wih the AWS Cloud Growth Equipment (CDK).

  1. Clone the repository:
git clone https://github.com/aws-samples/aws-ocpp-gateway.git
  1. Navigate to this mission in your laptop utilizing your terminal:
cd aws-ocpp-gateway
  1. Set up the mission dependencies by operating this command:
npm set up
  1. Set surroundings variables for CDK to the goal AWS account ID and area the place you want to deploy this stack

Notice: AWS IoT Core is obtainable in these AWS areas.

export CDK_DEPLOY_ACCOUNT=targetAccountId (e.g. 12345678910)
export CDK_DEPLOY_REGION=targetRegion (e.g. eu-west-1)
  1. (Non-obligatory) Bootstrap AWS CDK on the goal account and regioon

Notice: That is required when you’ve got by no means used AWS CDK earlier than on this account and area mixture. (Extra data on CDK bootstrapping).

npx cdk bootstrap aws://{targetAccountId}/{targetRegion}

(Non-obligatory) Allow WebSockets utilizing TLS with your individual area identify

If in case you have an Amazon Route 53 hosted zone in your account, this resolution can routinely:

  • Create subdomain (A Report) gateway.yourdomain.com
  • Create an AWS Certificates Supervisor (ACM) SSL certificates for it
  • Allow TLS in your gateway wss://gateway.yourdomain.com
  • Uncomment this line in /bin/aws-ocpp-gateway.ts and change yourdomain.com with your individual area identify (i.e. instance.com)
  // domainName: 'yourdomain.com',

Deploy the answer to your AWS Account

  1. Confirm that Docker is operating with the next command:
docker model

Notice: In the event you get an error just like the one beneath, then Docker is just not operating and have to be restarted:

Can not hook up with the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon operating?
  1. Deploy the OCPP Gateway utilizing the next CDK command:
npx cdk deploy

Notice: This step can take about 10 minutes, relying in your laptop and community velocity.

  1. You possibly can view the progress of your CDK deployment within the CloudFormation console within the chosen area.
Screenshot: CloudFormation stack resources
Screenshot: AWS CloudFormation stack assets
  1. As soon as deployed, pay attention to the AwsOcppGatewayStack.websocketURL worth

Notice: This WebSocket URL is the entry level that will likely be set in your CP configurations or within the
EV Cost Level simulator described beneath.

In the event you used your individual area, your output will seem like:

..
Outputs:
AwsOcppGatewayStack.loadBalancerDnsName = gateway.instance.com
👉 AwsOcppGatewayStack.websocketURL = wss://gateway.instance.com
...

In any other case, like this:

...
Outputs:
AwsOcppGatewayStack.loadBalancerDnsName = ocpp-gateway-xxxxxxx.elb.xx-xxxx-x.amazonaws.com
👉 AwsOcppGatewayStack.websocketURL = ws://ocpp-gateway-xxxxxxx.elb.xx-xxxx-x.amazonaws.com
...

Simulating CP connectivity

We’ve supplied the simulate.py Python script that will help you check and discover the potential of the OCPP Gateway and AWS IoT Core with out the necessity for a bodily CP. Different OCPP simulators, like OCPP-2.0-CP-Simulator, will also be used.

Simulation setup

  1. In AWS Explorer, choose your area and open AWS IoT Core, All gadgets, Issues. On the Issues tab select Create a issues.
  2. Choose Create single factor and select Subsequent
  3. Enter a Factor identify

Notice: Every EV Cost Level should map to a single IoT Factor. For our check, we’ll set the Factor identify as CP1

Screenshot: Creating an IoT Thing
Screenshot: Creating an IoT Factor
  1. Select Subsequent
  2. For Gadget certificates, choose Skip making a certificates right now, and select Create factor
Screenshot: Skip the certification creation
Screenshot: Skip the certification creation
  1. Navigate to this folder along with your terminal:
cd ev-charge-point-simulator
  1. Create a Python digital surroundings and activate it by operating this command:
python3 -m venv venv && supply venv/bin/activate
  1. Set up the Python dependencies by operating:
pip3 set up -r necessities.txt

Simulate an EV cost level boot and heartbeat notification

The Python script simulates some fundamental performance of an EV cost level:

  • Sending a BootNotification, together with attributes concerning the CP {hardware}
  • Sending Heartbeat messages primarily based on a frequency instructed by the CPO (that is outlined by the interval parameter returned within the response to the BootNotification)
  1. Run the Python script utilizing the next command, ensuring to exchange the --url worth with the AwsOcppGatewayStack.websocketURL returned from the cdk deployment:
python3 simulate.py --url {websocket URL generated from the AWS OCPP Stack} --cp-id CP1 

Notice: we’re utilizing --cp-id CP1 which should match the worth of the IoT Factor created above. If the --cp-id doesn’t match the IoT Factor identify, the connection will likely be rejected by the OCPP Gateway.

A profitable output ought to seem like this:

(venv) ev-charge-point-simulator % python3 simulate.py --url {websocket URL generated from the AWS OCPP Stack} --cp-id CP1 
INFO:ocpp:CP1: ship [2,"0678cb2a-a7a2-42bc-8037-d01164e77ac6","BootNotification",{"chargingStation":{"model":"ABC 123 XYZ","vendorName":"Acme Electrical Systems","firmwareVersion":"10.9.8.ABC","serialNumber":"CP1234567890A01","modem":{"iccid":"891004234814455936F","imsi":"310410123456789"}},"reason":"PowerUp"}]
INFO:ocpp:CP1: obtain message [3,"0678cb2a-a7a2-42bc-8037-d01164e77ac6",{"currentTime":"2023-02-16T19:00:18.630818","interval":10,"status":"Accepted"}]
INFO:root:CP1: related to central system
INFO:root:CP1: heartbeat interval set to 10
INFO:ocpp:CP1: ship [2,"9b7933a7-5216-496d-9bb0-dae45014bb98","Heartbeat",{}]
INFO:ocpp:CP1: obtain message [3,"9b7933a7-5216-496d-9bb0-dae45014bb98",{"currentTime":"2023-02-16T19:00:19.073675"}]

This change represents a profitable simulation of a CP, first sending a BootNotification, adopted by subsequent Heartbeat on the specified interval. The output consists of each the simulated OCPP message despatched from the CP to AWS IoT (prefixed ship) and the response obtained from AWS (prefixed obtained message).

  1. To simulate with a unique CP, set a unique worth for the --cp-id argument.

Notice: if the --cp-id worth doesn’t have a correspondent IoT Factor the OCPP Gateway will reject the connection. Right here is an unsuccessful instance passing --cp-id CP2, which is not registered as a Factor in IoT:

(venv) ev-charge-point-simulator % python3 simulate.py --url {websocket URL generated from the AWS OCPP Stack} --cp-id CP2 
INFO:ocpp:CP2: ship [2,"32dc5b6e-77b0-4105-b217-28e20b579ecc","BootNotification",{"chargingStation":{"model":"ABC 123 XYZ","vendorName":"Acme Electrical Systems","firmwareVersion":"10.9.8.ABC","serialNumber":"CP1234567890A01","modem":{"iccid":"891004234814455936F","imsi":"310410123456789"}},"reason":"PowerUp"}]
ERROR:root:CP2: obtained 1008 (coverage violation) Cost Level CP2 not registered as an IoT Factor; then despatched 1008 (coverage violation) Cost Level CP2 not registered as an IoT Factor

Monitor OCPP exercise within the AWS Console

Messages from and to the CP are brokered via AWS IoT Core. These messages make the most of the MQTT publish-and-subscribe protocol. You possibly can see these messages within the console.

    1. In AWS Explorer, choose your area and open AWS IoT Core, MQTT check shopper
    2. Within the check shopper, choose the Subscribe to a subject tab, and subscribe to those two matters by coming into these values within the Subject filter:

a. To view all messages from CP to AWS

+/in

b. To view all messages from AWS to CP

+/out
Screenshot: Subscribe to Topics
Screenshot: Subscribe to Subjects
  1. Run the Python script to simulate a CP and watch the messages within the MQTT check shopper

Observe EV Cost Level {hardware} attributes in system shadows

When a CP sends a BootNotification, its {hardware} attributes are saved in a Gadget Shadow related to the IoT Factor. You possibly can see these attributes within the console.

  1. In AWS Explorer, choose your area and open AWS IoT Core, All gadgets, Issues
  2. Toggle the verify field towards the Factor created beforehand
  3. Choose the Gadget Shadows tab.
  4. Choose the Traditional Shadow system shadow identify hyperlink to see the Gadget Shadow doc and the {hardware} attributes reported by the EV Cost Level:
{
  "state": {
    "reported": {
      "chargingStation": {
        "mannequin": "ABC 123 XYZ",
        "vendorName": "Acme Electrical Programs",
        "firmwareVersion": "10.9.8.ABC",
        "serialNumber": "CP1234567890A01",
        "modem": {
          "iccid": "891004234814455936F",
          "imsi": "310410123456789"
        }
      },
      "purpose": "PowerUp"
    }
  }
}
Screenshot: IoT Thing shadow document
Screenshot: IoT Factor shadow doc
  1. Simulate completely different CP {hardware} attributes by passing these arguments into the simulate.py script and confirm their have an effect on on the Gadget Shadow:
  • --cp-serial – to set the serial quantity
  • --cp-model – to set the mannequin identification
  • --cp-version – to set the firmware model
  • --cp-vendor – to set the seller identify

Conclusion

On this submit, you discovered how AWS Companies can be utilized to construct a highly-scalable, low-latency CPO. Utilizing AWS Fargate, you deployed the OCPP Gateway, an OCPP-to-MQTT proxy, which allowed you to make the most of AWS IoT Core’s managed routing and scaling performance to deploy and function your Cost Level Operator resolution on AWS. You discovered how Guidelines for AWS IoT can be utilized to filter and route messages from the EV cost level to downstream AWS providers like Amazon DynamoDB and AWS Lambda to create customized reporting and automatic workflows.

The answer and the pattern code have been made accessible as open-source and will be readily tailored to your particular enterprise wants.

We hope you discovered this submit informative and the walk-through useful. As at all times, AWS welcomes suggestions. Please be at liberty to attach/message the authors via their LinkedIn profiles embrace beneath.

(Non-obligatory) Extra issues to attempt your self

This part offers some instructed simulations and exams you’ll be able to attempt your self to higher admire the artwork of the doable because it pertains to constructing an OCPP-compliant CPO on AWS.

Load testing

AWS IoT Core is a completely managed, extremely elastic service that scales to help thousands and thousands of Issues. The OCPP Gateway makes use of auto-scaling to routinely scale-up as your fleet of CPs grows.

  1. Utilizing a load testing device or the included Apache JMeter configuration, simulate a load of 1000’s of CPs
  2. In AWS Explorer, choose your area and open Elastic Container Service
  3. Below Clusters open the hyperlink of the cluster created by the OCPP Gateway stack (will likely be prefixed AwsOcppGatewayStack)
  4. Choose the Metrics tab
  5. Watch how the variety of duties will increase from one to 2, and so forth. as your load will increase.

Auto-scaling is configured to set off when the common CPU utilization exceeds 60% — you’ll be able to drive extra load or lower this threshold to check the have an effect on.

If you’re utilizing JMeter or comparable load tester be cautious of the variety of threads (Issues) you create and period you run your check for. The answer will readily scale to many 1000’s of Issues and can run for indefinite intervals of time, which can lead to surprising expenses in your AWS account. We advise utilizing the load check to check scalability, however to halt the check shortly to cut back prices.

Guidelines for AWS IoT

Guidelines for AWS IoT can be utilized to filter MQTT messages and route them to different providers in AWS. Create a brand new rule to seize Heartbeat messages and report them in a DynamoDB desk for a final identified occasion.

  1. In AWS Explorer, choose your area and open DynamoDB
  2. Choose Create desk
  3. Present the Desk identify chargePointHeartbeat and set the Partition key to chargePointId
  4. Select Create desk
  5. In AWS Explorer, choose your area and open AWS IoT Core, Message routing, Guidelines
  6. Choose Create Rule
  7. Present the Rule identify chargePointHeartbeat and select Subsequent
  8. Enter the next into the SQL assertion and select Subsequent
SELECT 
  subject(1) AS chargePointId,
  timestamp() AS lastTimestamp
FROM '+/in'
WHERE get(*, 2) = 'Heartbeat'
  1. For Motion 1, select DynamoDBv2
Screenshot: IoT Rule SQL statement
Screenshot: IoT Rule SQL assertion
  1. Choose the Amazon DynamoDB desk created above for Desk identify
Screenshot: IoT Rule action
Screenshot: IoT Rule motion
  1. Choose Create new position, present the Position identify
    chargePointHeartbeat, select Create
  2. Select Subsequent and Create
  3. Navigate again to DynamoBD and choose Tables, Discover Gadgets
  4. For Tables, select the DynamoDB desk created beforehand
  5. Run the Python script to simulate a CP and watch as heartbeat are added and replace within the DynamoDB desk

Connection dealing with

A single CP ought to solely preserve one connection to at least one OCPP Gateway, in any other case routing of responses from the CPO to the correct connection could also be affected. You possibly can simulate a reconnection try.

  1. (Non-obligatory) In the event you don’t have already got it, obtain and set up the wscat utility
  2. Open a terminal home windows and set up a WebSocket connection:
wscat -c {AwsOcppGatewayStack.websocketURL}/CP1 -s ocpp2.0.1
Related (press CTRL+C to give up)
>
  1. In a second terminal window run the identical command, trying to create one other connection utilizing the identical CP, e.g.
    CP1
  2. As soon as this new connection is established you’ll see that the prior connection is routinely closed:
Disconnected (code: 1000, purpose: "")
  1. Testing a reference to a CP that isn’t configured as an IoT Factor will consequence within the connection try being rejected:
wscat -c {AwsOcppGatewayStack.websocketURL}/CPX -s ocpp2.0.1
Related (press CTRL+C to give up)
Disconnected (code: 1008, purpose: "Cost Level CPX not registered as an IoT Factor")

Clear up

If you end up finished operating simulations, deactivate the Python digital surroundings (venv) by executing this command in your terminal:

deactivate

You possibly can take away the OCPP Gateway Stack and all of the related assets created in your AWS account by operating the next command:

npx cdk destroy

In regards to the authors

Garry Galinsky

Garry Galinsky

Garry Galinsky is a Principal Options Architect supporting Amazon on AWS. He’s a part of the trouble to affect Amazon’s Final Mile supply fleets throughout North America and Europe. LinkedIn

Bigad Soleiman

Bigad Soleiman

Bigad Soleiman is a Sr. Lead Prototyping Engineer on the AWS Prototyping Group. Main largest and strategic AWS clients navigating complicated core enterprise issues from idea to manufacturing throughout a number of domains. LinkedIn

This submit is part of a broader effort to help the OCPP protocol on AWS. Particular due to David Goehrig, Sergey Pugachev, Clement Rey, and Ozan Cihangir for his or her contributions to this effort.



Supply hyperlink

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments