From bc9393271874e1d18c3e7e84f00dc210b9d3fc3d Mon Sep 17 00:00:00 2001 From: andig Date: Tue, 27 Aug 2024 21:35:11 +0200 Subject: [PATCH] Setting the scene --- charger/ocpp.go | 34 ++++++++++++++++++++++------------ 1 file changed, 22 insertions(+), 12 deletions(-) diff --git a/charger/ocpp.go b/charger/ocpp.go index c387463e59..21c9ca35c5 100644 --- a/charger/ocpp.go +++ b/charger/ocpp.go @@ -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 { @@ -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) } } @@ -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 } @@ -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 { @@ -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() }