diff --git a/charger/ocpp.go b/charger/ocpp.go index 613ec677f..6c2a53e27 100644 --- a/charger/ocpp.go +++ b/charger/ocpp.go @@ -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 } @@ -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 diff --git a/charger/ocpp/connector.go b/charger/ocpp/connector.go index 1c7e807ad..cd283963b 100644 --- a/charger/ocpp/connector.go +++ b/charger/ocpp/connector.go @@ -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 @@ -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, } @@ -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 } diff --git a/charger/ocpp/connector_core.go b/charger/ocpp/connector_core.go index c851a6e3a..ab2c7ec29 100644 --- a/charger/ocpp/connector_core.go +++ b/charger/ocpp/connector_core.go @@ -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 }