Skip to content

Commit d9bda4a

Browse files
authored
OCPP 2.0.1 compatibility (#6)
* add ProtocolVersion selector * backport OCPP 2.0.1 header * update changelog
1 parent 0ac4b49 commit d9bda4a

File tree

3 files changed

+12
-5
lines changed

3 files changed

+12
-5
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
### Added
66

77
- ~FTP over TLS support ([#3](https://github.com/matth-x/MicroOcppMongoose/pull/3))~ (see [#5](https://github.com/matth-x/MicroOcppMongoose/pull/5))
8+
- OCPP 2.0.1 compatibility ([#6](https://github.com/matth-x/MicroOcppMongoose/pull/6))
89

910
### Removed
1011

src/MicroOcppMongooseClient.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// matth-x/MicroOcppMongoose
2-
// Copyright Matthias Akstaller 2019 - 2023
2+
// Copyright Matthias Akstaller 2019 - 2024
33
// GPL-3.0 License (see LICENSE)
44

55
#include "MicroOcppMongooseClient.h"
@@ -23,7 +23,8 @@ MOcppMongooseClient::MOcppMongooseClient(struct mg_mgr *mgr,
2323
const char *charge_box_id_factory,
2424
const char *auth_key_factory,
2525
const char *CA_cert_factory,
26-
std::shared_ptr<FilesystemAdapter> filesystem) : mgr(mgr) {
26+
std::shared_ptr<FilesystemAdapter> filesystem,
27+
ProtocolVersion protocolVersion) : mgr(mgr), protocolVersion(protocolVersion) {
2728

2829
bool readonly;
2930

@@ -195,7 +196,7 @@ void MOcppMongooseClient::maintainWsConn() {
195196
this,
196197
opts,
197198
url.c_str(),
198-
"ocpp1.6",
199+
protocolVersion.major == 2 ? "ocpp2.0.1" : "ocpp1.6",
199200
*extra_headers ? extra_headers : nullptr);
200201

201202
if (websocket) {
@@ -209,7 +210,8 @@ void MOcppMongooseClient::maintainWsConn() {
209210
url.c_str(),
210211
ws_cb,
211212
this,
212-
"%s%s%s\r\n", "Sec-WebSocket-Protocol: ocpp1.6",
213+
"Sec-WebSocket-Protocol: %s%s%s\r\n",
214+
protocolVersion.major == 2 ? "ocpp2.0.1" : "ocpp1.6",
213215
basic_auth64.empty() ? "" : "\r\nAuthorization: Basic ",
214216
basic_auth64.empty() ? "" : basic_auth64.c_str()); // Create client
215217
#endif

src/MicroOcppMongooseClient.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
#include "mongoose.h"
1414
#include <MicroOcpp/Core/Connection.h>
15+
#include <MicroOcpp/Version.h>
1516

1617
#include <string>
1718
#include <memory>
@@ -61,6 +62,8 @@ class MOcppMongooseClient : public MicroOcpp::Connection {
6162
bool connection_closing {false};
6263
ReceiveTXTcallback receiveTXTcallback = [] (const char *, size_t) {return false;};
6364

65+
ProtocolVersion protocolVersion;
66+
6467
void reconnect();
6568

6669
void maintainWsConn();
@@ -71,7 +74,8 @@ class MOcppMongooseClient : public MicroOcpp::Connection {
7174
const char *charge_box_id_factory = nullptr,
7275
const char *auth_key_factory = nullptr,
7376
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)
74-
std::shared_ptr<MicroOcpp::FilesystemAdapter> filesystem = nullptr);
77+
std::shared_ptr<MicroOcpp::FilesystemAdapter> filesystem = nullptr,
78+
ProtocolVersion protocolVersion = ProtocolVersion(1,6));
7579

7680
~MOcppMongooseClient();
7781

0 commit comments

Comments
 (0)