feat(ocpp): implement BootNotification, Heartbeat, and StatusNotification actions with database integration
This commit is contained in:
@@ -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)
|
||||
}),
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user