Skip to content
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
8 changes: 8 additions & 0 deletions charger/ocpp/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@ import "time"

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
// proactively triggering a BootNotification. This allows the connection to
// stabilize and gives the charger a chance to send a spontaneous BootNotification.
Expand Down
2 changes: 1 addition & 1 deletion charger/ocpp/cp_core.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ var (
func (cp *CP) OnBootNotification(request *core.BootNotificationRequest) (*core.BootNotificationConfirmation, error) {
res := &core.BootNotificationConfirmation{
CurrentTime: types.Now(),
Interval: 60,
Interval: int(heartbeatInterval.Seconds()),
Status: core.RegistrationStatusAccepted,
}

Expand Down
3 changes: 3 additions & 0 deletions charger/ocpp/cp_core_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ func TestBootNotificationStoresResultAndConnects(t *testing.T) {
require.NoError(t, err)
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
assert.True(t, cp.Connected(), "should be connected after BootNotification")
assert.Equal(t, bootReq, cp.BootNotificationResult, "should store boot result")
Expand Down
4 changes: 4 additions & 0 deletions charger/ocpp/instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,10 @@ func NewServer(cfg Config, networkExternalUrl string) {
server := &interceptingServer{Server: ws.NewServer()}
server.SetCheckOriginHandler(func(r *http.Request) bool { return true })

timeouts := ws.NewServerTimeoutConfig()
timeouts.PingWait = pingWait
server.SetTimeoutConfig(timeouts)

dispatcher := ocppj.NewDefaultServerDispatcher(ocppj.NewFIFOQueueMap(0))

endpoint := ocppj.NewServer(server, dispatcher, nil, core.Profile, remotetrigger.Profile, smartcharging.Profile, security.Profile, firmware.Profile)
Expand Down
Loading