I’ve tried a script you’ve provided, but I’m unable to make it work on RM 3. It does (with some changes) put RM 3 into learning mode, and returns learned command, but if I try to resend that learned command, the action is not triggered (for example, does not change volume on my TV). What kind of test have you tried? I’m still trying to figure out the encryption of the payload, but I can’t get the right code to send, from the received code. I suppose that, as Lionello said, AES key and IV are not the same for RM 2 and RM 3.
@Davorf: Actually I was able to send the learned code to TV. I have two Minis, I do not know if the problem you have depend on the fact that you have only one. Moreover I simply downloaded the code into my raspberry without any customized python library and found no error. Have you tried to run the script on a clean install?
Have you seen if the packet is sent by python when you try to send a code?
What version of Python you use? I guess the script was made for 2.X, and that’s the reason I get so many errors. Besides, how do you distinguish between 2 RMs? Do you use it as an element of an array? I’ve tried printing learned and sent command, but it’s not hex at all.
Hi Davorf, I use the standard python version distributed with Raspbian
Python 2.7.9 (default, Mar 8 2015, 00:52:26)
[GCC 4.9.2] on linux2
If you follow instructions of the README you will see that devices is an array of all devices found on the network. You have to reference to one at at a time with an index
devices[0] is the first fiscovered
devices[1] is the second one
devices = broadlink.discover(timeout=5) // get devices
devices[0].auth() // get the key to talk with device[0]
devices[0].host // return the name of the first mini
devices[0].enter_learning() // the mini enter learning mode
// I operate the command
ir_packet = devices[0].check_data()
// ir_packet is the byte sequence unenecrypted
devices[0].send_data(ir_packet)
An example of ir_packet is a string that encodes hex bytes
as follows
As I supposed, you’re using 2.X Python. There is pretty big difference between 2.X and 3.X, and the code is not always compatible. I’ve managed to go past the last error (had to reinstall pycrypto from a wheel), but when I try to execute your code, I get the same error I’ve got last night:
es\broadlink-0.1-py3.5.egg\broadlink\__init__.py", line 34, in discover
packet[0x08] = timezone
TypeError: an integer is required
For some reason, Python 3.X represents this value as float. I’ll try to install Python 2.X on some virtual machine and see if it works that way. Thank you for your help.
I’ve managed to incorporate Broadlink package to BlackBeanControl. The new version should be used with Python 2.X only (because Broadlink package supports only Python 2.X). There are 2 new settings inside of BlackBeanControl.ini:
MACAddress - MAC address of the RM 3 mini
Timeout - time in seconds, between beginning of learning process and reading learned command (should be under 60 seconds)
Command line now includes -m switch (command line MAC address parameter) - in case you have more then one RM3. Syntax is similar:
BlackBeanControl.py -c [-i ] [-p ] [-m ]
If the command you send is found in the .ini file, it will send it. If it is not found, it will start learning process (after that, you should press the button on the remote, so RM3 receives it), wait until timeout, and then save learned command. Next time you use a command with that name, it will send code from the .ini file. If you encounter any errors, write about it here, or on github.
Yes, I forgot to mention you’ll have to install broadlink module too. The easiest way to do it would be downloading it from github, and running setup.py. If you’re using both Python 2.X and Python 3.X make sure you install all additional modules to the right version (2.X)
I have a RM3 Mini and have been watching this thread develop and all the work that has gone into it… what determination!
I’ve trying to duplicate some of the methods that have been suggested without success so far.
For my latest efforts -
installed e-Control app and captured the power toggle command for my AVR, which works from the app
installed tPatcketCapture on my phone
started e-Control
started tPacketCapture and put in running state with VPN
toggled power from e-Control to AVR (AVR powered off)
stopped tPacketCapture
Copied the file to my (windows) laptop for analysis with wireshark.
When looking at the packets in wireshark I can see traffice to and from my phone, and some broadcast packets, but no packets directed to the IP address of the RM3.
My phone is connected to the same wireless network as the RM3.
Did I miss something in my procedure?
Also, it seems from the latest posts that the python script can now be used to capture packets during learning, is that correct? If so, could someone give the steps for how this is setup? ie, what has to be connected to network, wireless etc?
Since Farhanito posted a broadlink package few days ago I’ve changed my script to use that package instead of intercepted UDP payload. Now it’s also possible to learn commands directly within a script, so you can avoid usage of e-Control app and packet sniffer. You’ll need to download a broadlink package from the github (you can find a link in a post from Farhanito), and run setup.py to install it. Note that you must use Python 2.X, because said package doesn’t work with Python 3.X. Besides manually installing broadlink package, you must install netaddr and pycrypto (you can do this via pip install). After that, just fill in IPAddress, Port, MACAddress and Timout in BlackBeanControl.ini and run BlackBeanControl.py with switch -c CommandName. That will put RM 3 into learning mode for X seconds (Timeout parameter in BlackBeanControl.ini - should be less than 60 seconds). After that, you should use the button on the remote you wish to learn from. Finally, just call BlackBeanControl.py -c CommandName with a name of the command you’ve learned and it will trigger that command.
The broadlink package Farhanito posted is meant for RM2 (as far as I know). Regarding my script, it’s pretty easy to set it up and test on your device, so you should just try and see if it works. I don’t have RM2, so I can’t tell you from my experience.
Also, is the idea here that we will always use the python script via the EXEC binding to use the RM3 with openhab? Or is the intention here to use the python script to get (learn) the code which we extract and use in UDP send command?
I have python 3 running on my raspi which is also running openhab. I’m not sure how well an install of python2 will co-exist on the same device. Can I install as you have suggested above onto my Ubuntu machine, learn the codes, then use them with UDP send or some other method that will work? Or will it be fine to also install python2 on my raspi and they will live happily together?
Python 2.7 is already installed in raspbian, at least in my raspberry v3. The davorf script worked out of the box in my case. I simply used the exec binding.
The udp binding that I tested had some problems, though: the binding tries to process the udp packet sent back by the mini, therefore the status of the associated items is undefined. They can be solved by writing a javascript function, instead of a simple map file.
The script should read the configuration file written by a suitably modified davorf python script, split the packet randomly modifying the required bytes and finally process the return packet, in order to let the item keep the right state. Unfortunately. I’m not a javascript programmer therefore I cannot actually implement it. I found easier, in my application to awitch to exec byinding with python But if someone is willing to try I’m more than happy to help.
Lionello