Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Sending telnet commands to turn on/off projector in node.js

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

I also found this page

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?

>Solution :

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.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading