Skip to content

Commit

Permalink
Update readme
Browse files Browse the repository at this point in the history
  • Loading branch information
PRO-2684 committed Feb 13, 2022
1 parent 491c340 commit efca9fa
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 5 deletions.
28 changes: 25 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,14 @@ Control Xiaomi wifispeaker to play local musics🎵.
Ensure your computer and wifispeaker are **under the same LAN**, input `\\<ip>` on the address bar of explorer, where `<ip>` ip refers to the ip address of your wifispeaker, and press enter to access. If you encounter an error, you can try to [enable SMBv1 client](https://docs.microsoft.com/en-us/windows-server/storage/file-server/troubleshoot/detect-enable-and-disable-smbv1-v2-v3#smbv1-on-smb-client), although it's [not recommend to do so](https://techcommunity.microsoft.com/t5/storage-at-microsoft/stop-using-smb1/ba-p/425858).
### 🤔 Other systems
Ensure your computer and wifispeaker are **under the same LAN**, and use a SMB client to connect to your wifispeaker. If a username is required, use `GUEST`, and leave the password blank. You may also need to enable SMB(v)1 somewhere.
## 🍪 Acquiring cookies
> A script *may* be developed to simplify this process.
## 🚩 Login
### 🔑 Using userid and password
```python
wifi_speaker = WifiSpeakerV3('<Mi id>', '<password>', '<serial number>')
# serial number is required if you have multiple wifispeakers and want to specify one you'd like to control.
# You may find the serial nummber on the bottom of your wifispeaker.
```
### 🍪 Using cookies
1. Ensure you **can capture https traffic on your phone/emulator**, even when apps don't trust user certificates.*(Emulator of Android 6 and below, together with Fiddler is recommended)*
2. Install "小爱音箱" APP (`com.xiaomi.mico`).
3. Open your packet capture software, ensure it works and then login in your Mi account on the APP.
Expand All @@ -29,8 +35,24 @@ Ensure your computer and wifispeaker are **under the same LAN**, and use a SMB c
'deviceId': '6e8h7506-8d34-65df-c0d7-e19480s7d3b4',
'serviceToken': 'tJYUMjSdn6MHAaEJzdchU8XZVqkGnbmrT3n4hhQaIqrrAl9OwgyWGwEZohfPDUENSaQ/aPJF1JVaX32nwCaHAvOACyJ7aJW5g7hw+GYJ5SrKBqVN8XG0wjvPaFYpyQ3Ha8Oelx6IH8OxydiqNop98RTUnOxHLW9G7AkfowucoGiYRls8XbhqBL22q3lBVntfZ7EnEpXY6x9FaNGE0DQWVQ=='
}
wifi_speaker = WifiSpeakerV3(my_cookie)
wifi_speaker = WifiSpeakerV3(cookie=my_cookie)
```
### 💡 Combine the above 2 methods
When logined, save the cookie to a file for future use. Next time you start the script, you can use the saved cookie. If the cookie is expired, relogin and refresh the cookie. Cookie can be fetched via `WifiSpeakerV3.cookie`.
Example:
```python
from json import load, dump
try:
with open('cookie') as f:
wifi_speaker = WifiSpeakerV3(cookie=load(f))
status = wifi_speaker.status
except:
print('Refreshing cookie...')
wifi_speaker = WifiSpeakerV3('<Mi id>', '<password>')
status = wifi_speaker.status
with open('cookie', 'w') as f:
dump(wifi_speaker.cookie.get_dict(), f)
```
## 📖 Usage
No documentations yet. Please refer to `demo.py`.
## ✅ Supported models
Expand Down
27 changes: 25 additions & 2 deletions README_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,14 @@
确保电脑与音箱**在同一局域网下**,系统文件管理器地址栏输入 `\\<ip>` ,其中 `<ip>` 为音箱 ip 地址,即可访问。若出现错误,请尝试[启用 SMBv1 客户端](https://docs.microsoft.com/zh-cn/windows-server/storage/file-server/troubleshoot/detect-enable-and-disable-smbv1-v2-v3#smbv1-on-smb-client),虽然在通常情况下我们[并不建议这么做](https://techcommunity.microsoft.com/t5/storage-at-microsoft/stop-using-smb1/ba-p/425858)
### 🤔 其他系统
确保电脑与音箱**在同一局域网下**,使用 SMB 客户端连接至音箱 ip ,若需要提供用户名,则填入 `GUEST` ,密码留空。你可能也需要在某处启用 SMBv1 。
## 🍪 Cookie 的获取
> 后续*可能*推出脚本以简化此流程。
## 🚩 登录
### 🔑 使用用户id和密码登录
```python
wifi_speaker = WifiSpeakerV3('<小米id>', '<密码>', '<序列号>')
# 如果你想要有多个网络音箱并且想指定你要控制的网络音箱,序列号是必须的。
# 你通常可以在音箱底部看到序列号。
```
### 🍪 使用 Cookie 登录
1. 确保**可正常抓取手机/模拟器的 https 包**,即使应用不信任用户证书。*(建议使用安卓6及以下的模拟器,配合 Fiddler 实现抓包)*
2. 手机/模拟器安装“小爱音箱”APP(`com.xiaomi.mico`)。
3. 打开抓包软件,确认可工作后登录“小爱音箱”软件。
Expand All @@ -31,6 +37,23 @@
}
wifi_speaker = WifiSpeakerV3(my_cookie)
```
### 💡 结合以上两种方法
当你登录成功后,保存 cookie 以备以后使用。下次使用脚本时,你就可以使用保存的 cookie 。如果 cookie 过期,重新登录并保存 cookie 。
Cookie 可以通过 `WifiSpeakerV3.cookie` 获取。
例子:
```python
from json import load, dump
try:
with open('cookie') as f:
wifi_speaker = WifiSpeakerV3(cookie=load(f))
status = wifi_speaker.status
except:
print('Refreshing cookie...')
wifi_speaker = WifiSpeakerV3('<Mi id>', '<password>')
status = wifi_speaker.status
with open('cookie', 'w') as f:
dump(wifi_speaker.cookie.get_dict(), f)
```
## 📖 用法
暂无文档,请参考 `demo.py`
## ✅ 支持的型号
Expand Down

0 comments on commit efca9fa

Please # to comment.