I have an Optoma project that I am trying to send commands to. I am able to ping the projector and connect to it with my script, but it is not turning on and off.
Here is my code:
const net = require('net');
// Some sample projector control codes
var NEC = {
port: 23,
ip: "xxx.xxx.x.xxx", // ip address
on: Buffer.from([0x7E, 0x30, 0x30, 0x30, 0x30, 0x20, 0x31]),
off: Buffer.from([0x7E, 0x30, 0x30, 0x30, 0x30, 0x20, 0x32])
};
var device = NEC;
var command = device.on;
const client = new net.Socket();
client.connect(device.port, device.ip, () => {
console.log(`Connected to projector at ${device.ip}:${device.port}`);
client.write(command);
});
client.on('data', (data) => {
console.log(`Received data from projector:`, data.toString("hex"));
client.end();
});
client.on('error', (err) => {
console.log('Error:', err.message);
});
client.on('end', () => {
console.log("Connection ended");
});
client.on('close', () => {
console.log("Connection closed");
});
This is the Optoma documentation with the commands
Am I writing out the commands correctly in my script?
I know the projector is able to be reached and the port is correct. Is my script the correct way to go about sending commands?
Telnet is by default line based. That means that each "command" needs the line-ending sequence "\r\n"
.
You need to add those to the commands you send to the device.