diff --git a/charger/ocpp/const.go b/charger/ocpp/const.go index be8458eaec..5e6bed0c07 100644 --- a/charger/ocpp/const.go +++ b/charger/ocpp/const.go @@ -20,6 +20,7 @@ const ( KeyMaxChargingProfilesInstalled = "MaxChargingProfilesInstalled" // Vendor specific keys + KeyAlfenAuthorizationMethod = "AuthorizationMethod" KeyAlfenPlugAndChargeIdentifier = "PlugAndChargeIdentifier" KeyEvBoxSupportedMeasurands = "evb_SupportedMeasurands" ) diff --git a/charger/ocpp/cp_core.go b/charger/ocpp/cp_core.go index ddb6dcb8a9..cf507d3811 100644 --- a/charger/ocpp/cp_core.go +++ b/charger/ocpp/cp_core.go @@ -21,6 +21,14 @@ func (cp *CP) Authorize(request *core.AuthorizeRequest) (*core.AuthorizeConfirma }, } + // Set idTag for all connectors in available state + for _, conn := range cp.connectors { + if conn.status.Status == core.ChargePointStatusAvailable { + conn.log.INFO.Printf("Set idTag %v from Authorization request", request.IdTag) + conn.idTag = request.IdTag + } + } + return res, nil } diff --git a/charger/ocpp/cp_setup.go b/charger/ocpp/cp_setup.go index 637b8b536f..0080dd3527 100644 --- a/charger/ocpp/cp_setup.go +++ b/charger/ocpp/cp_setup.go @@ -80,8 +80,13 @@ func (cp *CP) Setup(meterValues string, meterInterval time.Duration) error { // vendor-specific keys case KeyAlfenPlugAndChargeIdentifier: - cp.IdTag = *opt.Value - cp.log.DEBUG.Printf("overriding default `idTag` with Alfen-specific value: %s", cp.IdTag) + authMethod, ok := getConfigurationValue(resp, KeyAlfenAuthorizationMethod) + + // Override `idTag` with plug-and-charge id if PLUG_AND_CHARGE is configured + if ok && authMethod != "RFID" { + cp.IdTag = *opt.Value + cp.log.DEBUG.Printf("Alfen-specific: overriding `idTag` with PLUG_AND_CHARGE value: %s", cp.IdTag) + } case KeyEvBoxSupportedMeasurands: if meterValues == "" { @@ -146,6 +151,16 @@ func (cp *CP) Setup(meterValues string, meterInterval time.Duration) error { return nil } +// getConfigurationValue returns the value of a configuration key +func getConfigurationValue(resp *core.GetConfigurationConfirmation, key string) (string, bool) { + for _, opt := range resp.ConfigurationKey { + if opt.Key == key && opt.Value != nil { + return *opt.Value, true + } + } + return "", false +} + // GetConfiguration func (cp *CP) GetConfiguration() (*core.GetConfigurationConfirmation, error) { rc := make(chan error, 1)