OCPP: keep websocket alive between heartbeats (#33099)
This commit is contained in:
parent
83d322b5e9
commit
af4d14f65c
4 changed files with 16 additions and 1 deletions
|
|
@ -4,6 +4,14 @@ import "time"
|
||||||
|
|
||||||
var Timeout = time.Minute // default request / response timeout on protocol level
|
var Timeout = time.Minute // default request / response timeout on protocol level
|
||||||
|
|
||||||
|
const (
|
||||||
|
heartbeatInterval = time.Minute // heartbeat interval requested in BootNotification
|
||||||
|
|
||||||
|
// pingWait must exceed heartbeatInterval, otherwise chargers not sending
|
||||||
|
// websocket pings are disconnected while idle
|
||||||
|
pingWait = 3 * heartbeatInterval
|
||||||
|
)
|
||||||
|
|
||||||
// TriggerBootDelay defines how long to wait after WebSocket connect before
|
// TriggerBootDelay defines how long to wait after WebSocket connect before
|
||||||
// proactively triggering a BootNotification. This allows the connection to
|
// proactively triggering a BootNotification. This allows the connection to
|
||||||
// stabilize and gives the charger a chance to send a spontaneous BootNotification.
|
// stabilize and gives the charger a chance to send a spontaneous BootNotification.
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,7 @@ var (
|
||||||
func (cp *CP) OnBootNotification(request *core.BootNotificationRequest) (*core.BootNotificationConfirmation, error) {
|
func (cp *CP) OnBootNotification(request *core.BootNotificationRequest) (*core.BootNotificationConfirmation, error) {
|
||||||
res := &core.BootNotificationConfirmation{
|
res := &core.BootNotificationConfirmation{
|
||||||
CurrentTime: types.Now(),
|
CurrentTime: types.Now(),
|
||||||
Interval: 60,
|
Interval: int(heartbeatInterval.Seconds()),
|
||||||
Status: core.RegistrationStatusAccepted,
|
Status: core.RegistrationStatusAccepted,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -28,6 +28,9 @@ func TestBootNotificationStoresResultAndConnects(t *testing.T) {
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
assert.Equal(t, core.RegistrationStatusAccepted, res.Status)
|
assert.Equal(t, core.RegistrationStatusAccepted, res.Status)
|
||||||
|
|
||||||
|
// heartbeat must stay below the websocket inactivity timeout
|
||||||
|
assert.Less(t, time.Duration(res.Interval)*time.Second, pingWait)
|
||||||
|
|
||||||
// should be connected after BootNotification
|
// should be connected after BootNotification
|
||||||
assert.True(t, cp.Connected(), "should be connected after BootNotification")
|
assert.True(t, cp.Connected(), "should be connected after BootNotification")
|
||||||
assert.Equal(t, bootReq, cp.BootNotificationResult, "should store boot result")
|
assert.Equal(t, bootReq, cp.BootNotificationResult, "should store boot result")
|
||||||
|
|
|
||||||
|
|
@ -140,6 +140,10 @@ func NewServer(cfg Config, networkExternalUrl string) {
|
||||||
server := &interceptingServer{Server: ws.NewServer()}
|
server := &interceptingServer{Server: ws.NewServer()}
|
||||||
server.SetCheckOriginHandler(func(r *http.Request) bool { return true })
|
server.SetCheckOriginHandler(func(r *http.Request) bool { return true })
|
||||||
|
|
||||||
|
timeouts := ws.NewServerTimeoutConfig()
|
||||||
|
timeouts.PingWait = pingWait
|
||||||
|
server.SetTimeoutConfig(timeouts)
|
||||||
|
|
||||||
dispatcher := ocppj.NewDefaultServerDispatcher(ocppj.NewFIFOQueueMap(0))
|
dispatcher := ocppj.NewDefaultServerDispatcher(ocppj.NewFIFOQueueMap(0))
|
||||||
|
|
||||||
endpoint := ocppj.NewServer(server, dispatcher, nil, core.Profile, remotetrigger.Profile, smartcharging.Profile, security.Profile, firmware.Profile)
|
endpoint := ocppj.NewServer(server, dispatcher, nil, core.Profile, remotetrigger.Profile, smartcharging.Profile, security.Profile, firmware.Profile)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue