Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main'
Browse files Browse the repository at this point in the history
  • Loading branch information
matth-x committed May 27, 2024
2 parents ebf38f5 + 558d14f commit a4d7d32
Show file tree
Hide file tree
Showing 17 changed files with 100 additions and 47 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/build_docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ name: Docker
on:
push:
branches:
- master
- develop
- main

pull_request:

Expand Down
3 changes: 1 addition & 2 deletions .github/workflows/build_ubuntu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ name: Ubuntu
on:
push:
branches:
- master
- develop
- main

pull_request:

Expand Down
3 changes: 1 addition & 2 deletions .github/workflows/build_wasm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ name: WebAssembly
on:
push:
branches:
- master
- develop
- main

pull_request:

Expand Down
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,6 @@
[submodule "webapp-src"]
path = webapp-src
url = https://github.com/agruenb/arduino-ocpp-dashboard.git
[submodule "lib/mbedtls"]
path = lib/mbedtls
url = https://github.com/Mbed-TLS/mbedtls
68 changes: 56 additions & 12 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
# matth-x/MicroOcpp
# Copyright Matthias Akstaller 2019 - 2023
# MIT License
# matth-x/MicroOcppSimulator
# Copyright Matthias Akstaller 2022 - 2024
# GPL-3.0 License

cmake_minimum_required(VERSION 3.13)

set(CMAKE_CXX_STANDARD 11)

set(MO_SIM_SRC
src/evse.cpp
src/main.cpp
Expand Down Expand Up @@ -32,34 +34,76 @@ add_compile_definitions(
MO_DBG_LEVEL=MO_DL_INFO
MO_FILENAME_PREFIX="./mo_store/"
MO_ENABLE_V201=1
MO_ENABLE_MBEDTLS=1
)

add_executable(mo_simulator ${MO_SIM_SRC} ${MO_SIM_MG_SRC})

# find OpenSSL (skip for WebAssembly)
if (NOT ${CMAKE_SYSTEM_NAME} MATCHES "Emscripten")
find_package(OpenSSL REQUIRED)
endif()

target_include_directories(mo_simulator PUBLIC
"${CMAKE_CURRENT_SOURCE_DIR}/lib/ArduinoJson/src"
"${CMAKE_CURRENT_SOURCE_DIR}/lib/mongoose"
"${OPENSSL_INCLUDE_DIR}"
)

target_compile_definitions(mo_simulator PUBLIC
MO_NETLIB=MO_NETLIB_MONGOOSE
MG_ENABLE_OPENSSL=1
)

add_subdirectory(lib/MicroOcpp)
target_link_libraries(mo_simulator PUBLIC MicroOcpp)

# disable some warnings for MbedTLS which cause compilation errors on WASM
if (${CMAKE_SYSTEM_NAME} MATCHES "Emscripten")
add_compile_options(
-Wno-unused-but-set-variable
-Wno-documentation
)
endif()

# disable MbedTLS unit tests and test suites (not needed for the Simualtor)
option(ENABLE_TESTING "Build mbed TLS tests." OFF)
option(ENABLE_PROGRAMS "Build mbed TLS programs." OFF)

add_subdirectory(lib/mbedtls)
target_link_libraries(MicroOcpp PUBLIC
mbedtls
mbedcrypto
mbedx509
)

if (MO_SIM_BUILD_USE_OPENSSL)

message("Using OpenSSL for WebSocket")

# find OpenSSL
find_package(OpenSSL REQUIRED)
target_include_directories(mo_simulator PUBLIC
"${OPENSSL_INCLUDE_DIR}"
)
target_link_libraries(mo_simulator PUBLIC
${OPENSSL_LIBRARIES}
)
target_compile_definitions(mo_simulator PUBLIC
MG_ENABLE_OPENSSL=1
)

else()

message("Using MbedTLS for WebSocket")

target_link_libraries(mo_simulator PUBLIC
mbedtls
mbedcrypto
mbedx509
)
target_compile_definitions(mo_simulator PUBLIC
MG_ENABLE_MBEDTLS=1
)

endif()

add_subdirectory(lib/MicroOcppMongoose)
target_link_libraries(mo_simulator PUBLIC MicroOcppMongoose)

target_link_libraries(mo_simulator PUBLIC ${OPENSSL_LIBRARIES})

# experimental WebAssembly port
add_executable(mo_simulator_wasm ${MO_SIM_SRC} ${MO_SIM_WASM_SRC})

Expand Down
2 changes: 1 addition & 1 deletion lib/MicroOcpp
Submodule MicroOcpp updated 205 files
1 change: 1 addition & 0 deletions lib/mbedtls
Submodule mbedtls added at dd79db
4 changes: 4 additions & 0 deletions src/api.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
// matth-x/MicroOcppSimulator
// Copyright Matthias Akstaller 2022 - 2024
// GPL-3.0 License

#include "api.h"

#include <MicroOcpp/Debug.h>
Expand Down
4 changes: 4 additions & 0 deletions src/api.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
// matth-x/MicroOcppSimulator
// Copyright Matthias Akstaller 2022 - 2024
// GPL-3.0 License

#ifndef MO_SIM_API_H
#define MO_SIM_API_H

Expand Down
2 changes: 1 addition & 1 deletion src/evse.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// matth-x/MicroOcppSimulator
// Copyright Matthias Akstaller 2022 - 2024
// MIT License
// GPL-3.0 License

#include "evse.h"
#include <MicroOcpp.h>
Expand Down
2 changes: 1 addition & 1 deletion src/evse.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// matth-x/MicroOcppSimulator
// Copyright Matthias Akstaller 2022 - 2024
// MIT License
// GPL-3.0 License

#ifndef EVSE_H
#define EVSE_H
Expand Down
2 changes: 1 addition & 1 deletion src/main.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// matth-x/MicroOcppSimulator
// Copyright Matthias Akstaller 2022 - 2024
// MIT License
// GPL-3.0 License

#include <iostream>

Expand Down
21 changes: 11 additions & 10 deletions src/net_mongoose.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
// matth-x/MicroOcppSimulator
// Copyright Matthias Akstaller 2022 - 2024
// GPL-3.0 License

#include "net_mongoose.h"
#include "evse.h"
#include "api.h"
Expand All @@ -7,9 +11,6 @@
#include <MicroOcpp/Debug.h>
#include <MicroOcpp/Core/Configuration.h>

static const char *s_http_addr = "http://localhost:8000"; // HTTP port
static const char *s_root_dir = "web_root";

//cors_headers allow the browser to make requests from any domain, allowing all headers and all methods
#define DEFAULT_HEADER "Content-Type: application/json\r\n"
#define CORS_HEADERS "Access-Control-Allow-Origin: *\r\nAccess-Control-Allow-Headers:Access-Control-Allow-Headers, Origin,Accept, X-Requested-With, Content-Type, Access-Control-Request-Method, Access-Control-Request-Headers\r\nAccess-Control-Allow-Methods: GET,HEAD,OPTIONS,POST,PUT\r\n"
Expand Down Expand Up @@ -90,7 +91,7 @@ void http_serve(struct mg_connection *c, int ev, void *ev_data, void *fn_data) {
serializeJson(doc, serialized);
mg_http_reply(c, 200, final_headers, serialized.c_str());
return;
} else if(strncmp(message_data->uri.ptr, "/api", strlen("api")) == 0) {
} else if (strncmp(message_data->uri.ptr, "/api", strlen("api")) == 0) {
#define RESP_BUF_SIZE 1024
char resp_buf [RESP_BUF_SIZE];

Expand All @@ -106,12 +107,12 @@ void http_serve(struct mg_connection *c, int ev, void *ev_data, void *fn_data) {
resp_buf, RESP_BUF_SIZE);

mg_http_reply(c, status, final_headers, resp_buf);
}
//if no specific path is given serve dashboard application file
else if (mg_http_match_uri(message_data, "/")) {
struct mg_http_serve_opts opts = { .root_dir = "./public" };
opts.extra_headers = "Content-Type: text/html\r\nContent-Encoding: gzip\r\n";
mg_http_serve_file(c, message_data, "public/bundle.html.gz", &opts);
} else if (mg_http_match_uri(message_data, "/")) { //if no specific path is given serve dashboard application file
struct mg_http_serve_opts opts;
memset(&opts, 0, sizeof(opts));
opts.root_dir = "./public";
opts.extra_headers = "Content-Type: text/html\r\nContent-Encoding: gzip\r\n";
mg_http_serve_file(c, message_data, "public/bundle.html.gz", &opts);
} else {
mg_http_reply(c, 404, final_headers, "The required parameters are not given");
}
Expand Down
4 changes: 4 additions & 0 deletions src/net_mongoose.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
// matth-x/MicroOcppSimulator
// Copyright Matthias Akstaller 2022 - 2024
// GPL-3.0 License

#ifndef MO_NET_MONGOOSE_H
#define MO_NET_MONGOOSE_H

Expand Down
19 changes: 5 additions & 14 deletions src/net_wasm.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
// matth-x/MicroOcppSimulator
// Copyright Matthias Akstaller 2022 - 2024
// GPL-3.0 License

#include "net_wasm.h"

#include <string>
Expand All @@ -7,7 +11,6 @@
#include <MicroOcpp/Core/Connection.h>
#include <MicroOcpp/Core/Configuration.h>
#include <MicroOcpp/Debug.h>
#include "base64.hpp"

#include "api.h"

Expand Down Expand Up @@ -304,19 +307,7 @@ class WasmOcppConnection : public Connection {
}

if (!auth_key.empty()) {
std::string token = cb_id + ":" + auth_key;

MO_DBG_DEBUG("auth Token=%s", token.c_str());

unsigned int base64_length = encode_base64_length(token.length());
std::vector<unsigned char> base64 (base64_length + 1);

// encode_base64() places a null terminator automatically, because the output is a string
base64_length = encode_base64((const unsigned char*) token.c_str(), token.length(), &base64[0]);

MO_DBG_DEBUG("auth64 len=%u, auth64 Token=%s", base64_length, &base64[0]);

basic_auth64 = (const char*) &base64[0];
MO_DBG_WARN("WASM app does not support Securiy Profile 2 yet");
} else {
MO_DBG_DEBUG("no authentication");
(void) 0;
Expand Down
4 changes: 4 additions & 0 deletions src/net_wasm.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
// matth-x/MicroOcppSimulator
// Copyright Matthias Akstaller 2022 - 2024
// GPL-3.0 License

#ifndef MO_NET_WASM_H
#define MO_NET_WASM_H

Expand Down

0 comments on commit a4d7d32

Please sign in to comment.