-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
53 lines (44 loc) · 1.3 KB
/
index.js
File metadata and controls
53 lines (44 loc) · 1.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
const net = require('net');
const host = '192.168.9.69';
const port = 2000; // Default port as defined in Python code
function sendCommand(command) {
return new Promise((resolve, reject) => {
const client = new net.Socket();
let responseData = '';
client.connect(port, host, () => {
client.write(command);
});
client.on('data', (data) => {
responseData += data.toString();
client.destroy(); // kill client after server's response`
});
client.on('close', () => {
resolve(responseData);
});
client.on('error', (err) => {
reject(err);
});
});
}
async function getData() {
const commands = [
"\x1bRD90005f", // GET_STATUS
"\x1bRD100057", // GET_TEMPERATURE
"\x1bRD300059", // GET_POWERLEVEL
"\x1bRD40005A", // GET_PELLETSPEED
"\x1bRDA00067&", // GET_ERRORSTATE
"\x1bREF0006D&", // GET_EXHFANSPEED
"\x1bRD000056", // GET_FLUGASTEMP
"\x1bRC60005B&", // GET_SETPOINT (Optional, based on SUPPORT_SETPOINT in your code)
];
try {
for (const command of commands) {
const response = await sendCommand(command);
console.log(`Response for command ${command}: ${response}`);
}
} catch (err) {
console.error('Error communicating with stove:', err);
}
}
console.log("Trying to receive data");
getData();