homebridge-smartsystem 6.8.10 → 6.8.11

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/README.md CHANGED
@@ -314,6 +314,7 @@ Homebridge UI version
314
314
  - 8: 28 aug / less logging (through logConfig) for device set/get functions
315
315
  - 9: corrected reading the local config file + dump it in the logs
316
316
  - 10: wrong default port for cloud server
317
+ - 11: use new DNS entries + exponential backoff for new connections, give up after 16 seconds.
317
318
 
318
319
  ## Hardware
319
320
  A Raspberry Pi that connects to a Duotecno IP Node
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "homebridge-smartsystem",
3
3
  "displayname": "Duotecno Bridge",
4
- "version": "6.8.10",
4
+ "version": "6.8.11",
5
5
  "description": "SmartServer (Proxy TCP sockets to the cloud, Smappee MQTT, Duotecno IP Nodes, Homekit interface)",
6
6
  "main": "index.js",
7
7
  "author": "Johan Coppieters",
package/server/proxy.js CHANGED
@@ -5,7 +5,7 @@ const net = require("net");
5
5
  const child_process_1 = require("child_process");
6
6
  const process_1 = require("process");
7
7
  exports.kEmptyProxy = {
8
- cloudServer: "ws.duotecno.eu",
8
+ cloudServer: "masters.duotecno.eu",
9
9
  cloudPort: 5097,
10
10
  masterAddress: "",
11
11
  masterPort: 5001,
@@ -30,12 +30,12 @@ function setProxyConfig(c) {
30
30
  exports.setProxyConfig = setProxyConfig;
31
31
  try {
32
32
  const configPath = require.resolve('../config-proxy.json');
33
- console.log(`Using config file at: ${configPath}`);
33
+ console.log(`[PROXY] Using config file at: ${configPath}`);
34
34
  setProxyConfig(require(configPath));
35
35
  }
36
36
  catch (e) {
37
37
  setProxyConfig();
38
- log("No config-proxy.json found, using default values from homebridge or other.");
38
+ log("[PROXY] No config-proxy.json found, using default values from homebridge or other.");
39
39
  }
40
40
  let connectionChecker = null;
41
41
  const gCloudConnections = [];
@@ -61,19 +61,20 @@ function error(str) {
61
61
  // Start up the proxy server //
62
62
  ///////////////////////////////
63
63
  cleanStart(true);
64
- function makeNewCloudConnection(master, masterPort, server, serverPort, uniqueId, count = 0) {
64
+ function makeNewCloudConnection(master, masterPort, server, serverPort, uniqueId, count = 1) {
65
65
  // retry making a cloud connection
66
66
  function reconnect(err) {
67
- error(`[PROXY] → [CLOUD] Failed to connect ${count + 1} times to the Cloud server: ${err.message}`);
67
+ error(`[PROXY] → [CLOUD] Failed to connect ${count} times to the Cloud server: ${err.code || err.message}`);
68
68
  if (count < 3) {
69
69
  setTimeout(() => {
70
70
  makeNewCloudConnection(master, masterPort, server, serverPort, uniqueId, count + 1);
71
- }, 1000);
71
+ }, 1000 * count * count); // exponential backoff: 1 second, 4 seconds, 9 seconds -> give up
72
+ // we check every 16 seconds for a free connection, if none found -> restart
72
73
  }
73
74
  }
74
75
  const cloudSocket = new net.Socket();
75
76
  cloudSocket.once('error', reconnect);
76
- log(`[PROXY] → [CLOUD] Attempt ${count + 1} to start a new free connection for ${config.uniqueId} to the Cloud at ${server}:${serverPort}`);
77
+ log(`[PROXY] → [CLOUD] Attempt ${count} to start a new free connection for ${config.uniqueId} to the Cloud at ${server}:${serverPort}`);
77
78
  cloudSocket.connect(serverPort, server, () => {
78
79
  log(`[PROXY] → [CLOUD] Connected to Cloud at ${server}:${serverPort}`);
79
80
  cloudSocket.removeListener('error', reconnect);
@@ -101,19 +102,19 @@ function cleanStart(restart = false) {
101
102
  }
102
103
  if (restart) {
103
104
  if (config.uniqueId) {
104
- log(`[PROXY] → [CLOUD] Starting proxy with config: ${JSON.stringify(config, null, 2)}`);
105
+ log(`[PROXY] Starting proxy with config: ${JSON.stringify(config, null, 2)}`);
105
106
  makeNewCloudConnection(config.masterAddress, config.masterPort, config.cloudServer, config.cloudPort, config.uniqueId);
106
- // check every 10 second for a free connection
107
+ // check every 16 second for a free connection
107
108
  connectionChecker = setInterval(() => {
108
109
  const freeConnection = gCloudConnections.find((ctx) => (!ctx.deviceSocket) && ctx.cloudSocket && (ctx.cloudSocket.readyState === 'open'));
109
110
  if (freeConnection) {
110
- log(`[PROXY] → [CLOUD] Found free connection #${freeConnection.uniqueId} to the Cloud -> we're still ok.`);
111
+ debug(`[PROXY] → [CLOUD] Found free connection #${freeConnection.uniqueId} to the Cloud -> we're still ok.`);
111
112
  }
112
113
  else {
113
114
  error(`[PROXY] → [CLOUD] No free connections available, restarting proxy. ***************************`);
114
115
  cleanStart(true);
115
116
  }
116
- }, 10 * 1000);
117
+ }, 16 * 1000);
117
118
  }
118
119
  else {
119
120
  log(`[PROXY] → [CLOUD] Not restarting, no unique ID configured, not starting the proxy.`);
package/server/proxy.ts CHANGED
@@ -17,7 +17,7 @@ export interface ProxyConfig {
17
17
  }
18
18
 
19
19
  export const kEmptyProxy: ProxyConfig = {
20
- cloudServer: "ws.duotecno.eu",
20
+ cloudServer: "masters.duotecno.eu",
21
21
  cloudPort: 5097,
22
22
  masterAddress: "",
23
23
  masterPort: 5001,
@@ -45,12 +45,12 @@ export function setProxyConfig(c?: ProxyConfig): ProxyConfig {
45
45
 
46
46
  try {
47
47
  const configPath = require.resolve('../config-proxy.json');
48
- console.log(`Using config file at: ${configPath}`);
48
+ console.log(`[PROXY] Using config file at: ${configPath}`);
49
49
  setProxyConfig(require(configPath));
50
50
 
51
51
  } catch (e) {
52
52
  setProxyConfig();
53
- log("No config-proxy.json found, using default values from homebridge or other.");
53
+ log("[PROXY] No config-proxy.json found, using default values from homebridge or other.");
54
54
  }
55
55
 
56
56
 
@@ -84,21 +84,22 @@ function error(str: string) {
84
84
  cleanStart(true);
85
85
 
86
86
 
87
- export function makeNewCloudConnection(master: string, masterPort: number, server: string, serverPort: number, uniqueId: string, count = 0) {
87
+ export function makeNewCloudConnection(master: string, masterPort: number, server: string, serverPort: number, uniqueId: string, count = 1) {
88
88
  // retry making a cloud connection
89
- function reconnect(err: Error) {
90
- error(`[PROXY] → [CLOUD] Failed to connect ${count+1} times to the Cloud server: ${err.message}`);
89
+ function reconnect(err: NodeJS.ErrnoException) {
90
+ error(`[PROXY] → [CLOUD] Failed to connect ${count} times to the Cloud server: ${err.code || err.message}`);
91
91
  if (count < 3) {
92
92
  setTimeout(() => {
93
- makeNewCloudConnection(master, masterPort, server, serverPort, uniqueId, count + 1);
94
- }, 1000);
93
+ makeNewCloudConnection(master, masterPort, server, serverPort, uniqueId, count+1);
94
+ }, 1000 * count * count); // exponential backoff: 1 second, 4 seconds, 9 seconds -> give up
95
+ // we check every 16 seconds for a free connection, if none found -> restart
95
96
  }
96
97
  }
97
98
 
98
99
  const cloudSocket = new net.Socket();
99
100
  cloudSocket.once('error', reconnect);
100
101
 
101
- log(`[PROXY] → [CLOUD] Attempt ${count+1} to start a new free connection for ${config.uniqueId} to the Cloud at ${server}:${serverPort}`);
102
+ log(`[PROXY] → [CLOUD] Attempt ${count} to start a new free connection for ${config.uniqueId} to the Cloud at ${server}:${serverPort}`);
102
103
 
103
104
  cloudSocket.connect(serverPort, server, () => {
104
105
  log(`[PROXY] → [CLOUD] Connected to Cloud at ${server}:${serverPort}`);
@@ -133,21 +134,21 @@ export function cleanStart(restart: boolean = false) {
133
134
 
134
135
  if (restart) {
135
136
  if (config.uniqueId) {
136
- log(`[PROXY] → [CLOUD] Starting proxy with config: ${JSON.stringify(config, null, 2)}`);
137
+ log(`[PROXY] Starting proxy with config: ${JSON.stringify(config, null, 2)}`);
137
138
  makeNewCloudConnection(config.masterAddress, config.masterPort, config.cloudServer, config.cloudPort, config.uniqueId);
138
139
 
139
- // check every 10 second for a free connection
140
+ // check every 16 second for a free connection
140
141
  connectionChecker = setInterval(() => {
141
142
  const freeConnection = gCloudConnections.find((ctx: Context) =>
142
143
  (!ctx.deviceSocket) && ctx.cloudSocket && (ctx.cloudSocket.readyState === 'open')
143
144
  );
144
145
  if (freeConnection) {
145
- log(`[PROXY] → [CLOUD] Found free connection #${freeConnection.uniqueId} to the Cloud -> we're still ok.`);
146
+ debug(`[PROXY] → [CLOUD] Found free connection #${freeConnection.uniqueId} to the Cloud -> we're still ok.`);
146
147
  } else {
147
148
  error(`[PROXY] → [CLOUD] No free connections available, restarting proxy. ***************************`);
148
149
  cleanStart(true);
149
150
  }
150
- }, 10 * 1000);
151
+ }, 16 * 1000);
151
152
 
152
153
  } else {
153
154
  log(`[PROXY] → [CLOUD] Not restarting, no unique ID configured, not starting the proxy.`);