From 94aeaa6edcf49fc97702a1d3da414019dee1f626 Mon Sep 17 00:00:00 2001 From: Thomas Vandahl Date: Thu, 5 Oct 2023 20:33:41 +0200 Subject: [PATCH] Ocpp: support phase switching (#10183) --- charger/ocpp.go | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/charger/ocpp.go b/charger/ocpp.go index bf7a964cf..27601b6a9 100644 --- a/charger/ocpp.go +++ b/charger/ocpp.go @@ -92,12 +92,10 @@ func NewOCPPFromConfig(other map[string]interface{}) (api.Charger, error) { currentsG = c.currents } - // removed to avoid sending phases when updating currents var phasesS func(int) error - // if c.phaseSwitching { - // phasesS = c.phases1p3p - // } - _ = c.phases1p3p + if c.phaseSwitching { + phasesS = c.phases1p3p + } return decorateOCPP(c, powerG, totalEnergyG, currentsG, phasesS), nil } @@ -398,9 +396,9 @@ func (c *OCPP) updatePeriod(current float64) error { } func (c *OCPP) getTxChargingProfile(current float64, transactionId int) *types.ChargingProfile { + phases := c.phases period := types.NewChargingSchedulePeriod(0, current) if c.chargingRateUnit == types.ChargingRateUnitWatts { - var phases int // get (expectedly) active phases from loadpoint if c.lp != nil { phases = c.lp.GetPhases() @@ -411,6 +409,11 @@ func (c *OCPP) getTxChargingProfile(current float64, transactionId int) *types.C period = types.NewChargingSchedulePeriod(0, math.Trunc(230.0*current*float64(phases))) } + // OCPP assumes phases == 3 if not set + if phases != 0 { + period.NumberPhases = &phases + } + return &types.ChargingProfile{ ChargingProfileId: 1, TransactionId: transactionId,