@uns-kit/cli 2.0.68 → 2.0.70

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.
Files changed (61) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +168 -168
  3. package/dist/index.js +56 -52
  4. package/package.json +6 -6
  5. package/templates/api/src/examples/api-example.ts +155 -155
  6. package/templates/azure-pipelines.yml +21 -21
  7. package/templates/codegen/codegen.ts +15 -15
  8. package/templates/codegen/src/uns/uns-tags.ts +1 -1
  9. package/templates/codegen/src/uns/uns-topics.ts +1 -1
  10. package/templates/config-files/config-docker.json +32 -32
  11. package/templates/config-files/config-localhost.json +32 -32
  12. package/templates/cron/AGENTS.md +20 -20
  13. package/templates/cron/src/examples/cron-example.ts +71 -71
  14. package/templates/default/.prettierignore +1 -1
  15. package/templates/default/.prettierrc +7 -7
  16. package/templates/default/AGENTS.md +20 -20
  17. package/templates/default/README.md +101 -98
  18. package/templates/default/config.json +35 -35
  19. package/templates/default/eslint.config.js +30 -30
  20. package/templates/default/gitignore +51 -51
  21. package/templates/default/package.json +46 -46
  22. package/templates/default/src/config/project.config.extension.example +23 -23
  23. package/templates/default/src/config/project.config.extension.ts +6 -6
  24. package/templates/default/src/examples/data-example.ts +79 -78
  25. package/templates/default/src/examples/load-test-data.ts +107 -107
  26. package/templates/default/src/examples/schema-system-metadata-example.ts +123 -122
  27. package/templates/default/src/examples/subasset-example.ts +74 -73
  28. package/templates/default/src/examples/table-example.ts +96 -95
  29. package/templates/default/src/examples/table-window-load-test.ts +441 -442
  30. package/templates/default/src/examples/uns-gateway-cli.ts +10 -10
  31. package/templates/default/src/index.ts +40 -36
  32. package/templates/default/src/uns/uns-assets.ts +12 -12
  33. package/templates/default/src/uns/uns-dictionary.generated.ts +758 -758
  34. package/templates/default/src/uns/uns-measurements.generated.ts +366 -366
  35. package/templates/default/src/uns/uns-tags.ts +2 -2
  36. package/templates/default/src/uns/uns-topics.ts +2 -2
  37. package/templates/default/tsconfig.json +29 -29
  38. package/templates/python/app/README.md +8 -8
  39. package/templates/python/examples/README.md +134 -134
  40. package/templates/python/examples/api_handler.py +28 -28
  41. package/templates/python/examples/data_publish.py +11 -11
  42. package/templates/python/examples/data_subscribe.py +8 -8
  43. package/templates/python/examples/data_transformer.py +17 -17
  44. package/templates/python/examples/table_transformer.py +15 -15
  45. package/templates/python/gateway/cli.py +75 -75
  46. package/templates/python/gateway/client.py +155 -155
  47. package/templates/python/gateway/manager.py +97 -97
  48. package/templates/python/gen/__init__.py +1 -0
  49. package/templates/python/gen/uns_gateway_pb2.py +70 -0
  50. package/templates/python/gen/uns_gateway_pb2_grpc.py +312 -0
  51. package/templates/python/gitignore +47 -47
  52. package/templates/python/proto/uns-gateway.proto +105 -105
  53. package/templates/python/pyproject.toml +4 -4
  54. package/templates/python/runtime.json +4 -4
  55. package/templates/python/scripts/setup.sh +87 -87
  56. package/templates/uns-dictionary/uns-dictionary.json +650 -650
  57. package/templates/uns-measurements/uns-measurements.json +360 -360
  58. package/templates/vscode/.vscode/launch.json +164 -164
  59. package/templates/vscode/.vscode/settings.json +9 -9
  60. package/templates/vscode/.vscode/tasks.json +27 -27
  61. package/templates/vscode/uns-kit.code-workspace +13 -13
@@ -1,125 +1,126 @@
1
- /**
2
- * Example: publish schema-system metadata for object relationships and lifecycle timing.
3
- *
4
- * This is producer metadata. The controller stores these fields in
5
- * attribute_schema.schema_json and can later materialize relationship evidence
6
- * into object_id_relationship edges.
7
- */
8
- import { ConfigFile, UnsProxyProcess, getLogger } from "@uns-kit/core";
9
- import { registerAttributeDescriptions, registerObjectTypeDescriptions } from "@uns-kit/core/uns/uns-dictionary-registry.js";
10
- import type { ISO8601 } from "@uns-kit/core/uns/uns-interfaces.js";
11
- import { UnsTopics } from "@uns-kit/core/uns/uns-topics.js";
12
- import {
13
- GeneratedAttributeDescriptions,
14
- GeneratedObjectTypeDescriptions,
15
- GeneratedObjectTypes,
16
- } from "../uns/uns-dictionary.generated.js";
17
- import { resolveGeneratedAsset } from "../uns/uns-assets.js";
18
-
19
- const logger = getLogger(import.meta.url);
20
-
21
- const config = await ConfigFile.loadConfig();
22
- registerObjectTypeDescriptions(GeneratedObjectTypeDescriptions);
23
- registerAttributeDescriptions(GeneratedAttributeDescriptions);
24
-
25
- const unsProxyProcess = new UnsProxyProcess(config.infra.host!, {
26
- processName: config.uns.processName!,
27
- });
28
-
29
- const mqttOutput = await unsProxyProcess.createUnsMqttProxy(
30
- config.output?.host!,
31
- "templateSchemaMetadataOutput",
32
- config.uns.instanceMode!,
33
- config.uns.handover!,
34
- { publishThrottlingDelay: 1000 },
35
- );
36
-
37
- const now = new Date();
38
- const time = now.toISOString() as ISO8601;
39
- const topic: UnsTopics = "enterprise/site/area/line/";
40
- const asset = resolveGeneratedAsset("asset");
41
- const materialObjectType = GeneratedObjectTypes["material"];
42
- const currentMaterialId = "1124";
43
- const previousMaterialId = "112";
44
- const mergedParentMaterialIds = ["1122", "1123"];
45
-
46
- try {
47
- await mqttOutput.publishMqttMessage({
48
- topic,
49
- asset,
50
- assetDescription: "Example production line",
51
- objectType: materialObjectType,
52
- objectId: currentMaterialId,
53
- attributes: [
54
- {
55
- attribute: "previous-material",
56
- description: "Previous material ObjectId before this process stage.",
57
- valueType: "string",
58
- systemRole: "relationship-evidence",
59
- relationshipEvidence: {
60
- relationshipKey: "material-renumbering",
61
- ownerEndpoint: "target",
62
- valueEndpoint: "source",
63
- sourceObjectType: materialObjectType,
64
- targetObjectType: materialObjectType,
65
- sourceObjectIdFrom: "value",
66
- targetObjectIdFrom: "ownerObjectId",
67
- observedAtFrom: "packetTimestamp",
68
- defaultStatus: "suggested",
69
- },
70
- data: {
71
- dataGroup: "material-lineage",
72
- time,
73
- value: previousMaterialId,
74
- },
75
- },
76
- {
77
- attribute: "previous-materials",
78
- description: "Previous material ObjectIds that were joined into this material.",
79
- valueType: "array<string>",
80
- systemRole: "relationship-evidence",
81
- relationshipEvidence: {
82
- relationshipKey: "material-merge",
83
- ownerEndpoint: "target",
84
- valueEndpoint: "source",
85
- sourceObjectType: materialObjectType,
86
- targetObjectType: materialObjectType,
87
- sourceObjectIdFrom: "value[]",
88
- targetObjectIdFrom: "ownerObjectId",
89
- observedAtFrom: "packetTimestamp",
90
- defaultStatus: "suggested",
91
- },
92
- data: {
93
- dataGroup: "material-lineage",
94
- time,
95
- currentMaterialObjectId: currentMaterialId,
96
- operationId: "weld-1122-1123",
97
- value: mergedParentMaterialIds,
98
- },
99
- },
100
- {
101
- attribute: "process-state",
102
- description: "Material lifecycle state in this process stage.",
103
- valueType: "string",
104
- systemRole: "lifecycle-time-source",
105
- lifecycle: {
106
- timestampFrom: "packetTimestamp",
107
- startValues: ["entered", "processing"],
108
- endValues: ["done", "exited"],
109
- },
110
- validityMode: "lifecycle",
111
- lifecycleEndValue: "done",
112
- data: {
113
- dataGroup: "material-lifecycle",
114
- time,
115
- value: "processing",
116
- },
117
- },
118
- ],
119
- });
120
-
121
- logger.info(`Published schema-system metadata example for material ${currentMaterialId}.`);
1
+ /**
2
+ * Example: publish schema-system metadata for object relationships and lifecycle timing.
3
+ *
4
+ * This is producer metadata. The controller stores these fields in
5
+ * attribute_schema.schema_json and can later materialize relationship evidence
6
+ * into object_id_relationship edges.
7
+ */
8
+ import { ConfigFile, UnsProxyProcess, getLogger } from "@uns-kit/core";
9
+ import { registerAttributeDescriptions, registerObjectTypeDescriptions } from "@uns-kit/core/uns/uns-dictionary-registry.js";
10
+ import type { ISO8601 } from "@uns-kit/core/uns/uns-interfaces.js";
11
+ import { UnsTopics } from "@uns-kit/core/uns/uns-topics.js";
12
+ import {
13
+ GeneratedAttributeDescriptions,
14
+ GeneratedObjectTypeDescriptions,
15
+ GeneratedObjectTypes,
16
+ } from "../uns/uns-dictionary.generated.js";
17
+ import { resolveGeneratedAsset } from "../uns/uns-assets.js";
18
+
19
+ const logger = getLogger(import.meta.url);
20
+
21
+ const config = await ConfigFile.loadConfig();
22
+ registerObjectTypeDescriptions(GeneratedObjectTypeDescriptions);
23
+ registerAttributeDescriptions(GeneratedAttributeDescriptions);
24
+
25
+ const unsProxyProcess = new UnsProxyProcess(config.infra.host!, {
26
+ processName: config.uns.processName!,
27
+ });
28
+
29
+ const mqttOutput = await unsProxyProcess.createUnsMqttProxy(
30
+ config.output?.host!,
31
+ "templateSchemaMetadataOutput",
32
+ config.uns.instanceMode!,
33
+ config.uns.handover!,
34
+ { publishThrottlingDelay: 1000 },
35
+ );
36
+
37
+ const now = new Date();
38
+ const time = now.toISOString() as ISO8601;
39
+ const topic: UnsTopics = "enterprise/site/area/line/";
40
+ const asset = resolveGeneratedAsset("asset");
41
+ const materialObjectType = GeneratedObjectTypes["material"];
42
+ const currentMaterialId = "1124";
43
+ const previousMaterialId = "112";
44
+ const mergedParentMaterialIds = ["1122", "1123"];
45
+
46
+ try {
47
+ await mqttOutput.publishMqttMessage({
48
+ topic,
49
+ asset,
50
+ assetDescription: "Example production line",
51
+ objectType: materialObjectType,
52
+ objectId: currentMaterialId,
53
+ attributes: [
54
+ {
55
+ attribute: "previous-material",
56
+ description: "Previous material ObjectId before this process stage.",
57
+ valueType: "string",
58
+ systemRole: "relationship-evidence",
59
+ relationshipEvidence: {
60
+ relationshipKey: "material-renumbering",
61
+ ownerEndpoint: "target",
62
+ valueEndpoint: "source",
63
+ sourceObjectType: materialObjectType,
64
+ targetObjectType: materialObjectType,
65
+ sourceObjectIdFrom: "value",
66
+ targetObjectIdFrom: "ownerObjectId",
67
+ observedAtFrom: "packetTimestamp",
68
+ defaultStatus: "suggested",
69
+ },
70
+ data: {
71
+ dataGroup: "material-lineage",
72
+ time,
73
+ value: previousMaterialId,
74
+ },
75
+ },
76
+ {
77
+ attribute: "previous-materials",
78
+ description: "Previous material ObjectIds that were joined into this material.",
79
+ valueType: "array<string>",
80
+ systemRole: "relationship-evidence",
81
+ relationshipEvidence: {
82
+ relationshipKey: "material-merge",
83
+ ownerEndpoint: "target",
84
+ valueEndpoint: "source",
85
+ sourceObjectType: materialObjectType,
86
+ targetObjectType: materialObjectType,
87
+ sourceObjectIdFrom: "value[]",
88
+ targetObjectIdFrom: "ownerObjectId",
89
+ observedAtFrom: "packetTimestamp",
90
+ defaultStatus: "suggested",
91
+ },
92
+ data: {
93
+ dataGroup: "material-lineage",
94
+ time,
95
+ currentMaterialObjectId: currentMaterialId,
96
+ operationId: "weld-1122-1123",
97
+ value: mergedParentMaterialIds,
98
+ },
99
+ },
100
+ {
101
+ attribute: "process-state",
102
+ description: "Material lifecycle state in this process stage.",
103
+ valueType: "string",
104
+ systemRole: "lifecycle-time-source",
105
+ lifecycle: {
106
+ timestampFrom: "packetTimestamp",
107
+ startValues: ["entered", "processing"],
108
+ endValues: ["done", "exited"],
109
+ },
110
+ validityMode: "lifecycle",
111
+ lifecycleEndValue: "done",
112
+ data: {
113
+ dataGroup: "material-lifecycle",
114
+ time,
115
+ value: "processing",
116
+ },
117
+ },
118
+ ],
119
+ });
120
+
121
+ logger.info(`Published schema-system metadata example for material ${currentMaterialId}.`);
122
122
  } finally {
123
+ await mqttOutput.flush();
123
124
  await mqttOutput.stop();
124
- unsProxyProcess.shutdown();
125
+ await unsProxyProcess.shutdown();
125
126
  }
@@ -1,76 +1,77 @@
1
- /**
2
- * Example: publish a sub-asset under an existing parent asset.
3
- *
4
- * V1 sub-assets use the normal UNS publish fields:
5
- * - topic is the full parent asset path
6
- * - asset is only the leaf sub-asset name
7
- */
8
- import { ConfigFile, UnsProxyProcess, getLogger } from "@uns-kit/core";
9
- import { registerAttributeDescriptions, registerObjectTypeDescriptions } from "@uns-kit/core/uns/uns-dictionary-registry.js";
10
- import type { ISO8601 } from "@uns-kit/core/uns/uns-interfaces.js";
11
- import { UnsTopics } from "@uns-kit/core/uns/uns-topics.js";
12
- import { GeneratedPhysicalMeasurements } from "../uns/uns-measurements.generated.js";
13
- import {
14
- GeneratedAttributeDescriptions,
15
- GeneratedAttributesByType,
16
- GeneratedObjectTypeDescriptions,
17
- GeneratedObjectTypes,
18
- } from "../uns/uns-dictionary.generated.js";
19
- import { resolveGeneratedAsset } from "../uns/uns-assets.js";
20
-
21
- const logger = getLogger(import.meta.url);
22
-
23
- const config = await ConfigFile.loadConfig();
24
- registerObjectTypeDescriptions(GeneratedObjectTypeDescriptions);
25
- registerAttributeDescriptions(GeneratedAttributeDescriptions);
26
-
27
- const unsProxyProcess = new UnsProxyProcess(config.infra.host!, {
28
- processName: config.uns.processName!,
29
- });
30
-
31
- const mqttOutput = await unsProxyProcess.createUnsMqttProxy(
32
- config.output?.host!,
33
- "templateSubassetExampleOutput",
34
- config.uns.instanceMode!,
35
- config.uns.handover!,
36
- { publishThrottlingDelay: 1000 },
37
- );
38
-
39
- try {
40
- const parentAssetTopic: UnsTopics = "enterprise/site/area/line-1/";
41
- const subAsset = resolveGeneratedAsset("pump-1");
42
- const now = new Date();
43
- const time = now.toISOString() as ISO8601;
44
- const intervalStart = new Date(now.getTime() - 1000).toISOString() as ISO8601;
45
- const intervalEnd = time;
46
-
47
- await mqttOutput.publishMqttMessage({
48
- topic: parentAssetTopic,
49
- asset: subAsset,
50
- assetDescription: "Example pump owned by a separate microservice",
51
- objectType: GeneratedObjectTypes["equipment"],
52
- objectId: "main",
53
- attributes: {
54
- attribute: GeneratedAttributesByType["equipment"]["temperature"],
55
- description: "Example sub-asset temperature",
56
- valueType: "number",
57
- presentationKind: "chart",
58
- defaultAggregation: "last",
59
- data: {
60
- time,
61
- value: 42,
62
- uom: GeneratedPhysicalMeasurements.Celsius,
63
- intervalStart,
64
- intervalEnd,
65
- },
66
- },
67
- });
68
-
69
- logger.info(
70
- "Published sub-asset example to " +
71
- `${parentAssetTopic}${subAsset}/equipment/main/temperature`,
72
- );
1
+ /**
2
+ * Example: publish a sub-asset under an existing parent asset.
3
+ *
4
+ * V1 sub-assets use the normal UNS publish fields:
5
+ * - topic is the full parent asset path
6
+ * - asset is only the leaf sub-asset name
7
+ */
8
+ import { ConfigFile, UnsProxyProcess, getLogger } from "@uns-kit/core";
9
+ import { registerAttributeDescriptions, registerObjectTypeDescriptions } from "@uns-kit/core/uns/uns-dictionary-registry.js";
10
+ import type { ISO8601 } from "@uns-kit/core/uns/uns-interfaces.js";
11
+ import { UnsTopics } from "@uns-kit/core/uns/uns-topics.js";
12
+ import { GeneratedPhysicalMeasurements } from "../uns/uns-measurements.generated.js";
13
+ import {
14
+ GeneratedAttributeDescriptions,
15
+ GeneratedAttributesByType,
16
+ GeneratedObjectTypeDescriptions,
17
+ GeneratedObjectTypes,
18
+ } from "../uns/uns-dictionary.generated.js";
19
+ import { resolveGeneratedAsset } from "../uns/uns-assets.js";
20
+
21
+ const logger = getLogger(import.meta.url);
22
+
23
+ const config = await ConfigFile.loadConfig();
24
+ registerObjectTypeDescriptions(GeneratedObjectTypeDescriptions);
25
+ registerAttributeDescriptions(GeneratedAttributeDescriptions);
26
+
27
+ const unsProxyProcess = new UnsProxyProcess(config.infra.host!, {
28
+ processName: config.uns.processName!,
29
+ });
30
+
31
+ const mqttOutput = await unsProxyProcess.createUnsMqttProxy(
32
+ config.output?.host!,
33
+ "templateSubassetExampleOutput",
34
+ config.uns.instanceMode!,
35
+ config.uns.handover!,
36
+ { publishThrottlingDelay: 1000 },
37
+ );
38
+
39
+ try {
40
+ const parentAssetTopic: UnsTopics = "enterprise/site/area/line-1/";
41
+ const subAsset = resolveGeneratedAsset("pump-1");
42
+ const now = new Date();
43
+ const time = now.toISOString() as ISO8601;
44
+ const intervalStart = new Date(now.getTime() - 1000).toISOString() as ISO8601;
45
+ const intervalEnd = time;
46
+
47
+ await mqttOutput.publishMqttMessage({
48
+ topic: parentAssetTopic,
49
+ asset: subAsset,
50
+ assetDescription: "Example pump owned by a separate microservice",
51
+ objectType: GeneratedObjectTypes["equipment"],
52
+ objectId: "main",
53
+ attributes: {
54
+ attribute: GeneratedAttributesByType["equipment"]["temperature"],
55
+ description: "Example sub-asset temperature",
56
+ valueType: "number",
57
+ presentationKind: "chart",
58
+ defaultAggregation: "last",
59
+ data: {
60
+ time,
61
+ value: 42,
62
+ uom: GeneratedPhysicalMeasurements.Celsius,
63
+ intervalStart,
64
+ intervalEnd,
65
+ },
66
+ },
67
+ });
68
+
69
+ logger.info(
70
+ "Published sub-asset example to " +
71
+ `${parentAssetTopic}${subAsset}/equipment/main/temperature`,
72
+ );
73
73
  } finally {
74
+ await mqttOutput.flush();
74
75
  await mqttOutput.stop();
75
- unsProxyProcess.shutdown();
76
+ await unsProxyProcess.shutdown();
76
77
  }
@@ -1,107 +1,108 @@
1
- /**
2
- * Change this file according to your specifications and rename it to index.ts
3
- */
4
-
5
- import { UnsProxyProcess, ConfigFile, getLogger } from "@uns-kit/core";
6
- import { registerAttributeDescriptions, registerObjectTypeDescriptions } from "@uns-kit/core/uns/uns-dictionary-registry.js";
7
- import { UnsTopics } from "@uns-kit/core/uns/uns-topics.js";
8
- import {
9
- GeneratedObjectTypes,
10
- GeneratedAttributeDescriptions,
11
- GeneratedObjectTypeDescriptions,
12
- } from "../uns/uns-dictionary.generated.js";
13
- import { GeneratedAssets, resolveGeneratedAsset } from "../uns/uns-assets.js";
14
- import type { IUnsTableColumn, IUnsTableColumnMetadata } from "@uns-kit/core/uns/uns-interfaces.js";
15
- import type { ISO8601 } from "@uns-kit/core/uns/uns-interfaces.js";
16
- import { GeneratedPhysicalMeasurements } from "../uns/uns-measurements.generated.js";
17
-
18
- const logger = getLogger(import.meta.url);
19
-
20
- /**
21
- * Load the configuration from a file.
22
- * On the server, this file is provided by the `uns-datahub-controller`.
23
- * In the development environment, you are responsible for creating and maintaining this file and its contents.
24
- */
25
- const config = await ConfigFile.loadConfig();
26
- registerObjectTypeDescriptions(GeneratedObjectTypeDescriptions);
27
- registerAttributeDescriptions(GeneratedAttributeDescriptions);
28
-
29
- /**
30
- * Load and configure input and output brokers from config.json
31
- */
32
- const unsProxyProcess = new UnsProxyProcess(config.infra.host!, {processName: config.uns.processName!});
33
- const mqttInput = await unsProxyProcess.createUnsMqttProxy((config.input?.host)!, "templateUnsRttInput", config.uns.instanceMode!, config.uns.handover!, {
34
- mqttSubToTopics: ["raw/#"],
35
- });
1
+ /**
2
+ * Change this file according to your specifications and rename it to index.ts
3
+ */
4
+
5
+ import { UnsProxyProcess, ConfigFile, getLogger } from "@uns-kit/core";
6
+ import { registerAttributeDescriptions, registerObjectTypeDescriptions } from "@uns-kit/core/uns/uns-dictionary-registry.js";
7
+ import { UnsTopics } from "@uns-kit/core/uns/uns-topics.js";
8
+ import {
9
+ GeneratedObjectTypes,
10
+ GeneratedAttributeDescriptions,
11
+ GeneratedObjectTypeDescriptions,
12
+ } from "../uns/uns-dictionary.generated.js";
13
+ import { GeneratedAssets, resolveGeneratedAsset } from "../uns/uns-assets.js";
14
+ import type { IUnsTableColumn, IUnsTableColumnMetadata } from "@uns-kit/core/uns/uns-interfaces.js";
15
+ import type { ISO8601 } from "@uns-kit/core/uns/uns-interfaces.js";
16
+ import { GeneratedPhysicalMeasurements } from "../uns/uns-measurements.generated.js";
17
+
18
+ const logger = getLogger(import.meta.url);
19
+
20
+ /**
21
+ * Load the configuration from a file.
22
+ * On the server, this file is provided by the `uns-datahub-controller`.
23
+ * In the development environment, you are responsible for creating and maintaining this file and its contents.
24
+ */
25
+ const config = await ConfigFile.loadConfig();
26
+ registerObjectTypeDescriptions(GeneratedObjectTypeDescriptions);
27
+ registerAttributeDescriptions(GeneratedAttributeDescriptions);
28
+
29
+ /**
30
+ * Load and configure input and output brokers from config.json
31
+ */
32
+ const unsProxyProcess = new UnsProxyProcess(config.infra.host!, {processName: config.uns.processName!});
33
+ const mqttInput = await unsProxyProcess.createUnsMqttProxy((config.input?.host)!, "templateUnsRttInput", config.uns.instanceMode!, config.uns.handover!, {
34
+ mqttSubToTopics: ["raw/#"],
35
+ });
36
36
  const mqttOutput = await unsProxyProcess.createUnsMqttProxy((config.output?.host)!, "templateUnsRttOutput", config.uns.instanceMode!, config.uns.handover!, {
37
37
  publishThrottlingDelay: 1000,
38
38
  });
39
39
 
40
40
  /**
41
41
  * The input worker connects to the upstream broker and listens for incoming messages.
42
- * It processes the messages and transforms them into a table-type IUnsMessage.
43
- * The resulting message is published to the output broker.
44
- */
45
- mqttInput.event.on("input", async (event) => {
46
- try {
47
- if (event.topic === "raw/data") {
48
- const values = event.message.split(",");
49
- const [countRaw, timestampRaw, sensorRaw] = values;
50
- if (!countRaw || !timestampRaw || !sensorRaw) {
51
- logger.warn(`Skipping malformed raw/data payload: ${event.message}`);
52
- return;
53
- }
54
-
55
- const currentValue = Number.parseFloat(countRaw);
56
- const eventDate = new Date(Number.parseInt(timestampRaw, 10));
57
- const sensorValue = Number.parseFloat(sensorRaw);
58
-
59
- const time: ISO8601 = eventDate.toISOString() as ISO8601;
60
- const intervalStart: ISO8601 = new Date(eventDate.getTime() - 1000).toISOString() as ISO8601;
61
- const intervalEnd: ISO8601 = eventDate.toISOString() as ISO8601;
62
- const dataGroup = "sensor_table";
63
- const columns: IUnsTableColumn[] = [
64
- { name: "current", type: "double", value: currentValue, uom: GeneratedPhysicalMeasurements.Ampere },
65
- { name: "voltage", type: "double", value: sensorValue },
66
- { name: "active_energy_total", type: "double", value: currentValue, uom: GeneratedPhysicalMeasurements.KiloWattHour },
67
- ];
68
- const tableColumns: IUnsTableColumnMetadata[] = [
69
- {
70
- name: "active_energy_total",
71
- valueType: "number",
72
- presentationKind: "counter",
73
- defaultAggregation: "last",
74
- counterResetPolicy: "new-value",
75
- },
76
- ];
77
- const topic: UnsTopics = "enterprise/site/area/line/";
78
- const asset = resolveGeneratedAsset("asset");
79
- const assetDescription = ""; // customize manually
80
- mqttOutput.publishMqttMessage({
42
+ * It processes the messages and transforms them into a table-type IUnsMessage.
43
+ * The resulting message is published to the output broker.
44
+ */
45
+ mqttInput.event.on("input", async (event) => {
46
+ try {
47
+ if (event.topic === "raw/data") {
48
+ const values = event.message.split(",");
49
+ const [countRaw, timestampRaw, sensorRaw] = values;
50
+ if (!countRaw || !timestampRaw || !sensorRaw) {
51
+ logger.warn(`Skipping malformed raw/data payload: ${event.message}`);
52
+ return;
53
+ }
54
+
55
+ const currentValue = Number.parseFloat(countRaw);
56
+ const eventDate = new Date(Number.parseInt(timestampRaw, 10));
57
+ const sensorValue = Number.parseFloat(sensorRaw);
58
+
59
+ const time: ISO8601 = eventDate.toISOString() as ISO8601;
60
+ const intervalStart: ISO8601 = new Date(eventDate.getTime() - 1000).toISOString() as ISO8601;
61
+ const intervalEnd: ISO8601 = eventDate.toISOString() as ISO8601;
62
+ const dataGroup = "sensor_table";
63
+ const columns: IUnsTableColumn[] = [
64
+ { name: "current", type: "double", value: currentValue, uom: GeneratedPhysicalMeasurements.Ampere },
65
+ { name: "voltage", type: "double", value: sensorValue },
66
+ { name: "active_energy_total", type: "double", value: currentValue, uom: GeneratedPhysicalMeasurements.KiloWattHour },
67
+ ];
68
+ const tableColumns: IUnsTableColumnMetadata[] = [
69
+ {
70
+ name: "active_energy_total",
71
+ valueType: "number",
72
+ presentationKind: "counter",
73
+ defaultAggregation: "last",
74
+ counterResetPolicy: "new-value",
75
+ },
76
+ ];
77
+ const topic: UnsTopics = "enterprise/site/area/line/";
78
+ const asset = resolveGeneratedAsset("asset");
79
+ const assetDescription = ""; // customize manually
80
+ await mqttOutput.publishMqttMessage({
81
81
  topic,
82
82
  asset,
83
83
  assetDescription,
84
- objectType: GeneratedObjectTypes["energy-resource"],
85
- objectId: "main",
86
- attributes: [
87
- {
88
- attribute: "measurements",
89
- description: GeneratedAttributeDescriptions["status"] ?? "Table measurements with a counter column",
90
- tableColumns,
91
- table: {
92
- dataGroup,
93
- time,
94
- intervalStart,
95
- intervalEnd,
96
- columns,
97
- },
98
- },
99
- ],
84
+ objectType: GeneratedObjectTypes["energy-resource"],
85
+ objectId: "main",
86
+ virtualGroup: "metering",
87
+ attributes: [
88
+ {
89
+ attribute: "measurements",
90
+ description: GeneratedAttributeDescriptions["status"] ?? "Table measurements with a counter column",
91
+ tableColumns,
92
+ table: {
93
+ dataGroup,
94
+ time,
95
+ intervalStart,
96
+ intervalEnd,
97
+ columns,
98
+ },
99
+ },
100
+ ],
100
101
  });
101
102
  }
102
103
  } catch (error) {
103
- const reason = error instanceof Error ? error : new Error(String(error));
104
- logger.error(`Error publishing message to MQTT: ${reason.message}`);
105
- throw reason;
106
- }
107
- });
104
+ const reason = error instanceof Error ? error : new Error(String(error));
105
+ logger.error(`Error publishing message to MQTT: ${reason.message}`);
106
+ throw reason;
107
+ }
108
+ });