v2c-any 0.4.2 → 0.5.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.
|
@@ -6,6 +6,8 @@ export const energyInformationSchema = z.object({
|
|
|
6
6
|
export const mqttPushBridgeFeedSchema = z
|
|
7
7
|
.object({
|
|
8
8
|
url: z.string(),
|
|
9
|
+
username: z.string().optional(),
|
|
10
|
+
password: z.string().optional(),
|
|
9
11
|
device: z.string(),
|
|
10
12
|
topic: z.string(),
|
|
11
13
|
})
|
|
@@ -62,6 +64,8 @@ export const mqttProviderSchema = z.object({
|
|
|
62
64
|
provider: z.literal('mqtt'),
|
|
63
65
|
properties: z.object({
|
|
64
66
|
url: z.string(),
|
|
67
|
+
username: z.string().optional(),
|
|
68
|
+
password: z.string().optional(),
|
|
65
69
|
meters: mqttMetersSchema,
|
|
66
70
|
}),
|
|
67
71
|
});
|
|
@@ -29,7 +29,10 @@ export class MqttBridgeService extends AbstractExecutableService {
|
|
|
29
29
|
*/
|
|
30
30
|
async doStart() {
|
|
31
31
|
logger.info('Starting MQTT bridge service');
|
|
32
|
-
this.client = await createMqttClient(this.properties.url
|
|
32
|
+
this.client = await createMqttClient(this.properties.url, {
|
|
33
|
+
username: this.properties.username,
|
|
34
|
+
password: this.properties.password,
|
|
35
|
+
});
|
|
33
36
|
this.client.on('message', (topic, message) => {
|
|
34
37
|
if (topic === this.properties.topic) {
|
|
35
38
|
const data = JSON.parse(message.toString());
|
|
@@ -57,7 +57,10 @@ export class MqttService extends AbstractExecutableService {
|
|
|
57
57
|
*/
|
|
58
58
|
async doStart() {
|
|
59
59
|
logger.info('Starting MQTT mode');
|
|
60
|
-
this.client = await createMqttClient(this.properties.url
|
|
60
|
+
this.client = await createMqttClient(this.properties.url, {
|
|
61
|
+
username: this.properties.username,
|
|
62
|
+
password: this.properties.password,
|
|
63
|
+
});
|
|
61
64
|
logger.info('MQTT client started');
|
|
62
65
|
}
|
|
63
66
|
/**
|
package/dist/utils/mqtt.js
CHANGED
|
@@ -8,8 +8,8 @@ import { logger } from './logger.js';
|
|
|
8
8
|
* @returns A promise that resolves to a connected MqttClient instance
|
|
9
9
|
* @throws {Error} If the underlying connection fails
|
|
10
10
|
*/
|
|
11
|
-
export async function createMqttClient(url) {
|
|
12
|
-
const client = await mqtt.connectAsync(url);
|
|
11
|
+
export async function createMqttClient(url, options) {
|
|
12
|
+
const client = await mqtt.connectAsync(url, options);
|
|
13
13
|
client.on('reconnect', () => logger.info('Reconnecting...'));
|
|
14
14
|
return client;
|
|
15
15
|
}
|