Add keepalive option for MQTT (#2767)

This commit is contained in:
Twan Coenraad
2020-01-17 21:38:46 +01:00
committed by Koen Kanters
parent 39ed95371e
commit dd0ca2a392
3 changed files with 8 additions and 0 deletions
+5
View File
@@ -22,6 +22,11 @@ class MQTT extends events.EventEmitter {
},
};
if (mqttSettings.keepalive) {
logger.debug(`Using MQTT keepalive: ${mqttSettings.keepalive}`);
options.keepalive = mqttSettings.keepalive;
}
if (mqttSettings.ca) {
logger.debug(`MQTT SSL/TLS: Path to CA certificate = ${mqttSettings.ca}`);
options.ca = fs.readFileSync(mqttSettings.ca);
+1
View File
@@ -121,6 +121,7 @@ const schema = {
properties: {
base_topic: {type: 'string'},
server: {type: 'string'},
keepalive: {type: 'number'},
ca: {type: 'string'},
key: {type: 'string'},
cert: {type: 'string'},
+2
View File
@@ -57,6 +57,7 @@ describe('Controller', () => {
const configuration = {
base_topic: "zigbee2mqtt",
server: "mqtt://localhost",
keepalive: 30,
ca, cert, key,
password: 'pass',
user: 'user1',
@@ -69,6 +70,7 @@ describe('Controller', () => {
expect(MQTT.connect).toHaveBeenCalledTimes(1);
const expected = {
"will": {"payload": "offline", "retain": true, "topic": "zigbee2mqtt/bridge/state"},
keepalive: 30,
ca: Buffer.from([99, 97]),
key: Buffer.from([107, 101, 121]),
cert: Buffer.from([99, 101, 114, 116]),