esp sa teraz pripaja na wifi
This commit is contained in:
@@ -3,8 +3,6 @@ runner = "espflash flash --monitor --chip esp32"
|
|||||||
|
|
||||||
[env]
|
[env]
|
||||||
ESP_LOG="info"
|
ESP_LOG="info"
|
||||||
SSID = "nazov_wifi"
|
|
||||||
PASSWORD = "heslo"
|
|
||||||
|
|
||||||
[build]
|
[build]
|
||||||
rustflags = [
|
rustflags = [
|
||||||
|
|||||||
2
test1/.env_temp
Normal file
2
test1/.env_temp
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
SSID = "nazov_wifi_siete"
|
||||||
|
PASSWORD = "heslo_od_wifi"
|
||||||
1
test1/.gitignore
vendored
1
test1/.gitignore
vendored
@@ -4,6 +4,7 @@ target/
|
|||||||
.vscode/
|
.vscode/
|
||||||
.zed/
|
.zed/
|
||||||
.helix/
|
.helix/
|
||||||
|
.env
|
||||||
|
|
||||||
# These are backup files generated by rustfmt
|
# These are backup files generated by rustfmt
|
||||||
**/*.rs.bk
|
**/*.rs.bk
|
||||||
|
|||||||
7
test1/Cargo.lock
generated
7
test1/Cargo.lock
generated
@@ -234,6 +234,12 @@ dependencies = [
|
|||||||
"litrs",
|
"litrs",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "dotenvy"
|
||||||
|
version = "0.15.7"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "1aaf95b3e5c8f23aa320147307562d361db0ae0d51242340f558153b4eb2439b"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "embassy-embedded-hal"
|
name = "embassy-embedded-hal"
|
||||||
version = "0.3.2"
|
version = "0.3.2"
|
||||||
@@ -1388,6 +1394,7 @@ name = "test1"
|
|||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"critical-section",
|
"critical-section",
|
||||||
|
"dotenvy",
|
||||||
"embassy-executor",
|
"embassy-executor",
|
||||||
"embassy-net",
|
"embassy-net",
|
||||||
"embassy-time 0.4.0",
|
"embassy-time 0.4.0",
|
||||||
|
|||||||
@@ -67,6 +67,8 @@ static_cell = "2.1.1"
|
|||||||
rust-mqtt = { version = "0.3.0", default-features = false, features = ["no_std"] }
|
rust-mqtt = { version = "0.3.0", default-features = false, features = ["no_std"] }
|
||||||
heapless = "0.9.1"
|
heapless = "0.9.1"
|
||||||
|
|
||||||
|
[build-dependencies]
|
||||||
|
dotenvy = "0.15.7"
|
||||||
|
|
||||||
[profile.dev]
|
[profile.dev]
|
||||||
# Rust debug is too slow.
|
# Rust debug is too slow.
|
||||||
|
|||||||
9
test1/Makefile
Normal file
9
test1/Makefile
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
.PHONY: all build flash
|
||||||
|
|
||||||
|
all: build flash
|
||||||
|
|
||||||
|
build:
|
||||||
|
cargo build --release
|
||||||
|
|
||||||
|
flash:
|
||||||
|
cargo espflash flash --release --monitor
|
||||||
@@ -1,4 +1,17 @@
|
|||||||
fn main() {
|
fn main() {
|
||||||
|
// load .env and pass SSID/PASSWORD to compiler
|
||||||
|
if let Ok(dotenv_path) = dotenvy::dotenv() {
|
||||||
|
// Only rebuild if .env changes
|
||||||
|
println!("cargo:rerun-if-changed={}", dotenv_path.display());
|
||||||
|
}
|
||||||
|
|
||||||
|
if let Ok(ssid) = std::env::var("SSID") {
|
||||||
|
println!("cargo:rustc-env=SSID={}", ssid);
|
||||||
|
}
|
||||||
|
if let Ok(password) = std::env::var("PASSWORD") {
|
||||||
|
println!("cargo:rustc-env=PASSWORD={}", password);
|
||||||
|
}
|
||||||
|
|
||||||
linker_be_nice();
|
linker_be_nice();
|
||||||
// make sure linkall.x is the last linker script (otherwise might cause problems with flip-link)
|
// make sure linkall.x is the last linker script (otherwise might cause problems with flip-link)
|
||||||
println!("cargo:rustc-link-arg=-Tlinkall.x");
|
println!("cargo:rustc-link-arg=-Tlinkall.x");
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ use esp_backtrace as _;
|
|||||||
use esp_hal::clock::CpuClock;
|
use esp_hal::clock::CpuClock;
|
||||||
use esp_hal::timer::timg::TimerGroup;
|
use esp_hal::timer::timg::TimerGroup;
|
||||||
use log::info;
|
use log::info;
|
||||||
|
use esp_wifi::wifi::{ClientConfiguration, Configuration, WifiController};
|
||||||
|
|
||||||
extern crate alloc;
|
extern crate alloc;
|
||||||
|
|
||||||
@@ -19,6 +20,10 @@ extern crate alloc;
|
|||||||
// For more information see: <https://docs.espressif.com/projects/esp-idf/en/stable/esp32/api-reference/system/app_image_format.html#application-description>
|
// 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_bootloader_esp_idf::esp_app_desc!();
|
||||||
|
|
||||||
|
// Pull SSID/PASSWORD from .cargo/config.toml at compile time
|
||||||
|
const SSID: &str = env!("SSID");
|
||||||
|
const PASSWORD: &str = env!("PASSWORD");
|
||||||
|
|
||||||
#[esp_hal_embassy::main]
|
#[esp_hal_embassy::main]
|
||||||
async fn main(spawner: Spawner) {
|
async fn main(spawner: Spawner) {
|
||||||
// generator version: 0.5.0
|
// generator version: 0.5.0
|
||||||
@@ -39,15 +44,28 @@ async fn main(spawner: Spawner) {
|
|||||||
let timer1 = TimerGroup::new(peripherals.TIMG0);
|
let timer1 = TimerGroup::new(peripherals.TIMG0);
|
||||||
let wifi_init =
|
let wifi_init =
|
||||||
esp_wifi::init(timer1.timer0, rng).expect("Failed to initialize WIFI/BLE controller");
|
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)
|
let (mut controller, _interfaces) = esp_wifi::wifi::new(&wifi_init, peripherals.WIFI)
|
||||||
.expect("Failed to initialize WIFI controller");
|
.expect("Failed to initialize WIFI controller");
|
||||||
|
|
||||||
// TODO: Spawn some tasks
|
let client_conf = Configuration::Client(ClientConfiguration {
|
||||||
let _ = spawner;
|
ssid: SSID.try_into().unwrap(),
|
||||||
|
password: PASSWORD.try_into().unwrap(),
|
||||||
|
..Default::default()
|
||||||
|
});
|
||||||
|
controller.set_configuration(&client_conf).unwrap();
|
||||||
|
|
||||||
|
info!("Starting WiFi...");
|
||||||
|
controller.start_async().await.unwrap();
|
||||||
|
info!("WiFi started, connecting...");
|
||||||
|
|
||||||
|
match controller.connect_async().await {
|
||||||
|
Ok(_) => info!("Connected to WiFi!"),
|
||||||
|
Err(e) => info!("Failed to connect: {:?}", e),
|
||||||
|
}
|
||||||
|
|
||||||
|
// keep task alive
|
||||||
loop {
|
loop {
|
||||||
info!("Hello world!");
|
Timer::after(Duration::from_secs(5)).await;
|
||||||
Timer::after(Duration::from_secs(1)).await;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// for inspiration have a look at the examples at https://github.com/esp-rs/esp-hal/tree/esp-hal-v1.0.0-rc.0/examples/src/bin
|
// for inspiration have a look at the examples at https://github.com/esp-rs/esp-hal/tree/esp-hal-v1.0.0-rc.0/examples/src/bin
|
||||||
|
|||||||
Reference in New Issue
Block a user