Expand description
§Types and async api for the Awtrix3 device.
From https://blueforcer.github.io/awtrix3/#/api
This crate is a WIP poorly documented and untested !!! Use at your own risk, kwnowing that it will change / break in the future.
The main types are:
Awtrix3HttpClient
for http communicationAwtrix3MqttClient
for mqtt communicationTopic
andMessage
for in/out communication
§Example
use awtrix3::*;
#[tokio::main]
async fn main() {
// Http usage
let client = Awtrix3HttpClient::new("xxx.xxx.xxx.xxx", 80)
.with_credentials("user", "password");
let stats = Topic::Stats.http_get(&client).await.unwrap();
println!("{:?}", stats);
// Send message
Message::Settings(Settings {
scroll_speed: Some(10),
..Default::default()
})
.http_send(&client)
.await
.unwrap();
println!("Message sent via http");
// Mqtt usage
let (client, mut eventloop) = Awtrix3MqttClient::new(
Awtrix3MqttClientOptions {
client_id: "awtrix3".to_string(),
host: "localhost".to_string(),
port: 1883,
username: Some("user".to_string()),
password: Some("password".to_string()),
},
10,
"clock",
)
.unwrap();
// Listen for messages and decode the messages and topics received.
tokio::task::spawn(async move {
while let Ok(msg) = eventloop.poll().await {
println!("Message {:?}", msg);
if let Ok(Some((topic, message))) = eventloop.decode(msg) {
println!("{:?} {:?}", topic, message);
}
}
});
// Subscribe to a topic
client.subscribe("/stats").await.unwrap();
println!("Subscribed to /stats");
// Send messages
Message::MoodLightOn(Mood {
brightness: Some(120),
color: Some(Color::Rgb(255, 0, 0)),
kelvin: None,
})
.mqtt_send(&client)
.await
.unwrap();
println!("Message sent via mqtt");
// Wait for a while
println!("Waiting for 60 seconds");
tokio::time::sleep(std::time::Duration::from_secs(60)).await;
}
}
Structs§
- App
- Awtrix3 app.
- Awtrix3
Http Client - HTTP client for Awtrix3.
- Awtrix3
Mqtt Client - MQTT client for Awtrix3.
- Awtrix3
Mqtt Client Options - MQTT basic client options.
Can be converted into
MqttOptions
usingInto
. - Colored
Text - Colored text fragment.
- Effect
- Effect definition.
- Effect
Setting - Effect settings.
- Indicator
- Mood
- Notification
- Awtix3 notification definition.
- Settings
- Stats
Enums§
- Awtrix3
Error - Color
- Color.
- Indicator
Id - Lifetime
Mode - App lifetime mode.
- Message
- Overlay
Effect - Overlay effect name.
- Push
Icon - Icon position.
- Text
- Text (basic or colored).
- Text
Case - Text case.
- Topic
- Transition
Effect