feat: Implement NUT client library and initial project scaffolding for UPS communication.
This commit is contained in:
62
debug_nut.js
Normal file
62
debug_nut.js
Normal file
@@ -0,0 +1,62 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
/**
|
||||
* Debug script for NUT connection
|
||||
*/
|
||||
|
||||
import * as net from 'net';
|
||||
|
||||
const NUT_HOST = '10.8.0.17';
|
||||
const NUT_PORT = 3493;
|
||||
|
||||
async function sendNUTCommand(command) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const socket = new net.Socket();
|
||||
let data = '';
|
||||
|
||||
socket.on('connect', () => {
|
||||
console.log(`✅ Connected to ${NUT_HOST}:${NUT_PORT}`);
|
||||
console.log(`📤 Sending: ${command}\n`);
|
||||
socket.write(command + '\n');
|
||||
});
|
||||
|
||||
socket.on('data', (chunk) => {
|
||||
data += chunk.toString();
|
||||
});
|
||||
|
||||
socket.on('end', () => {
|
||||
console.log('📥 Received:');
|
||||
console.log(data);
|
||||
console.log('---\n');
|
||||
resolve(data);
|
||||
});
|
||||
|
||||
socket.on('error', (err) => {
|
||||
console.error('❌ Error:', err.message);
|
||||
reject(err);
|
||||
});
|
||||
|
||||
socket.connect(NUT_PORT, NUT_HOST);
|
||||
|
||||
// Close connection after 2 seconds
|
||||
setTimeout(() => {
|
||||
socket.end();
|
||||
}, 2000);
|
||||
});
|
||||
}
|
||||
|
||||
async function debugNUT() {
|
||||
try {
|
||||
console.log('🔍 Testing NUT commands...\n');
|
||||
|
||||
// Try different commands
|
||||
await sendNUTCommand('LIST UPS');
|
||||
await sendNUTCommand('VER');
|
||||
await sendNUTCommand('HELP');
|
||||
|
||||
} catch (error) {
|
||||
console.error('Fatal error:', error);
|
||||
}
|
||||
}
|
||||
|
||||
debugNUT();
|
||||
Reference in New Issue
Block a user