Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
212 changes: 125 additions & 87 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ moonraker = { path = "moonraker", optional = true }
multer = { version = "3.1.0", features = ["json"] }
openssl = { version = "0", features = ["vendored"] }
opentelemetry = "0.32.0"
opentelemetry-otlp = "0.27.0"
opentelemetry-otlp = { version = "0.32.0", default-features = false, features = ["grpc-tonic", "trace", "metrics", "logs", "internal-logs"] }
opentelemetry_sdk = { version = "0.32.1", features = ["rt-tokio"] }
parse-display = "0.11.0"
prometheus-client = "0.25.0"
Expand Down
2 changes: 1 addition & 1 deletion bambulabs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ lazy_static = "1.5.0"
nanoid = "0.5.0"
parse-display = "0.11.0"
rumqttc = "0.25.1"
rustls = "0.22"
rustls = "0.23"
schemars = { version = "0.8", features = ["uuid", "url"] }
serde = { version = "1", features = ["derive"] }
serde_json = "1"
Expand Down
16 changes: 9 additions & 7 deletions bambulabs/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ impl Client {
Ok(Self {
ip,
access_code,
topic_device_request: format!("device/{}/request", &serial),
topic_device_report: format!("device/{}/report", &serial),
topic_device_request: format!("device/{}/request", serial),
topic_device_report: format!("device/{}/report", serial),
serial,
client: Arc::new(client),
event_loop: Arc::new(Mutex::new(event_loop)),
Expand All @@ -60,10 +60,12 @@ impl Client {
fn get_config(ip: &str, access_code: &str) -> Result<rumqttc::MqttOptions> {
let client_id = format!("bambu-api-{}", nanoid::nanoid!(8));

let ssl_config = rustls::ClientConfig::builder()
.dangerous()
.with_custom_certificate_verifier(Arc::new(crate::no_auth::NoAuth::new()))
.with_no_client_auth();
let ssl_config =
rustls::ClientConfig::builder_with_provider(Arc::new(rustls::crypto::aws_lc_rs::default_provider()))
.with_safe_default_protocol_versions()?
.dangerous()
.with_custom_certificate_verifier(Arc::new(crate::no_auth::NoAuth::new()))
.with_no_client_auth();

let mut opts = rumqttc::MqttOptions::new(client_id, ip, MQTT_PORT);
opts.set_max_packet_size(MAX_PACKET_SIZE, MAX_PACKET_SIZE);
Expand Down Expand Up @@ -136,7 +138,7 @@ impl Client {
let response = self.responses.get(&SequenceId::status());
if let Some(response) = response {
if let Message::Print(Print::PushStatus(status)) = response.value() {
return Ok(Some(status.clone()));
return Ok(Some(status.as_ref().clone()));
}
}

Expand Down
2 changes: 1 addition & 1 deletion bambulabs/src/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ pub enum Print {
/// Calibration.
Calibration(Calibration),
/// The status of the print.
PushStatus(PushStatus),
PushStatus(Box<PushStatus>),
/// The gcode line.
GcodeLine(GcodeLine),
/// A gcode file.
Expand Down
6 changes: 3 additions & 3 deletions bambulabs/src/templates.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ pub enum Template {
/// The template for the machine settings.
Machine(Box<Machine>),
/// The template for a machine model.
MachineModel(MachineModel),
MachineModel(Box<MachineModel>),
/// The template for the filament settings.
Filament(Filament),
Filament(Box<Filament>),
/// The template for the process settings.
Process(Process),
Process(Box<Process>),
}

impl Template {
Expand Down
11 changes: 3 additions & 8 deletions src/bin/machine-api/cmd_serve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ where
* I have no idea what the real fix is, but this ain't it. This
* just stops graphs from lying when the box goes offline. */

for (_, gauge) in sensors.iter_mut() {
for gauge in sensors.values_mut() {
gauge.set(0.0);
}

Expand Down Expand Up @@ -156,13 +156,8 @@ pub async fn main(_cli: &Cli, cfg: &Config, bind: &str) -> Result<()> {
let bind_addr: SocketAddr = bind.parse()?;
tokio::spawn(async move {
let bind_addr = bind_addr;
let responder = libmdns::Responder::new().unwrap();
let _svc = responder.register(
"_machine-api._tcp".to_owned(),
"Machine Api Server".to_owned(),
bind_addr.port(),
&["path=/"],
);
let responder = libmdns::Responder::new();
let _svc = responder.register("_machine-api._tcp", "Machine Api Server", bind_addr.port(), &["path=/"]);

tracing::info!(
bind_addr = bind_addr.to_string(),
Expand Down
9 changes: 3 additions & 6 deletions src/bin/machine-api/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,11 +127,8 @@ async fn main() -> Result<()> {
)
};

let provider = opentelemetry_sdk::trace::TracerProvider::builder()
.with_batch_exporter(
opentelemetry_otlp::SpanExporter::builder().with_tonic().build()?,
opentelemetry_sdk::runtime::Tokio,
)
let provider = opentelemetry_sdk::trace::SdkTracerProvider::builder()
.with_batch_exporter(opentelemetry_otlp::SpanExporter::builder().with_tonic().build()?)
.build();

opentelemetry::global::set_tracer_provider(provider.clone());
Expand Down Expand Up @@ -169,7 +166,7 @@ async fn main() -> Result<()> {

let cfg: Config = toml::from_str(
&std::fs::read_to_string(&cli.config)
.map_err(|_| anyhow::anyhow!("Config file not found at {}", &cli.config))?,
.map_err(|_| anyhow::anyhow!("Config file not found at {}", cli.config))?,
)?;

match cli.command {
Expand Down
6 changes: 3 additions & 3 deletions src/server/endpoints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ pub enum ExtraMachineInfoResponse {
#[cfg(debug_assertions)]
#[cfg(not(test))]
/// The raw status message from the machine.
raw_status: bambulabs::message::PushStatus,
raw_status: Box<bambulabs::message::PushStatus>,
},
}

Expand Down Expand Up @@ -125,7 +125,7 @@ impl MachineInfoResponse {
nozzle_diameter: status.nozzle_diameter,
#[cfg(debug_assertions)]
#[cfg(not(test))]
raw_status: status,
raw_status: Box::new(status),
})
}
_ => None,
Expand Down Expand Up @@ -209,7 +209,7 @@ pub async fn get_machine(
)),
None => Err(HttpError::for_not_found(
None,
format!("machine not found by id: {:?}", &params.id),
format!("machine not found by id: {:?}", params.id),
)),
}
}
Expand Down
10 changes: 3 additions & 7 deletions src/server/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ pub async fn create_server(
default_request_body_max_bytes: 107374182400, // 100 Gigiabytes.
default_handler_task_mode: dropshot::HandlerTaskMode::CancelOnDisconnect,
log_headers: Default::default(),
compression: Default::default(),
};

let api_context = Arc::new(Context {
Expand Down Expand Up @@ -102,13 +103,8 @@ pub async fn serve(
let (server, _api_context) = create_server(bind, machines, registry).await?;
let addr: SocketAddr = bind.parse()?;

let responder = libmdns::Responder::new().unwrap();
let _svc = responder.register(
"_machine-api._tcp".to_owned(),
"Machine Api Server".to_owned(),
addr.port(),
&["path=/"],
);
let responder = libmdns::Responder::new();
let _svc = responder.register("_machine-api._tcp", "Machine Api Server", addr.port(), &["path=/"]);

// For Cloud run & ctrl+c, shutdown gracefully.
// "The main process inside the container will receive SIGTERM, and after a grace period,
Expand Down
Loading