58 lines
1.6 KiB
TypeScript
58 lines
1.6 KiB
TypeScript
/**
|
|
* Main file to be executed.
|
|
*
|
|
* Monitor and upload different KNX events
|
|
*/
|
|
|
|
import { readAddresses, readMessage, KNXMessage } from 'knx-lib'
|
|
import knx from 'knx';
|
|
import { database } from './appwrite'
|
|
import dotenv from 'dotenv'
|
|
import { DPT } from 'dptlib/lib/definitions';
|
|
import { getDPTforAddress } from './processTelegram';
|
|
import { mainModule } from 'process';
|
|
|
|
// read the addresses and DPTs.
|
|
// let addresses = readAddresses("")
|
|
|
|
dotenv.config({ override: false })
|
|
|
|
// TODO: Create the map address -> DPT
|
|
// TODO: Automatic load addresses to DB
|
|
|
|
async function verify() {
|
|
getDPTforAddress({ dest_addr: '3/5/6' })
|
|
}
|
|
|
|
verify().then(() => console.log("---")).catch(e => console.log('Error: ', e))
|
|
|
|
|
|
|
|
async function main(evt: string, src: string, dest: string, value: Buffer) {
|
|
|
|
const dpt: DPT = (await getDPTforAddress({ dest_addr: dest })).dpt
|
|
|
|
console.log("%s **** KNX EVENT: %j, src: %j, dest: %j, value: %j (DPT: %j}",
|
|
new Date().toISOString().replace(/T/, ' ').replace(/\..+/, ''),
|
|
evt, src, dest, dpt.decoder(value));
|
|
}
|
|
|
|
// Create the connection
|
|
const connection = new knx.Connection({
|
|
ipAddr: process.env.KNX_GATEWAY_IP,
|
|
ipPort: Number.parseInt(process.env.KNX_GATEWAY_PORT),
|
|
physAddr: process.env.KNX_GATEWAY_KNX_ADDRESS,
|
|
//loglevel: 'trace',
|
|
handlers: {
|
|
connected: function () {
|
|
console.log('Connected!');
|
|
},
|
|
event: function (evt: string, src: string, dest: string, value: Buffer) {
|
|
|
|
main(evt, src, dest, value).then(() => { }).catch(e => console.log('Error: ', e))
|
|
|
|
|
|
//readMessage(value,new Date(), )
|
|
}
|
|
}
|
|
}); |