fbacker / broadlink-mqtt-bridge

Bridge Broadlink RM Devices with MQTT and API for e.g. OpenHAB
41 stars 14 forks source link

Convert RF to Bin file #20

Closed NovaGL closed 3 years ago

NovaGL commented 4 years ago

Hi,

I have the following HEX, but I can't learn RF codes as I have lost the remote. I currently works with IHC app but want it working on this.

How can I convert the following to work

-78, 4, -124, 3, 13, 23, 24, 11, 25, 11, 24, 12, 24, 11, 13, 23, 12, 23, 13, 23, 24, 11, 25, 11, 24, 12, 12, 23, 13, 23, 13, 22, 25, 11, 24, 11, 13, 23, 13, 23, 12, 23, 13, 23, 12, 23, 25, 11, 13, 23, 24, 11, 13, 23, 12, 23, 13, 23, 24, 11, 13, 23, 12, 23, 13, 23, 24, 0, 1, 0, -97, 49, 12, 23, 13, 23, 24, 11, 13, 23, 25, 10, 13, 23, 13, 22, 13, 23, 12, 24, 24, 11, 24, 12, 24, 11, 25, 11, 12, 23, 13, 23, 12, 23, 25, 11, 24, 12, 24, 11, 13, 22, 13, 23, 13, 23, 24, 11, 24, 12, 12, 23, 13, 23, 12, 23, 13, 23, 13, 22, 25, 11, 12, 23, 25, 11, 12, 24, 12, 23, 12, 23, 25, 11, 12, 23, 13, 23, 13, 23, 24, 0, 1, 0, -97, 48, 13, 22, 13, 23, 25, 11, 12, 23, 25, 11, 12, 23, 12, 24, 12, 23, 13, 23, 25, 10, 25, 11, 25, 11, 24, 11, 13, 23, 12, 23, 13, 23, 24, 11, 25, 11, 24, 12, 12, 23, 13, 22, 13, 23, 24, 12, 24, 11, 13, 23, 13, 22, 13, 23, 13, 23, 12, 23, 24, 12, 12, 23, 25, 11, 13, 22, 13, 23, 12, 23, 25, 11, 13, 23, 12, 23, 13, 23, 24, 0, 1, 0, -97, 48, 13, 23, 13, 22, 25, 11, 13, 22, 25, 11, 13, 23, 12, 23, 13, 22, 13, 23, 25, 11, 24, 11, 25, 11, 24, 11, 13, 23, 13, 22, 13, 23, 24, 12, 24, 11, 25, 11, 13, 22, 13, 23, 13, 22, 25, 11, 25, 11, 12, 23, 13, 23, 12, 23, 13, 23, 12, 23, 24, 12, 12, 23, 25, 11, 13, 22, 13, 23, 13, 22, 25, 11, 12, 24, 12, 23, 13, 23, 24, 0, 1, 0, -97, 48, 13, 23, 12, 23, 25, 11, 13, 22, 25, 11, 13, 22, 13, 23, 13, 23, 12, 23, 25, 11, 24, 11, 25, 11, 24, 11, 13, 23, 12, 24, 12, 23, 25, 11, 24, 11, 25, 11, 13, 22, 13, 23, 12, 23, 25, 11, 24, 12, 12, 23, 13, 23, 12, 23, 13, 23, 13, 23, 24, 11, 12, 24, 24, 11, 13, 23, 12, 23, 13, 23, 24, 11, 13, 23, 12, 23, 13, 23, 24, 0, 1, 0, -96, 48, 12, 23, 13, 23, 24, 11, 13, 23, 25, 10, 13, 23, 13, 22, 13, 23, 13, 23, 24, 11, 25, 11, 24, 11, 25, 11, 13, 23, 12, 23, 13, 22, 25, 11, 25, 11, 24, 11, 13, 23, 13, 23, 12, 23, 24, 12, 24, 11, 13, 23, 13, 22, 13, 23, 12, 23, 13, 23, 24, 12, 12, 23, 25, 11, 12, 23, 13, 22, 13, 23, 25, 11, 12, 23, 13, 23, 13, 23, 24, 0, 1, 0, -97, 48, 13, 23, 13, 23, 24, 11, 13, 23, 24, 11, 13, 23, 12, 24, 12, 23, 13, 23, 24, 11, 25, 11, 24, 11, 25, 11, 13, 22, 13, 23, 13, 23, 24, 11, 25, 11, 24, 11, 13, 23, 13, 22, 13, 23, 24, 11, 25, 11, 13, 22, 13, 23, 13, 23, 12, 23, 13, 23, 24, 11, 13, 23, 25, 10, 13, 23, 12, 23, 13, 23, 24, 12, 12, 23, 13, 23, 12, 23, 25, -1, -96, 48, 13, 22, 13, 23, 25, 11, 12, 23, 25, 11, 13, 22, 13, 23, 13, 23, 12, 23, 25, 11, 24, 11, 25, 11, 24, 11, 13, 23, 12, 24, 12, 23, 24, 12, 24, 11, 24, 11, 13, 23, 13, 23, 12, 23, 25, 11, 24, 11, 13, 23, 12, 23, 13, 23, 12, 23, 13, 23, 24, 12, 12, 23, 24, 11, 13, 23, 13, 23, 12, 23, 25, 11, 12, 23, 13, 23, 13, 23, 24, 0, 1, 0, -97, 48, 12, 23, 13, 23, 24, 12, 12, 23, 25, 11, 12, 23, 13, 22, 13, 23, 13, 23, 24, 11, 25, 11, 24, 12, 24, 11, 13, 23, 12, 23, 13, 23, 24, 11, 25, 11, 24, 11, 13, 23, 12, 23, 13, 23, 24, 11, 25, 11, 13, 23, 12, 23, 13, 23, 12, 23, 13, 23, 24, 11, 13, 23, 24, 11, 13, 23, 12, 23, 13, 23, 25, 10, 13, 23, 12, 24, 12, 23, 25, -1, -96, 47, 13, 23, 13, 22, 25, 11, 13, 22, 25, 11, 13, 23, 12, 23, 13, 23, 12, 23, 25, 11, 24, 11, 25, 11, 24, 11, 13, 23, 13, 22, 13, 23, 25, 11, 24, 11, 24, 12, 12, 23, 13, 23, 12, 23, 25, 11, 24, 11, 13, 23, 12, 24, 12, 23, 12, 23, 13, 23, 24, 12, 12, 23, 24, 12, 12, 23, 13, 22, 13, 23, 25, 11, 12, 23, 13, 23, 13, 22, 25, -1, -96, 48, 13, 22, 13, 23, 25, 11, 12, 23, 25, 10, 13, 23, 13, 23, 12, 23, 13, 23, 24, 11, 25, 11, 24, 11, 25, 11, 12, 23, 13, 23, 13, 23, 24, 11, 25, 11, 24, 11, 13, 23, 12, 23, 13, 23, 24, 11, 25, 11, 12, 23, 13, 23, 12, 23, 13, 23, 12, 23, 25, 11, 12, 23, 25, 11, 12, 23, 13, 23, 12, 24, 24, 11, 12, 24, 12, 23, 13, 23, 24, 0, 5, -36, 0, 0, 0, 0
fbacker commented 4 years ago

Not really sure, Think the device plugin I'm using decrypts aes-128-cbc data to js Buffer. When I get it to the program I save it to a file.

So maybe convert the string to a utf8 buffer and save it to a *.bin file, place it in the command folder and see if it works. Please let me know.

xscope44 commented 4 years ago

Not really sure, Think the device plugin I'm using decrypts aes-128-cbc data to js Buffer. When I get it to the program I save it to a file.

So maybe convert the string to a utf8 buffer and save it to a *.bin file, place it in the command folder and see if it works. Please let me know.

I am trying to reuse already learned codes i gathered from e-control Database. What is the command to convert them and save as yours bin files ?

Example of RF code from e-control DB: e900a201131113111311131113111311081b1411091d1310091b091a091b091b091b1410091b150f150f150f150f150f1510140f0a1a0a1a150f150f0a1a0a1a0b19150f0a1a0a1a0a1a150e0b190a1a0a1a160001259d32160e160e160e170e150e160e0b19170d0c18170d0b190b190b190c180b19170d0b19160e170d160e160e170d160e160f0a190b1a160d17100a180b190c18170e0b190a190b1a160e0b180b1a0a19170001289f31170d170d170d170d170d170d0c18180e0a18170d0d190b190b180d170c19160e0b19170d170d170d170d170d160e160e0c180c18170d170d0b190b190b18170e0b190b180c19170e0b170c180c18170001239f32160d170d170d170d170d170d0c18170d0d17180c0c180d170c180d170c18170d0c19160d170d170d170d170e160d170e0b180c19160d170d0c180c180d18170e0b190b180c18180e0b170c180c19160001229e32180c170d170e160d170d170d0c17190c0c19180b0d170c180b180c1a0c18170d0c18180c190b170e160d170d170f150e0b190b18180e160c0c1a0a180c18180d0b180c180c18180c0c180c180c18170005dc000000000000

fbacker commented 4 years ago

I'm using a fork for handling broadlink messages. https://github.com/fbacker/broadlinkjs-rm

Maybe just try to name the file to *.bin and see if it works? Else check the broadlinkjs project. Please let us know if you figure something out.

doing something with "decrypts aes-128-cbc" and bufferdata.

NovaGL commented 4 years ago

Just wanted to say thanks! @fbacker

I finally got around to doing this and the key was converting the string to a buffer! I looked all over but all the results I saw talked about converting to HEX and Base64

All I had to do was to convert the JSON string to a buffer using:

 Buffer.from(string)

Then saving the output as a bin file and your app does the rest!

fbacker commented 4 years ago

@NovaGL nice work. Did a little CLI script with method to convert. However I have no idea if it works. Can you try it out and if it not work give me pointers on what you did?

Upgrade to 2.1.4 and in project folder run ./cli.js This should give you an output help

Then you can try example js ./cli.js convert -f myfile.hex You can use the -o to put the bin file directly in commands folder (I hope) and it should work (fingers crossed).

NovaGL commented 4 years ago

Will do. Can you put an example hex.

I just want to see the format you use so I can match it.

fbacker commented 4 years ago

I took what @xscope44 posted. However I have no way of testing if it works :) To test it you need your example files, then convert it and play them, having a device that receives the request.

NovaGL commented 4 years ago

Ok. I'll let you know. However mine is a JSON string so it won't work the same.

HEX to buffer might be different https://www.w3schools.com/nodejs/met_buffer_from.asp

So using this page it seems you need to do

Buffer.from(string, 'hex')

I'll try later

NovaGL commented 4 years ago

Not sure how to run that cli file.

However if you want you can try your script with this and i'll tell you if it works

2600CA008F941036101410370F3710140F140F380F141014103711121211123512351211123512351211123512351235113512351235121112351212111212111212111212120F1410370F380F3710370F380F140F150F380F140F1410140F140F1410370F380FAE8E941037101310370F380F150F140F380F140F1410370F150F140F3810370F140F380F380F140F380F380F3710370F380F380F140F380F1410140F140F150F140F1410140F37103710370F380F380F140F150F370F150F140F1410140F1410370F380F000D050000000000000000000000000000

I still think you need to change the buffer.from section

fbacker commented 4 years ago

Not sure what I'm doing here :)

but you can take the files that you want to convert. In broadlink folder just run

cli.js -f myfiletoconvert.hex

and it will output a new file myfiletoconvert.bin that you can try to play with broadlink.

fbacker commented 3 years ago

stale