How to send HEX buffer via NodeRed

Hi!

I'm a newbie using Node-RED and I'm having some issues when I try to send messages in HEX. This is the conversion table that I need:

01 - table

I have a setup with 4 stepper motors and I'm connecting through bluetooth. My idea is to controll the motors with Node-RED. The first test that I made was using my cellphone and it worked with the following "setup".

What I need to do is to send this messages with Node-RED, but I'm having trouble converting it. What's the easiest way to do it? Using a msg.payload (buffer) as

"["254","254","254","254","254","254","254","254"]" that's my answer.

buffer[8]raw

0: 0xfe
1: 0xfe
2: 0xfe
3: 0xfe
4: 0xfe
5: 0xfe
6: 0xfe
7: 0xfe

Using this function I managed to send a Buffer [5] with the return of 01 FE, but it doesn't work.

msg.payload = Buffer("01 FE");
Buffer.toString('hex');
return msg;

Thanks in advance!

Hi it is not 100% clear what you are trying to achieve.

Are you providing a page where you can enter a value in HEXADECIMAL that should then be transmitted to the bluetooth node as a byte array / buffer?

e.g. if your entry was 01 FE you want to have a buffer of [1,254] transmitted?

Hi, Steve!

My problem was a typo, I'm sorry... It is done and if anyone is looking for the same thing, here's how I'm doing:

Motor 01 - clockwise:

msg.payload = new Buffer([01,254]);
return msg;

Motor 01 - anti-clockwise

msg.payload = new Buffer([02,253]);
return msg;

Thanks!

new Buffer(...) is depreciated.

This is the correct way...

msg.payload = Buffer.from([1, 254]);
return msg;
msg.payload = Buffer.from([2, 253);
return msg;

Oh, updated here, thank you!

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.