need senzor implementation next
This commit is contained in:
@@ -6,7 +6,6 @@
|
|||||||
clippy::mem_forget,
|
clippy::mem_forget,
|
||||||
reason = "mem::forget is generally not safe to do with esp_hal types"
|
reason = "mem::forget is generally not safe to do with esp_hal types"
|
||||||
)]
|
)]
|
||||||
// TODO WARNING core 1 should be logic, core 0 wifi, its flipped now
|
|
||||||
|
|
||||||
use embassy_executor::Spawner;
|
use embassy_executor::Spawner;
|
||||||
use embassy_futures::select::{select, Either};
|
use embassy_futures::select::{select, Either};
|
||||||
@@ -14,15 +13,13 @@ use embassy_net::{Runner, StackResources};
|
|||||||
use embassy_sync::blocking_mutex::raw::CriticalSectionRawMutex;
|
use embassy_sync::blocking_mutex::raw::CriticalSectionRawMutex;
|
||||||
use embassy_sync::signal::Signal;
|
use embassy_sync::signal::Signal;
|
||||||
use embassy_time::{Duration, Instant, Timer};
|
use embassy_time::{Duration, Instant, Timer};
|
||||||
use projekt_final::mqtt::client;
|
use projekt_final::mqtt::client::{mqtt_publish, mqtt_task};
|
||||||
|
|
||||||
use esp_alloc as _;
|
use esp_alloc as _;
|
||||||
use esp_backtrace as _;
|
use esp_backtrace as _;
|
||||||
|
|
||||||
use esp_hal::{
|
use esp_hal::{
|
||||||
clock::CpuClock,
|
clock::CpuClock,
|
||||||
gpio::InputConfig,
|
|
||||||
gpio::{Input, Pull},
|
|
||||||
rng::Rng,
|
rng::Rng,
|
||||||
system::{CpuControl, Stack},
|
system::{CpuControl, Stack},
|
||||||
timer::timg::TimerGroup,
|
timer::timg::TimerGroup,
|
||||||
@@ -32,18 +29,12 @@ use esp_wifi::{
|
|||||||
EspWifiController,
|
EspWifiController,
|
||||||
};
|
};
|
||||||
|
|
||||||
use core::cell::RefCell;
|
// use core::cell::RefCell;
|
||||||
use core::fmt::Write;
|
// use core::fmt::Write;
|
||||||
use heapless::String;
|
|
||||||
use log::info;
|
use log::info;
|
||||||
use pages_tui::input::Key;
|
|
||||||
use rust_mqtt::packet::v5::publish_packet::QualityOfService;
|
use rust_mqtt::packet::v5::publish_packet::QualityOfService;
|
||||||
use static_cell::StaticCell;
|
use static_cell::StaticCell;
|
||||||
|
|
||||||
use projekt_final::mqtt::client::{
|
|
||||||
mqtt_events, mqtt_publish, mqtt_subscribe, mqtt_task, mqtt_try_publish, IncomingMsg,
|
|
||||||
};
|
|
||||||
|
|
||||||
extern crate alloc;
|
extern crate alloc;
|
||||||
|
|
||||||
static APP_CORE_STACK: StaticCell<Stack<8192>> = StaticCell::new();
|
static APP_CORE_STACK: StaticCell<Stack<8192>> = StaticCell::new();
|
||||||
@@ -93,11 +84,7 @@ async fn main(spawner: Spawner) -> ! {
|
|||||||
|
|
||||||
let seed = (rng.random() as u64) << 32 | rng.random() as u64;
|
let seed = (rng.random() as u64) << 32 | rng.random() as u64;
|
||||||
|
|
||||||
let config = InputConfig::default().with_pull(Pull::Down);
|
// Core1 is now general stuff and core0 is for wifi and mqtt
|
||||||
let button_select = Input::new(peripherals.GPIO32, config);
|
|
||||||
let button_next = Input::new(peripherals.GPIO35, config);
|
|
||||||
|
|
||||||
// Core1 is now general stuff and core 0 is for wifi and mqtt
|
|
||||||
let mut cpu_control = CpuControl::new(peripherals.CPU_CTRL);
|
let mut cpu_control = CpuControl::new(peripherals.CPU_CTRL);
|
||||||
let _guard = cpu_control
|
let _guard = cpu_control
|
||||||
.start_app_core(APP_CORE_STACK.init(Stack::new()), move || {
|
.start_app_core(APP_CORE_STACK.init(Stack::new()), move || {
|
||||||
@@ -111,33 +98,20 @@ async fn main(spawner: Spawner) -> ! {
|
|||||||
})
|
})
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
// Wait for network to be ready (signaled from core 1)
|
// Core0 WiFi and MQTT
|
||||||
NETWORK_READY.wait().await;
|
|
||||||
info!("Network ready, starting core 0 tasks");
|
|
||||||
|
|
||||||
// Start core 0 for WiFi and MQTT (network stack created there)
|
|
||||||
spawner
|
spawner
|
||||||
.spawn(network_task(spawner, controller, wifi_interface, seed))
|
.spawn(network_task(spawner, controller, wifi_interface, seed))
|
||||||
.unwrap();
|
.unwrap();
|
||||||
mqtt_subscribe("esp32/read").await;
|
|
||||||
mqtt_publish("esp32/imu", b"online", QualityOfService::QoS1, false).await;
|
|
||||||
|
|
||||||
let mqtt_rx = mqtt_events();
|
// Wait for network to be ready (signaled from core0)
|
||||||
let mut mqtt_msg_count: u32 = 0;
|
NETWORK_READY.wait().await;
|
||||||
let mut mqtt_publish_drops: u32 = 0;
|
info!("Network ready");
|
||||||
let mut last_mqtt_publish = Instant::now();
|
|
||||||
let mqtt_publish_interval = Duration::from_secs(3);
|
mqtt_publish("esp32/post", b"online", QualityOfService::QoS1, false).await;
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
match select(mqtt_rx.receive(), Timer::after(Duration::from_secs(5))).await {
|
Timer::after(Duration::from_secs(10)).await;
|
||||||
Either::First(msg) => {
|
mqtt_publish("esp32/post", b"abba", QualityOfService::QoS1, false).await;
|
||||||
mqtt_msg_count += 1;
|
|
||||||
handle_mqtt_message(msg).await;
|
|
||||||
}
|
|
||||||
Either::Second(_) => {
|
|
||||||
info!("Ahoj",);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -182,17 +156,6 @@ async fn network_task(
|
|||||||
spawner.spawn(mqtt_task(stack)).ok();
|
spawner.spawn(mqtt_task(stack)).ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn handle_mqtt_message(msg: IncomingMsg) {
|
|
||||||
if let Ok(txt) = core::str::from_utf8(&msg.payload) {
|
|
||||||
match txt {
|
|
||||||
"status" => {
|
|
||||||
mqtt_publish("esp32/status", b"running", QualityOfService::QoS1, false).await;
|
|
||||||
}
|
|
||||||
_ => {}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[embassy_executor::task]
|
#[embassy_executor::task]
|
||||||
async fn connection_task(mut controller: WifiController<'static>) {
|
async fn connection_task(mut controller: WifiController<'static>) {
|
||||||
loop {
|
loop {
|
||||||
|
|||||||
Reference in New Issue
Block a user