initial mqtt connect

This commit is contained in:
Vladan Popovic 2022-06-25 18:35:35 +02:00
parent a4c8d03eb9
commit 8d7d4d898d
2 changed files with 13 additions and 1 deletions

View file

@ -17,6 +17,7 @@ anyhow = "1.0.57"
embedded-hal = "0.2.7" embedded-hal = "0.2.7"
esp-idf-hal = "0.37.4" esp-idf-hal = "0.37.4"
esp-idf-sys = { version = "0.31.5", features = ["binstart", "native"] } esp-idf-sys = { version = "0.31.5", features = ["binstart", "native"] }
mqtt-protocol = "0.11.2"
nb = "1.0.0" nb = "1.0.0"
[build-dependencies] [build-dependencies]

View file

@ -10,6 +10,10 @@ use esp_idf_hal::prelude::*;
use esp_idf_hal::peripherals::Peripherals; use esp_idf_hal::peripherals::Peripherals;
use esp_idf_hal::serial; use esp_idf_hal::serial;
use mqtt::control::ConnectReturnCode;
use mqtt::packet::{ConnackPacket, ConnectPacket, PublishPacketRef, QoSWithPacketIdentifier};
use mqtt::{Decodable, Encodable, TopicName};
fn main() -> anyhow::Result<()> { fn main() -> anyhow::Result<()> {
esp_idf_sys::link_patches(); esp_idf_sys::link_patches();
@ -65,7 +69,14 @@ fn main() -> anyhow::Result<()> {
let _ = mdm.tcp_set_quick_mode(false); let _ = mdm.tcp_set_quick_mode(false);
let _ = mdm.tcp_set_manual_receive()?; let _ = mdm.tcp_set_manual_receive()?;
let _ = mdm.tcp_connect("51.158.66.64", 9988)?; let _ = mdm.tcp_connect("51.158.66.64", 9988)?;
let _ = mdm.tcp_send("aaaaa")?;
let client_id = "e-bike-tracker";
let mut conn = ConnectPacket::new(client_id);
conn.set_clean_session(true);
let mut buf = Vec::new();
let _ = conn.encode(&mut buf)?;
let _ = mdm.tcp_send(&mut buf)?;
thread::sleep(Duration::from_millis(1000)); thread::sleep(Duration::from_millis(1000));
println!("+++++++++++++++++++++++++++++++++"); println!("+++++++++++++++++++++++++++++++++");
let size = mdm.tcp_receive_reply_len()?; let size = mdm.tcp_receive_reply_len()?;