dufourgilles / knx-ip

KNX IP Gateway protocol implementation
30 stars 9 forks source link

read always timeout #2

Closed nyotiemon closed 4 years ago

nyotiemon commented 4 years ago

I tried to read a group address but seems it always return timeout even after i put wait() function as the example. Using ETS5 to monitor the group, it shows there is read request and response, however since it just timed out after read, i didnt get to print the response. Current example doesnt help much because of different naming too.

Update: monitorBus doesnt do any thing as well.

const wait = (t=3000) => {
    return new Promise(resolve => {
        setTimeout(() => { resolve(); }, t);
    });
};
const dpa = KNXAddress.createFromString('1/0/0', KNXAddressType.TYPE_GROUP);
const dp = createDataPoint(dpa, 'Switch');
const kns = new KNXTunnelSocket("1.2.2");
dp.bind(kns);
kns.connectAsync('192.168.11.36', 3671)
.then(() => wait())
.then(() => console.log("Connected through channel id", kns.channelID))
.then(() => kns.readAsync(dpa)) // dp.read() result is the same
.then(() => wait(1000))
.then((val) => console.log(`${val}`))
.then(() => {
    console.log('monitoring');
    kns.on('indication', handleBusEvent);
    kns.monitorBus();
.then(() => wait(10000))
.catch(err => {console.log(err);})
.then(() => process.exit(0));

error message:

Connected through channel id  3
Error: Request 0 timed out
    at KNXClient._setTimerAndCallback (/home/user/test-knx/node_modules/knx-ip/src/KNXClient.ts:317:28)
    at KNXClient.sendReadRequest (/home/user/test-knx/node_modules/knx-ip/src/KNXClient.ts:187:14)
    at /home/user/test-knx/node_modules/knx-ip/src/KNXTunnelSocket.ts:98:29
    at new Promise (<anonymous>)
    at KNXTunnelSocket.readAsync (/home/user/test-knx/node_modules/knx-ip/src/KNXTunnelSocket.ts:97:16)
    at /home/user/test-knx/src/dto/protocol-knx.dto.ts:105:17
dufourgilles commented 4 years ago

Could you try ´1.0.0’ instead of ´1/0/0’

Thanks

Gilles

Le 4 août 2020 à 05:12, nyot notifications@github.com a écrit :

 I tried to read a group address but seems it always return timeout even after i put wait() function as the example. Current example doesnt help much because of different naming too.

const wait = (t=3000) => { return new Promise(resolve => { setTimeout(() => { resolve(); }, t); }); }; const dpa = KNXAddress.createFromString('1/0/0', KNXAddressType.TYPE_GROUP); const dp = createDataPoint(dpa, 'Switch'); const kns = new KNXTunnelSocket("1.2.2"); dp.bind(kns); kns.connectAsync('192.168.11.36', 3671) .then(() => wait()) .then(() => console.log("Connected through channel id", kns.channelID)) .then(() => kns.readAsync(dpa)) // dp.read() result is the same .then(() => wait(1000)) .then((val) => console.log(${val})) .catch(err => {console.log(err);}) .then(() => process.exit(0)); error message:

Connected through channel id 3 Error: Request 0 timed out at KNXClient._setTimerAndCallback (/home/user/test-knx/node_modules/knx-ip/src/KNXClient.ts:317:28) at KNXClient.sendReadRequest (/home/user/test-knx/node_modules/knx-ip/src/KNXClient.ts:187:14) at /home/user/test-knx/node_modules/knx-ip/src/KNXTunnelSocket.ts:98:29 at new Promise () at KNXTunnelSocket.readAsync (/home/user/test-knx/node_modules/knx-ip/src/KNXTunnelSocket.ts:97:16) at /home/user/test-knx/src/dto/protocol-knx.dto.ts:105:17 — You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub, or unsubscribe.

nyotiemon commented 4 years ago

just tried it, still gave the same error..

Thanks

dufourgilles commented 4 years ago

I’m on vacations and currently no access to a computer. But I can try to help. Did you try the bus monitoring feature to see if it works and verify the knx address of your switch?

Thanks for testing.

Gilles.

Le 4 août 2020 à 10:27, nyot notifications@github.com a écrit :

 just tried it, still gave the same error..

Thanks

— You are receiving this because you commented. Reply to this email directly, view it on GitHub, or unsubscribe.

nyotiemon commented 4 years ago

Hi,

Turns out it failed because of firewall. When i disabled it, i successfully get the response. Still not sure what rule i should add on firewall to let knxip work though. I tried to allow 3671 tcp/udp, but it still doesnt work. Thank you for taking the time to reply! Appreciate it. Nyot

nyotiemon commented 4 years ago

Hi, i tried to capture packages when creating tunnel and read request using wireshark. It shows that every time the tunnel is created, the dgram.socket will pick a random port to be used as the subsequent transaction. This is not nice, because it mean i will need to set firewall to allow all udp package from specific address, or turn the firewall off. However in my app, the ip of the knx gateway is not always the same.

I tried to bind the port on udp socket so it will always use the same one. Therefore firewall can be set to only allow one port.

class KNXClient {
    constructor() {
        ...
        this._clientSocket = dgram_1.default.createSocket('udp4');
        this._clientSocket.bind(52999, '0.0.0.0');
    }
}

Do you think this is a good idea?