Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Connecting to socket from embassy-net 0.4.0 #37

Open
tlhenvironment opened this issue Mar 11, 2024 · 2 comments
Open

Connecting to socket from embassy-net 0.4.0 #37

tlhenvironment opened this issue Mar 11, 2024 · 2 comments

Comments

@tlhenvironment
Copy link

tlhenvironment commented Mar 11, 2024

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
Copy link

flyaruu commented Apr 15, 2024

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

@tlhenvironment
Copy link
Author

Thanks a lot, got it to work!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants