From 18625d447b6850eecb2af386a5d31f0f26bd945c Mon Sep 17 00:00:00 2001 From: Daniel Kluge Date: Thu, 26 Oct 2023 16:41:31 +0200 Subject: [PATCH] Work on connector --- lib/src/example_modules/mqttConnector.ts | 11 +++++++++-- lib/src/interfaceConnectionObject.ts | 11 +++++++---- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/lib/src/example_modules/mqttConnector.ts b/lib/src/example_modules/mqttConnector.ts index 05435d3..ec0c28c 100644 --- a/lib/src/example_modules/mqttConnector.ts +++ b/lib/src/example_modules/mqttConnector.ts @@ -1,5 +1,5 @@ import * as mqtt from "mqtt"; -import { Property, Operation, OperationVariable, BasicEventElement } from "@aas-core-works/aas-core3.0-typescript/dist/types/types"; +import type { Property, Operation, OperationVariable, BasicEventElement } from "@aas-core-works/aas-core3.0-typescript/dist/types/types"; import InterfaceConnectionObject from "interfaceConnectionObject"; class MQTTConnector extends InterfaceConnectionObject { @@ -10,8 +10,15 @@ class MQTTConnector extends InterfaceConnectionObject { private client: mqtt.MqttClient|null = null; + private store: Record = {}; + public connect(): boolean { - if (!this.client) this.client = mqtt.connect(this.config); + if (!this.client) this.client = mqtt.connect(this.connectionParameter); + this.client.on("message", (topic, message) => { + // If json is expected you could parse it here + this.store[topic] = message.toString("utf-8"); + }); + this.client.subscribe("#"); return this.client.connected; } diff --git a/lib/src/interfaceConnectionObject.ts b/lib/src/interfaceConnectionObject.ts index d87581b..462e434 100644 --- a/lib/src/interfaceConnectionObject.ts +++ b/lib/src/interfaceConnectionObject.ts @@ -1,4 +1,5 @@ import type { types } from "@aas-core-works/aas-core3.0-typescript"; +import type { EndpointMetadata } from "types/aidConf"; type ConnectionType = "ON_DEMAND" | "PERMANENT"; @@ -10,11 +11,13 @@ export default abstract class InterfaceConnectionObject { protected abstract readonly connectionType: ConnectionType; protected abstract readonly supportsSubscriptions: boolean; - protected config: ConfigInterface; - private onResponseCallback: OnResponseCallback; + protected readonly connectionParameter: ConfigInterface; + protected readonly endpointMetadata: EndpointMetadata; + private readonly onResponseCallback: OnResponseCallback; - public constructor(config: ConfigInterface, onResponseCallback: OnResponseCallback) { - this.config = config; + public constructor(connectionParameter: ConfigInterface, endpointMetadata: EndpointMetadata, onResponseCallback: OnResponseCallback) { + this.connectionParameter = connectionParameter; + this.endpointMetadata = endpointMetadata; this.onResponseCallback = onResponseCallback; }