feat(ocpp): implement BootNotification, Heartbeat, and StatusNotification actions with database integration

This commit is contained in:
2026-03-10 10:42:20 +08:00
parent 0f47b3d382
commit 4fce1c6bdd
11 changed files with 2837 additions and 136 deletions

View File

@@ -7,11 +7,7 @@ import { cors } from 'hono/cors'
import { logger } from 'hono/logger'
import { showRoutes } from 'hono/dev'
import { auth } from './lib/auth.ts'
import {
isSupportedOCPP,
SUPPORTED_OCPP_VERSIONS,
type SupportedOCPPVersion,
} from './constants.ts'
import { createOcppHandler } from './ocpp/handler.ts'
const app = new Hono<{
Variables: {
@@ -74,28 +70,8 @@ app.get(
'/ocpp/:chargePointId',
upgradeWebSocket((c) => {
const chargePointId = c.req.param('chargePointId')
return {
onOpen(evt, ws) {
const subProtocol = ws.protocol || 'unknown'
if (!isSupportedOCPP(subProtocol)) {
ws.close(1002, 'Unsupported subprotocol')
return
}
const connInfo = getConnInfo(c)
console.log(
`New connection from ${connInfo.remote.address}:${connInfo.remote.port} for station ${chargePointId}`,
)
},
onMessage(evt, ws) {
console.log(`Received message: ${evt.data}`)
ws.send(`Echo: ${evt.data}`)
},
onClose(evt, ws) {
console.log('Connection closed: ', evt.code, evt.reason)
},
}
const connInfo = getConnInfo(c)
return createOcppHandler(chargePointId, connInfo.remote.address)
}),
)