Skip to content

Commit

Permalink
Merge pull request EVerest#58 from ChrisWeissmann/feature/add-citrine…
Browse files Browse the repository at this point in the history
…-support-signedoff

Add general citrine support
  • Loading branch information
shankari authored Jun 26, 2024
2 parents 67b82a9 + 2f400af commit 6ac3228
Show file tree
Hide file tree
Showing 7 changed files with 562 additions and 255 deletions.
27 changes: 27 additions & 0 deletions citrineos/acme_account_key.pem
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
-----BEGIN RSA PRIVATE KEY-----
MIIEowIBAAKCAQEA8ul5QIk9qf+grKDCN1sKPPYsxT4HegfPOm4APr3pISo3rJNy
Ns8MfEryn58h8QJ8w7vSh0ZPlLpJq8oY8Y9ckaiJkNIWvRJYfFjwbMeWTLKteCOQ
lYTUzKEwxhRmQB1HlKPZYo1SFjgqF7ww4q98YFQQw67gzgs/rpLeEZ4pWzOVn4qM
+cBw2B0EgLFER6MI6dVja3t2NkNYRo6Jx0zs+UPKoYci7c9WETFcGOQwv2GjpOrm
ekkCLnp7/3/5tmkKmUFbkTZU8+Qoq+Hgj8pAqgRYik2dl9WyE21PHygL7a6psKZR
kjvOCPUqCkwjVdf/7oOfp8JAWSnWtyU4sKVU+wIDAQABAoIBAANTmjL9jighVZB3
pSE/8Gx0TJmo505PBBH/RqaVUDeBjgChhktk231qQ1dXRQ45Y/8EN/ZdSqK1SGP/
YQcR2Qkvny6qCeCt+yM8zpIWy6KiQcjm58h8aLOis3nK9rmDDSNmeQgl+k1OmJj5
nUvFbnUdQZuEbhS0R7t6zGq+WT+j9uCIt0DV3m2+qWw0uN8ObZpr16GOWBp8yo6+
3LBOwQ5+9/nqwTdOLMbpsZlJd/KOQikV9izOQkmL6tC2dxPXRqKPNST5987kYY37
H+0iIfIyvFCx5gTKpoUy2JxGvXZOlKdibaav9b4P5P663YIb4sTUVPHi1cyZPYkc
pnoLSjkCgYEA+zAuQ5i5FTLry7f5iPjGNSdWSJ8Fb8RJ6dqTBP/PDezI6K48vJJ1
gkll3JMyXfMBScd90qq1QVAUmb8Nz2mQXCIHsNBexjeuGNBnXxB21XSM3bA+1mL9
zJ5eUnBUgih60CJE/8jdo9GNUY0Ce0XEOTpl1LKYPJc2uSXC1y6kLcMCgYEA95C0
6c9hat9/VDRab+0VZrMb+FBj3f1XsHGRSWbQDuWuO7CfOEYhwTcLrE9WexTEjNL6
6IVvN3CqhcxGTHD4fgW+9QFGAXC2SoNKCsPokzC1X1ikUusPtriyn/IvUP6qYHus
eB4xsCD5ulyGfJJRbBRa5dmzlqxnKyimPfC+MGkCgYEAxoibWHQifX3k3vyHb1pp
luODkByYOHGllf9bSo1BwxjO5xGoEceUtyh6KS/ylE0YTI8vhM3GO1wnHCnkqXYf
UqLW/0qCThr+MMCvo3So6CeZmzLNR7ewMAVQOcptEP8bqtwbOyww+mULVFSmjHZl
FHJyv/101BcUepw89sT3oO8CgYB4GQI63vkCcLQDdHZfD+Ou87rg5pbcDVfp5940
fqT2ZSP2HwPOt+8OHZcTG1X31aZYLs272WePvJ9s0yFTWgailEUD9H8ymaxFT5Wu
zUVZimqie40UEKaJ3OYCw+mCYFjk/3o2t2cha43ag6JWcmD/joxeLxN5R9+wx0KG
j/Cj6QKBgF0WuXRkQwItF2F/swibuFcnqlGjz6I5k5wBuuZiRk8PcPgCPSyoWald
YzN6CLKfQSIZjO0fj7S329hc+CbKx1o+HNPjC72lP9fC/KCh8FAxMhUkcCwP7Bvt
fpRG66KTIz6EZtWWAI/VjWxUo9LOX4YVTBSVLeMI+bNmKHw4VLKI
-----END RSA PRIVATE KEY-----
215 changes: 215 additions & 0 deletions citrineos/add-charger-and-rfid-card.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,215 @@
#!/usr/bin/env bash

# Configuration
DIRECTUS_API_URL="http://localhost:8055"
CHARGEPOINT_ID="cp001"
CP_PASSWORD="DEADBEEFDEADBEEF"
DIRECTUS_EMAIL="[email protected]"
DIRECTUS_PASSWORD="CitrineOS!"
ID_TOKEN="DEADBEEF"
ID_TOKEN_TYPE="ISO14443"

#TODO put github images
PROJECT_LOGO_IMAGE_URL="https://public-citrineos-logo.s3.amazonaws.com/Citrine-Directus-Project-Logo.png"
PUBLIC_BACKGROUND_IMAGE_URL="https://public-citrineos-logo.s3.amazonaws.com/Citrine-Directus-Public-Background.png"

# 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"
}

# Function to upload an image via URL to Directus
upload_image() {

local token=$1
local image_url=$2
local title=$3
local response=$(curl -s -X POST "${DIRECTUS_API_URL}/files/import" \
-H "Authorization: Bearer ${token}" \
-H "Content-Type: application/json" \
-d "{
\"url\": \"${image_url}\",
\"data\": {
\"title\": \"${title}\"
}
}"| tee /dev/tty && echo)

local file_id=$(jq -r '.data.id' <<< "$response")

echo "$file_id"
}

# Function to set the project image
set_project_image() {
local token=$1
local project_logo=$2
local project_background=$3
curl -s -X PATCH "${DIRECTUS_API_URL}/settings" \
-H "Authorization: Bearer ${token}" \
-H "Content-Type: application/json" \
-d "{
\"project_logo\": \"${project_logo}\",
\"public_background\": \"${project_background}\"
}" | tee /dev/tty && echo
}

# Function to add a new 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
}

# Function to add new ev driver authorization information
add_evdriver_authorization() {
local response
local success=false
local attempt=1
local idToken=$1
local idTokenType=$2

until $success; do
echo "Attempt $attempt: Adding ev driver authorization..."
response=$(curl -s -o /dev/null -w "%{http_code}" --location --request PUT "http://localhost:8080/data/evdriver/authorization?idToken=${idToken}&type=${idTokenType}" \
--header "Content-Type: application/json" \
--data-raw '{
"idToken": {
"idToken": "'"$idToken"'",
"type": "'"$idTokenType"'"
},
"idTokenInfo": {
"status": "Accepted"
}
}' | tee /dev/tty)


if [[ $response -ge 200 && $response -lt 300 ]]; then
echo "Authorization update successful."
success=true
else
echo "Authorization 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

# Upload image and set as project logo
echo "Uploading project images..."
FILE_ID_LOGO=$(upload_image "$TOKEN" "$PROJECT_LOGO_IMAGE_URL" "Citrine Logo")

if [ -z "$FILE_ID_LOGO" ]; then
echo "Failed to upload project image."
exit 1
fi
FILE_ID_BACKGROUND=$(upload_image "$TOKEN" "$PUBLIC_BACKGROUND_IMAGE_URL" "Citrine Background")
if [ -z "$FILE_ID_BACKGROUND" ]; then
echo "Failed to upload project image."
exit 1
fi

echo "Setting project image..."
set_project_image "$TOKEN" "$FILE_ID_LOGO" "$FILE_ID_BACKGROUND"

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"

echo "Add ev driver rfid authorization to citrine..."
add_evdriver_authorization "$ID_TOKEN" "$ID_TOKEN_TYPE"
Loading

0 comments on commit 6ac3228

Please sign in to comment.