Skip to content

Commit a033a00

Browse files
authored
fix: Use correct client id pattern (#24)
Fixes #23
1 parent b8e650e commit a033a00

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# Changelog
22

3+
## [1.1.8]
4+
- Fix connection to remove broker by using the correct client ID pattern
5+
36
## [1.1.7]
47
- Added health check endpoint for better monitoring and automatic recovery
58
- Added Docker health check configuration

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "hame-relay",
3-
"version": "1.1.7",
3+
"version": "1.1.8",
44
"description": "MQTT message forwarder between brokers",
55
"main": "dist/forwarder.js",
66
"scripts": {

src/forwarder.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,7 @@ class MQTTForwarder {
229229
private initializeBrokers(): void {
230230
const options = {
231231
keepalive: 30,
232+
clientId: this.generateClientId()
232233
};
233234
this.configBroker = mqtt.connect(this.config.broker_url, options);
234235

@@ -243,6 +244,14 @@ class MQTTForwarder {
243244
this.setupBrokerEventHandlers();
244245
}
245246

247+
private generateClientId() {
248+
let randomClientId = "";
249+
for (let i = 0; i < 24; i++) {
250+
randomClientId += Math.floor(Math.random() * 16).toString(16);
251+
}
252+
return `hm_${randomClientId}`;
253+
}
254+
246255
private setupBrokerEventHandlers(): void {
247256
// Config broker event handlers
248257
this.configBroker.on('connect', () => {

0 commit comments

Comments
 (0)