@@ -64,30 +64,53 @@ MOcppMongooseClient::MOcppMongooseClient(struct mg_mgr *mgr,
6464 readonly = true ;
6565 }
6666
67- setting_backend_url_str = declareConfiguration<const char *>(
68- MO_CONFIG_EXT_PREFIX " BackendUrl" , backend_url_factory, MO_WSCONN_FN, readonly, true );
69- setting_cb_id_str = declareConfiguration<const char *>(
70- MO_CONFIG_EXT_PREFIX " ChargeBoxId" , charge_box_id_factory, MO_WSCONN_FN, readonly, true );
71-
7267 if (auth_key_factory_len > MO_AUTHKEY_LEN_MAX) {
7368 MO_DBG_WARN (" auth_key_factory too long - will be cropped" );
7469 auth_key_factory_len = MO_AUTHKEY_LEN_MAX;
7570 }
7671
7772#if MO_ENABLE_V201
7873 if (protocolVersion.major == 2 ) {
79- websocketSettings = makeVariableContainerVolatile (MO_WSCONN_FN_V201, true );
80- auto variable = websocketSettings->createVariable (Variable::InternalDataType::String, Variable::AttributeType::Actual);
81- variable->setComponentId (" SecurityCtrlr" );
82- variable->setName (" BasicAuthPassword" );
83- char basicAuthPassword [MO_AUTHKEY_LEN_MAX + 1 ];
84- snprintf (basicAuthPassword, sizeof (basicAuthPassword), " %.*s" , (int )auth_key_factory_len, auth_key_factory ? (const char *)auth_key_factory : " " );
85- variable->setString (basicAuthPassword);
86- websocketSettings->add (std::move (variable));
87- basicAuthPasswordString = websocketSettings->getVariable (" SecurityCtrlr" , " BasicAuthPassword" );
74+ websocketSettings = std::unique_ptr<VariableContainerOwning>(new VariableContainerOwning ());
75+ if (filesystem) {
76+ websocketSettings->enablePersistency (filesystem, MO_WSCONN_FN_V201);
77+ }
78+
79+ auto csmsUrl = makeVariable (Variable::InternalDataType::String, Variable::AttributeType::Actual);
80+ csmsUrl->setComponentId (" SecurityCtrlr" );
81+ csmsUrl->setName (" CsmsUrl" );
82+ csmsUrl->setString (backend_url_factory ? backend_url_factory : " " );
83+ csmsUrl->setPersistent ();
84+ v201csmsUrlString = csmsUrl.get ();
85+ websocketSettings->add (std::move (csmsUrl));
86+
87+ auto identity = makeVariable (Variable::InternalDataType::String, Variable::AttributeType::Actual);
88+ identity->setComponentId (" SecurityCtrlr" );
89+ identity->setName (" Identity" );
90+ identity->setString (charge_box_id_factory ? charge_box_id_factory : " " );
91+ identity->setPersistent ();
92+ v201identityString = identity.get ();
93+ websocketSettings->add (std::move (identity));
94+
95+ auto basicAuthPassword = makeVariable (Variable::InternalDataType::String, Variable::AttributeType::Actual);
96+ basicAuthPassword->setComponentId (" SecurityCtrlr" );
97+ basicAuthPassword->setName (" BasicAuthPassword" );
98+ char basicAuthPasswordVal [MO_AUTHKEY_LEN_MAX + 1 ];
99+ snprintf (basicAuthPasswordVal, sizeof (basicAuthPasswordVal), " %.*s" , (int )auth_key_factory_len, auth_key_factory ? (const char *)auth_key_factory : " " );
100+ basicAuthPassword->setString (basicAuthPasswordVal);
101+ basicAuthPassword->setPersistent ();
102+ v201basicAuthPasswordString = basicAuthPassword.get ();
103+ websocketSettings->add (std::move (basicAuthPassword));
104+
105+ websocketSettings->load (); // if settings on flash already exist, this overwrites factory defaults
88106 } else
89107#endif
90108 {
109+ setting_backend_url_str = declareConfiguration<const char *>(
110+ MO_CONFIG_EXT_PREFIX " BackendUrl" , backend_url_factory, MO_WSCONN_FN, readonly, true );
111+ setting_cb_id_str = declareConfiguration<const char *>(
112+ MO_CONFIG_EXT_PREFIX " ChargeBoxId" , charge_box_id_factory, MO_WSCONN_FN, readonly, true );
113+
91114 char auth_key_hex [2 * MO_AUTHKEY_LEN_MAX + 1 ];
92115 auth_key_hex[0 ] = ' \0 ' ;
93116 if (auth_key_factory) {
@@ -366,10 +389,21 @@ void MOcppMongooseClient::setBackendUrl(const char *backend_url_cstr) {
366389 return ;
367390 }
368391
369- if (setting_backend_url_str) {
370- setting_backend_url_str->setString (backend_url_cstr);
371- configuration_save ();
392+ #if MO_ENABLE_V201
393+ if (protocolVersion.major == 2 ) {
394+ if (v201csmsUrlString) {
395+ v201csmsUrlString->setString (backend_url_cstr);
396+ websocketSettings->commit ();
397+ }
398+ } else
399+ #endif
400+ {
401+ if (setting_backend_url_str) {
402+ setting_backend_url_str->setString (backend_url_cstr);
403+ configuration_save ();
404+ }
372405 }
406+
373407}
374408
375409void MOcppMongooseClient::setChargeBoxId (const char *cb_id_cstr) {
@@ -378,10 +412,21 @@ void MOcppMongooseClient::setChargeBoxId(const char *cb_id_cstr) {
378412 return ;
379413 }
380414
381- if (setting_cb_id_str) {
382- setting_cb_id_str->setString (cb_id_cstr);
383- configuration_save ();
415+ #if MO_ENABLE_V201
416+ if (protocolVersion.major == 2 ) {
417+ if (v201identityString) {
418+ v201identityString->setString (cb_id_cstr);
419+ websocketSettings->commit ();
420+ }
421+ } else
422+ #endif
423+ {
424+ if (setting_cb_id_str) {
425+ setting_cb_id_str->setString (cb_id_cstr);
426+ configuration_save ();
427+ }
384428 }
429+
385430}
386431
387432void MOcppMongooseClient::setAuthKey (const char *auth_key_cstr) {
@@ -404,8 +449,8 @@ void MOcppMongooseClient::setAuthKey(const unsigned char *auth_key, size_t len)
404449 if (protocolVersion.major == 2 ) {
405450 char basicAuthPassword [MO_AUTHKEY_LEN_MAX + 1 ];
406451 snprintf (basicAuthPassword, sizeof (basicAuthPassword), " %.*s" , (int )len, auth_key ? (const char *)auth_key : " " );
407- if (basicAuthPasswordString ) {
408- basicAuthPasswordString ->setString (basicAuthPassword);
452+ if (v201basicAuthPasswordString ) {
453+ v201basicAuthPasswordString ->setString (basicAuthPassword);
409454 }
410455 } else
411456#endif
@@ -433,23 +478,32 @@ void MOcppMongooseClient::reloadConfigs() {
433478 /*
434479 * reload WS credentials from configs
435480 */
436- if (setting_backend_url_str) {
437- backend_url = setting_backend_url_str->getString ();
438- }
439-
440- if (setting_cb_id_str) {
441- cb_id = setting_cb_id_str->getString ();
442- }
443481
444482#if MO_ENABLE_V201
445483 if (protocolVersion.major == 2 ) {
446- if (basicAuthPasswordString) {
447- snprintf ((char *)auth_key, sizeof (auth_key), " %s" , basicAuthPasswordString->getString ());
484+ if (v201csmsUrlString) {
485+ backend_url = v201csmsUrlString->getString ();
486+ }
487+
488+ if (v201identityString) {
489+ cb_id = v201identityString->getString ();
490+ }
491+
492+ if (v201basicAuthPasswordString) {
493+ snprintf ((char *)auth_key, sizeof (auth_key), " %s" , v201basicAuthPasswordString->getString ());
448494 auth_key_len = strlen ((char *)auth_key);
449495 }
450496 } else
451497#endif
452498 {
499+ if (setting_backend_url_str) {
500+ backend_url = setting_backend_url_str->getString ();
501+ }
502+
503+ if (setting_cb_id_str) {
504+ cb_id = setting_cb_id_str->getString ();
505+ }
506+
453507 if (setting_auth_key_hex_str) {
454508 auto auth_key_hex = setting_auth_key_hex_str->getString ();
455509 auto auth_key_hex_len = strlen (setting_auth_key_hex_str->getString ());
@@ -531,8 +585,8 @@ unsigned long MOcppMongooseClient::getLastConnected() {
531585}
532586
533587#if MO_ENABLE_V201
534- std::shared_ptr< VariableContainer> MOcppMongooseClient::getVariableContainer () {
535- return websocketSettings;
588+ VariableContainer * MOcppMongooseClient::getVariableContainer () {
589+ return websocketSettings. get () ;
536590}
537591#endif
538592
0 commit comments