forked from EVerest/everest-demo
-
Notifications
You must be signed in to change notification settings - Fork 2
/
demo-iso15118-2-ac-plus-ocpp.sh
executable file
·402 lines (323 loc) · 14.7 KB
/
demo-iso15118-2-ac-plus-ocpp.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
#!/usr/bin/env bash
DEMO_REPO="https://github.com/everest/everest-demo.git"
DEMO_BRANCH="main"
CSMS_REPO="https://github.com/louisg1337/maeve-csms.git"
# CSMS_BRANCH="b990d0eddf2bf80be8d9524a7b08029fbb305c7d" # patch files are based on this commit
CSMS_BRANCH="set_charging_profile"
CSMS="maeve"
usage="usage: $(basename "$0") [-r <repo>] [-b <branch>] [-c <csms>] [-j|1|2|3] [-h]
This script will run EVerest ISO 15118-2 AC charging with OCPP demos.
Pro Tip: to use a local copy of this everest-demo repo, provide the current
directory to the -r option (e.g., '-r \$(pwd)').
where:
-r URL to everest-demo repo to use (default: $DEMO_REPO)
-b Branch of everest-demo repo to use (default: $DEMO_BRANCH)
-c Use CitrineOS CSMS (default: MaEVe)
-j OCPP v1.6j
-1 OCPP v2.0.1 Security Profile 1
-2 OCPP v2.0.1 Security Profile 2
-3 OCPP v2.0.1 Security Profile 3
-h Show this message"
DEMO_VERSION=
DEMO_COMPOSE_FILE_NAME=
# loop through positional options/arguments
while getopts ':r:b:cj123h' option; do
case "$option" in
r) DEMO_REPO="$OPTARG" ;;
b) DEMO_BRANCH="$OPTARG" ;;
c) CSMS="citrine"
CSMS_REPO="https://github.com/citrineos/citrineos-core"
CSMS_BRANCH="63670f3adc09266a0977862d972b0f7e440c577f" ;;
j) DEMO_VERSION="v1.6j"
DEMO_COMPOSE_FILE_NAME="docker-compose.ocpp16j.yml" ;;
1) DEMO_VERSION="v2.0.1-sp1"
DEMO_COMPOSE_FILE_NAME="docker-compose.ocpp201.yml" ;;
2) DEMO_VERSION="v2.0.1-sp2"
DEMO_COMPOSE_FILE_NAME="docker-compose.ocpp201.yml" ;;
3) DEMO_VERSION="v2.0.1-sp3"
DEMO_COMPOSE_FILE_NAME="docker-compose.ocpp201.yml" ;;
h) echo -e "$usage"; exit ;;
\?) echo -e "illegal option: -$OPTARG\n" >&2
echo -e "$usage" >&2
exit 1 ;;
esac
done
if [[ ! "${DEMO_VERSION}" ]]; then
echo 'Error: no demo version option provided.'
echo
echo -e "$usage"
exit 1
fi
DEMO_DIR="$(mktemp -d)"
if [[ ! "${DEMO_DIR}" || ! -d "${DEMO_DIR}" ]]; then
echo 'Error: Failed to create a temporary directory for the demo.'
exit 1
fi
delete_temporary_directory() { rm -rf "${DEMO_DIR}"; }
trap delete_temporary_directory EXIT
echo "DEMO REPO: $DEMO_REPO"
echo "DEMO BRANCH: $DEMO_BRANCH"
echo "DEMO VERSION: $DEMO_VERSION"
echo "DEMO CONFIG: $DEMO_COMPOSE_FILE_NAME"
echo "DEMO DIR: $DEMO_DIR"
cd "${DEMO_DIR}" || exit 1
echo "Cloning EVerest from ${DEMO_REPO} into ${DEMO_DIR}/everest-demo"
git clone --branch "${DEMO_BRANCH}" "${DEMO_REPO}" everest-demo
# cp -r "${DEMO_REPO}" everest-demo
if [[ "$DEMO_VERSION" != v1.6j ]]; then
echo "Cloning ${CSMS} CSMS from ${CSMS_REPO} into ${DEMO_DIR}/${CSMS}-csms and starting it"
if [[ ${CSMS} == "maeve" ]]; then
git clone --branch "${CSMS_BRANCH}" "${CSMS_REPO}" ${CSMS}-csms
else
git clone ${CSMS_REPO} ${CSMS}-csms
fi
pushd ${CSMS}-csms || exit 1
git reset --hard ${CSMS_BRANCH}
# Set up CSMS
echo "Setting up ${CSMS}"
if [[ "$CSMS" == "citrine" ]]; then
npm run install-all
if [[ "$?" != 0 ]]; then
echo 'Error: Failed to install dependencies.'
exit 1
fi
npm run build
if [[ "$?" != 0 ]]; then
echo 'Error: Failed to build the project.'
exit 1
fi
else
cp ../everest-demo/manager/cached_certs_correct_name_emaid.tar.gz .
fi
# Set up certificates for SP2 and SP3
if [[ "$DEMO_VERSION" =~ sp2 || "$DEMO_VERSION" =~ sp3 ]]; then
if [[ "$CSMS" == "citrine" ]]; then
echo "Security profile 2/3 is not supported with Citrine yet!"
exit 1
else
echo "Copying certs into ${DEMO_DIR}/maeve-csms/config/certificates"
tar xf cached_certs_correct_name_emaid.tar.gz
cat dist/etc/everest/certs/client/csms/CSMS_LEAF.pem \
dist/etc/everest/certs/ca/csms/CPO_SUB_CA2.pem \
dist/etc/everest/certs/ca/csms/CPO_SUB_CA1.pem \
> config/certificates/csms.pem
cat dist/etc/everest/certs/ca/csms/CPO_SUB_CA2.pem \
dist/etc/everest/certs/ca/csms/CPO_SUB_CA1.pem \
> config/certificates/trust.pem
cp dist/etc/everest/certs/client/csms/CSMS_LEAF.key config/certificates/csms.key
cp dist/etc/everest/certs/ca/v2g/V2G_ROOT_CA.pem config/certificates/root-V2G-cert.pem
cp dist/etc/everest/certs/ca/mo/MO_ROOT_CA.pem config/certificates/root-MO-cert.pem
echo "Validating that the certificates are set up correctly"
openssl verify -show_chain \
-CAfile config/certificates/root-V2G-cert.pem \
-untrusted config/certificates/trust.pem \
config/certificates/csms.pem
echo "Patching the CSMS to enable EVerest organization"
patch -p1 -i ../everest-demo/maeve/maeve-csms-everest-org.patch
echo "Patching the CSMS to enable local mo root"
patch -p1 -i ../everest-demo/maeve/maeve-csms-local-mo-root.patch
echo "Patching the CSMS to enable local mo root"
patch -p1 -i ../everest-demo/maeve/maeve-csms-ignore-ocsp.patch
fi
elif [[ ${CSMS} == "maeve" ]]; then
echo "Patching the CSMS to disable WSS"
patch -p1 -i ../everest-demo/maeve/maeve-csms-no-wss.patch
fi
# Start the CSMS
echo "Starting the CSMS"
if [[ ${CSMS} == "citrine" ]]; then
cd Server
chmod -R 777 data/
# Remap the CitrineOS 8081 port (HTTP w/ no auth) to 80 port
CITRINE_DOCKER="docker-compose.yml"
if [[ -f "$CITRINE_DOCKER" ]]; then
# Use sed to find and replace the string
sed -i '' 's/8082:8082/80:8082/g' "$CITRINE_DOCKER"
echo "Replaced mapping CitrineOS 8082 to 80 completed successfully."
else
echo "Error: File $CITRINE_DOCKER does not exist."
exit 1
fi
fi
docker compose build
docker compose up -d
echo "Waiting 5s for CSMS to start..."
sleep 5
if [[ ${CSMS} == "citrine" ]]; then
# Configuration
DIRECTUS_API_URL="http://localhost:8055"
CHARGEPOINT_ID="cp001"
CP_PASSWORD="DEADBEEFDEADBEEF"
DIRECTUS_EMAIL="admin@citrineos.com"
DIRECTUS_PASSWORD="CitrineOS!"
# Function to get the Directus token
get_directus_token() {
local login_url="${DIRECTUS_API_URL}/auth/login"
local json_body=$(printf '{"email": "%s", "password": "%s"}' "$DIRECTUS_EMAIL" "$DIRECTUS_PASSWORD")
local response=$(curl -s -X POST "$login_url" -H "Content-Type: application/json" -d "$json_body")
# Extract token from the response
local token=$(jq -r '.data.access_token' <<< "$response")
echo "$token"
}
# Create new charger location
add_location() {
local token=$1
local response=$(curl -s -X POST "${DIRECTUS_API_URL}/items/Locations" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer ${token}" \
-d '{
"id": "2",
"name": "New EVerst",
"coordinates": {
"type": "Point",
"coordinates": [-74.0620872, 41.041548]
}
}' | tee /dev/tty && echo)
local location_id=$(jq -r '.data.id' <<< "$response")
echo "$location_id"
}
# Function to add a charging station
add_charging_station() {
local token=$1
local location_id=$2
local chargepointId=$3
curl -s --request POST \
--url "${DIRECTUS_API_URL}/items/ChargingStations" \
--header "Authorization: Bearer $token" \
--header "Content-Type: application/json" \
--data '{
"id": "'"$chargepointId"'",
"locationId": "'"$location_id"'"
}' | tee /dev/tty && echo
}
# Function to update SP1 password
add_cp001_password() {
local response
local success=false
local attempt=1
local passwordString=$1
until $success; do
echo "Attempt $attempt: Updating SP1 password..."
response=$(curl -s -o /dev/null -w "%{http_code}" --location --request PUT "http://localhost:8080/data/monitoring/variableAttribute?stationId=${CHARGEPOINT_ID}&setOnCharger=true" \
--header "Content-Type: application/json" \
--data-raw '{
"component": {
"name": "SecurityCtrlr"
},
"variable": {
"name": "BasicAuthPassword"
},
"variableAttribute": [
{
"value": "'"$passwordString"'"
}
],
"variableCharacteristics": {
"dataType": "passwordString",
"supportsMonitoring": false
}
}' | tee /dev/tty)
if [[ $response -ge 200 && $response -lt 300 ]]; then
echo "Password update successful."
success=true
else
echo "Password update failed with HTTP status: $response. Retrying in 2 second..."
sleep 2
((attempt++))
fi
done
}
# Main script execution
TOKEN=$(get_directus_token)
echo "Received Token: $TOKEN"
if [ -z "$TOKEN" ]; then
echo "Failed to retrieve access token."
exit 1
fi
echo "Adding a new location..."
LOCATION_ID=$(add_location "$TOKEN")
if [ -z "$LOCATION_ID" ]; then
echo "Failed to add new location."
exit 1
fi
echo "Location ID: $LOCATION_ID"
echo "Adding new station..."
add_charging_station "$TOKEN" "$LOCATION_ID" "$CHARGEPOINT_ID"
echo "Add cp001 password to citrine..."
add_cp001_password "$CP_PASSWORD"
else
if [[ "$DEMO_VERSION" =~ sp1 ]]; then
echo "MaEVe CSMS started, adding charge station with Security Profile 1 (note: profiles in MaEVe start with 0 so SP-0 == OCPP SP-1)"
curl http://localhost:9410/api/v0/cs/cp001 -H 'content-type: application/json' \
-d '{"securityProfile": 0, "base64SHA256Password": "3oGi4B5I+Y9iEkYtL7xvuUxrvGOXM/X2LQrsCwf/knA="}'
elif [[ "$DEMO_VERSION" =~ sp2 ]]; then
echo "MaEVe CSMS started, adding charge station with Security Profile 2 (note: profiles in MaEVe start with 0 so SP-1 == OCPP SP-2)"
curl http://localhost:9410/api/v0/cs/cp001 -H 'content-type: application/json' \
-d '{"securityProfile": 1, "base64SHA256Password": "3oGi4B5I+Y9iEkYtL7xvuUxrvGOXM/X2LQrsCwf/knA="}'
elif [[ "$DEMO_VERSION" =~ sp3 ]]; then
echo "MaEVe CSMS started, adding charge station with Security Profile 3 (note: profiles in MaEVe start with 0 so SP-2 == OCPP SP-3)"
curl http://localhost:9410/api/v0/cs/cp001 -H 'content-type: application/json' -d '{"securityProfile": 2}'
fi
echo "Charge station added, adding user token"
curl http://localhost:9410/api/v0/token -H 'content-type: application/json' -d '{
"countryCode": "GB",
"partyId": "TWK",
"type": "RFID",
"uid": "DEADBEEF",
"contractId": "GBTWK012345678V",
"issuer": "Thoughtworks",
"valid": true,
"cacheMode": "ALWAYS"
}'
curl http://localhost:9410/api/v0/token -H 'content-type: application/json' -d '{"countryCode": "UK", "partyId": "Switch", "contractId": "UKSWI123456789G", "uid": "UKSWI123456789G", "issuer": "Switch", "valid": true, "cacheMode": "ALWAYS"}'
fi
echo "API calls to CSMS finished, starting EVerest..."
popd || exit 1
fi
pushd everest-demo || exit 1
docker compose --project-name everest-ac-demo --file "${DEMO_COMPOSE_FILE_NAME}" up -d --wait
echo "Configuring and restarting nodered"
docker cp nodered/config/config-sil-iso15118-ac-flow.json everest-ac-demo-nodered-1:/config/config-sil-two-evse-flow.json
docker restart everest-ac-demo-nodered-1
echo "Copying over all EVerest patches"
docker cp config-sil-ocpp201-pnc.yaml everest-ac-demo-manager-1:/ext/source/config/config-sil-ocpp201-pnc.yaml
docker cp manager/enable_payment_method.patch everest-ac-demo-manager-1:/tmp/
docker cp manager/support_payment_in_jsevmanager.patch everest-ac-demo-manager-1:/tmp/
docker cp manager/ocpp201.module.patch everest-ac-demo-manager-1:/tmp/
docker cp manager/libocpp.patch everest-ac-demo-manager-1:/tmp/
echo "Applying the ones that need recompile first"
docker exec everest-ac-demo-manager-1 /bin/bash -c "apk add patch && cd /ext/source && patch -p0 -i /tmp/ocpp201.module.patch"
docker exec everest-ac-demo-manager-1 /bin/bash -c "cd /ext/cache/cpm/libocpp/6502037f667273b3f55e917ec94a3fe0a2d27720 && patch -p0 -i /tmp/libocpp.patch"
echo "Recompiling"
docker exec everest-ac-demo-manager-1 /bin/bash -c "cd /ext/source/build && make install -j6"
echo "Now applying the patches that don't need recompile and will, in fact, be overridden by recompile"
docker cp manager/enable_evcc_logging.cfg everest-ac-demo-manager-1:/ext/source/build/dist/etc/everest/default_logging.cfg
docker exec everest-ac-demo-manager-1 /bin/bash -c "cd /ext && patch -p0 -i /tmp/enable_payment_method.patch"
docker exec everest-ac-demo-manager-1 /bin/bash -c "cd /ext/source/build/dist/libexec/everest && patch -p1 -i /tmp/support_payment_in_jsevmanager.patch"
if [[ "$DEMO_VERSION" =~ sp2 || "$DEMO_VERSION" =~ sp3 ]]; then
docker cp manager/cached_certs_correct_name_emaid.tar.gz everest-ac-demo-manager-1:/ext/source/build
docker exec everest-ac-demo-manager-1 /bin/bash -c "pushd /ext/source/build && tar xf cached_certs_correct_name_emaid.tar.gz"
echo "Configured everest certs, validating that the chain is set up correctly"
docker exec everest-ac-demo-manager-1 /bin/bash -c "pushd /ext/source/build && openssl verify -show_chain -CAfile dist/etc/everest/certs/ca/v2g/V2G_ROOT_CA.pem --untrusted dist/etc/everest/certs/ca/csms/CPO_SUB_CA1.pem --untrusted dist/etc/everest/certs/ca/csms/CPO_SUB_CA2.pem dist/etc/everest/certs/client/csms/CSMS_LEAF.pem"
fi
if [[ ${CSMS} == "citrine" && ! ("$DEMO_VERSION" =~ sp1) ]]; then
echo "TODO: Set up device model correctly!"
else
if [[ "$DEMO_VERSION" =~ sp1 ]]; then
echo "Copying device DB, configured to SecurityProfile: 1"
docker cp manager/device_model_storage_maeve_sp1.db \
everest-ac-demo-manager-1:/ext/source/build/dist/share/everest/modules/OCPP201/device_model_storage.db
elif [[ "$DEMO_VERSION" =~ sp2 ]]; then
echo "Copying device DB, configured to SecurityProfile: 2"
docker cp manager/device_model_storage_maeve_sp2.db \
everest-ac-demo-manager-1:/ext/source/build/dist/share/everest/modules/OCPP201/device_model_storage.db
elif [[ "$DEMO_VERSION" =~ sp3 ]]; then
echo "Copying device DB, configured to SecurityProfile: 3"
docker cp manager/device_model_storage_maeve_sp3.db \
everest-ac-demo-manager-1:/ext/source/build/dist/share/everest/modules/OCPP201/device_model_storage.db
fi
fi
if [[ "$DEMO_VERSION" =~ v2.0.1 ]]; then
echo "Starting software in the loop simulation"
docker exec everest-ac-demo-manager-1 sh /ext/source/build/run-scripts/run-sil-ocpp201-pnc.sh
fi