Skip to content

Instantly share code, notes, and snippets.

@tlhenvironment
tlhenvironment / mqtt_rust_tls.rs
Last active November 10, 2024 20:56
Rust MQTT TLS on ESP32
//use rust-mqtt = { git = "https://github.com/obabec/rust-mqtt.git", rev = "b5ed04efc694c5a0e4f6925b7f90ebaac9f0504f", default-features = false, features = ["log", "tls"] }
//tcp
let mqtt_broker_addr = stack.dns_query(broker_str, embassy_net::dns::DnsQueryType::A).await.unwrap();
let mqtt_endpoint = IpEndpoint::new(endpoint, 8883);
let mut socket = embassy_net::tcp::TcpSocket::new(stack, &mut rx_buffer, &mut tx_buffer);
socket.connect(mqtt_endpoint).await.unwrap();
//tls
let config: TlsConfig<'_> = TlsConfig::new().with_server_name(&broker_str).enable_rsa_signatures();