Erriez / milight_ibox2_control_python

MiLight iBox2 Controller interface with Python by using UDP socket
MIT License
5 stars 4 forks source link

Trying to use the library with a "Mi-light Wifi Controller". Older (and different?) model. #15

Open vmonteco opened 2 weeks ago

vmonteco commented 2 weeks ago

Hello,

I'm searching for informations and advices about this library and the way it works.

I found in a drawer an old Mi-light Wifi Controller bought in 2015 I'm trying to use with a compatible bulb. And I'm unsure about the differences with the Mi-light iBox2/Wifi controller this library is meant to work with.

I ensured that my device's IP is 10.10.100.254 and I can access the web interface that is identical to the one in the README. The Other Setting > Port ID setting is 8899 (I've also tried with 5987 like in the example showed in the README`).

Anyway, I'm trying the following MRE without success (Output in comments). Any idea?

#!/usr/bin/env python3

import milight_ibox2

ibox2 = milight_ibox2.MilightIBox(
    ibox_ip="10.10.100.254",    # IP of my device (AP mode).
    ibox_port=8899,             # This is the port set in the web interface.
                                # I've also tried: 5987,
    sock_timeout=2,
    tx_retries=5,
    verbose=True,
)

# Trying to scan devices
# Output (No matter the port):
# []
print(ibox2.scan())

# Trying to connect anyway:
# I only get 5 timeout with this.
ibox2.connect()

# Output:       Send link zone 1...
#               Error: Not connected
ibox2.link(zone=1)

# Output:       Socket close...
ibox2.disconnect()

I'd also like to ensure that there could be a solution other than setting it to work with the STA/STA+AP mode, as I'm not willing to connect it to our (shared) wifi if possible.

Erriez commented 2 weeks ago

Thanks for creating an issue. In the mean time, there are multiple versions of the Mi-Light boxes released with different behavior, so I'm not sure which one you have. Are both Python script and MiLight box running on the same WiFi network? The Mi-Light box should connect to the same WiFi network which is a different connection than the configuration web interface.

vmonteco commented 2 weeks ago

Hello and thank you for the answer.

I explicitly connected my laptop to the milight_XXXXXX wifi access point provided by the device.

> ip a
...
4: wlp9s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default qlen 1000
    link/ether a0:59:50:64:14:e6 brd ff:ff:ff:ff:ff:ff
    inet 10.10.100.150/24 brd 10.10.100.255 scope global dynamic wlp9s0
       valid_lft 2591841sec preferred_lft 2267841sec
    inet6 fe80::4e30:bb51:42b:7de1/64 scope link 
       valid_lft forever preferred_lft forever
...
> iwgetid
wlp9s0    ESSID:"milight_A6B5CE"

I can also confirm that I was able to ping 10.10.100.254 while running my previous script.

Here are also some software information about the device:

Given the look of the device and the time when it was bought, I really think it is the one I linked in my previous post.

IMG_20240618_000446~2

Was the description of the protocol in your README.md based on some reverse engineering or on a specific documentation? If it's the latter, perhaps the source (if still available today) could give some hint?

Erriez commented 2 weeks ago

I found mi Mi-Light which is called WiFi iBox Controller. It may be slightly different. The IP address 10.10.100.254 is the configuration page and cannot be used by the Python script. The MiLight WiFi controller should be configured into AP+STA mode first to let it connect to your WiFi network. On the System page I've Software version v1.0.8.

Yes, fully reverse engineered and found some minimal sources on other websites.

Did you follow https://github.com/Erriez/milight_ibox2_control_python/blob/master/README.md#ibox2-wifi-configuration? I've executed a factory reset first, then open the web configuration page and and followed the instructions in the README.md.

$ git clone git@github.com:Erriez/milight_ibox2_control_python.git
$ cd milight_ibox2_control_python
$ virtualenv venv
$ . venv/bin/activate
$ python3 setup.py install
$ python examples/ibox2_client_example.py 
Scan MiLight iBox2 devices...
Found 1 iBox2 devices:
  192.168.16.166:5987 (F0:FE:6B:XX:XX:XX)
Connecting to 192.168.16.166:5987
Zone 0 off...
Zone 0 on...
Zone 0 off...
Zone 0 on...
Zone 4 off...
Zone 4 on...
Zone 0 set brightness 75...
Zone 0 set saturation 0...
Zone 0 set color 200...
Zone 0 set color 240...
Zone 0 set color 10...
Zone 0 set color 25...
Zone 0 set color 40...
Zone 0 set color 70...
Zone 0 set color 95...
Zone 0 set color 120...
Zone 0 set color 180...
Zone 0 set white mode...
Zone 0 set saturation 127...
Zone 0 set saturation 255...
Zone 0 set mode 1...
Zone 0 set mode 9...
Zone 0 set temperature 6500...
Zone 0 set temperature 2700...
Zone 0 set brightness 5
Zone 0 night light on...
Zone 1 off...
Zone 1 on...
Zone 1 off...
Zone 1 on...
Zone 4 off...
Zone 4 on...
Zone 1 set brightness 75...
Zone 1 set saturation 0...
Zone 1 set color 200...
Zone 1 set color 240...
Zone 1 set color 10...
Zone 1 set color 25...
Zone 1 set color 40...
Zone 1 set color 70...
Zone 1 set color 95...
Zone 1 set color 120...
Zone 1 set color 180...
Zone 1 set white mode...
Zone 1 set saturation 127...
Zone 1 set saturation 255...
Zone 1 set mode 1...
Zone 1 set mode 9...
Zone 1 set temperature 6500...
Zone 1 set temperature 2700...
Zone 1 set brightness 5
Zone 1 night light on...
Zone 2 off...
Zone 2 on...
Zone 2 off...
Zone 2 on...
Zone 4 off...
Zone 4 on...
Zone 2 set brightness 75...
Zone 2 set saturation 0...
Zone 2 set color 200...
Zone 2 set color 240...
Zone 2 set color 10...
Zone 2 set color 25...
Zone 2 set color 40...
Zone 2 set color 70...
Zone 2 set color 95...
Zone 2 set color 120...
Zone 2 set color 180...
Zone 2 set white mode...
Zone 2 set saturation 127...
Zone 2 set saturation 255...
Zone 2 set mode 1...
Zone 2 set mode 9...
Zone 2 set temperature 6500...
Zone 2 set temperature 2700...
Zone 2 set brightness 5
Zone 2 night light on...
Zone 3 off...
Zone 3 on...
Zone 3 off...
Zone 3 on...
Zone 4 off...
Zone 4 on...
Zone 3 set brightness 75...
Zone 3 set saturation 0...
Zone 3 set color 200...
Zone 3 set color 240...
Zone 3 set color 10...
Zone 3 set color 25...
Zone 3 set color 40...
Zone 3 set color 70...
Zone 3 set color 95...
Zone 3 set color 120...
Zone 3 set color 180...
Zone 3 set white mode...
Zone 3 set saturation 127...
Zone 3 set saturation 255...
Zone 3 set mode 1...
Zone 3 set mode 9...
Zone 3 set temperature 6500...
Zone 3 set temperature 2700...
Zone 3 set brightness 5
Zone 3 night light on...
Done

Success!