From 3e24c9103cce2d9b3b222b536faf48d19d103e49 Mon Sep 17 00:00:00 2001 From: premultiply <4681172+premultiply@users.noreply.github.com> Date: Mon, 19 Aug 2024 09:39:18 +0200 Subject: [PATCH] Ocpp: compatibility enhancements (#15479) --- charger/ocpp.go | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/charger/ocpp.go b/charger/ocpp.go index df27c92e8..8538f5004 100644 --- a/charger/ocpp.go +++ b/charger/ocpp.go @@ -42,7 +42,7 @@ type OCPP struct { const ( defaultIdTag = "evcc" // RemoteStartTransaction only - desiredMeasurands = "Energy.Active.Import.Register,Power.Active.Import,SoC,Current.Offered,Power.Offered,Current.Import,Voltage" + desiredMeasurands = "Power.Active.Import,Energy.Active.Import.Register,SoC,Current.Offered,Power.Offered,Current.Import,Voltage" ) func init() { @@ -179,13 +179,10 @@ func NewOCPP(id string, connector int, idtag string, // fix timing issue in EVBox when switching OCPP protocol version time.Sleep(time.Second) - var ( - rc = make(chan error, 1) + var rc = make(chan error, 1) - // If a key value is defined as a CSL, it MAY be accompanied with a [KeyName]MaxLength key, indicating the - // max length of the CSL in items. If this key is not set, a safe value of 1 (one) item SHOULD be assumed. - meterValuesSampledDataMaxLength = 1 - ) + meterValuesSampledData := "" + meterValuesSampledDataMaxLength := len(strings.Split(desiredMeasurands, ",")) err = ocpp.Instance().GetConfiguration(cp.ID(), func(resp *core.GetConfigurationConfirmation, err error) { if err == nil { @@ -216,6 +213,12 @@ func NewOCPP(id string, connector int, idtag string, c.chargingProfileId = val } + case ocpp.KeyMeterValuesSampledData: + if opt.Readonly { + meterValuesSampledDataMaxLength = 0 + } + meterValuesSampledData = *opt.Value + case ocpp.KeyMeterValuesSampledDataMaxLength: if val, err := strconv.Atoi(*opt.Value); err == nil { meterValuesSampledDataMaxLength = val @@ -229,7 +232,7 @@ func NewOCPP(id string, connector int, idtag string, case ocpp.KeySupportedFeatureProfiles: if !c.hasProperty(*opt.Value, smartcharging.ProfileName) { - err = fmt.Errorf("the mandatory SmartCharging profile is not supported") + c.log.WARN.Printf("the required SmartCharging feature profile is not indicated as supported") } c.hasRemoteTriggerFeature = c.hasProperty(*opt.Value, remotetrigger.ProfileName) @@ -281,12 +284,12 @@ func NewOCPP(id string, connector int, idtag string, // configure measurands if meterValues != "" { - if err := c.configure(ocpp.KeyMeterValuesSampledData, meterValues); err != nil { - return nil, err + if err := c.configure(ocpp.KeyMeterValuesSampledData, meterValues); err == nil { + meterValuesSampledData = meterValues } } - c.meterValuesSample = meterValues + c.meterValuesSample = meterValuesSampledData // trigger initial meter values if c.hasRemoteTriggerFeature {