@@ -2,6 +2,7 @@ package ocpp16
22
33import (
44 "fmt"
5+
56 "github.com/lorenzodonini/ocpp-go/ocpp"
67 "github.com/lorenzodonini/ocpp-go/ocppj"
78 "github.com/lorenzodonini/ocpp-go/ws"
@@ -243,7 +244,7 @@ func (cp *chargePoint) SendRequest(request ocpp.Request) (ocpp.Confirmation, err
243244func (cp * chargePoint ) SendRequestAsync (request ocpp.Request , callback func (confirmation ocpp.Confirmation , err error )) error {
244245 switch request .GetFeatureName () {
245246 case AuthorizeFeatureName , BootNotificationFeatureName , DataTransferFeatureName , HeartbeatFeatureName , MeterValuesFeatureName , StartTransactionFeatureName , StopTransactionFeatureName , StatusNotificationFeatureName ,
246- DiagnosticsStatusNotificationFeatureName , FirmwareStatusNotificationFeatureName :
247+ DiagnosticsStatusNotificationFeatureName , FirmwareStatusNotificationFeatureName :
247248 break
248249 default :
249250 return fmt .Errorf ("unsupported action %v on charge point, cannot send request" , request .GetFeatureName ())
@@ -281,6 +282,9 @@ func (cp *chargePoint) sendResponse(confirmation ocpp.Confirmation, err error, r
281282// Connects to the central system and starts the charge point routine.
282283// The function doesn't block and returns right away, after having attempted to open a connection to the central system.
283284// If the connection couldn't be opened, an error is returned.
285+ //
286+ // Optional client options must be set before calling this function. Refer to NewChargePoint.
287+ //
284288// No auto-reconnect logic is implemented as of now, but is planned for the future.
285289func (cp * chargePoint ) Start (centralSystemUrl string ) error {
286290 // TODO: implement auto-reconnect logic
@@ -405,7 +409,25 @@ func (cp *chargePoint) handleIncomingRequest(request ocpp.Request, requestId str
405409// The dispatcher and client parameters may be omitted, in order to use a default configuration:
406410// chargePoint := NewChargePoint("someUniqueId", nil, nil)
407411//
408- // It is recommended to use the default configuration, unless a custom networking / ocppj layer is required.
412+ // Additional networking parameters (e.g. TLS or proxy configuration) may be passed, by creating a custom client.
413+ // Here is an example for a client using TLS configuration with a self-signed certificate:
414+ // cp := NewChargePoint("someUniqueId", nil, ws.NewTLSClient(func (dialer *websocket.Dialer) {
415+ // certPool := x509.NewCertPool()
416+ // data, err := ioutil.ReadFile("serverSelfSignedCertFilename")
417+ // if err != nil {
418+ // log.Fatal(err)
419+ // }
420+ // ok = certPool.AppendCertsFromPEM(data)
421+ // if !ok {
422+ // log.Fatal("couldn't parse PEM certificate")
423+ // }
424+ // dialer.TLSClientConfig = &tls.Config{
425+ // RootCAs: certPool,
426+ // }
427+ // }))
428+ //
429+ // For more advanced options, or if a customer networking/occpj layer is required,
430+ // please refer to ocppj.ChargePoint and ws.WsClient.
409431func NewChargePoint (id string , dispatcher * ocppj.ChargePoint , client ws.WsClient ) ChargePoint {
410432 if client == nil {
411433 client = ws .NewClient ()
@@ -824,11 +846,11 @@ func (cs *centralSystem) SetChargePointDisconnectedHandler(handler func(chargePo
824846func (cs * centralSystem ) SendRequestAsync (clientId string , request ocpp.Request , callback func (confirmation ocpp.Confirmation , err error )) error {
825847 switch request .GetFeatureName () {
826848 case ChangeAvailabilityFeatureName , ChangeConfigurationFeatureName , ClearCacheFeatureName , DataTransferFeatureName , GetConfigurationFeatureName , RemoteStartTransactionFeatureName , RemoteStopTransactionFeatureName , ResetFeatureName , UnlockConnectorFeatureName ,
827- GetLocalListVersionFeatureName , SendLocalListFeatureName ,
828- GetDiagnosticsFeatureName , UpdateFirmwareFeatureName ,
829- ReserveNowFeatureName , CancelReservationFeatureName ,
830- TriggerMessageFeatureName ,
831- SetChargingProfileFeatureName , ClearChargingProfileFeatureName , GetCompositeScheduleFeatureName :
849+ GetLocalListVersionFeatureName , SendLocalListFeatureName ,
850+ GetDiagnosticsFeatureName , UpdateFirmwareFeatureName ,
851+ ReserveNowFeatureName , CancelReservationFeatureName ,
852+ TriggerMessageFeatureName ,
853+ SetChargingProfileFeatureName , ClearChargingProfileFeatureName , GetCompositeScheduleFeatureName :
832854 default :
833855 return fmt .Errorf ("unsupported action %v on central system, cannot send request" , request .GetFeatureName ())
834856 }
@@ -993,6 +1015,9 @@ func (cs *centralSystem) handleIncomingError(chargePointId string, err *ocpp.Err
9931015//
9941016// It is recommended to use the default configuration, unless a custom networking / ocppj layer is required.
9951017// The default dispatcher supports all OCPP 1.6 profiles out-of-the-box.
1018+ //
1019+ // If you need a TLS server, you may use the following:
1020+ // cs := NewCentralSystem(nil, ws.NewTLSServer("certificatePath", "privateKeyPath"))
9961021func NewCentralSystem (dispatcher * ocppj.CentralSystem , server ws.WsServer ) CentralSystem {
9971022 if server == nil {
9981023 server = ws .NewServer ()
0 commit comments