ocpp

package
v0.6.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 23, 2026 License: MIT Imports: 13 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const (
	MessageTypeCall       = 2
	MessageTypeCallResult = 3
	MessageTypeCallError  = 4
)

OCPP 1.6 Message Types

View Source
const (
	ActionBootNotification       = "BootNotification"
	ActionHeartbeat              = "Heartbeat"
	ActionStatusNotification     = "StatusNotification"
	ActionStartTransaction       = "StartTransaction"
	ActionStopTransaction        = "StopTransaction"
	ActionMeterValues            = "MeterValues"
	ActionRemoteStartTransaction = "RemoteStartTransaction"
	ActionRemoteStopTransaction  = "RemoteStopTransaction"
	ActionChangeConfiguration    = "ChangeConfiguration"
	ActionGetConfiguration       = "GetConfiguration"
	ActionReset                  = "Reset"
	ActionSetChargingProfile     = "SetChargingProfile"
	ActionClearChargingProfile   = "ClearChargingProfile"
	ActionGetLocalListVersion    = "GetLocalListVersion"
	ActionSendLocalList          = "SendLocalList"
	ActionTriggerMessage         = "TriggerMessage"
	ActionUnlockConnector        = "UnlockConnector"
	ActionDataTransfer           = "DataTransfer"
	ActionChangeAvailability     = "ChangeAvailability"
	ActionClearCache             = "ClearCache"
	ActionGetCompositeSchedule   = "GetCompositeSchedule"
)

OCPP 1.6 Actions

View Source
const (
	StatusAvailable     = "Available"     // No vehicle plugged in, ready for new vehicle
	StatusPreparing     = "Preparing"     // Vehicle plugged in, waiting for auth/communication
	StatusCharging      = "Charging"      // Actively charging
	StatusSuspendedEVSE = "SuspendedEVSE" // Vehicle plugged in, charger not delivering power (charger-side reason)
	StatusSuspendedEV   = "SuspendedEV"   // Vehicle plugged in, vehicle not accepting power (vehicle-side reason)
	StatusFinishing     = "Finishing"     // Charging ended, vehicle still plugged in
	StatusReserved      = "Reserved"      // Reserved for specific user/vehicle
	StatusUnavailable   = "Unavailable"   // Not available (maintenance, restart pending)
	StatusFaulted       = "Faulted"       // Experiencing fault or issue
)

Connector Status values (OCPP 1.6)

Variables

View Source
var (
	ErrInvalidMessage = &OCPPError{Code: "FormationViolation", Description: "Invalid message format"}
)

Error types

Functions

func CreateCallErrorMessage

func CreateCallErrorMessage(messageId, errorCode, errorDescription string, errorDetails interface{}) ([]byte, error)

CreateCallErrorMessage creates an OCPP CallError message

func CreateCallMessage

func CreateCallMessage(messageId, action string, payload interface{}) ([]byte, error)

CreateCallMessage creates an OCPP Call message

func CreateCallResultMessage

func CreateCallResultMessage(messageId string, payload interface{}) ([]byte, error)

CreateCallResultMessage creates an OCPP CallResult message

func FormatTimestamp

func FormatTimestamp(t time.Time) string

FormatTimestamp formats a time as OCPP timestamp

func ParseOCPPMessage

func ParseOCPPMessage(data []byte) (messageType int, messageId string, action string, payload json.RawMessage, err error)

ParseOCPPMessage parses an OCPP WebSocket message

Types

type AuthorizationData

type AuthorizationData struct {
	IdTag     string    `json:"idTag"`
	IdTagInfo IdTagInfo `json:"idTagInfo,omitempty"`
}

AuthorizationData represents an authorization entry in the local list

type BootNotificationRequest

type BootNotificationRequest struct {
	ChargePointVendor       string `json:"chargePointVendor"`
	ChargePointModel        string `json:"chargePointModel"`
	ChargePointSerialNumber string `json:"chargePointSerialNumber,omitempty"`
	ChargeBoxSerialNumber   string `json:"chargeBoxSerialNumber,omitempty"`
	FirmwareVersion         string `json:"firmwareVersion,omitempty"`
	Iccid                   string `json:"iccid,omitempty"`
	Imsi                    string `json:"imsi,omitempty"`
	MeterType               string `json:"meterType,omitempty"`
	MeterSerialNumber       string `json:"meterSerialNumber,omitempty"`
}

BootNotificationRequest represents a BootNotification.req

type BootNotificationResponse

type BootNotificationResponse struct {
	Status      string `json:"status"`
	CurrentTime string `json:"currentTime"`
	Interval    int    `json:"interval"`
}

BootNotificationResponse represents a BootNotification.conf

type ChangeAvailabilityRequest

type ChangeAvailabilityRequest struct {
	ConnectorId int    `json:"connectorId"`
	Type        string `json:"type"` // Operative or Inoperative
}

ChangeAvailabilityRequest represents a ChangeAvailability.req from central system

type ChangeAvailabilityResponse

type ChangeAvailabilityResponse struct {
	Status string `json:"status"` // Accepted, Rejected, Scheduled
}

ChangeAvailabilityResponse represents a ChangeAvailability.conf

type ChangeConfigurationRequest

type ChangeConfigurationRequest struct {
	Key   string `json:"key"`
	Value string `json:"value"`
}

ChangeConfigurationRequest represents a ChangeConfiguration.req from central system

type ChangeConfigurationResponse

type ChangeConfigurationResponse struct {
	Status string `json:"status"` // Accepted, Rejected, RebootRequired, NotSupported
}

ChangeConfigurationResponse represents a ChangeConfiguration.conf

type ChargingProfile

type ChargingProfile struct {
	ChargingProfileId      int64            `json:"chargingProfileId"`
	TransactionId          *int64           `json:"transactionId,omitempty"`
	StackLevel             int              `json:"stackLevel"`
	ChargingProfilePurpose string           `json:"chargingProfilePurpose"`
	ChargingProfileKind    string           `json:"chargingProfileKind"`
	RecurrencyKind         string           `json:"recurrencyKind,omitempty"`
	ValidFrom              string           `json:"validFrom,omitempty"`
	ValidTo                string           `json:"validTo,omitempty"`
	ChargingSchedule       ChargingSchedule `json:"chargingSchedule"`
}

ChargingProfile represents a ChargingProfile object (OCPP 1.6) Note: Date fields are kept as strings to avoid parsing at the emulator layer.

type ChargingSchedule

type ChargingSchedule struct {
	Duration               *int64                   `json:"duration,omitempty"`
	StartSchedule          string                   `json:"startSchedule,omitempty"`
	ChargingRateUnit       string                   `json:"chargingRateUnit"`
	ChargingSchedulePeriod []ChargingSchedulePeriod `json:"chargingSchedulePeriod"`
	MinChargingRate        *float64                 `json:"minChargingRate,omitempty"`
}

ChargingSchedule represents a ChargingSchedule object (OCPP 1.6)

type ChargingSchedulePeriod

type ChargingSchedulePeriod struct {
	StartPeriod  int64   `json:"startPeriod"`
	Limit        float64 `json:"limit"`
	NumberPhases *int    `json:"numberPhases,omitempty"`
}

ChargingSchedulePeriod represents a ChargingSchedulePeriod object (OCPP 1.6)

type ClearCacheRequest

type ClearCacheRequest struct{}

ClearCacheRequest represents a ClearCache.req from central system

type ClearCacheResponse

type ClearCacheResponse struct {
	Status string `json:"status"` // Accepted, Rejected
}

ClearCacheResponse represents a ClearCache.conf

type ClearChargingProfileRequest

type ClearChargingProfileRequest struct {
	Id                     *int64 `json:"id,omitempty"`
	ConnectorId            *int   `json:"connectorId,omitempty"`
	ChargingProfilePurpose string `json:"chargingProfilePurpose,omitempty"`
	StackLevel             *int   `json:"stackLevel,omitempty"`
}

ClearChargingProfileRequest represents a ClearChargingProfile.req

type ClearChargingProfileResponse

type ClearChargingProfileResponse struct {
	Status string `json:"status"`
}

ClearChargingProfileResponse represents a ClearChargingProfile.conf

type ConfigurationKey

type ConfigurationKey struct {
	Key      string `json:"key"`
	Readonly bool   `json:"readonly"`
	Value    string `json:"value,omitempty"`
}

ConfigurationKey represents a single configuration key-value pair

type Connector

type Connector struct {
	ID           int     `json:"id"`
	Status       string  `json:"status"`
	ErrorCode    string  `json:"errorCode"`
	CurrentPower float64 `json:"currentPower"`
	EnergyWh     float64 `json:"energyWh"`
}

Connector represents a charging connector

type DataTransferRequest

type DataTransferRequest struct {
	VendorId  string `json:"vendorId"`
	MessageId string `json:"messageId,omitempty"`
	Data      string `json:"data,omitempty"`
}

DataTransferRequest represents a DataTransfer.req from central system

type DataTransferResponse

type DataTransferResponse struct {
	Status string `json:"status"`
	Data   string `json:"data,omitempty"`
}

DataTransferResponse represents a DataTransfer.conf

type GetCompositeScheduleRequest

type GetCompositeScheduleRequest struct {
	ConnectorId      int    `json:"connectorId"`
	Duration         int    `json:"duration"`
	ChargingRateUnit string `json:"chargingRateUnit,omitempty"` // W or A
}

GetCompositeScheduleRequest represents a GetCompositeSchedule.req from central system

type GetCompositeScheduleResponse

type GetCompositeScheduleResponse struct {
	Status           string            `json:"status"` // Accepted, Rejected
	ConnectorId      *int              `json:"connectorId,omitempty"`
	ScheduleStart    string            `json:"scheduleStart,omitempty"`
	ChargingSchedule *ChargingSchedule `json:"chargingSchedule,omitempty"`
}

GetCompositeScheduleResponse represents a GetCompositeSchedule.conf

type GetConfigurationRequest

type GetConfigurationRequest struct {
	Key []string `json:"key,omitempty"`
}

GetConfigurationRequest represents a GetConfiguration.req from central system

type GetConfigurationResponse

type GetConfigurationResponse struct {
	ConfigurationKey []ConfigurationKey `json:"configurationKey,omitempty"`
	UnknownKey       []string           `json:"unknownKey,omitempty"`
}

GetConfigurationResponse represents a GetConfiguration.conf

type GetLocalListVersionRequest

type GetLocalListVersionRequest struct{}

GetLocalListVersionRequest represents a GetLocalListVersion.req from central system

type GetLocalListVersionResponse

type GetLocalListVersionResponse struct {
	ListVersion int `json:"listVersion"`
}

GetLocalListVersionResponse represents a GetLocalListVersion.conf

type HeartbeatRequest

type HeartbeatRequest struct{}

HeartbeatRequest represents a Heartbeat.req

type HeartbeatResponse

type HeartbeatResponse struct {
	CurrentTime string `json:"currentTime"`
}

HeartbeatResponse represents a Heartbeat.conf

type IdTagInfo

type IdTagInfo struct {
	ExpiryDate  string `json:"expiryDate,omitempty"`
	ParentIdTag string `json:"parentIdTag,omitempty"`
	Status      string `json:"status"`
}

IdTagInfo represents authorization info

type MeterValue

type MeterValue struct {
	Timestamp    string         `json:"timestamp"`
	SampledValue []SampledValue `json:"sampledValue"`
}

MeterValue represents a meter value sample

type MeterValuesDebug

type MeterValuesDebug struct {
	VoltageL1    float64                `json:"voltage_L1"`
	VoltageL2    float64                `json:"voltage_L2"`
	VoltageL3    float64                `json:"voltage_L3"`
	CurrentL1    float64                `json:"current_L1"`
	CurrentL2    float64                `json:"current_L2"`
	CurrentL3    float64                `json:"current_L3"`
	PowerW       float64                `json:"power_W"`
	EnergyWh     float64                `json:"energy_Wh"`
	SampleJSON   string                 `json:"sample_meter_values_json"`
	ExpectedCSMS map[string]interface{} `json:"expected_csms_output"`
}

MeterValuesDebug contains debug information about current meter values

type MeterValuesRequest

type MeterValuesRequest struct {
	ConnectorId   int          `json:"connectorId"`
	TransactionId int          `json:"transactionId,omitempty"`
	MeterValue    []MeterValue `json:"meterValue"`
}

MeterValuesRequest represents a MeterValues.req

type MeterValuesResponse

type MeterValuesResponse struct{}

MeterValuesResponse represents a MeterValues.conf

type OCPPError

type OCPPError struct {
	Code        string
	Description string
}

OCPPError represents an OCPP error

func (*OCPPError) Error

func (e *OCPPError) Error() string

type RemoteStartTransactionRequest

type RemoteStartTransactionRequest struct {
	ConnectorId     int              `json:"connectorId,omitempty"`
	IdTag           string           `json:"idTag"`
	ChargingProfile *ChargingProfile `json:"chargingProfile,omitempty"`
}

RemoteStartTransactionRequest represents a RemoteStartTransaction.req from central system

type RemoteStartTransactionResponse

type RemoteStartTransactionResponse struct {
	Status string `json:"status"`
}

RemoteStartTransactionResponse represents a RemoteStartTransaction.conf

type RemoteStopTransactionRequest

type RemoteStopTransactionRequest struct {
	TransactionId int `json:"transactionId"`
}

RemoteStopTransactionRequest represents a RemoteStopTransaction.req from central system

type RemoteStopTransactionResponse

type RemoteStopTransactionResponse struct {
	Status string `json:"status"`
}

RemoteStopTransactionResponse represents a RemoteStopTransaction.conf

type ResetRequest

type ResetRequest struct {
	Type string `json:"type"` // Hard or Soft
}

ResetRequest represents a Reset.req from central system

type ResetResponse

type ResetResponse struct {
	Status string `json:"status"` // Accepted, Rejected
}

ResetResponse represents a Reset.conf

type SampledValue

type SampledValue struct {
	Value     string `json:"value"`
	Context   string `json:"context,omitempty"`
	Format    string `json:"format,omitempty"`
	Measurand string `json:"measurand,omitempty"`
	Phase     string `json:"phase,omitempty"`
	Location  string `json:"location,omitempty"`
	Unit      string `json:"unit,omitempty"`
}

SampledValue represents a single sampled value

type SendLocalListRequest

type SendLocalListRequest struct {
	ListVersion            int                 `json:"listVersion"`
	LocalAuthorizationList []AuthorizationData `json:"localAuthorizationList,omitempty"`
	UpdateType             string              `json:"updateType"`
}

SendLocalListRequest represents a SendLocalList.req from central system

type SendLocalListResponse

type SendLocalListResponse struct {
	Status string `json:"status"`
}

SendLocalListResponse represents a SendLocalList.conf

type Server

type Server struct {
	// contains filtered or unexported fields
}

Server represents an OCPP charge point simulator

func NewServer

func NewServer(id int, port int, vendor, model string, numConnectors int, maxPowerKW float64) *Server

NewServer creates a new OCPP charge point simulator

func (*Server) Address

func (s *Server) Address() string

Address returns the server address

func (*Server) ApplyConfiguration

func (s *Server) ApplyConfiguration(config map[string]string)

ApplyConfiguration merges configuration values into the OCPP configuration map

func (*Server) Category

func (s *Server) Category() device.Category

Category returns the device category

func (*Server) GenerateValues

func (s *Server) GenerateValues(simTime time.Time)

GenerateValues generates simulated values based on time

func (*Server) GetConnectors

func (s *Server) GetConnectors() map[int]*Connector

GetConnectors returns all connectors

func (*Server) GetLogs

func (s *Server) GetLogs(limit int) []device.LogEntry

GetLogs returns operation logs

func (*Server) GetMeterValuesDebug

func (s *Server) GetMeterValuesDebug() MeterValuesDebug

GetMeterValuesDebug returns debug information about current meter values

func (*Server) GetOCPPURL

func (s *Server) GetOCPPURL() string

GetOCPPURL returns the configured Central System URL

func (*Server) GetState

func (s *Server) GetState() map[string]interface{}

GetState returns the current charger state

func (*Server) GetTransactions

func (s *Server) GetTransactions() map[int]*Transaction

GetTransactions returns all active transactions

func (*Server) Protocol

func (s *Server) Protocol() device.Protocol

Protocol returns the protocol type

func (*Server) SerialNumber

func (s *Server) SerialNumber() string

SerialNumber returns the serial number

func (*Server) SetOCPPURL

func (s *Server) SetOCPPURL(url string)

SetOCPPURL sets the Central System URL to connect to (enables client mode)

func (*Server) SetPort

func (s *Server) SetPort(port int)

SetPort updates the server port (should be called while stopped)

func (*Server) SetSerialNumber

func (s *Server) SetSerialNumber(sn string)

SetSerialNumber sets the serial number

func (*Server) SetValue

func (s *Server) SetValue(key string, value interface{}) error

SetValue sets a charger state value

func (*Server) SetVendorModel

func (s *Server) SetVendorModel(vendor, model string)

SetVendorModel updates the vendor and model

func (*Server) Start

func (s *Server) Start() error

Start starts the OCPP server (or connects as client if URL is set)

func (*Server) Stop

func (s *Server) Stop() error

Stop stops the OCPP server

type SetChargingProfileRequest

type SetChargingProfileRequest struct {
	ConnectorId        int             `json:"connectorId"`
	CsChargingProfiles ChargingProfile `json:"csChargingProfiles"`
}

SetChargingProfileRequest represents a SetChargingProfile.req

type SetChargingProfileResponse

type SetChargingProfileResponse struct {
	Status string `json:"status"`
}

SetChargingProfileResponse represents a SetChargingProfile.conf

type StartTransactionRequest

type StartTransactionRequest struct {
	ConnectorId   int    `json:"connectorId"`
	IdTag         string `json:"idTag"`
	MeterStart    int    `json:"meterStart"`
	Timestamp     string `json:"timestamp"`
	ReservationId int    `json:"reservationId,omitempty"`
}

StartTransactionRequest represents a StartTransaction.req

type StartTransactionResponse

type StartTransactionResponse struct {
	IdTagInfo     IdTagInfo `json:"idTagInfo"`
	TransactionId int       `json:"transactionId"`
}

StartTransactionResponse represents a StartTransaction.conf

type StatusNotificationRequest

type StatusNotificationRequest struct {
	ConnectorId     int    `json:"connectorId"`
	ErrorCode       string `json:"errorCode"`
	Status          string `json:"status"`
	Timestamp       string `json:"timestamp,omitempty"`
	Info            string `json:"info,omitempty"`
	VendorId        string `json:"vendorId,omitempty"`
	VendorErrorCode string `json:"vendorErrorCode,omitempty"`
}

StatusNotificationRequest represents a StatusNotification.req

type StatusNotificationResponse

type StatusNotificationResponse struct{}

StatusNotificationResponse represents a StatusNotification.conf

type StopTransactionRequest

type StopTransactionRequest struct {
	IdTag           string       `json:"idTag,omitempty"`
	MeterStop       int          `json:"meterStop"`
	Timestamp       string       `json:"timestamp"`
	TransactionId   int          `json:"transactionId"`
	Reason          string       `json:"reason,omitempty"`
	TransactionData []MeterValue `json:"transactionData,omitempty"`
}

StopTransactionRequest represents a StopTransaction.req

type StopTransactionResponse

type StopTransactionResponse struct {
	IdTagInfo *IdTagInfo `json:"idTagInfo,omitempty"`
}

StopTransactionResponse represents a StopTransaction.conf

type Transaction

type Transaction struct {
	ID          int       `json:"id"`
	ConnectorID int       `json:"connectorId"`
	IdTag       string    `json:"idTag"`
	StartTime   time.Time `json:"startTime"`
	MeterStart  int       `json:"meterStart"`
	MeterNow    int       `json:"meterNow"`
}

Transaction represents an active charging transaction

type TriggerMessageRequest

type TriggerMessageRequest struct {
	RequestedMessage string `json:"requestedMessage"`
	ConnectorId      *int   `json:"connectorId,omitempty"`
}

TriggerMessageRequest represents a TriggerMessage.req from central system

type TriggerMessageResponse

type TriggerMessageResponse struct {
	Status string `json:"status"`
}

TriggerMessageResponse represents a TriggerMessage.conf

type UnlockConnectorRequest

type UnlockConnectorRequest struct {
	ConnectorId int `json:"connectorId"`
}

UnlockConnectorRequest represents an UnlockConnector.req from central system

type UnlockConnectorResponse

type UnlockConnectorResponse struct {
	Status string `json:"status"`
}

UnlockConnectorResponse represents an UnlockConnector.conf

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL