changes to more modern way
This commit is contained in:
@@ -32,7 +32,6 @@ use rust_mqtt::packet::v5::publish_packet::QualityOfService;
|
||||
use static_cell::StaticCell;
|
||||
use core::cell::RefCell;
|
||||
|
||||
// Our crate
|
||||
use projekt_final::{
|
||||
bus,
|
||||
display,
|
||||
@@ -46,9 +45,11 @@ use alloc::format;
|
||||
static I2C_BUS: StaticCell<RefCell<I2cInner>> = StaticCell::new();
|
||||
|
||||
macro_rules! mk_static {
|
||||
($t:ty, $val:expr) => {{
|
||||
static STATIC_CELL: StaticCell<$t> = StaticCell::new();
|
||||
STATIC_CELL.init($val)
|
||||
($t:ty,$val:expr) => {{
|
||||
static STATIC_CELL: static_cell::StaticCell<$t> = static_cell::StaticCell::new();
|
||||
#[deny(unused_attributes)]
|
||||
let x = STATIC_CELL.uninit().write(($val));
|
||||
x
|
||||
}};
|
||||
}
|
||||
|
||||
@@ -61,9 +62,9 @@ esp_bootloader_esp_idf::esp_app_desc!();
|
||||
#[esp_hal_embassy::main]
|
||||
async fn main(spawner: Spawner) -> ! {
|
||||
esp_println::logger::init_logger_from_env();
|
||||
info!("═══════════════════════════════════════════════════════════");
|
||||
info!("===============================");
|
||||
info!(" ESP32 IoT Firmware Starting");
|
||||
info!("═══════════════════════════════════════════════════════════");
|
||||
info!("===============================");
|
||||
|
||||
let config = esp_hal::Config::default().with_cpu_clock(CpuClock::max());
|
||||
let peripherals = esp_hal::init(config);
|
||||
@@ -108,7 +109,6 @@ async fn main(spawner: Spawner) -> ! {
|
||||
|
||||
spawner.spawn(connection_task(controller)).expect("spawn connection_task");
|
||||
spawner.spawn(net_task(runner)).expect("spawn net_task");
|
||||
|
||||
wait_for_network(stack).await;
|
||||
|
||||
spawner.spawn(mqtt_task(stack)).expect("spawn mqtt_task");
|
||||
@@ -116,8 +116,8 @@ async fn main(spawner: Spawner) -> ! {
|
||||
spawner.spawn(mpu::task::mpu_task(mpu_i2c)).expect("spawn mpu_task");
|
||||
|
||||
display::api::set_status("Booting...").await;
|
||||
mqtt_subscribe("esp32/cmd").await;
|
||||
mqtt_publish("esp32/status", b"online", QualityOfService::QoS1, false).await;
|
||||
mqtt_subscribe("esp32/topic").await;
|
||||
mqtt_publish("esp32/topic", b"online", QualityOfService::QoS1, false).await;
|
||||
|
||||
display::api::set_status("Running").await;
|
||||
display::api::set_mqtt_status(true, 0).await;
|
||||
@@ -197,10 +197,12 @@ async fn connection_task(mut controller: WifiController<'static>) {
|
||||
info!("Wi-Fi starting...");
|
||||
controller.start_async().await.unwrap();
|
||||
}
|
||||
if let Err(e) = controller.connect_async().await {
|
||||
info!("Wi-Fi reconnect failed: {:?}", e);
|
||||
} else {
|
||||
info!("Wi-Fi connected.");
|
||||
match controller.connect_async().await {
|
||||
Ok(_) => info!("Wifi connected!"),
|
||||
Err(e) => {
|
||||
info!("Failed to connect to wifi: {e:#?}");
|
||||
Timer::after(Duration::from_millis(5000)).await
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -150,12 +150,6 @@ async fn run_one_session(
|
||||
}
|
||||
|
||||
// Operational loop
|
||||
let default_topic = "esp32/topic";
|
||||
match client.subscribe_to_topic(default_topic).await {
|
||||
Ok(_) => info!("Subscribed to '{}'", default_topic),
|
||||
Err(e) => info!("Default subscribe failed: {:?}", e),
|
||||
};
|
||||
|
||||
loop {
|
||||
let net_or_ping = select(client.receive_message(), Timer::after(PING_PERIOD));
|
||||
|
||||
|
||||
Reference in New Issue
Block a user