Skip to content

Instantly share code, notes, and snippets.

@paulc
Created October 3, 2025 15:39
Show Gist options
  • Save paulc/45846694bc886fdeaf3c4154e6dc6415 to your computer and use it in GitHub Desktop.
Save paulc/45846694bc886fdeaf3c4154e6dc6415 to your computer and use it in GitHub Desktop.
eep-now
#![no_std]
#![no_main]
#![feature(type_alias_impl_trait)]
#![feature(extend_one)]
#![deny(
clippy::mem_forget,
reason = "mem::forget is generally not safe to do with esp_hal types, especially those \
holding buffers for the duration of a data transfer."
)]
use esp_hal::clock::CpuClock;
use esp_hal::timer::systimer::SystemTimer;
use esp_hal::timer::timg::TimerGroup;
use embassy_executor::Spawner;
use embassy_time::{Duration, Ticker};
use panic_rtt_target as _;
extern crate alloc;
// This creates a default app-descriptor required by the esp-idf bootloader.
// For more information see: <https://docs.espressif.com/projects/esp-idf/en/stable/esp32/api-reference/system/app_image_format.html#application-description>
esp_bootloader_esp_idf::esp_app_desc!();
#[esp_hal_embassy::main]
async fn main(spawner: Spawner) {
// generator version: 0.5.0
rtt_target::rtt_init_defmt!();
defmt::info!("RTT Init");
let config = esp_hal::Config::default().with_cpu_clock(CpuClock::max());
let peripherals = esp_hal::init(config);
esp_alloc::heap_allocator!(size: 64 * 1024);
let timer0 = SystemTimer::new(peripherals.SYSTIMER);
esp_hal_embassy::init(timer0.alarm0);
defmt::info!("Embassy Init");
let rng = esp_hal::rng::Rng::new(peripherals.RNG);
let timer1 = TimerGroup::new(peripherals.TIMG0);
let wifi_init =
esp_wifi::init(timer1.timer0, rng).expect("Failed to initialize WIFI/BLE controller");
let (mut _wifi_controller, interfaces) = esp_wifi::wifi::new(&wifi_init, peripherals.WIFI)
.expect("Failed to initialize WIFI controller");
let esp_now = interfaces.esp_now;
esp_now
.set_channel(11)
.expect("Error setting ESP-NOW channel");
let _ = spawner;
let mut count = 0_u32;
let mut ticker = Ticker::every(Duration::from_secs(5));
loop {
defmt::info!("Tick [{}]", count);
count += 1;
ticker.next().await;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment