Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to forward a Telegram to another network? #12

Open
illia-piskurov opened this issue Sep 20, 2024 · 0 comments
Open

How to forward a Telegram to another network? #12

illia-piskurov opened this issue Sep 20, 2024 · 0 comments

Comments

@illia-piskurov
Copy link

illia-piskurov commented Sep 20, 2024

I am writing a program that will allow you to send telegrams from one network to another and back, it works, but unfortunately not with all types of telegrams. I can't understand why the telegram receiving event doesn't have a data type, so that I can specify it in the justification. Need help!

const KNX = require('knx');

const knxConfig1 = {
    ipAddr: '192.168.31.12',
    ipPort: 3671,
    // physAddr: '1.1.112'
};

const knxConfig2 = {
    ipAddr: '192.168.31.11',
    ipPort: 3671,
    // physAddr: '0.0.253'
};

const knxConnection1 = new KNX.Connection(knxConfig1);
const knxConnection2 = new KNX.Connection(knxConfig2);

knxConnection1.on('connected', () => {
    console.log('Connected to KNX network 1');
});
knxConnection2.on('connected', () => {
    console.log('Connected to KNX network 2');
});

knxConnection1.on('event', (evt, src, dest, value) => {
    debugger;
    knxConnection2.writeRaw(dest, value, (err) => {
        if (err) {
            console.error('Error forwarding telegram to network 2:', err);
        } else {
            console.log(`Forwarded telegram to network 2: ${dest} with value ${value}`);
        }
    });
});

knxConnection2.on('event', (evt, src, dest, value) => {
    knxConnection1.writeRaw(dest, value, (err) => {
        if (err) {
            console.error('Error forwarding telegram to network 1:', err);
        } else {
            console.log(`Forwarded telegram to network 1: ${dest} with value ${value}`);
        }
    });
});

knxConnection1.on('error', (err) => {
    console.error('Error in KNX connection 1:', err);
});

knxConnection2.on('error', (err) => {
    console.error('Error in KNX connection 2:', err);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant