#命令行工具 #设备 #pixoo #通道 #控制 #I/O #divoom

app divoom-cli

用于控制 divoom 设备的命令行工具

10 个版本

0.1.42 2022 年 8 月 7 日
0.1.39 2022 年 8 月 6 日
0.1.23 2022 年 7 月 30 日

#1829命令行工具

32 每月下载量

Apache-2.0

285KB
6.5K SLoC

divoom-cli

Divoom

基于 divoom API 构建的命令行工具,用于控制 divoom 设备,如 pixoo(以及根据 divoom 的 api/doc 组织,未来可能还有更多)。

License: Apache 2.0 Build Status

发布 状态
Crates.io Crates.io
安装 winget divoom-cli
Nuget
Nuget Nuget Nuget
Nuget Nuget Nuget Nuget
Nuget
# Check current channel
> divoom-cli 192.168.0.123 channel get
clock

# Set channel to clock with id 100
> divoom-cli 192.168.0.164 channel set-clock 100

# Get clock channel info
> divoom-cli 192.168.0.164 channel get-clock
---
clock-id: 100
brightness: 100

如何安装

通过 Cargo

cargo install divoom-cli

通过 winget

winget install DivoomCli

通过 scoop

由于我们尚未达到 Scoop 主存储桶的纳入标准,我们目前需要使用自己的存储桶。

# Add our scoop bucket for the first time.
scoop bucket add r12f https://github.com/r12f/scoop-bucket

# Install
scoop install divoom-cli

如何使用

使用命令行工具非常简单。通常,我们分为两步进行:

  • 使用设备发现 API 查找局域网中我们所在的所有设备。
  • 使用设备 API 控制设备。在这个过程中不需要登录/认证。

在同一局域网中查找设备

> divoom-cli discover
---
- device-name: Pixoo
  device-id: 300000001
  device-private-ip: 192.168.0.123

使用设备 API 控制设备

所有设备 API 都具有相同的格式

divoom-cli <device-address> <api-category> <api> [parameters]

因此,我们可以运行如下命令:

# Check current channel
> divoom-cli 192.168.0.123 channel get
---
clock

# Check current clock
> divoom-cli 192.168.0.123 channel get-clock
---
clock_id: 100
brightness: 67

# Set channel to clock with id 100
> divoom-cli 192.168.0.164 channel set-clock 100

# Play a gif from Internet by calling the API provided by Divoom Device.
# Please note that: this API can be unstable and only accepts GIF with 16x16, 32x32 and 64x64 image size.
> divoom-cli 192.168.0.123 animation gif play --url https://www.gifandgif.eu/animated_gif/Planets/Animated%20Gif%20Planets%20(16).GIF

# To help playing GIF in a more stable way, we can use the image animation API to craft an animation and draw the GIF
# frames into it and send to device to play, e.g.:
> divoom-cli 192.168.0.123 animation image render-gif "logo-16-rotate-4-frames.gif" 16 -s 100

# Create the same GIF animation as above, but with size stretched, rotation 30 degrees and opacity 0.5.
> divoom-cli 192.168.0.123 animation image render-gif "logo-16-rotate-4-frames.gif" 32 -s 100 -f stretch -o 0.5 -r 30

# Create a text animation
# Please note that: this API only works after we use "animation image render-gif" API to draw anything. This API call will be ignored, 
# when the device is showing other things, like clock or channel.
> divoom-cli 192.168.0.123 animation text set 1 "Hello world!"
> divoom-cli 192.168.0.123 animation text set 2 "The gray fox jumped over the lazy dog" -y 20

# Modify existing text animation. E.g. changing "Hello world!" above to "Hello Divoom!"
> divoom-cli 192.168.0.123 animation text set 1 "Hello Divoom!"

# Send a raw request
#
# NOTICE: the double quotes in json string passed into the program needs to escaped with '\',
# otherwise, rust runtime (not clap) will eat them before reaching main function, even we 
# pass the whole string as a string.
> divoom-cli 192.168.0.164 raw '{\"Command\": \"Device/SetHighLightMode\", \"Mode\": 0}'

参数/输出格式

默认情况下,divoom-cli 使用 yaml 作为输出格式,所有字段名称均为 kebab-case。除了 yaml,我们还支持 json 格式。

要指定输出格式,我们可以使用 -o 参数

> divoom-cli -o json 192.168.0.164 channel get-clock
{"clock-id":100,"brightness":67}

> divoom-cli -o yaml 192.168.0.164 channel get-clock
---
clock-id: 100
brightness: 67

对于值,divoom-cli 总是期望使用 camelCase,无论是参数还是输出。

> divoom-cli 192.168.0.123 channel set customPage

> divoom-cli 192.168.0.123 channel get
---
customPage

更多信息

我们可以在以下命令帮助中找到更多信息。

> divoom-cli
divoom-cli 0.0.1
r12f
https://github.com/r12f/divoom

USAGE:
    divoom-cli.exe [OPTIONS] [device-address] <SUBCOMMAND>

FLAGS:
    -h, --help       Prints help information
    -V, --version    Prints version information

OPTIONS:
    -o, --output <output>    Output format. [default: yaml]

ARGS:
    <device-address>    Device Address. Required when using device APIs, such as "channel get".

SUBCOMMANDS:
    animation    Animation related APIs
    batch        Batch related APIs
    channel      Channel related APIs
    discover     Discover divoom devices by calling into divoom service API
    help         Prints this message or the help of the given subcommand(s)
    raw          Sending raw request
    system       System/device related APIs
    tool         APIs to launch some tools

调试

为了调试并查看日志和发送的原始请求,我们可以使用 RUST_LOG 环境变量将日志级别更改为 debug 以启用日志记录

在 Windows 的 powershell 上

$env:RUST_LOG="debug"; divoom-cli 192.168.0.123 channel get

在 Windows 的 cmd 上

set RUST_LOG=debug && divoom-cli 192.168.0.164 channel get

以及 Linux 上

RUST_LOG=debug divoom-cli 192.168.0.123 channel get

然后我们将看到如下输出日志:

[2022-07-10T00:33:50Z DEBUG divoom::clients::common::divoom_rest_client] Sending request: Url = "http://192.168.0.123/post", Body = "{"Command":"Channel/GetIndex"}"
[2022-07-10T00:33:50Z DEBUG reqwest::connect] starting new connection: http://192.168.0.123/
[2022-07-10T00:33:50Z DEBUG hyper::client::connect::http] connecting to 192.168.0.123:80
[2022-07-10T00:33:50Z DEBUG hyper::client::connect::http] connected to 192.168.0.123:80
[2022-07-10T00:33:50Z DEBUG hyper::proto::h1::io] flushed 107 bytes
[2022-07-10T00:33:50Z DEBUG hyper::proto::h1::io] parsed 2 headers
[2022-07-10T00:33:50Z DEBUG hyper::proto::h1::conn] incoming body is chunked encoding
[2022-07-10T00:33:50Z DEBUG hyper::proto::h1::decode] incoming chunked header: 0x22 (34 bytes)
[2022-07-10T00:33:50Z DEBUG reqwest::async_impl::client] response '200 OK' for http://192.168.0.123/post
[2022-07-10T00:33:50Z DEBUG divoom::clients::common::divoom_rest_client] Response header received: StatusCode = 200
[2022-07-10T00:33:50Z DEBUG hyper::proto::h1::conn] incoming body completed
[2022-07-10T00:33:50Z DEBUG hyper::client::pool] pooling idle connection for ("http", 192.168.0.123)
[2022-07-10T00:33:50Z DEBUG divoom::clients::common::divoom_rest_client] Response received: Body = "{"error_code": 0, "SelectIndex":3}"
---
customPage

要恢复,我们可以使用相同的方式将 RUST_LOG 设置为 warn 级别

> $env:RUST_LOG="warn"; divoom-cli 192.168.0.123 channel get
---
customPage

API && SDK

如果您对这个工具调用的 API 和它使用的 Rust SDK 感兴趣,请在此查看: https://github.com/r12f/divoom/blob/main/README.md

许可

Apache-2.0: https://www.apache.org/licenses/LICENSE-2.0

依赖项

~17–37MB
~590K SLoC