homebridge-openwrt-control 0.3.1-beta.9 → 0.3.2
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/CHANGELOG.md +10 -0
- package/README.md +5 -3
- package/package.json +7 -3
- package/src/mqtt.js +66 -63
- package/src/router.js +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -9,6 +9,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
9
9
|
|
|
10
10
|
- After update to v0.1.0 the plugin need to be reconfigured!
|
|
11
11
|
|
|
12
|
+
## [0.3.2] - (18.02.2026)
|
|
13
|
+
|
|
14
|
+
## Changes
|
|
15
|
+
|
|
16
|
+
- MQTT refactor
|
|
17
|
+
- add funding
|
|
18
|
+
- bump deependencies
|
|
19
|
+
- readme updated
|
|
20
|
+
- cleanup
|
|
21
|
+
|
|
12
22
|
## [0.3.1] - (25.01.2026)
|
|
13
23
|
|
|
14
24
|
## Changes
|
package/README.md
CHANGED
|
@@ -13,7 +13,9 @@
|
|
|
13
13
|
[](https://github.com/grzegorz914/homebridge-openwrt-control/pulls)
|
|
14
14
|
[](https://github.com/grzegorz914/homebridge-openwrt-control/issues)
|
|
15
15
|
|
|
16
|
-
|
|
16
|
+
Homebridge plugin for OpenWrt devices.
|
|
17
|
+
|
|
18
|
+
<a href="https://buycoffee.to/grzegorz914" target="_blank"><img src="https://buycoffee.to/static/img/share/share-button-primary.png" style="width: 234px; height: 61px" alt="Postaw mi kawę na buycoffee.to"></a>
|
|
17
19
|
|
|
18
20
|
</span>
|
|
19
21
|
|
|
@@ -24,11 +26,11 @@
|
|
|
24
26
|
| [Homebridge](https://github.com/homebridge/homebridge) | [Homebridge Wiki](https://github.com/homebridge/homebridge/wiki) | HomeKit Bridge | Required |
|
|
25
27
|
| [Homebridge UI](https://github.com/homebridge/homebridge-config-ui-x) | [Homebridge UI Wiki](https://github.com/homebridge/homebridge-config-ui-x/wiki) | Homebridge User Interface | Recommended |
|
|
26
28
|
| [OpenWrt Control](https://www.npmjs.com/package/homebridge-openwrt-control) | [Plug-In Wiki](https://github.com/grzegorz914/homebridge-openwrt-control/wiki) | Homebridge Plug-In | Required |
|
|
27
|
-
| [OpenWrt ACL File](https://github.com/grzegorz914/homebridge-openwrt-control/blob/
|
|
29
|
+
| [OpenWrt ACL File](https://github.com/grzegorz914/homebridge-openwrt-control/blob/main/homebridge-acl.json) | `/usr/share/rpcd/acl.d/` | Access Control | Recommended |
|
|
28
30
|
|
|
29
31
|
## Note
|
|
30
32
|
|
|
31
|
-
* To use all of functions
|
|
33
|
+
* To use all of functions use [ACL File](https://github.com/grzegorz914/homebridge-openwrt-control/blob/main/homebridge-acl.json) and put in to `/usr/share/rpcd/acl.d/` folder on your router.
|
|
32
34
|
* After put it restart OpenWrt or RPCD service.
|
|
33
35
|
|
|
34
36
|
## About The Plugin
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"displayName": "OpenWrt Control",
|
|
3
3
|
"name": "homebridge-openwrt-control",
|
|
4
|
-
"version": "0.3.
|
|
4
|
+
"version": "0.3.2",
|
|
5
5
|
"description": "Homebridge plugin to control OpenWrt flashed devices.",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"author": "grzegorz914",
|
|
@@ -34,8 +34,8 @@
|
|
|
34
34
|
"node": "^20 || ^22 || ^24 || ^25"
|
|
35
35
|
},
|
|
36
36
|
"dependencies": {
|
|
37
|
-
"mqtt": "^5.
|
|
38
|
-
"axios": "^1.13.
|
|
37
|
+
"mqtt": "^5.15.0",
|
|
38
|
+
"axios": "^1.13.5",
|
|
39
39
|
"express": "^5.2.1"
|
|
40
40
|
},
|
|
41
41
|
"keywords": [
|
|
@@ -47,6 +47,10 @@
|
|
|
47
47
|
"wireless",
|
|
48
48
|
"router"
|
|
49
49
|
],
|
|
50
|
+
"funding": {
|
|
51
|
+
"type": "Buy Coffee To",
|
|
52
|
+
"url": "https://buycoffee.to/grzegorz914"
|
|
53
|
+
},
|
|
50
54
|
"contributors": [],
|
|
51
55
|
"scripts": {
|
|
52
56
|
"test": "echo \"Error: no test specified\" && exit 1"
|
package/src/mqtt.js
CHANGED
|
@@ -4,6 +4,7 @@ import EventEmitter from 'events';
|
|
|
4
4
|
class Mqtt extends EventEmitter {
|
|
5
5
|
constructor(config) {
|
|
6
6
|
super();
|
|
7
|
+
this.config = config;
|
|
7
8
|
|
|
8
9
|
const url = `mqtt://${config.host}:${config.port}`;
|
|
9
10
|
const subscribeTopic = `${config.prefix}/Set`;
|
|
@@ -15,60 +16,70 @@ class Mqtt extends EventEmitter {
|
|
|
15
16
|
protocolVersion: 5,
|
|
16
17
|
clean: false,
|
|
17
18
|
properties: {
|
|
18
|
-
sessionExpiryInterval: 60 * 60,
|
|
19
|
+
sessionExpiryInterval: 60 * 60,
|
|
19
20
|
userProperties: {
|
|
20
21
|
source: 'node-client'
|
|
21
22
|
}
|
|
22
23
|
}
|
|
23
24
|
};
|
|
24
25
|
|
|
25
|
-
this.mqttClient = connect(url, options)
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
26
|
+
this.mqttClient = connect(url, options)
|
|
27
|
+
.on('connect', async () => {
|
|
28
|
+
this.emit('connected', 'MQTT v5 connected.');
|
|
29
|
+
|
|
30
|
+
try {
|
|
31
|
+
await new Promise((resolve, reject) => {
|
|
32
|
+
this.mqttClient.subscribe(subscribeTopic,
|
|
33
|
+
{
|
|
34
|
+
qos: 1,
|
|
35
|
+
properties: {
|
|
36
|
+
userProperties: {
|
|
37
|
+
type: 'subscription'
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
},
|
|
41
|
+
(error) => {
|
|
42
|
+
if (error) return reject(error);
|
|
43
|
+
resolve();
|
|
44
|
+
}
|
|
45
|
+
);
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
this.emit('connected', `MQTT Subscribe topic: ${subscribeTopic}`);
|
|
49
|
+
} catch (error) {
|
|
50
|
+
if (config.logWarn) this.emit('warn', `MQTT Subscribe error: ${error.message}`);
|
|
51
|
+
}
|
|
52
|
+
})
|
|
53
|
+
.on('message', (topic, payload, packet) => {
|
|
54
|
+
try {
|
|
55
|
+
const parsedMessage = JSON.parse(payload.toString());
|
|
56
|
+
if (config.logDebug) this.emit('debug', `MQTT Received Topic: ${topic}, Payload: ${JSON.stringify(parsedMessage, null, 2)}`);
|
|
57
|
+
|
|
58
|
+
for (const [key, value] of Object.entries(parsedMessage)) {
|
|
59
|
+
this.emit('set', key, value);
|
|
39
60
|
}
|
|
40
|
-
})
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
if (config.logDebug) this.emit('debug', `MQTT Received:\nTopic: ${topic}\nPayload: ${JSON.stringify(obj, null, 2)}\nProperties: ${JSON.stringify(packet.properties, null, 2)}`);
|
|
55
|
-
|
|
56
|
-
const key = Object.keys(obj)[0];
|
|
57
|
-
const value = Object.values(obj)[0];
|
|
58
|
-
this.emit('set', key, value);
|
|
59
|
-
|
|
60
|
-
} catch (error) {
|
|
61
|
-
if (config.logWarn) this.emit('warn', `MQTT Parse error: ${error}`);
|
|
62
|
-
}
|
|
63
|
-
});
|
|
61
|
+
} catch (error) {
|
|
62
|
+
if (config.logWarn) this.emit('warn', `MQTT Parse error: ${error.message}`);
|
|
63
|
+
}
|
|
64
|
+
})
|
|
65
|
+
.on('error', (error) => {
|
|
66
|
+
this.emit('warn', `MQTT Error: ${error.message}`);
|
|
67
|
+
})
|
|
68
|
+
.on('reconnect', () => {
|
|
69
|
+
if (config.logDebug) this.emit('debug', 'MQTT Reconnecting...');
|
|
70
|
+
})
|
|
71
|
+
.on('close', () => {
|
|
72
|
+
if (config.logDebug) this.emit('debug', 'MQTT Connection closed.');
|
|
73
|
+
});
|
|
74
|
+
}
|
|
64
75
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
const publishMessage = JSON.stringify(message);
|
|
76
|
+
publish(topic, message) {
|
|
77
|
+
return new Promise((resolve, reject) => {
|
|
78
|
+
const fullTopic = `${this.config.prefix}/${topic}`;
|
|
79
|
+
const publishMessage = JSON.stringify(message);
|
|
70
80
|
|
|
71
|
-
|
|
81
|
+
this.mqttClient.publish(fullTopic, publishMessage,
|
|
82
|
+
{
|
|
72
83
|
qos: 1,
|
|
73
84
|
properties: {
|
|
74
85
|
contentType: 'application/json',
|
|
@@ -77,25 +88,17 @@ class Mqtt extends EventEmitter {
|
|
|
77
88
|
action: 'set'
|
|
78
89
|
}
|
|
79
90
|
}
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
});
|
|
87
|
-
|
|
88
|
-
// === ERRORS / STATE ===
|
|
89
|
-
this.mqttClient.on('error', (err) => {
|
|
90
|
-
if (config.logWarn) this.emit('warn', `MQTT Error: ${err.message}`);
|
|
91
|
-
});
|
|
92
|
-
|
|
93
|
-
this.mqttClient.on('reconnect', () => {
|
|
94
|
-
if (config.logDebug) this.emit('debug', 'MQTT Reconnecting...');
|
|
95
|
-
});
|
|
91
|
+
},
|
|
92
|
+
(error) => {
|
|
93
|
+
if (error) {
|
|
94
|
+
if (this.config.logWarn) this.emit('warn', `MQTT Publish error: ${error.message}`);
|
|
95
|
+
return reject(error);
|
|
96
|
+
}
|
|
96
97
|
|
|
97
|
-
|
|
98
|
-
|
|
98
|
+
if (this.config.logDebug) this.emit('debug', `MQTT Publish Topic: ${fullTopic}, Payload: ${publishMessage}`);
|
|
99
|
+
resolve();
|
|
100
|
+
}
|
|
101
|
+
);
|
|
99
102
|
});
|
|
100
103
|
}
|
|
101
104
|
}
|
package/src/router.js
CHANGED
|
@@ -176,7 +176,7 @@ class Router extends EventEmitter {
|
|
|
176
176
|
|
|
177
177
|
// External integrations
|
|
178
178
|
if (this.restFulConnected) this.restFul1.update('info', openWrtInfo);
|
|
179
|
-
if (this.mqttConnected) this.mqtt1.
|
|
179
|
+
if (this.mqttConnected) await this.mqtt1.publish('Info', openWrtInfo);
|
|
180
180
|
});
|
|
181
181
|
}
|
|
182
182
|
|