@@ -200,10 +200,10 @@ void ChargePoint::stop() {
200
200
this ->message_queue ->stop ();
201
201
}
202
202
203
- void ChargePoint::connect_websocket () {
203
+ void ChargePoint::connect_websocket (std::optional<std::string> config_slot ) {
204
204
if (!this ->websocket ->is_connected ()) {
205
205
this ->disable_automatic_websocket_reconnects = false ;
206
- this ->init_websocket ();
206
+ this ->init_websocket (config_slot );
207
207
this ->websocket ->connect ();
208
208
}
209
209
}
@@ -647,19 +647,23 @@ bool ChargePoint::send(CallError call_error) {
647
647
return true ;
648
648
}
649
649
650
- void ChargePoint::init_websocket () {
650
+ void ChargePoint::init_websocket (std::optional<std::string> config_slot) {
651
+
652
+ std::string configuration_slot;
651
653
if (this ->device_model ->get_value <std::string>(ControllerComponentVariables::ChargePointId).find (' :' ) !=
652
654
std::string::npos) {
653
655
EVLOG_AND_THROW (std::runtime_error (" ChargePointId must not contain \' :\' " ));
654
656
}
655
657
656
- const auto configuration_slot =
657
- ocpp::get_vector_from_csv (
658
- this ->device_model ->get_value <std::string>(ControllerComponentVariables::NetworkConfigurationPriority))
659
- .at (this ->network_configuration_priority );
660
-
661
- EVLOG_info << " congfig -------> : " << configuration_slot.size ();
662
-
658
+ if (config_slot.has_value ()) {
659
+ EVLOG_info << " using configuration slot --->" << config_slot.value ();
660
+ configuration_slot = config_slot.value ();
661
+ } else {
662
+ configuration_slot = ocpp::get_vector_from_csv (this ->device_model ->get_value <std::string>(
663
+ ControllerComponentVariables::NetworkConfigurationPriority))
664
+ .at (this ->network_configuration_priority );
665
+ }
666
+ EVLOG_info << " config -------> : " << configuration_slot.size ();
663
667
const auto connection_options = this ->get_ws_connection_options (std::stoi (configuration_slot));
664
668
const auto network_connection_profile = this ->get_network_connection_profile (std::stoi (configuration_slot));
665
669
@@ -674,7 +678,7 @@ void ChargePoint::init_websocket() {
674
678
switch (status = config_status.wait_for (std::chrono::seconds (config_timeout.value ())); status) {
675
679
case std::future_status::deferred:
676
680
case std::future_status::timeout:
677
- EVLOG_info << " timeout or deferred" ;
681
+ EVLOG_info << " ======== timeout or deferred======== " ;
678
682
EVLOG_warning
679
683
<< " NetworkConnectionProfile could not be retrieved or configuration of network with the given "
680
684
" profile failed" ;
@@ -757,7 +761,7 @@ void ChargePoint::init_websocket() {
757
761
}
758
762
// call the disconnected callback if it exists
759
763
if (this ->callbacks .websocket_disconnected_callback .has_value ()) {
760
- this ->callbacks .websocket_disconnected_callback .value ();
764
+ this ->callbacks .websocket_disconnected_callback .value ()() ;
761
765
}
762
766
this ->client_certificate_expiration_check_timer .stop ();
763
767
this ->v2g_certificate_expiration_check_timer .stop ();
@@ -774,7 +778,9 @@ void ChargePoint::init_websocket() {
774
778
[this , reason]() {
775
779
if (reason != websocketpp::close ::status::service_restart) {
776
780
this ->next_network_configuration_priority ();
781
+ EVLOG_info << " next network config ---->" ;
777
782
}
783
+ EVLOG_info << " start websocket after close---->" ;
778
784
this ->start_websocket ();
779
785
},
780
786
WEBSOCKET_INIT_DELAY);
@@ -3016,7 +3022,27 @@ void ChargePoint::set_connector_operative_status(int32_t evse_id, int32_t connec
3016
3022
3017
3023
bool ChargePoint::on_try_switch_network_connection_profile (const std::string configuration_slot) {
3018
3024
EVLOG_info << " =============on_try_switch_network_profile============" << configuration_slot;
3019
- return false ;
3025
+
3026
+ // check if the configuration slot is valid
3027
+ try
3028
+ {
3029
+ // call disconnect
3030
+ this ->disconnect_websocket (); // normal close
3031
+ while (!this ->is_offline ())
3032
+ {
3033
+ /* code */
3034
+ }
3035
+
3036
+ // call connect with the config_slot option
3037
+ this ->connect_websocket (configuration_slot);
3038
+ return true ;
3039
+
3040
+ }
3041
+ catch (std::exception &e)
3042
+ {
3043
+ EVLOG_info << " ERROR===============>" ;
3044
+ return false ;
3045
+ }
3020
3046
}
3021
3047
bool ChargePoint::are_all_connectors_effectively_inoperative () {
3022
3048
// Check that all connectors on all EVSEs are inoperative
0 commit comments