2个版本
0.1.1 | 2022年3月12日 |
---|---|
0.1.0 | 2022年3月12日 |
#1097 in 硬件支持
81KB
1.5K SLoC
关于
通过BLE(蓝牙低功耗)获取您的Xiaomi Mijia 365电动滑板车的信息。这是使用btleplug,它是一个异步Rust BLE库,支持Windows 10、macOS、Linux和iOS。我仅在Linux笔记本电脑上进行了测试,理论上应与其他系统兼容。
使用方法
每个示例都向您展示如何与您的滑板车交互。在您能够读取任何信息之前,您需要获取认证令牌。
支持的滑板车
此协议用于m365、mi-lite-1-s、mi-pro、mi-pro2和mi-pro3。
注意
注册/配对设备将取消与所有其他应用程序的配对!如果配对后想与其他应用程序使用设备,请在应用程序内重新安装或删除/重新添加设备。
查找滑板车的MAC地址
此包包含扫描和列出附近M365电动滑板车的示例。只需按如下方式执行包
$ cargo run --example scanner
2022-03-01T20:24:52.433166Z DEBUG m365::scanner: Starting scanning for new devices
2022-03-01T20:24:52.445873Z DEBUG m365::scanner: Watching for events in background
2022-03-01T20:25:25.786072Z INFO scanner: Found scooter nearby: MIScooter7353 with mac: D5:01:45:37:ED:FD
注册
要从小滑板车获取认证令牌,运行register示例并传递您的滑板车的MAC地址。注册令牌将作为文件.mi-token
持久化
$ cargo run --example register D5:01:45:37:ED:FD
登录
您可以使用此示例查看如何登录并读取序列号
$ cargo run --example login D5:01:45:37:ED:FD
关于
从滑板车读取所有信息
$ cargo run --example about D5:01:45:37:ED:FD
2022-03-12T18:35:47.751207Z INFO about: Searching scooter with address: D5:01:45:37:ED:FD
2022-03-12T18:35:47.769772Z INFO m365::scanner: Found your scooter
2022-03-12T18:36:02.811852Z INFO m365::login: Validating did
2022-03-12T18:36:02.930741Z INFO m365::login: Logged in!
2022-03-12T18:36:03.350317Z INFO about: Logged in with success, reading data...
2022-03-12T18:36:03.410690Z INFO about: Battery info: BatteryInfo { capacity: 7392, percent: 63, current: 0.01, voltage: 36.74, temperature_1: 44, temperature_2: 44 }
2022-03-12T18:36:03.502199Z INFO about: Battery cells (V): [36.71, 36.73, 36.71, 36.75, 36.74, 36.76, 36.78, 36.78, 36.8, 36.77]
2022-03-12T18:36:03.561323Z INFO about: Serial number 26354/00467353
2022-03-12T18:36:03.652204Z INFO about: Motor info: MotorInfo { battery_percent: 63, speed_kmh: 0, speed_average_kmh: 0, total_distance_m: 1306083, trip_distance_m: 0, uptime: 260s, frame_temperature: 24.0 }
2022-03-12T18:36:03.710897Z INFO about: Supplementary info SupplementaryInfo { kers: Weak, is_cruise: false, tail_light: Off }
2022-03-12T18:36:03.771259Z INFO about: General info GeneralInfo { serial: "26354/00467", pin: "353000", version: "00" }
2022-03-12T18:36:03.830117Z INFO about: Distance left 28.35 km
2022-03-12T18:36:03.890595Z INFO about: Trip distance 0 km
2022-03-12T18:36:03.951109Z INFO about: Current Speed 0 km/h
2022-03-12T18:36:04.011104Z INFO about: Cruise enabled: false
2022-03-12T18:36:04.070594Z INFO about: Tail light enabled: Off
2022-03-12T18:36:04.130628Z INFO about: Battery 36.74 V
2022-03-12T18:36:04.221106Z INFO about: 0 A
2022-03-12T18:36:04.311157Z INFO about: 63 %
2022-03-12T18:36:04.370719Z INFO about: BatteryInfo { capacity: 7392, percent: 63, current: 0.0, voltage: 36.74, temperature_1: 44, temperature_2: 44 }
设置
您可以使用此示例查看如何更改尾灯和巡航模式
$ cargo run --example settings D5:01:45:37:ED:FD
许可
查看LICENSE.md
免责声明
我绝不是Xiaomi或其任何子公司的附属,也不是其产品的附属。此代码仅供研究目的提供。
参考
- https://github.com/danielkucera/mi-standardauth
- https://learning-rust.github.io/docs/a4.cargo,crates_and_basic_project_structure.html
- https://github.com/CamiAlfa/M365-BLE-PROTOCOL
- https://github.com/AntonHakansson/m365py
- https://github.com/michaljach/m365-info/blob/master/M365Info.swift
- https://learn.adafruit.com/introduction-to-bluetooth-low-energy/gatt
- https://github.com/drogue-iot/burrboard/blob/9e10c87a596fe29055e2a302c2753963bcc545cd/gatt-client/src/board.rs
- https://github.com/deviceplug/btleplug
- https://github.com/pretzelhammer/rust-blog/blob/master/posts/common-rust-lifetime-misconceptions.md#2-if-t-static-then-t-must-be-valid-for-the-entire-program
- https://github.com/cheetahdotcat/m365-mi
- https://github.com/dnandha/miauth/tree/main/lib/java
- https://github.com/dnandha/miauth
- https://pypi.ac.cn/project/miauth/#files
- https://github.com/cheetahdotcat/m365-mi/blob/master/mim365mi/m365scooter.py
- https://github.com/stepanbenes/doorkeeper/blob/a70c08ad738fe4390e374c925e779fc6b9e67433/src/main.rs
- https://github.com/tokio-rs/tokio/discussions/3362
- https://depth-first.com/articles/2020/06/22/returning-rust-iterators/
- https://github.com/Emeryth/ReadM365/blob/master/readM365.py
- https://github.com/heardrwt/Xiaomi-M365-Display/blob/5414aa9ef6a7d6d76c8b88deedc90e148b1812f4/ninebot_module.c#L175
依赖项
~9-39MB
~589K SLoC