diff --git a/charger/ocpp/connector.go b/charger/ocpp/connector.go index e0348123d5..3f24bb60b5 100644 --- a/charger/ocpp/connector.go +++ b/charger/ocpp/connector.go @@ -50,16 +50,16 @@ func NewConnector(log *util.Logger, id int, cp *CP, idTag string) (*Connector, e } // trigger status for all connectors - if cp.HasRemoteTriggerFeature { - var ok bool - // apply cached status if available - instance.WithConnectorStatus(cp.ID(), id, func(status *core.StatusNotificationRequest) { - if _, err := cp.OnStatusNotification(status); err == nil { - ok = true - } - }) + var ok bool + // apply cached status if available + instance.WithConnectorStatus(cp.ID(), id, func(status *core.StatusNotificationRequest) { + if _, err := cp.OnStatusNotification(status); err == nil { + ok = true + } + }) + if cp.HasRemoteTriggerFeature { // only trigger if we don't already have a status if !ok { if err := cp.TriggerMessageRequest(0, core.StatusNotificationFeatureName); err != nil { @@ -110,7 +110,9 @@ func (conn *Connector) WatchDog(timeout time.Duration) { conn.mu.Unlock() if update { - conn.TriggerMessageRequest(core.MeterValuesFeatureName) + if conn.cp.HasRemoteTriggerFeature { + conn.TriggerMessageRequest(core.MeterValuesFeatureName) + } } } } @@ -125,7 +127,9 @@ func (conn *Connector) Initialized() error { return nil case <-trigger: // try to trigger StatusNotification again as last resort - conn.TriggerMessageRequest(core.StatusNotificationFeatureName) + if conn.cp.HasRemoteTriggerFeature { + conn.TriggerMessageRequest(core.StatusNotificationFeatureName) + } case <-timeout: return api.ErrTimeout diff --git a/charger/ocpp/cs.go b/charger/ocpp/cs.go index 59ddd656fc..677e14ddf5 100644 --- a/charger/ocpp/cs.go +++ b/charger/ocpp/cs.go @@ -133,8 +133,7 @@ func (cs *CS) NewChargePoint(chargePoint ocpp16.ChargePointConnection) { // update id cp.RegisterID(chargePoint.ID()) - - cs.regs[chargePoint.ID()].cp = cp + cs.regs[chargePoint.ID()] = reg delete(cs.regs, "") cp.connect(true) diff --git a/charger/ocpp/cs_core.go b/charger/ocpp/cs_core.go index 9801280f42..d56e7e325c 100644 --- a/charger/ocpp/cs_core.go +++ b/charger/ocpp/cs_core.go @@ -62,19 +62,18 @@ func (cs *CS) OnMeterValues(id string, request *core.MeterValuesRequest) (*core. } func (cs *CS) OnStatusNotification(id string, request *core.StatusNotificationRequest) (*core.StatusNotificationConfirmation, error) { - if cp, err := cs.ChargepointByID(id); err == nil { - return cp.OnStatusNotification(request) - } - cs.mu.Lock() - defer cs.mu.Unlock() - // cache status for future cp connection if reg, ok := cs.regs[id]; ok && request != nil { reg.mu.Lock() reg.status[request.ConnectorId] = request reg.mu.Unlock() } + cs.mu.Unlock() + + if cp, err := cs.ChargepointByID(id); err == nil { + return cp.OnStatusNotification(request) + } return new(core.StatusNotificationConfirmation), nil }