we now have address of the I2C
This commit is contained in:
@@ -7,6 +7,7 @@
|
||||
reason = "mem::forget is generally not safe to do with esp_hal types"
|
||||
)]
|
||||
|
||||
use defmt::error;
|
||||
use embassy_executor::Spawner;
|
||||
use embassy_futures::select::{select, Either};
|
||||
use embassy_net::{Runner, StackResources};
|
||||
@@ -78,10 +79,30 @@ async fn main(spawner: Spawner) -> ! {
|
||||
.into_async();
|
||||
|
||||
let mut buffer = [0u8; 1];
|
||||
let SAD = 0x5C;
|
||||
let SUB = &[0x0F];
|
||||
i2c.write_read_async(SAD, SUB, &mut buffer).await.unwrap();
|
||||
info!("WHO_AM_I: {:x}", buffer[0]);
|
||||
let mut devices_count = 0;
|
||||
|
||||
info!("Starting I2C bus scan...");
|
||||
|
||||
for addr in 0x08..=0x77 {
|
||||
match i2c.write_read_async(addr, &[0x0F], &mut buffer).await {
|
||||
Ok(_) => {
|
||||
info!(
|
||||
"Found device at address: 0x{:02X} (WHO_AM_I: 0x{:02X})",
|
||||
addr, buffer[0]
|
||||
);
|
||||
devices_count += 1;
|
||||
}
|
||||
Err(_) => {
|
||||
// No device responded at this address, continue silently
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if devices_count == 0 {
|
||||
info!("Scan complete: No devices found.");
|
||||
} else {
|
||||
info!("Scan complete: {} device(s) found.", devices_count);
|
||||
}
|
||||
|
||||
info!("Initializing WiFi...");
|
||||
let timg0 = TimerGroup::new(peripherals.TIMG0);
|
||||
@@ -123,11 +144,12 @@ async fn main(spawner: Spawner) -> ! {
|
||||
NETWORK_READY.wait().await;
|
||||
info!("Network ready");
|
||||
|
||||
mqtt_publish("esp32/post", b"online", QualityOfService::QoS1, false).await;
|
||||
// mqtt_publish("esp32/post", b"online", QualityOfService::QoS1, false).await;
|
||||
// mqtt_publish("esp32/post", &whoami, QualityOfService::QoS1, false).await;
|
||||
|
||||
loop {
|
||||
Timer::after(Duration::from_secs(10)).await;
|
||||
mqtt_publish("esp32/post", b"abba", QualityOfService::QoS1, false).await;
|
||||
mqtt_publish("esp32/post", b"aaaa", QualityOfService::QoS1, false).await;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user