@totemsdk/edge-ocpp 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +202 -0
- package/NOTICE +60 -0
- package/README.md +111 -2
- package/dist/cjs/gateway.d.ts +49 -0
- package/dist/cjs/gateway.js +184 -0
- package/dist/cjs/index.d.ts +7 -0
- package/dist/cjs/index.js +15 -0
- package/dist/cjs/ocpp.d.ts +40 -0
- package/dist/cjs/ocpp.js +101 -0
- package/dist/cjs/package.json +1 -0
- package/dist/cjs/sensor-bridge.d.ts +32 -0
- package/dist/cjs/sensor-bridge.js +72 -0
- package/dist/cjs/transport.d.ts +16 -0
- package/dist/cjs/transport.js +9 -0
- package/dist/gateway.d.ts +49 -0
- package/dist/gateway.js +181 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +3 -0
- package/dist/ocpp.d.ts +40 -0
- package/dist/ocpp.js +92 -0
- package/dist/sensor-bridge.d.ts +32 -0
- package/dist/sensor-bridge.js +69 -0
- package/dist/transport.d.ts +16 -0
- package/dist/transport.js +8 -0
- package/package.json +64 -3
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* OCPP Sensor Bridge — publishes locally sampled meter values as both OCPP
|
|
3
|
+
* MeterValues and Edge proofs.
|
|
4
|
+
*/
|
|
5
|
+
export function createOcppSensorBridge(config) {
|
|
6
|
+
const timers = [];
|
|
7
|
+
let running = false;
|
|
8
|
+
async function pollBinding(binding) {
|
|
9
|
+
try {
|
|
10
|
+
const samples = await binding.read();
|
|
11
|
+
if (samples.length === 0)
|
|
12
|
+
return;
|
|
13
|
+
const proof = config.runtime.ports.proof;
|
|
14
|
+
if (proof) {
|
|
15
|
+
for (const sample of samples) {
|
|
16
|
+
await proof.createProof({
|
|
17
|
+
subject: `sensor:${binding.sensorId}`,
|
|
18
|
+
claims: [{
|
|
19
|
+
sensorId: binding.sensorId,
|
|
20
|
+
connectorId: binding.connectorId,
|
|
21
|
+
value: sample.value,
|
|
22
|
+
unit: sample.unit,
|
|
23
|
+
measurand: sample.measurand ?? 'Energy.Active.Import.Register',
|
|
24
|
+
context: sample.context ?? 'Sample.Periodic',
|
|
25
|
+
timestamp: sample.timestamp ?? Date.now(),
|
|
26
|
+
...(sample.transactionId !== undefined ? { transactionId: sample.transactionId } : {}),
|
|
27
|
+
}],
|
|
28
|
+
}).catch(() => { });
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
const timestamp = new Date().toISOString();
|
|
32
|
+
await config.gateway.call('MeterValues', {
|
|
33
|
+
connectorId: binding.connectorId,
|
|
34
|
+
...(samples[0].transactionId !== undefined ? { transactionId: samples[0].transactionId } : {}),
|
|
35
|
+
meterValue: [{
|
|
36
|
+
timestamp,
|
|
37
|
+
sampledValue: samples.map((sample) => ({
|
|
38
|
+
value: String(sample.value),
|
|
39
|
+
unit: sample.unit,
|
|
40
|
+
...(sample.measurand ? { measurand: sample.measurand } : {}),
|
|
41
|
+
...(sample.context ? { context: sample.context } : {}),
|
|
42
|
+
})),
|
|
43
|
+
}],
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
catch { /* non-fatal */ }
|
|
47
|
+
}
|
|
48
|
+
return {
|
|
49
|
+
async start() {
|
|
50
|
+
if (running)
|
|
51
|
+
return;
|
|
52
|
+
for (const binding of config.bindings) {
|
|
53
|
+
await pollBinding(binding);
|
|
54
|
+
timers.push(setInterval(() => pollBinding(binding), binding.intervalMs));
|
|
55
|
+
}
|
|
56
|
+
running = true;
|
|
57
|
+
},
|
|
58
|
+
async stop() {
|
|
59
|
+
for (const timer of timers)
|
|
60
|
+
clearInterval(timer);
|
|
61
|
+
timers.length = 0;
|
|
62
|
+
running = false;
|
|
63
|
+
},
|
|
64
|
+
async poll() {
|
|
65
|
+
for (const binding of config.bindings)
|
|
66
|
+
await pollBinding(binding);
|
|
67
|
+
},
|
|
68
|
+
};
|
|
69
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* OCPP transport port — injected by the caller.
|
|
3
|
+
*
|
|
4
|
+
* The caller supplies a WebSocket (or test) transport that carries OCPP-J text
|
|
5
|
+
* frames. The connector owns framing, correlation, CALL handling, heartbeats
|
|
6
|
+
* and proof shaping.
|
|
7
|
+
*/
|
|
8
|
+
export interface OcppTransportPort {
|
|
9
|
+
connect(url: string, protocols?: string[]): Promise<void>;
|
|
10
|
+
close(): Promise<void>;
|
|
11
|
+
send(message: string): Promise<void>;
|
|
12
|
+
onMessage(handler: (message: string) => void): () => void;
|
|
13
|
+
onClose(handler: () => void): () => void;
|
|
14
|
+
onError(handler: (err: Error) => void): () => void;
|
|
15
|
+
readonly state?: 'closed' | 'connecting' | 'open';
|
|
16
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,67 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@totemsdk/edge-ocpp",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Edge runtime adapter for OCPP — EV charging, charge-point WebSocket JSON, meter proofs",
|
|
5
|
+
"main": "dist/cjs/index.js",
|
|
6
|
+
"types": "dist/cjs/index.d.ts",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"import": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"default": "./dist/index.js"
|
|
12
|
+
},
|
|
13
|
+
"require": {
|
|
14
|
+
"types": "./dist/cjs/index.d.ts",
|
|
15
|
+
"default": "./dist/cjs/index.js"
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
"files": [
|
|
20
|
+
"dist",
|
|
21
|
+
"README.md",
|
|
22
|
+
"LICENSE",
|
|
23
|
+
"NOTICE"
|
|
24
|
+
],
|
|
25
|
+
"dependencies": {
|
|
26
|
+
"@totemsdk/edge": "^1.5.1"
|
|
27
|
+
},
|
|
28
|
+
"devDependencies": {
|
|
29
|
+
"@types/node": "^20.0.0",
|
|
30
|
+
"typescript": "^7.0.2"
|
|
31
|
+
},
|
|
32
|
+
"engines": {
|
|
33
|
+
"node": ">=18.0.0"
|
|
34
|
+
},
|
|
35
|
+
"publishConfig": {
|
|
36
|
+
"access": "public"
|
|
37
|
+
},
|
|
38
|
+
"license": "Apache-2.0",
|
|
39
|
+
"author": "Totem SDK",
|
|
40
|
+
"homepage": "https://docs.totem.ing",
|
|
41
|
+
"repository": {
|
|
42
|
+
"type": "git",
|
|
43
|
+
"url": "git+https://github.com/Totem-Edge/totem-sdk.git",
|
|
44
|
+
"directory": "packages/edge-ocpp"
|
|
45
|
+
},
|
|
46
|
+
"keywords": [
|
|
47
|
+
"totem",
|
|
48
|
+
"totemsdk",
|
|
49
|
+
"minima",
|
|
50
|
+
"blockchain",
|
|
51
|
+
"edge",
|
|
52
|
+
"ocpp",
|
|
53
|
+
"ev-charging",
|
|
54
|
+
"ocpp16j",
|
|
55
|
+
"ocpp201"
|
|
56
|
+
],
|
|
57
|
+
"bugs": {
|
|
58
|
+
"url": "https://github.com/Totem-Edge/totem-sdk/issues"
|
|
59
|
+
},
|
|
60
|
+
"type": "module",
|
|
61
|
+
"scripts": {
|
|
62
|
+
"build": "tsc && tsc -p tsconfig.cjs.json && node -e \"require('fs').writeFileSync('dist/cjs/package.json', JSON.stringify({type:'commonjs'})+'\\n')\"",
|
|
63
|
+
"clean": "rm -rf dist",
|
|
64
|
+
"test": "jest --config ../../tests/jest/edge-ocpp.cjs",
|
|
65
|
+
"test:integration": "node --test ../../tests/qualification/edge-ocpp/integration.test.mjs"
|
|
66
|
+
}
|
|
6
67
|
}
|