Skip to content

Commit

Permalink
Setting the scene
Browse files Browse the repository at this point in the history
  • Loading branch information
andig committed Aug 27, 2024
1 parent e6d3ad3 commit bc93932
Showing 1 changed file with 22 additions and 12 deletions.
34 changes: 22 additions & 12 deletions charger/ocpp.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ func NewOCPP(id string, connector int, idtag string,

rc := make(chan error, 1)

// CP
err = ocpp.Instance().GetConfiguration(cp.ID(), func(resp *core.GetConfigurationConfirmation, err error) {
if err == nil {
for _, opt := range resp.ConfigurationKey {
Expand Down Expand Up @@ -273,21 +274,18 @@ func NewOCPP(id string, connector int, idtag string,

// see who's there
if c.hasRemoteTriggerFeature {
if err := conn.TriggerMessageRequest(core.StatusNotificationFeatureName); err != nil {
c.log.DEBUG.Printf("failed triggering StatusNotification: %v", err)
// CP
if err := ocpp.Instance().TriggerMessageRequest(cp.ID(), core.BootNotificationFeatureName); err != nil {
c.log.DEBUG.Printf("failed triggering BootNotification: %v", err)
}

if err := ocpp.Instance().TriggerMessageRequest(cp.ID(), core.BootNotificationFeatureName); err == nil {
select {
case <-time.After(timeout):
c.log.DEBUG.Printf("BootNotification timeout")
case res := <-cp.BootNotificationRequest():
if res != nil {
c.bootNotification = res
}
select {
case <-time.After(timeout):
c.log.DEBUG.Printf("BootNotification timeout")
case res := <-cp.BootNotificationRequest():
if res != nil {
c.bootNotification = res
}
} else {
c.log.DEBUG.Printf("failed triggering BootNotification: %v", err)
}
}

Expand All @@ -299,6 +297,7 @@ func NewOCPP(id string, connector int, idtag string,

// configure measurands
if meterValues != "" {
// CP
if err := c.configure(ocpp.KeyMeterValuesSampledData, meterValues); err == nil {
meterValuesSampledData = meterValues
}
Expand All @@ -308,6 +307,7 @@ func NewOCPP(id string, connector int, idtag string,

// trigger initial meter values
if c.hasRemoteTriggerFeature {
// CP
if err := conn.TriggerMessageRequest(core.MeterValuesFeatureName); err == nil {
// wait for meter values
select {
Expand All @@ -320,18 +320,28 @@ func NewOCPP(id string, connector int, idtag string,

// configure sample rate
if meterInterval > 0 {
// CP
if err := c.configure(ocpp.KeyMeterValueSampleInterval, strconv.Itoa(int(meterInterval.Seconds()))); err != nil {
c.log.WARN.Printf("failed configuring MeterValueSampleInterval: %v", err)
}
}

if c.hasRemoteTriggerFeature {
// CP
go conn.WatchDog(10 * time.Second)
}

// configure ping interval
// CP
c.configure(ocpp.KeyWebSocketPingInterval, "30")

// CONN
if c.hasRemoteTriggerFeature {
if err := conn.TriggerMessageRequest(core.StatusNotificationFeatureName); err != nil {
c.log.DEBUG.Printf("failed triggering StatusNotification: %v", err)
}
}

return c, conn.Initialized()
}

Expand Down

0 comments on commit bc93932

Please sign in to comment.