Added temperature sensor
This commit is contained in:
parent
73c2710e77
commit
1c518b6b95
45
Cargo.lock
generated
45
Cargo.lock
generated
|
@ -50,6 +50,7 @@ dependencies = [
|
|||
name = "air_filter"
|
||||
version = "0.2.0"
|
||||
dependencies = [
|
||||
"bme280",
|
||||
"cfg-if",
|
||||
"const_format",
|
||||
"cortex-m",
|
||||
|
@ -223,6 +224,17 @@ dependencies = [
|
|||
"generic-array 0.14.7",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "bme280"
|
||||
version = "0.5.0"
|
||||
source = "git+https://github.com/Remmirad/bme280-rs/?branch=fix_reset_setup_time#67700603706fccd5ffab8c465cf38d04058b7f48"
|
||||
dependencies = [
|
||||
"defmt",
|
||||
"embedded-hal 1.0.0",
|
||||
"embedded-hal-async",
|
||||
"maybe-async-cfg",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "buffered-io"
|
||||
version = "0.5.0"
|
||||
|
@ -1457,6 +1469,19 @@ version = "0.8.0"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0ca88d725a0a943b096803bd34e73a4437208b6077654cc4ecb2947a5f91618d"
|
||||
|
||||
[[package]]
|
||||
name = "maybe-async-cfg"
|
||||
version = "0.2.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "21fb8fac02158b9b529eb692491895d8459dbac939f3bc6e32159969646ffe55"
|
||||
dependencies = [
|
||||
"proc-macro-error",
|
||||
"proc-macro2",
|
||||
"pulldown-cmark",
|
||||
"quote",
|
||||
"syn 1.0.109",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "memchr"
|
||||
version = "2.6.2"
|
||||
|
@ -1740,6 +1765,17 @@ dependencies = [
|
|||
"unicode-ident",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "pulldown-cmark"
|
||||
version = "0.9.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "57206b407293d2bcd3af849ce869d52068623f19e1b5ff8e8778e3309439682b"
|
||||
dependencies = [
|
||||
"bitflags 2.4.0",
|
||||
"memchr",
|
||||
"unicase",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "quote"
|
||||
version = "1.0.33"
|
||||
|
@ -2186,6 +2222,15 @@ version = "1.16.0"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "497961ef93d974e23eb6f433eb5fe1b7930b659f06d12dec6fc44a8f554c0bba"
|
||||
|
||||
[[package]]
|
||||
name = "unicase"
|
||||
version = "2.7.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f7d2d4dafb69621809a81864c9c1b864479e1235c0dd4e199924b9742439ed89"
|
||||
dependencies = [
|
||||
"version_check",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "unicode-ident"
|
||||
version = "1.0.11"
|
||||
|
|
|
@ -22,6 +22,8 @@ embassy-rp = { version = "0.1", features = [
|
|||
"unstable-pac",
|
||||
"time-driver",
|
||||
"critical-section-impl",
|
||||
"intrinsics",
|
||||
"rom-v2-intrinsics",
|
||||
] }
|
||||
embassy-boot-rp = { version = "0.2", features = ["defmt"] }
|
||||
embassy-boot = { version = "0.2", features = ["defmt"] }
|
||||
|
@ -67,10 +69,12 @@ smoltcp = { version = "0.11", default-features = false, features = [
|
|||
] }
|
||||
updater = { version = "0.1.0", path = "../iot_tools/updater" }
|
||||
portable-atomic = { version = "1.6", features = ["critical-section"] }
|
||||
bme280 = { version = "0.5.0", features = ["async", "defmt"] }
|
||||
|
||||
[patch.crates-io]
|
||||
# Make mqtt:// and mqtts:// actually work
|
||||
nourl = { git = "https://git.huizinga.dev/Dreaded_X/nourl" }
|
||||
bme280 = { git = "https://github.com/Remmirad/bme280-rs/", branch = "fix_reset_setup_time" }
|
||||
|
||||
[features]
|
||||
include_firmwares = []
|
||||
|
|
35
src/main.rs
35
src/main.rs
|
@ -3,7 +3,9 @@
|
|||
#![feature(type_alias_impl_trait)]
|
||||
|
||||
use core::{cell::RefCell, str::from_utf8};
|
||||
use core::fmt::Debug;
|
||||
|
||||
use bme280::{i2c::AsyncBME280, Measurements};
|
||||
use const_format::formatcp;
|
||||
use cyw43::PowerManagementMode;
|
||||
use cyw43_pio::PioSpi;
|
||||
|
@ -17,12 +19,13 @@ use embassy_rp::{
|
|||
clocks::RoscRng,
|
||||
flash::{Flash, WRITE_SIZE},
|
||||
gpio::{Flex, Input, Level, Output, Pin, Pull},
|
||||
peripherals::{DMA_CH1, PIN_23, PIN_25, PIO0},
|
||||
i2c,
|
||||
peripherals::{DMA_CH1, I2C0, PIN_23, PIN_25, PIO0},
|
||||
pio::{self, Pio},
|
||||
Peripheral,
|
||||
};
|
||||
use embassy_sync::blocking_mutex::Mutex;
|
||||
use embassy_time::{Duration, Ticker, Timer};
|
||||
use embassy_time::{Delay, Duration, Ticker, Timer};
|
||||
use heapless::Vec;
|
||||
use nourl::Url;
|
||||
use rand::{
|
||||
|
@ -43,6 +46,7 @@ use {defmt_rtt as _, panic_probe as _};
|
|||
|
||||
bind_interrupts!(struct Irqs {
|
||||
PIO0_IRQ_0 => pio::InterruptHandler<PIO0>;
|
||||
I2C0_IRQ => i2c::InterruptHandler<I2C0>;
|
||||
});
|
||||
|
||||
const ID: &str = env!("ID");
|
||||
|
@ -63,14 +67,23 @@ struct SetMessage {
|
|||
struct StateMessage {
|
||||
state: State,
|
||||
manual: bool,
|
||||
temperature: f32,
|
||||
humidity: f32,
|
||||
pressure: f32,
|
||||
}
|
||||
|
||||
impl StateMessage {
|
||||
pub fn new((state, manual): (State, bool)) -> Self {
|
||||
Self { state, manual }
|
||||
pub fn new<E: Debug>((state, manual): (State, bool), measurements: Measurements<E>) -> Self {
|
||||
Self {
|
||||
state,
|
||||
manual,
|
||||
temperature: measurements.temperature,
|
||||
humidity: measurements.humidity,
|
||||
pressure: measurements.pressure,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn vec(&self) -> Vec<u8, 64> {
|
||||
pub fn vec(&self) -> Vec<u8, 128> {
|
||||
serde_json_core::to_vec(self)
|
||||
.expect("The buffer should be large enough to contain all the data")
|
||||
}
|
||||
|
@ -287,6 +300,11 @@ async fn main(spawner: Spawner) {
|
|||
|
||||
let mut controller = Controller::new(p.PIN_28, p.PIN_27, p.PIN_26, p.PIN_22);
|
||||
|
||||
let i2c = i2c::I2c::new_async(p.I2C0, p.PIN_1, p.PIN_0, Irqs, i2c::Config::default());
|
||||
let mut bme280 = AsyncBME280::new_primary(i2c);
|
||||
let mut delay = Delay {};
|
||||
bme280.init(&mut delay).await.unwrap();
|
||||
|
||||
let pwr = Output::new(p.PIN_23, Level::Low);
|
||||
let cs = Output::new(p.PIN_25, Level::High);
|
||||
|
||||
|
@ -413,8 +431,7 @@ async fn main(spawner: Spawner) {
|
|||
.await
|
||||
{
|
||||
Either3::First(_) => {
|
||||
client.send_ping().await.unwrap();
|
||||
None
|
||||
Some(StateMessage::new(controller.get_state(), bme280.measure(&mut delay).await.unwrap()))
|
||||
}
|
||||
Either3::Second(message) => match message {
|
||||
Ok((TOPIC_UPDATE, url)) => {
|
||||
|
@ -457,7 +474,7 @@ async fn main(spawner: Spawner) {
|
|||
|
||||
controller.set_state(message.get_state());
|
||||
|
||||
Some(StateMessage::new(controller.get_state()))
|
||||
Some(StateMessage::new(controller.get_state(), bme280.measure(&mut delay).await.unwrap()))
|
||||
}
|
||||
Ok(_) => None,
|
||||
Err(err) => {
|
||||
|
@ -468,7 +485,7 @@ async fn main(spawner: Spawner) {
|
|||
cortex_m::peripheral::SCB::sys_reset();
|
||||
}
|
||||
},
|
||||
Either3::Third(state) => Some(StateMessage::new(state)),
|
||||
Either3::Third(state) => Some(StateMessage::new(state, bme280.measure(&mut delay).await.unwrap())),
|
||||
};
|
||||
|
||||
if let Some(message) = message {
|
||||
|
|
Loading…
Reference in New Issue
Block a user