uhppoted-db-web/uhppoted.js
2025-08-31 13:33:03 -06:00

34 lines
843 B
JavaScript

const uhppoted = require("uhppoted")
const os = require('os');
const bind = '0.0.0.0'
const broadcast = '255.255.255.255:60000'
const listen = '0.0.0.0:60001'
const timeout = 2500
const debug = true
const devices = [{ deviceId: 423163924, address: "10.0.0.128:60000" }]
const ctx = {
config: new uhppoted.Config("uhppoted", bind, broadcast, listen, timeout, devices, debug)
}
function getLocalIPAddress() {
const interfaces = os.networkInterfaces();
for (const name of Object.keys(interfaces)) {
for (const iface of interfaces[name]) {
if (iface.family === 'IPv4' && !iface.internal) {
return iface.address;
}
}
}
return null;
}
const localIP = getLocalIPAddress();
console.log('Local IP address:', localIP);
uhppoted.setListener(ctx, 423163924, localIP, 60001, 1);
uhppoted.listen(ctx, (msg) => {
console.log(msg)
})