From 43ad0fc9090b46709e49e2786ef659a7a31836c7 Mon Sep 17 00:00:00 2001 From: matth-x <63792403+matth-x@users.noreply.github.com> Date: Tue, 27 Feb 2024 23:18:03 +0100 Subject: [PATCH 1/3] add ProtocolVersion selector --- src/MicroOcppMongooseClient.cpp | 6 ++++-- src/MicroOcppMongooseClient.h | 6 +++++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/MicroOcppMongooseClient.cpp b/src/MicroOcppMongooseClient.cpp index b4201f0..387ac3c 100644 --- a/src/MicroOcppMongooseClient.cpp +++ b/src/MicroOcppMongooseClient.cpp @@ -23,7 +23,8 @@ MOcppMongooseClient::MOcppMongooseClient(struct mg_mgr *mgr, const char *charge_box_id_factory, const char *auth_key_factory, const char *CA_cert_factory, - std::shared_ptr filesystem) : mgr(mgr) { + std::shared_ptr filesystem, + ProtocolVersion protocolVersion) : mgr(mgr), protocolVersion(protocolVersion) { bool readonly; @@ -209,7 +210,8 @@ void MOcppMongooseClient::maintainWsConn() { url.c_str(), ws_cb, this, - "%s%s%s\r\n", "Sec-WebSocket-Protocol: ocpp1.6", + "Sec-WebSocket-Protocol: %s%s%s\r\n", + protocolVersion.major == 2 ? "ocpp2.0.1" : "ocpp1.6", basic_auth64.empty() ? "" : "\r\nAuthorization: Basic ", basic_auth64.empty() ? "" : basic_auth64.c_str()); // Create client #endif diff --git a/src/MicroOcppMongooseClient.h b/src/MicroOcppMongooseClient.h index c812210..d91c940 100644 --- a/src/MicroOcppMongooseClient.h +++ b/src/MicroOcppMongooseClient.h @@ -12,6 +12,7 @@ #include "mongoose.h" #include +#include #include #include @@ -61,6 +62,8 @@ class MOcppMongooseClient : public MicroOcpp::Connection { bool connection_closing {false}; ReceiveTXTcallback receiveTXTcallback = [] (const char *, size_t) {return false;}; + ProtocolVersion protocolVersion; + void reconnect(); void maintainWsConn(); @@ -71,7 +74,8 @@ class MOcppMongooseClient : public MicroOcpp::Connection { const char *charge_box_id_factory = nullptr, const char *auth_key_factory = nullptr, const char *CA_cert_factory = nullptr, //forwards this string to Mongoose as ssl_ca_cert (see https://github.com/cesanta/mongoose/blob/ab650ec5c99ceb52bb9dc59e8e8ec92a2724932b/mongoose.h#L4192) - std::shared_ptr filesystem = nullptr); + std::shared_ptr filesystem = nullptr, + ProtocolVersion protocolVersion = ProtocolVersion(1,6)); ~MOcppMongooseClient(); From c4214662498ac29852b33842ffa949537aff9b92 Mon Sep 17 00:00:00 2001 From: matth-x <63792403+matth-x@users.noreply.github.com> Date: Sun, 21 Apr 2024 20:07:00 +0200 Subject: [PATCH 2/3] backport OCPP 2.0.1 header --- src/MicroOcppMongooseClient.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/MicroOcppMongooseClient.cpp b/src/MicroOcppMongooseClient.cpp index 387ac3c..be4c32a 100644 --- a/src/MicroOcppMongooseClient.cpp +++ b/src/MicroOcppMongooseClient.cpp @@ -1,5 +1,5 @@ // matth-x/MicroOcppMongoose -// Copyright Matthias Akstaller 2019 - 2023 +// Copyright Matthias Akstaller 2019 - 2024 // GPL-3.0 License (see LICENSE) #include "MicroOcppMongooseClient.h" @@ -196,7 +196,7 @@ void MOcppMongooseClient::maintainWsConn() { this, opts, url.c_str(), - "ocpp1.6", + protocolVersion.major == 2 ? "ocpp2.0.1" : "ocpp1.6", *extra_headers ? extra_headers : nullptr); if (websocket) { From f0eadf7cb310076f3fc70cabefd89f3aa86bddfe Mon Sep 17 00:00:00 2001 From: matth-x <63792403+matth-x@users.noreply.github.com> Date: Sun, 21 Apr 2024 20:13:37 +0200 Subject: [PATCH 3/3] update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 758ad1a..15f1fb5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ ### Added - ~FTP over TLS support ([#3](https://github.com/matth-x/MicroOcppMongoose/pull/3))~ (see [#5](https://github.com/matth-x/MicroOcppMongoose/pull/5)) +- OCPP 2.0.1 compatibility ([#6](https://github.com/matth-x/MicroOcppMongoose/pull/6)) ### Removed