Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
12 changes: 9 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,14 @@ RUN cmake --build ./build -j 16 --target mo_simulator -j 16
# Grant execute permissions to the shell script
RUN chmod +x /MicroOcppSimulator/build/mo_simulator

# Expose port 8000
EXPOSE 8000
# Copy pre-built frontend public folder for runtime API configuration
COPY public /public

# Copy entrypoint script for runtime environment setup
COPY entrypoint.sh /entrypoint.sh
RUN chmod +x /entrypoint.sh

# Run the shell script inside the container
ENTRYPOINT ["/entrypoint.sh"]
CMD ["./build/mo_simulator"]

EXPOSE 8000
47 changes: 17 additions & 30 deletions build-webapp/build_webapp.ps1
Original file line number Diff line number Diff line change
@@ -1,40 +1,27 @@
#build, compress the web-app and move the bundle file to the public folder
# build_webapp.ps1
# Build and compress frontend, do not handle API_ROOT

#exit script on error
$ErrorActionPreference = "Stop"
#check relevant installs
echo "[info] NodeJS and npm need to be installed to build the web-app"
$ErrorActionPreference = 'Stop'
Write-Host "[info] Installing dependencies and building frontend..."

cd ./webapp-src

#fetch most recent version
Set-Location ./webapp-src
git pull

echo "Building web-app..."

#check .env.production file exists
$file = ".env.production"

#If the file does not exist, create it.
if (Test-Path -Path $file -PathType Leaf) {
echo "production environment found"
}else{
echo "no .env.production file found"
cd ..
exit 1
}


#install dependencies
npm install
#build the webapp
npm run build
#compress the project
npm run compress

#move the compressed file into the public folder
Move-Item ./dist/bundle.html.gz ../public/ -Force
# Ensure bundle.html.gz exists
if (-not (Test-Path "./dist/bundle.html.gz")) {
Write-Error "[error] Missing dist/bundle.html.gz, build failed"
exit 1
}

echo "[success] Up-to-date version of the web-app bundle was placed in the /public folder!"
# Move compressed file to public
if (-not (Test-Path "../public")) {
New-Item -ItemType Directory -Path "../public" | Out-Null
}
Move-Item "./dist/bundle.html.gz" "../public/" -Force

cd ..
Write-Host "[success] Frontend resources packaged and placed in public/ directory"
Set-Location ..
21 changes: 21 additions & 0 deletions entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/bin/sh
set -e

# Runtime API endpoint configuration
TARGET_FILE="./public/bundle.html.gz"
TEMP_HTML="/tmp/bundle.html"

if [ -z "$API_ROOT" ]; then
echo "[warn] API_ROOT environment variable not detected, frontend will use {{API_ROOT}} placeholder"
else
echo "[info] Runtime replacement: {{API_ROOT}} → $API_ROOT"
# Decompress to temporary file
gzip -d -c "$TARGET_FILE" > "$TEMP_HTML"
# Replace all placeholders
sed -i "s|{{API_ROOT}}|$API_ROOT|g" "$TEMP_HTML"
# Recompress back to original path
gzip -9 -c "$TEMP_HTML" > "$TARGET_FILE"
fi

# Start the C++ simulator
exec "./build/mo_simulator"
14 changes: 12 additions & 2 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,20 @@ void load_ocpp_version(std::shared_ptr<MicroOcpp::FilesystemAdapter> filesystem)
}

void app_setup(MicroOcpp::Connection& connection, std::shared_ptr<MicroOcpp::FilesystemAdapter> filesystem) {
// Configure charger credentials from environment variables or use defaults
const char *envId = std::getenv("CHARGER_ID");
const char *envKey = std::getenv("CHARGER_KEY");
std::string chargerId = envId ? envId : "MicroOcpp Simulator";
std::string chargerKey = envKey ? envKey : "MicroOcpp";

// Log runtime configuration values for debugging
std::cout << "[INFO] Charger ID: " << chargerId << std::endl;
std::cout << "[INFO] Charger Key: " << chargerKey << std::endl;

mocpp_initialize(connection,
g_isOcpp201 ?
ChargerCredentials::v201("MicroOcpp Simulator", "MicroOcpp") :
ChargerCredentials("MicroOcpp Simulator", "MicroOcpp"),
ChargerCredentials::v201(chargerId.c_str(), chargerKey.c_str()) :
ChargerCredentials(chargerId.c_str(), chargerKey.c_str()),
filesystem,
false,
g_isOcpp201 ?
Expand Down
2 changes: 1 addition & 1 deletion webapp-src