knx-listener
Version:
A thin client that creates a tunnel to knx gateway to listen to telegrams within knx net
112 lines (95 loc) • 3.69 kB
Markdown
# KNX Listener
A thin node client to monitor, write and read groups telegrams through KNX gateway
[](https://badge.fury.io/js/knx-listener) []()
## Install
Install the knx-listener globally and use commands from the command line
```
sudo npm install -g knx-listener
```
## Remote access to the knx net
### Monitor telegrams
```
Usage bin/busmonitor.js -s <ip address>
Options:
-t, --timeout Seconds to retry, 0 - fail on first attemp [default: 0]
-p, --port Remote port number [default: 3671]
-s, --server Remote ip address [required]
-h, --help Show help [boolean]
```
```
busmonitor -s 192.168.1.100
```

### Write value **1** to **0/0/1** through **192.168.1.100**
```
Usage bin/groupswrite.js -s <ip address> -g <group address> -d <XX:XX:..>
Options:
-s, --server Remote ip address [required]
-p, --port Remote port number [default: 3671]
-g, --groupAddress Group address to issue the write telegram to [required]
-d, --data Data to write [required]
-h, --help Show help [boolean]
```
```
groupswrite -s 192.168.1.100 -g 0/0/1 -d 01
```

### Read value from **0/0/1** through **192.168.1.100**
```
Usage bin/groupsread.js -s <ip address> -g <group address>
Options:
-s, --server Remote ip address [required]
-p, --port Remote port number [default: 3671]
-g, --groupAddress Group address to issue the read telegram to [required]
-h, --help Show help [boolean]
```
```
groupsread -s 192.168.1.100 -g 0/0/1
```

## Development use cases
```js
const KnxListener = require("knx-listener");
// 1. Initialize bus listener
const client = new KnxListener.BusListener();
// helper to terminate tunnel
const die = () => {
return client.disconnect().then(
() => process.exit(),
() => process.exit());
};
// 2. Establish tunneling with recovery time of 1s
client.bind("192.168.1.105", 3671, {
timeout: 1000,
});
// 3. Print processed queries to the console
client.on("query", console.log);
client.ready(() => {
// 4. When connection is established
// 5. Send read telegram and receive response with data
client.read(KnxListener.utils.knxAddr2num("0/0/1")).then((res) => {
console.log("Remote responded with", res);
}, (err) => {
console.error("Request failed", err);
});
// 6. Send write telegram with data 0xFF to the group address 0/0/2
client.write([0xFF], KnxListener.utils.knxAddr2num("0/0/2")).then(() => {
console.log("Success");
}, (err) => {
console.error("Request failed", err);
});
});
// ctrl+c to exit
process.on('SIGINT', die);
```
## TODO
* Generate JSDoc
* Integration testing
* Create another npm module for data types encoding/decoding
## What is next?
* You may create stream using websockets to broadcast telegrams to rich web apps
* You may create ETS project parser to get group address and store them in db
* You may create REST API with express
* You may record telegrams to a database and return last values on demand
* You may build visualization with any KNX gateway
* You may delegate endcoding/decoding of data to your rich clients