obabec / rust-mqtt

Rust native mqtt client for both std and no_std environmnents.
MIT License
43 stars 24 forks source link

Connecting to socket from embassy-net 0.4.0 #37

Open tlhenvironment opened 8 months ago

tlhenvironment commented 8 months ago

I'm getting an linker error when I want to want to connect to a broker on a embassy-net socket. Here is some info:


embassy-net = { version = "0.4.0", features = ["medium-ip", "tcp", "medium-ethernet", "dhcpv4", "log", "udp", "dns"] }

rust-mqtt = { version = "0.3.0", features = ["no_std"], default-features = false }

esp-wifi        = { version = "0.3.0", features = ["esp32c3", "wifi-logs", "wifi", "utils", "wifi-default", "embassy-net", "async"] }

//dns query of mqtt broker ip
let mqtt_ip: Vec<_, 1>;
loop{
    println!("DNS query to MQTT server...");
    if let Ok(ip_addr) = stack.dns_query("broker.mqttdashboard.com", embassy_net::dns::DnsQueryType::A).await {
        println!("DNS query to MQTT server success!");
        mqtt_ip = ip_addr;
        break;
    }
    Timer::after(Duration::from_millis(1000)).await;
}

println!("MQTT IP is: {:?}", mqtt_ip);

//connect to mqtt broker
println!("Connecting to socket...");
let endpoint = IpEndpoint::new(mqtt_ip[0], 1883);
let mut socket = embassy_net::tcp::TcpSocket::new(stack, &mut rx_buffer, &mut tx_buffer);
socket.connect(endpoint).await.map_err(|_| ReasonCode::NetworkError).unwrap();
println!("Connected to MQTT broker...");

let mut config: ClientConfig<'_, 20, CountingRng> = ClientConfig::new(
    rust_mqtt::client::client_config::MqttVersion::MQTTv5,
    CountingRng(20000),
);

config.add_max_subscribe_qos(rust_mqtt::packet::v5::publish_packet::QualityOfService::QoS1);
config.add_client_id("client");
config.max_packet_size = 20;

let mut recv_buffer = [0; 80];
let mut write_buffer = [0; 80];

let mut client = MqttClient::new(
    socket,
    &mut write_buffer,
    80,
    &mut recv_buffer,
    80,
    config,
);

println!("Connecting to broker...");
client.connect_to_broker().await.unwrap();

Compilation error comes when the last line is included in my code.

error: linking with rust-lld failed: exit status: 1

and a lot of

= note: rust-lld: error: undefined symbol: _defmt_acquire
rust-lld: error: undefined symbol: _defmt_release
rust-lld: error: undefined symbol: _defmt_write`

Would be very happy for any suggestion how to fix this, I wouldn't like to go far too back in dependency hell and use old versions of embassy-net and then hal and esp-wifi :D

flyaruu commented 6 months ago

I ran into this one as well, I fixed it by removing the no_std feature.

tlhenvironment commented 6 months ago

Thanks a lot, got it to work!