Closed nyotiemon closed 3 years ago
Do you have the KNX doc ? I can't find them anymore.
KNX spec 03_08_02 Core v01.05.01 AS.pdf The spec is available on KNX official website after login
I saw your new commit (9e23158) and tried the new update. The heartbeat works perfectly by sending connection state request every 60s.
However when the request timed out without response (~10s), there are no retries. Nor there are subsequent request after 60s after the last request. Is this intended?
Actually, I did not want the library to control retry, or reconnect, ... Instead, when an event like dead or timeout occurs, an event gets fired and it is up to your application to decide to retransmit or not.
Ok, I can understand how you design the lib. But somehow KNXTunnelSocket.on("disconnected")
didnt get called when connection is lost.
this._knx = new KNXTunnelSocket('0.0.1');
this._knx.bindSocketPortAsync(socketPort);
// setup monitoring callback
this._knx.on(KNXTunnelSocketEvents.indication, (src, dst, npdu) => {
this._logger.info(`indication ${src.toString()} -> ${dst.toString()}`);
});
// setup reconnect on disconnected
this._knx.on(KNXTunnelSocketEvents.disconnected, async () => {
this._logger.warn(`disconnected`);
});
// setup error handler
this._knx.on(KNXTunnelSocketEvents.error, (err) => {
this._logger.error(`error ${err}}`);
})
Tried the disconnect event by unplugging the device, the event never get triggered
Found out that KNXTunnelSocket didn't emit error on KNXClient.on(error)
, but it emits disconnected.
// KNXTunnelSocket.ts
private _init(): void {
this._knxClient.on(KNXClient.KNXClientEvents.connected, () => {
...
}).on(KNXClient.KNXClientEvents.error, (err: Error) => {
// no emit error
}).on(KNXClient.KNXClientEvents.disconnected, () => {
// tunnel socket emit disconnected
this.emit(KNXTunnelSocketEvents.disconnected);
}).on(KNXClient.KNXClientEvents.discover, this._processDiscoredHost);
}
And while at this, would it be more clear when KNXClient's heartbeat reach max timeout, it will send disconnect request and finished by emitting disconnected event?
// KNXClient.ts
getConnectionStatus(host: string, port: number, channelID?: number): void {
...
this._heartbeatTimer = setTimeout(() => {
this._heartbeatTimer = null;
this.emit(KNXClient.KNXClientEvents.error, timeoutError);
this._heartbeatFailures++;
if (this._heartbeatFailures >= this.max_HeartbeatFailures) {
this.emit(KNXClient.KNXClientEvents.error, deadError);
// either emit disconnected on this line
this.emit(KNXClient.KNXClientEvents.disconnected, `${host}:${port}`, channelID);
this.disconnect(host, port, this._channelID); // or inside disconnect method
}
}, 1000 * KNX_CONSTANTS.CONNECTIONSTATE_REQUEST_TIMEOUT);
...
}
Disconnected event on max heartbeat timeout is a very clear indication that user can/should retry the connection. The error event at the other hand has too much error variant int it. It also will clutter the app if user needs to catch specific error to find out if the socket is disconnected or not
Yes. I will make the change to emit disconnected.
as in KNX spec: