Ocpp: split connection and runtime timeouts (#6898)
This commit is contained in:
parent
25ad1cf5cb
commit
ec8c763106
7 changed files with 37 additions and 16 deletions
|
|
@ -47,6 +47,7 @@ func NewOCPPFromConfig(other map[string]interface{}) (api.Charger, error) {
|
|||
Connector int
|
||||
MeterInterval time.Duration
|
||||
MeterValues string
|
||||
ConnectTimeout time.Duration
|
||||
Timeout time.Duration
|
||||
BootNotification *bool
|
||||
GetConfiguration *bool
|
||||
|
|
@ -54,9 +55,10 @@ func NewOCPPFromConfig(other map[string]interface{}) (api.Charger, error) {
|
|||
Quirks interface{} // TODO deprecated
|
||||
InitialReset interface{} // TODO deprecated
|
||||
}{
|
||||
Connector: 1,
|
||||
IdTag: defaultIdTag,
|
||||
Timeout: time.Minute,
|
||||
Connector: 1,
|
||||
IdTag: defaultIdTag,
|
||||
ConnectTimeout: 2 * time.Minute,
|
||||
Timeout: 2 * time.Minute,
|
||||
}
|
||||
|
||||
if err := util.DecodeOther(other, &cc); err != nil {
|
||||
|
|
@ -75,7 +77,10 @@ func NewOCPPFromConfig(other map[string]interface{}) (api.Charger, error) {
|
|||
boot := cc.BootNotification != nil && *cc.BootNotification
|
||||
noConfig := cc.GetConfiguration != nil && !*cc.GetConfiguration
|
||||
|
||||
c, err := NewOCPP(cc.StationId, cc.Connector, cc.IdTag, cc.MeterValues, cc.MeterInterval, boot, noConfig, cc.Timeout)
|
||||
c, err := NewOCPP(cc.StationId, cc.Connector, cc.IdTag,
|
||||
cc.MeterValues, cc.MeterInterval,
|
||||
boot, noConfig,
|
||||
cc.ConnectTimeout, cc.Timeout)
|
||||
if err != nil {
|
||||
return c, err
|
||||
}
|
||||
|
|
@ -106,7 +111,11 @@ func NewOCPPFromConfig(other map[string]interface{}) (api.Charger, error) {
|
|||
// go:generate go run ../cmd/tools/decorate.go -f decorateOCPP -b *OCPP -r api.Charger -t "api.Meter,CurrentPower,func() (float64, error)" -t "api.MeterEnergy,TotalEnergy,func() (float64, error)" -t "api.PhaseCurrents,Currents,func() (float64, float64, float64, error)" -t "api.PhaseSwitcher,Phases1p3p,func(int) (error)"
|
||||
|
||||
// NewOCPP creates OCPP charger
|
||||
func NewOCPP(id string, connector int, idtag string, meterValues string, meterInterval time.Duration, boot, noConfig bool, timeout time.Duration) (*OCPP, error) {
|
||||
func NewOCPP(id string, connector int, idtag string,
|
||||
meterValues string, meterInterval time.Duration,
|
||||
boot, noConfig bool,
|
||||
connectTimeout, timeout time.Duration,
|
||||
) (*OCPP, error) {
|
||||
unit := "ocpp"
|
||||
if id != "" {
|
||||
unit = id
|
||||
|
|
@ -126,10 +135,10 @@ func NewOCPP(id string, connector int, idtag string, meterValues string, meterIn
|
|||
timeout: timeout,
|
||||
}
|
||||
|
||||
c.log.DEBUG.Printf("waiting for chargepoint: %v", timeout)
|
||||
c.log.DEBUG.Printf("waiting for chargepoint: %v", connectTimeout)
|
||||
|
||||
select {
|
||||
case <-time.After(timeout):
|
||||
case <-time.After(connectTimeout):
|
||||
return nil, api.ErrTimeout
|
||||
case <-cp.HasConnected():
|
||||
}
|
||||
|
|
|
|||
|
|
@ -44,11 +44,12 @@ type CP struct {
|
|||
connector int
|
||||
|
||||
connectC, statusC chan struct{}
|
||||
updated time.Time
|
||||
status *core.StatusNotificationRequest
|
||||
|
||||
timeout time.Duration
|
||||
updated time.Time
|
||||
meterUpdated time.Time
|
||||
timeout time.Duration
|
||||
|
||||
measurements map[string]types.SampledValue
|
||||
|
||||
txnCount int // change initial value to the last known global transaction. Needs persistence
|
||||
|
|
@ -184,7 +185,7 @@ func (cp *CP) CurrentPower() (float64, error) {
|
|||
cp.mu.Lock()
|
||||
defer cp.mu.Unlock()
|
||||
|
||||
if cp.timeout > 0 && time.Since(cp.meterUpdated) > cp.timeout {
|
||||
if cp.txnId != 0 && cp.timeout > 0 && time.Since(cp.meterUpdated) > cp.timeout {
|
||||
return 0, api.ErrNotAvailable
|
||||
}
|
||||
|
||||
|
|
@ -202,7 +203,7 @@ func (cp *CP) TotalEnergy() (float64, error) {
|
|||
cp.mu.Lock()
|
||||
defer cp.mu.Unlock()
|
||||
|
||||
if cp.timeout > 0 && time.Since(cp.meterUpdated) > cp.timeout {
|
||||
if cp.txnId != 0 && cp.timeout > 0 && time.Since(cp.meterUpdated) > cp.timeout {
|
||||
return 0, api.ErrNotAvailable
|
||||
}
|
||||
|
||||
|
|
@ -235,7 +236,7 @@ func (cp *CP) Currents() (float64, float64, float64, error) {
|
|||
cp.mu.Lock()
|
||||
defer cp.mu.Unlock()
|
||||
|
||||
if cp.timeout > 0 && time.Since(cp.meterUpdated) > cp.timeout {
|
||||
if cp.txnId != 0 && cp.timeout > 0 && time.Since(cp.meterUpdated) > cp.timeout {
|
||||
return 0, 0, 0, api.ErrNotAvailable
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -11,4 +11,5 @@ render:
|
|||
stationid: EVB-P12354 # Die Stations-ID der Wallbox (oder des Ladepunkts) # Optional
|
||||
connector: 1 # Ladepunkt, normalerweise 1 für den ersten Anschluss. # Optional
|
||||
idtag: '04E6B78921BBA0' # Token-ID welche für die Freischaltung der Ladevorgänge an den Ladepunkt zurückgesendet wird # Optional
|
||||
timeout: 10m # Optional
|
||||
connecttimeout: 5m # Optional
|
||||
timeout: 2m # Optional
|
||||
|
|
|
|||
|
|
@ -26,6 +26,7 @@ render:
|
|||
stationid: EVB-P12354 # Die Stations-ID der Wallbox (oder des Ladepunkts) # Optional
|
||||
connector: 1 # Ladepunkt, normalerweise 1 für den ersten Anschluss. # Optional
|
||||
idtag: '04E6B78921BBA0' # Token-ID welche für die Freischaltung der Ladevorgänge an den Ladepunkt zurückgesendet wird # Optional
|
||||
timeout: 10m # Optional
|
||||
connecttimeout: 5m # Optional
|
||||
timeout: 2m # Optional
|
||||
getconfiguration: true # Deaktivierung kann bei einigen Chargern hilfreich sein # Optional
|
||||
bootnotification: false # Aktivierung kann bei einigen Chargern hilfreich sein # Optional
|
||||
|
|
|
|||
|
|
@ -11,4 +11,5 @@ render:
|
|||
stationid: EVB-P12354 # Die Stations-ID der Wallbox (oder des Ladepunkts) # Optional
|
||||
connector: 1 # Ladepunkt, normalerweise 1 für den ersten Anschluss. # Optional
|
||||
idtag: '04E6B78921BBA0' # Token-ID welche für die Freischaltung der Ladevorgänge an den Ladepunkt zurückgesendet wird # Optional
|
||||
timeout: 10m # Optional
|
||||
connecttimeout: 5m # Optional
|
||||
timeout: 2m # Optional
|
||||
|
|
|
|||
|
|
@ -363,8 +363,15 @@ presets:
|
|||
de: Token-ID welche für die Freischaltung der Ladevorgänge an den Ladepunkt zurückgesendet wird
|
||||
advanced: true
|
||||
example: 04E6B78921BBA0
|
||||
- name: connecttimeout
|
||||
description:
|
||||
de: Zeitlimit für Registrierung des Ladepunktes
|
||||
en: Timeout for initial connection
|
||||
advanced: true
|
||||
type: duration
|
||||
default: 5m
|
||||
- name: timeout
|
||||
default: 10m
|
||||
default: 2m
|
||||
|
||||
mqtt:
|
||||
params:
|
||||
|
|
|
|||
|
|
@ -9,5 +9,6 @@ connector: {{ .connector }}
|
|||
{{- if ne .idtag "" }}
|
||||
idtag: {{ .idtag }}
|
||||
{{- end }}
|
||||
connecttimeout: {{ .connecttimeout }}
|
||||
timeout: {{ .timeout }}
|
||||
{{- end }}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue