GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com โ€” GitHub - Jaypatelbond/ocpp-kotlin: Type-safe OCPP 1.6 & 2.0.1 client library for Kotlin/Android. Build EV charging station apps with ease.

BranchesTags
Open more actions menu

Latest commit

 

History

10 Commits
10 Commits

Folders and files

NameName
Last commit message
Last commit date
docs
docs
 
 
gradle
gradle
 
 
ocpp-1.6
ocpp-1.6
 
 
ocpp-2.0.1
ocpp-2.0.1
 
 
ocpp-android
ocpp-android
 
 
ocpp-core
ocpp-core
 
 
ocpp-simulator
ocpp-simulator
 
 
sample-app
sample-app
 
 
screenshots
screenshots
 
 
.gitignore
.gitignore
 
 
CONTRIBUTING.md
CONTRIBUTING.md
 
 
LICENSE
LICENSE
 
 
README.md
README.md
 
 
build.gradle.kts
build.gradle.kts
 
 
gradle.properties
gradle.properties
 
 
gradlew
gradlew
 
 
gradlew.bat
gradlew.bat
 
 
jitpack.yml
jitpack.yml
 
 
settings.gradle.kts
settings.gradle.kts
 
 

Repository files navigation

OCPP Kotlin

License: MIT API Kotlin

A comprehensive, type-safe OCPP (Open Charge Point Protocol) client library for Kotlin and Android. Built for EV charging station developers who need reliable, production-ready OCPP communication.

โœจ Features

  • ๐Ÿ”Œ OCPP 2.0.1 - Full support for all 47+ message types across 15 functional blocks
  • ๐Ÿ”Œ OCPP 1.6 - Core, Smart Charging, Firmware Management profiles
  • ๐Ÿ“ฑ Android-First - Lifecycle-aware components, ViewModel support
  • ๐Ÿ”’ Type-Safe - Compile-time safety with Kotlin data classes and enums
  • โšก Coroutines - Modern async/await patterns with Kotlin Coroutines and Flow
  • ๐Ÿ”„ Auto-Reconnect - Automatic reconnection with exponential backoff
  • ๐Ÿ” Secure - Basic auth and certificate-based authentication support

๐Ÿ“ธ Screenshots

Home Charging History Settings
Home Charging History Settings

๐Ÿ“ฆ Installation

Add JitPack repository to your project's settings.gradle.kts:

dependencyResolutionManagement {
    repositories {
        maven { url = uri("https://jitpack.io") }
    }
}

Add the dependencies to your module's build.gradle.kts:

dependencies {
    // Core library (required)
    implementation("com.github.Jaypatelbond.ocpp-kotlin:ocpp-core:1.1.0")
    
    // OCPP 2.0.1 support
    implementation("com.github.Jaypatelbond.ocpp-kotlin:ocpp-2.0.1:1.1.0")
    
    // OCPP 1.6 support (optional)
    implementation("com.github.Jaypatelbond.ocpp-kotlin:ocpp-1.6:1.1.0")
    
    // Android extensions (optional, for Android apps)
    implementation("com.github.Jaypatelbond.ocpp-kotlin:ocpp-android:1.1.0")
}

๐Ÿš€ Quick Start

Basic Connection (OCPP 2.0.1)

import com.ocpp.v201.client.Ocpp201Client
import com.ocpp.v201.types.*

// Create client
val client = Ocpp201Client()

// Connect to CSMS
client.connect("ws://csms.example.com/ocpp", "CP001")

// Send BootNotification
val response = client.bootNotification(
    chargingStation = ChargingStationType(
        model = "FastCharger",
        vendorName = "MyCompany"
    ),
    reason = BootReasonEnumType.PowerUp
)

when (response.status) {
    RegistrationStatusEnumType.Accepted -> println("Charger registered!")
    RegistrationStatusEnumType.Pending -> println("Registration pending...")
    RegistrationStatusEnumType.Rejected -> println("Registration rejected")
}

Android ViewModel Integration

class ChargingViewModel : Ocpp201ViewModel() {
    
    fun startCharging(customerId: String) {
        viewModelScope.launch {
            // Authorize customer
            val authResult = authorize(customerId)
            if (authResult.isSuccess) {
                // Start transaction
                startTransaction(
                    transactionId = UUID.randomUUID().toString(),
                    evseId = 1,
                    connectorId = 1,
                    idToken = customerId,
                    timestamp = Instant.now().toString()
                )
            }
        }
    }
}

๐Ÿงฉ Generic API (Version Agnostic)

Write code that works with both OCPP 1.6 and 2.0.1:

// Select adapter
val client: GenericOcppClient = when (config.version) {
    "1.6" -> GenericOcpp16Adapter()
    "2.0.1" -> GenericOcpp201Adapter()
    else -> throw IllegalArgumentException("Unknown version")
}

// Connect & Authenticate (works for both!)
client.connect(url, chargePointId)
val bootParams = client.bootNotification("MyCharger", "MyCompany").getOrThrow()

if (bootParams.accepted) {
    client.startTransaction(connectorId = 1, idToken = "TAG123", meterStart = 0)
}

Complete Transaction Flow

// 1. Boot & Register
client.bootNotification(station, BootReasonEnumType.PowerUp)

// 2. Report Available
client.statusNotification(timestamp, ConnectorStatusEnumType.Available, evseId = 1, connectorId = 1)

// 3. Authorize Customer
val auth = client.authorize(idToken).getOrThrow()

// 4. Start Transaction
client.transactionEvent(TransactionEventEnumType.Started, timestamp, TriggerReasonEnumType.Authorized, seqNo = 0, transactionInfo)

// 5. Charging - Send Meter Values
client.transactionEvent(TransactionEventEnumType.Updated, timestamp, TriggerReasonEnumType.MeterValuePeriodic, seqNo = 1, transactionInfo, meterValue = meterValues)

// 6. Stop Transaction
client.transactionEvent(TransactionEventEnumType.Ended, timestamp, TriggerReasonEnumType.Local, seqNo = 2, transactionInfo)

๐Ÿ“– See Full Transaction Examples โ†’

๐Ÿ—๏ธ Architecture

OCPP Architecture

๐Ÿ“š Modules

Module Description
ocpp-core Base transport, message parsing, request/response correlation
ocpp-2.0.1 OCPP 2.0.1 messages, types, and type-safe client
ocpp-1.6 OCPP 1.6 messages, types, and type-safe client
ocpp-android Android lifecycle integration, ViewModel base classes
sample-app Demo Android app with charging simulation
ocpp-simulator CSMS simulator for testing

๐Ÿ”Œ Supported OCPP 2.0.1 Messages

Charging Station โ†’ CSMS

  • BootNotification, Heartbeat, StatusNotification
  • Authorize, TransactionEvent, MeterValues
  • FirmwareStatusNotification, LogStatusNotification
  • SecurityEventNotification, DataTransfer
  • And more...

CSMS โ†’ Charging Station

  • RequestStartTransaction, RequestStopTransaction
  • SetVariables, GetVariables, GetBaseReport
  • SetChargingProfile, ClearChargingProfile
  • TriggerMessage, Reset, UnlockConnector
  • And more...

๐Ÿงช Testing with Simulator

Run the included OCPP CSMS simulator for testing:

./gradlew :ocpp-simulator:run

Then run the sample app on an Android emulator and connect to:

  • Emulator: ws://10.0.2.2:8080/ocpp
  • Physical device: ws://YOUR_PC_IP:8080/ocpp

๐Ÿค Contributing

Contributions are welcome! Please see CONTRIBUTING.md for guidelines.

๐Ÿ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

๐Ÿ™ Acknowledgments

  • Open Charge Alliance for the OCPP specification
  • OkHttp for WebSocket support
  • kotlinx.serialization for JSON handling

โ“ FAQ

Q: Does this library support different connector types (Type 2, CCS, CHAdeMO)? A: Yes. The library operates at the OCPP protocol level, which is agnostic to the physical connector type. It supports configuring and separately managing multiple connectors/EVSEs using standard OCPP identifiers (connectorId / evseId). The actual physical hardware control is handled by your charger's firmware, not this client library.

About

Type-safe OCPP 1.6 & 2.0.1 client library for Kotlin/Android. Build EV charging station apps with ease.

Topics

androidandroid-librarycharging-stationscsmselectric-vehiclesemobilityevchargingjitpackkotlinkotlin-libraryocppocpp-clientocpp16ocpp201websocket

Resources

Readme
MIT license

Contributing

Contributing
Activity

Stars

3 stars

Watchers

0 watching

Forks

0 forks
Report repository

Releases

Packages

Contributors

Languages

You are visitor 01402792 โ€” GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800ร—600. No cookies required.