Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OCPP: allow waiting for meter values #15226

Merged
merged 6 commits into from
Aug 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion charger/ocpp.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ func NewOCPP(id string, connector int, idtag string,
conn.TriggerMessageRequest(core.BootNotificationFeatureName)
select {
case <-time.After(timeout):
c.log.DEBUG.Printf("BootNotification timeout")
c.log.WARN.Printf("boot notification timeout")
case res := <-cp.BootNotificationRequest():
c.bootNotification = res
}
Expand Down Expand Up @@ -285,6 +285,13 @@ func NewOCPP(id string, connector int, idtag string,
if c.hasMeasurement(types.MeasurandPowerActiveImport) || c.hasMeasurement(types.MeasurandEnergyActiveImportRegister) {
conn.TriggerMessageRequest(core.MeterValuesFeatureName)

// wait for meter values
select {
case <-time.After(timeout):
c.log.WARN.Println("meter value timeout")
case <-c.conn.MeterSampled():
}

if meterInterval > 0 && meterInterval != meterSampleInterval {
if err := c.configure(ocpp.KeyMeterValueSampleInterval, strconv.Itoa(int(meterInterval.Seconds()))); err != nil {
return nil, err
Expand Down
6 changes: 6 additions & 0 deletions charger/ocpp/connector.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ type Connector struct {

status *core.StatusNotificationRequest
statusC chan struct{}
meterC chan map[types.Measurand]types.SampledValue

meterUpdated time.Time
measurements map[types.Measurand]types.SampledValue
Expand All @@ -42,6 +43,7 @@ func NewConnector(log *util.Logger, id int, cp *CP, timeout time.Duration) (*Con
clock: clock.New(),
statusC: make(chan struct{}),
measurements: make(map[types.Measurand]types.SampledValue),
meterC: make(chan map[types.Measurand]types.SampledValue),
timeout: timeout,
}

Expand All @@ -54,6 +56,10 @@ func (conn *Connector) TestClock(clock clock.Clock) {
conn.clock = clock
}

func (conn *Connector) MeterSampled() <-chan map[types.Measurand]types.SampledValue {
return conn.meterC
}

func (conn *Connector) ChargePoint() *CP {
return conn.cp
}
Expand Down
5 changes: 5 additions & 0 deletions charger/ocpp/connector_core.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,11 @@ func (conn *Connector) MeterValues(request *core.MeterValuesRequest) (*core.Mete
}
}

select {
case conn.meterC <- conn.measurements:
default:
}

return new(core.MeterValuesConfirmation), nil
}

Expand Down