Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/add citrine support #53

Open
wants to merge 22 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
80a66b1
add SP1 citrineos support
ChrisWeissmann May 29, 2024
335ffdb
add citrineos cert support
ChrisWeissmann May 29, 2024
b7e47c0
Add citrineos urls to sp2 and sp3 device models
ChrisWeissmann May 29, 2024
f6a79af
patch in local certificates
ChrisWeissmann May 29, 2024
ead6af5
set citrine as first priority in the connection slots
ChrisWeissmann May 29, 2024
9d7c9cb
adjusting for new citrineos branch
thanaParis Jun 3, 2024
9c23e60
building all citrineos images
ChrisWeissmann Jun 3, 2024
35cbf44
explicitly setting version tag for EVerest dockercompose to 0.0.14; …
ChrisWeissmann Jun 4, 2024
e86f47d
updating demo repo & branch
ChrisWeissmann Jun 4, 2024
9537d38
making maeve the default again
ChrisWeissmann Jun 4, 2024
f76d903
updating with pr to adapt for 0.0.15
thanaParis Jun 4, 2024
825ff7f
removing unneeded files & code
thanaParis Jun 4, 2024
0e02b03
adding maeve db support
thanaParis Jun 4, 2024
6f658e5
making maeve default again
thanaParis Jun 4, 2024
e56c491
Merge branch 'main' into feature/add-citrine-support
thanaParis Jun 4, 2024
a435152
Merge remote-tracking branch 'upstream/main' into feature/add-citrine…
ChrisWeissmann Jun 5, 2024
09a33c7
Rename device model to be explicit and small fixes based on PR feedback
ChrisWeissmann Jun 5, 2024
dd87883
fix: Slight adjustment for static code analysis
ChrisWeissmann Jun 5, 2024
c93fed5
Merge branch 'main' into feature/add-citrine-support
shankari Jun 9, 2024
f7604ba
fixing typo for variable naming
thanaParis Jun 10, 2024
63d915e
Merging paths
thanaParis Jun 10, 2024
d80abb2
slight adjustment from static code analysis action to avoid globbing
ChrisWeissmann Jun 10, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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-----
176 changes: 176 additions & 0 deletions citrineos/add-charger.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,176 @@
#!/usr/bin/env bash

# Configuration
DIRECTUS_API_URL="http://localhost:8055"
CHARGEPOINT_ID="cp001"
CP_PASSWORD="DEADBEEFDEADBEEF"
DIRECTUS_EMAIL="admin@citrineos.com"
DIRECTUS_PASSWORD="CitrineOS!"

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

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

shankari marked this conversation as resolved.
Show resolved Hide resolved
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"
Loading