Divoom
Rust Library for controlling divoom devices that support REST APIs, such as pixoo-64 (and from how divoom's api/doc organizes, maybe more in the future).
// Get current channel
use *;
println!;
// Output: Clock
How to use
The library contains 2 major parts:
- Divoom service APIs, that is used for talking to Divoom's backend service for device discovery etc.
- Pixoo device APIs, that is used for talking to a specific device via its REST APIs.
Divoom service APIs
To discover all devices in your LAN, we can use the get_same_lan_devices
API to get all devices from Divoom's backend service.
use *;
let divoom = new;
let devices = divoom.get_same_lan_devices.await?;
devices.iter.for_each;
This will output:
DivoomDeviceInfo { device_name: "Pixoo", device_id: 300000001, device_private_ip: "192.168.0.123" }
Pixoo device APIs
Once we get the device ip, we can use it to create a pixoo client and start talking to it:
use *;
let pixoo = new;
let result = pixoo.get_current_channel.await?;
println!;
This will output:
Clock
Currently, we have these APIs supported:
- Channel APIs
- Select channel
- Get current channel
- Select clock
- Get selected clock info
- Select cloud channel
- Select visualizer
- Select custom page
- System/Device APIs
- Get device settings
- Get device time
- Set device brightness
- Set device time
- Set device high light mode
- Set device hour mode
- Set device mirror mode
- Set device rotation angle
- Set device screen power state
- Set device temperature unit
- Set device time zone
- Set device weather area
- Set device white balance
- Tools APIs
- Set countdown tool
- Set noise tool
- Set scoreboard tool
- Set stopwatch tool
- Animation APIs
- Play gif from file
- Get next animation id
- Reset next animation id
- Send image animation
- Send text animation
- Clear all text area
- Play buzzer
- Batch APIs
- Batching commands
- Execute commands from url
Image Animation
Devices like Pixoo-64 supports play GIF file from file or even Internet directly, all we need is to specify a URL as below:
use *;
let pixoo = new;
pixoo.play_gif_file.await?;
Text Animation
To create a text animation, we can use DivoomTextAnimation
structure and send_text_animation
API to help us:
use *;
let pixoo = new;
let animation = default;
animation.text_string = "Foo".to_string;
pixoo.send_text_animation.await?;
Command batching
In certain cases, we might want to run a lot of commands at the same time, such as initialize the settings. Pixoo devices supports batching all commands into a single request, but with only 1 single result being returned for indicating if everything succeeded or not.
Here is an example that we batch executed multiple commands to update the device settings:
use *;
let pixoo = new;
pixoo.start_batch
.set_device_rotation_angle
.set_device_mirror_mode
.set_device_brightness
.execute.await.expect;
Debugging
The debug logs are logged at debug level. Once we set the log level to debug, we will be able to start see it:
.init;
from_env
Or we can use RUST_LOG
environment variable to change the level and enable the logs:
With the command tool (covered below soon), on windows:
> $env:RUST_LOG="debug"; .\divoom-cli.exe 192.168.0.123 channel get
And on linux:
RUST_LOG=debug
Then we will see the output log like below:
[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
To revert it back:
> $env:RUST_LOG="warn"; .\divoom-cli.exe 192.168.0.123 channel get
CustomPage
Command line tool
In order to help quickly give the APIs a try, we have also developed a command line tool. It also serves as an example on how to uses these APIs.
This tool is currently under construction and doesn't have all API covered yet.
Device discovery
> divoom-cli.exe
Devices APIs
# Check current channel
> .\divoom-cli.exe
# Check current clock
> .\divoom-cli.exe
# Create a text animation
> .\divoom-cli.exe
# Play a gif from Internet
> .\divoom-cli.exe )
Help
> .\divoom-cli.exe
<device-ip> Device
)
License
Apache-2.0: https://www.apache.org/licenses/LICENSE-2.0